diff options
author | dzwdz | 2021-07-31 14:54:09 +0200 |
---|---|---|
committer | dzwdz | 2021-07-31 14:54:09 +0200 |
commit | e56a5a519b157f62a2236c6395b45fc2d4ac7b66 (patch) | |
tree | fdd591db1fc3affad898e4857810effafbe9e38d /src | |
parent | 95e33f7f9362aadd9c6169b41437ca478aa3be14 (diff) |
change the syscall naming convention; same one in kernel and userland
Diffstat (limited to 'src')
-rw-r--r-- | src/init/main.c | 28 | ||||
-rw-r--r-- | src/init/syscalls.c | 17 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 18 | ||||
-rw-r--r-- | src/kernel/syscalls.h | 16 |
4 files changed, 44 insertions, 35 deletions
diff --git a/src/init/main.c b/src/init/main.c index c32ac01..5615980 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -1,28 +1,14 @@ #include <kernel/syscalls.h> -#include <stddef.h> -#include <stdint.h> - -int _syscall(int, int, int, int); - -_Noreturn void exit(const char *msg, size_t len) { - _syscall(SC_EXIT, (int)msg, len, 0); - __builtin_unreachable(); -} - -int debuglog(const char *msg, size_t len) { - return _syscall(SC_DEBUGLOG, (int)msg, len, 0); -} - int main() { - debuglog("hello from init! ", - sizeof("hello from init! ") - 1); + _syscall_debuglog("hello from init! ", + sizeof("hello from init! ") - 1); - _syscall(SC_FORK, 0, 0, 0); + _syscall_fork(); - debuglog("i got forked. ", - sizeof("i got forked. ") - 1); + _syscall_debuglog("i got forked. ", + sizeof("i got forked. ") - 1); - exit( "bye from init! ", - sizeof("bye from init! ") - 1); + _syscall_exit("bye from init! ", + sizeof("bye from init! ") - 1); } diff --git a/src/init/syscalls.c b/src/init/syscalls.c new file mode 100644 index 0000000..d0da33e --- /dev/null +++ b/src/init/syscalls.c @@ -0,0 +1,17 @@ +// this file could probably just get generated by a script +#include <kernel/syscalls.h> + +int _syscall(int, int, int, int); + +_Noreturn void _syscall_exit(const char *msg, size_t len) { + _syscall(_SYSCALL_EXIT, (int)msg, len, 0); + __builtin_unreachable(); +} + +int _syscall_fork() { + return _syscall(_SYSCALL_FORK, 0, 0, 0); +} + +int _syscall_debuglog(const char *msg, size_t len) { + return _syscall(_SYSCALL_DEBUGLOG, (int)msg, len, 0); +} diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 3d35a4a..ece21db 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -4,7 +4,7 @@ #include <kernel/syscalls.h> #include <stdint.h> -_Noreturn void sc_exit(const char *msg, size_t len) { +_Noreturn void _syscall_exit(const char *msg, size_t len) { process_current->state = PS_DEAD; process_current = process_find(PS_RUNNING); @@ -15,13 +15,13 @@ _Noreturn void sc_exit(const char *msg, size_t len) { panic(); } -int sc_fork() { +int _syscall_fork() { struct process *orig = process_current; process_current = process_clone(orig); process_switch(process_current); } -int sc_debuglog(const char *msg, size_t len) { +int _syscall_debuglog(const char *msg, size_t len) { struct pagedir *pages = process_current->pages; void *phys = pagedir_virt2phys(pages, msg, true, false); @@ -37,12 +37,12 @@ int sc_debuglog(const char *msg, size_t len) { int syscall_handler(int num, int a, int b, int c) { switch (num) { - case SC_EXIT: - sc_exit((void*)a, b); - case SC_FORK: - return sc_fork(); - case SC_DEBUGLOG: - return sc_debuglog((void*)a, b); + case _SYSCALL_EXIT: + _syscall_exit((void*)a, b); + case _SYSCALL_FORK: + return _syscall_fork(); + case _SYSCALL_DEBUGLOG: + return _syscall_debuglog((void*)a, b); default: log_const("unknown syscall "); panic(); diff --git a/src/kernel/syscalls.h b/src/kernel/syscalls.h index ceb90c1..c010a61 100644 --- a/src/kernel/syscalls.h +++ b/src/kernel/syscalls.h @@ -1,9 +1,15 @@ +// note: this file gets included in both kernel and userland #pragma once +#include <stddef.h> -// not caring about stable syscall numbers just yet enum { - SC_EXIT, - SC_FORK, - - SC_DEBUGLOG + // idc about stable syscall numbers just yet + _SYSCALL_EXIT, + _SYSCALL_FORK, + + _SYSCALL_DEBUGLOG }; + +_Noreturn void _syscall_exit(const char *msg, size_t len); +int _syscall_fork(); +int _syscall_debuglog(const char *msg, size_t len); |