modules
This commit is contained in:
@@ -2,6 +2,5 @@
|
||||
|
||||
#include <zinnia/errno.h>
|
||||
#include <stdint.h>
|
||||
#include <uapi/archctl.h>
|
||||
|
||||
errno_t arch_archctl(uintptr_t op, uintptr_t value);
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include <zinnia/elf.h>
|
||||
// TODO: Ensure bits are defining values right.
|
||||
|
||||
@@ -57,10 +57,10 @@ struct cmdline_option {
|
||||
};
|
||||
union {
|
||||
const char** str_limit;
|
||||
struct cmdline_option_limit_int {
|
||||
struct cmdline_limit_int {
|
||||
intptr_t min, max;
|
||||
}* intptr_limit;
|
||||
struct cmdline_option_limit_uint {
|
||||
struct cmdline_limit_uint {
|
||||
uintptr_t min, max;
|
||||
}* uintptr_limit;
|
||||
void* limit;
|
||||
@@ -69,14 +69,3 @@ struct cmdline_option {
|
||||
|
||||
// Parses the command line and invokes all options.
|
||||
void cmdline_parse(const char* cmdline);
|
||||
|
||||
static_assert(
|
||||
0 ==
|
||||
_Generic(
|
||||
(cmdline_parse),
|
||||
void (*)(const char*): CMDLINE_STRING,
|
||||
void (*)(bool): CMDLINE_BOOL,
|
||||
void (*)(intptr_t): CMDLINE_INTPTR,
|
||||
void (*)(uintptr_t): CMDLINE_UINTPTR
|
||||
)
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#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.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <zinnia/module.h>
|
||||
|
||||
struct device {
|
||||
const char* name;
|
||||
struct module* owner;
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <zinnia/compiler.h>
|
||||
#include <zinnia/types.h>
|
||||
#include <zinnia/utils.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define __init __used, __section(".init.text"), __cold
|
||||
#define __initdata __used, __section(".init.data")
|
||||
@@ -28,7 +28,9 @@ struct boot_info {
|
||||
phys_t rsdp;
|
||||
};
|
||||
|
||||
[[__visibility("hidden")]]
|
||||
extern uint8_t __ld_stack_top[];
|
||||
[[__visibility("hidden")]]
|
||||
extern uint8_t __ld_stack_bottom[];
|
||||
|
||||
extern phys_t rsdp_addr;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <zinnia/compiler.h>
|
||||
#include <zinnia/utils.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MODULE_PROPERTY(name, data) \
|
||||
[[__used, __section(".mod." name)]] \
|
||||
static const char UNIQUE_IDENT(_name)[] = data;
|
||||
|
||||
#define MODULE(desc, author, license, version, entry) \
|
||||
void __module_start(struct module* _module) { \
|
||||
entry(_module); \
|
||||
} \
|
||||
MODULE_PROPERTY("author", author); \
|
||||
MODULE_PROPERTY("desc", desc); \
|
||||
MODULE_PROPERTY("version", version); \
|
||||
MODULE_PROPERTY("license", license);
|
||||
|
||||
struct module {
|
||||
const char* name;
|
||||
struct module* owner;
|
||||
};
|
||||
|
||||
#define THIS_MODULE (struct module*)nullptr
|
||||
+19
-1
@@ -9,7 +9,25 @@
|
||||
|
||||
ASSERT_TYPE(struct arch_percpu); // bits/percpu.h
|
||||
|
||||
#define __percpu __used, __section(".percpu")
|
||||
/*
|
||||
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_ref(x) ((typeof(&(x)))((void*)percpu_get() + ((void*)&(x) - (void*)&percpu_bsp)))
|
||||
|
||||
// CPU-relative information.
|
||||
struct percpu {
|
||||
|
||||
@@ -19,7 +19,7 @@ errno_t vma_new(struct vma** out);
|
||||
void vma_free(struct vma* v);
|
||||
|
||||
errno_t vma_map(
|
||||
struct vma* vm,
|
||||
struct vma* vma,
|
||||
struct vmo* vmo,
|
||||
uintptr_t addr,
|
||||
size_t len,
|
||||
|
||||
Reference in New Issue
Block a user