This commit is contained in:
2026-09-25 15:39:16 +02:00
committed by Marvin Friedrich
parent b9ee87aed4
commit 6e92817f3f
35 changed files with 271 additions and 157 deletions
+1 -1
View File
@@ -3,4 +3,4 @@
#include <zinnia/errno.h>
#include <stdint.h>
errno_t arch_archctl(uintptr_t op, uintptr_t value);
struct syscall_ret arch_archctl(uintptr_t op, uintptr_t value);
+16
View File
@@ -3,10 +3,26 @@
#include <stddef.h>
#include <stdint.h>
[[gnu::pure]]
bool arch_mem_addr_is_user(uintptr_t addr);
[[gnu::pure]]
size_t arch_mem_page_size();
[[gnu::pure]]
size_t arch_mem_page_bits();
[[gnu::pure]]
size_t arch_mem_level_bits();
[[gnu::pure]]
size_t arch_mem_num_levels();
[[gnu::pure]]
uintptr_t arch_mem_hhdm_addr();
[[gnu::pure]]
uintptr_t arch_mem_pfndb_addr();
[[gnu::pure]]
uintptr_t arch_mem_mapping_addr();
+1 -1
View File
@@ -2,7 +2,7 @@
#ifndef __ZINNIA_UAPI_UTSNAME_H
#define __ZINNIA_UAPI_UTSNAME_H
struct utsname {
struct __utsname {
char sysname[65];
char nodename[65];
char release[65];
+5 -14
View File
@@ -9,22 +9,13 @@ typedef enum memory_order {
ATOMIC_SEQ_CST = __ATOMIC_SEQ_CST
} memory_order;
#define atomic(T) _Atomic(T)
#define atomic_store(ptr, des, order) __atomic_store_n(ptr, des, order)
#define atomic_load(ptr, order) __atomic_load_n(ptr, order)
#define atomic(T) _Atomic(T)
#define atomic_store(ptr, des, order) __atomic_store_n(ptr, des, order)
#define atomic_load(ptr, order) __atomic_load_n(ptr, order)
#define atomic_exchange(ptr, des, order) __atomic_exchange_n(ptr, des, order)
#define atomic_fetch_add(ptr, op, order) __atomic_fetch_add(ptr, op, order)
#define atomic_fetch_sub(ptr, op, order) __atomic_fetch_sub(ptr, op, order)
#define atomic_fetch_or(ptr, op, order) __atomic_fetch_or(ptr, op, order)
#define atomic_fetch_or(ptr, op, order) __atomic_fetch_or(ptr, op, order)
#define atomic_fetch_xor(ptr, op, order) __atomic_fetch_xor(ptr, op, order)
#define atomic_fetch_and(ptr, op, order) __atomic_fetch_and(ptr, op, order)
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_thread_fence(order) __atomic_thread_fence(order)
+5 -4
View File
@@ -12,13 +12,11 @@
#define __used gnu::used
#define __unused gnu::unused
#define __format(like, ...) gnu::format(like, __VA_ARGS__)
#define __likely(x) __builtin_expect(!!(x), 1)
#define __unlikely(x) __builtin_expect(!!(x), 0)
#define __always_inline gnu::always_inline
#define __visibility gnu::visibility
// Only clang has these hints, GCC will throw a warning here.
// They also don't support the C23 attribute format.
// Only clang has these hints, GCC would throw a warning here.
// clang::noderef also don't support the C23 attribute format.
#ifdef __clang__
#define __user __attribute__((noderef, address_space(1)))
#define __phys __attribute__((noderef, address_space(2)))
@@ -26,3 +24,6 @@
#define __user
#define __phys
#endif
#define __likely(x) __builtin_expect(!!(x), 1)
#define __unlikely(x) __builtin_expect(!!(x), 0)
+8 -2
View File
@@ -3,6 +3,7 @@
#include <zinnia/compiler.h>
#include <zinnia/types.h>
#include <zinnia/utils.h>
#include <config.h>
#include <stddef.h>
#include <stdint.h>
@@ -25,16 +26,21 @@ struct boot_info {
uintptr_t hhdm_base;
struct boot_file* files;
size_t num_files;
#if CONFIG_OF
void* dtb;
#endif
#if CONFIG_ACPI
phys_t rsdp;
#endif
};
extern struct boot_info boot_info;
[[__visibility("hidden")]]
extern uint8_t __ld_stack_top[];
[[__visibility("hidden")]]
extern uint8_t __ld_stack_bottom[];
extern phys_t rsdp_addr;
// Entry point for the kernel after arch-specific setup has finished.
void kernel_entry();
+24 -28
View File
@@ -4,41 +4,37 @@
#include <zinnia/irq.h>
#include <zinnia/sched.h>
#include <zinnia/usercopy.h>
#include <bits/percpu.h>
#include <stddef.h>
ASSERT_TYPE(struct arch_percpu); // bits/percpu.h
// # On using per-CPU data
//
// Defining variables with `[[__percpu]]` will put them in a special section.
// This section is unique for every CPU. To access the correct memory of the
// caller's CPU, use `percpu_ref`.
//
// ## Example
//
// ```
// [[__percpu]]
// int my_cpu_data = 0;
//
// int get_foo() {
// return *percpu_ref(my_cpu_data);
// }
// ```
/*
On using per-CPU data
---------------------
Defining variables with `[[__percpu]]` will put them in a special section.
This section is unique for every CPU. To access the correct memory of the
caller's CPU, use `percpu_ref`.
# Example
[[__percpu]]
int my_cpu_data = 0;
int get_foo() {
return *percpu_ref(my_cpu_data);
}
*/
#define __percpu __used, __section(".percpu")
#define __percpu __used, __section(".percpu.data")
#define percpu_ref(x) ((typeof(&(x)))((void*)percpu_get() + ((void*)&(x) - (void*)&percpu_bsp)))
// CPU-relative information.
struct percpu {
struct percpu* self; // A pointer to this structure.
size_t id; // The virtual ID of this CPU.
bool online; // Whether this CPU is initialized and active.
uintptr_t kernel_stack; // The kernel mode stack.
uintptr_t user_stack; // The user mode stack.
struct arch_percpu arch; // Architecture-specific fields.
struct irq_percpu irq; // IRQ information.
struct scheduler sched; // Scheduler information.
struct percpu* self; // A pointer to this structure.
size_t id; // The virtual ID of this CPU.
bool online; // Whether this CPU is initialized and active.
uintptr_t kernel_stack; // The kernel mode stack.
uintptr_t user_stack; // The user mode stack.
struct irq_percpu irq; // IRQ information.
struct scheduler sched; // Scheduler information.
};
struct percpu* percpu_new();
+2 -2
View File
@@ -4,9 +4,9 @@
// SYSCALL_DECLARE(0, exit, -1)
// SYSCALL_DECLARE(1, syslog, -1)
SYSCALL_DECLARE(2, getuname, -1)
SYSCALL_DECLARE(2, getuname, 1)
// SYSCALL_DECLARE(3, setuname, -1)
SYSCALL_DECLARE(4, archctl, -1)
SYSCALL_DECLARE(4, archctl, 2)
// SYSCALL_DECLARE(5, reboot, -1)
// SYSCALL_DECLARE(6, mmap, -1)
// SYSCALL_DECLARE(7, munmap, -1)
+14 -14
View File
@@ -8,8 +8,8 @@
#define tailq_link(type) \
struct { \
type* tqe_next; \
type** tqe_prev; \
type* tql_next; \
type** tql_prev; \
}
#define tailq_init(head) \
@@ -20,33 +20,33 @@
#define tailq_first(head) ((head)->tqh_first)
#define tailq_next(elm, field) ((elm)->field.tqe_next)
#define tailq_next(elm, field) ((elm)->field.tql_next)
#define tailq_empty(head) (tailq_first(head) == nullptr)
#define tailq_insert_tail(head, elm, field) \
do { \
(elm)->field.tqe_next = nullptr; \
(elm)->field.tqe_prev = (head)->tqh_last; \
(elm)->field.tql_next = nullptr; \
(elm)->field.tql_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_last = &(elm)->field.tql_next; \
} while (0)
#define tailq_insert_head(head, elm, field) \
do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != nullptr) \
(head)->tqh_first->field.tqe_prev = &(elm)->field.tqe_next; \
if (((elm)->field.tql_next = (head)->tqh_first) != nullptr) \
(head)->tqh_first->field.tql_prev = &(elm)->field.tql_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_last = &(elm)->field.tql_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
(elm)->field.tql_prev = &(head)->tqh_first; \
} while (0)
#define tailq_remove(head, elm, field) \
do { \
if (((elm)->field.tqe_next) != nullptr) \
(elm)->field.tqe_next->field.tqe_prev = (elm)->field.tqe_prev; \
if (((elm)->field.tql_next) != nullptr) \
(elm)->field.tql_next->field.tql_prev = (elm)->field.tql_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
(head)->tqh_last = (elm)->field.tql_prev; \
*(elm)->field.tql_prev = (elm)->field.tql_next; \
} while (0)