diff --git a/modules.yaml b/modules.yaml index 009afcc..fe23e1f 100644 --- a/modules.yaml +++ b/modules.yaml @@ -139,6 +139,7 @@ modules: #- LACKS_TIME_H source: - src/libraries/libc/arch/x86_64/_Exit.s + - src/libraries/libc/arch/x86_64/syscalls.s - src/libraries/libc/ctype/isalnum.c - src/libraries/libc/ctype/isalpha.c - src/libraries/libc/ctype/isblank.c diff --git a/scripts/templates/build.ninja.j2 b/scripts/templates/build.ninja.j2 index a28af56..2b48eb8 100644 --- a/scripts/templates/build.ninja.j2 +++ b/scripts/templates/build.ninja.j2 @@ -47,7 +47,8 @@ asflags = $ -DVERSION_MAJOR={{ version_major }} $ -DVERSION_MINOR={{ version_minor }} $ -DVERSION_PATCH={{ version_patch }} $ - -DVERSION_GITSHA=0x{{ version_sha }} + -DVERSION_GITSHA=0x{{ version_sha }} $ + -I${srcroot}/src/include cflags = -std=c11 cxxflags = -std=c++14 diff --git a/src/drivers/nulldrv/main.cpp b/src/drivers/nulldrv/main.cpp index 4e7592a..73afacb 100644 --- a/src/drivers/nulldrv/main.cpp +++ b/src/drivers/nulldrv/main.cpp @@ -5,53 +5,38 @@ #include "j6/errors.h" #include "j6/signals.h" +#include + const char message[] = "Hello! This is a message being sent over a channel!"; char inbuf[1024]; j6_handle_t chan = j6_handle_invalid; extern "C" { - j6_status_t system_log(const char *msg); - - j6_status_t object_wait(j6_handle_t obj, j6_signal_t sig, j6_signal_t *out); - j6_status_t object_signal(j6_handle_t obj, j6_signal_t sig); - - j6_status_t process_koid(j6_koid_t *koid); - - j6_status_t thread_koid(j6_koid_t *koid); - j6_status_t thread_create(void (*koid)(), j6_handle_t *handle); - j6_status_t thread_sleep(uint64_t til); - j6_status_t thread_exit(int64_t status); - - j6_status_t channel_create(j6_handle_t *handle); - j6_status_t channel_close(j6_handle_t handle); - j6_status_t channel_send(j6_handle_t handle, size_t len, void *data); - j6_status_t channel_receive(j6_handle_t handle, size_t *len, void *data); - int main(int, const char **); } void thread_proc() { - system_log("sub thread starting"); + _syscall_system_log("sub thread starting"); - j6_status_t result = object_signal(chan, j6_signal_user0); + j6_status_t result = _syscall_object_signal(chan, j6_signal_user0); if (result != j6_status_ok) - thread_exit(result); + _syscall_thread_exit(result); - system_log("sub thread signaled user0"); + _syscall_system_log("sub thread signaled user0"); - result = channel_send(chan, sizeof(message), (void*)message); + result = _syscall_channel_send(chan, sizeof(message), (void*)message); if (result != j6_status_ok) - thread_exit(result); + _syscall_thread_exit(result); - system_log("sub thread sent on channel"); + _syscall_system_log("sub thread sent on channel"); for (int i = 1; i < 5; ++i) - thread_sleep(i*10); + _syscall_thread_sleep(i*10); - system_log("sub thread exiting"); - thread_exit(0); + _syscall_system_log("sub thread exiting"); + _syscall_thread_exit(0); } int @@ -60,32 +45,32 @@ main(int argc, const char **argv) j6_handle_t child = j6_handle_invalid; j6_signal_t out = 0; - system_log("main thread starting"); + _syscall_system_log("main thread starting"); - j6_status_t result = channel_create(&chan); + j6_status_t result = _syscall_channel_create(&chan); if (result != j6_status_ok) return result; - system_log("main thread created channel"); + _syscall_system_log("main thread created channel"); - result = thread_create(&thread_proc, &child); + result = _syscall_thread_create(reinterpret_cast(&thread_proc), &child); if (result != j6_status_ok) return result; - system_log("main thread waiting on user0"); + _syscall_system_log("main thread waiting on user0"); - result = object_wait(chan, j6_signal_user0, &out); + result = _syscall_object_wait(chan, j6_signal_user0, &out); if (result != j6_status_ok) return result; - system_log("main thread waiting on can_recv"); + _syscall_system_log("main thread waiting on can_recv"); - result = object_wait(chan, j6_signal_channel_can_recv, &out); + result = _syscall_object_wait(chan, j6_signal_channel_can_recv, &out); if (result != j6_status_ok) return result; size_t len = sizeof(inbuf); - result = channel_receive(chan, &len, (void*)inbuf); + result = _syscall_channel_receive(chan, &len, (void*)inbuf); if (result != j6_status_ok) return result; @@ -94,21 +79,21 @@ main(int argc, const char **argv) return 127; } - system_log("main thread received on channel"); + _syscall_system_log("main thread received on channel"); - system_log("main thread waiting on child"); + _syscall_system_log("main thread waiting on child"); - result = object_wait(child, -1ull, &out); + result = _syscall_object_wait(child, -1ull, &out); if (result != j6_status_ok) return result; - result = channel_close(chan); + result = _syscall_channel_close(chan); if (result != j6_status_ok) return result; - system_log("main thread closed channel"); + _syscall_system_log("main thread closed channel"); - system_log("main thread done, exiting"); + _syscall_system_log("main thread done, exiting"); return 0; } diff --git a/src/drivers/nulldrv/main.s b/src/drivers/nulldrv/main.s index 015a161..5fce330 100644 --- a/src/drivers/nulldrv/main.s +++ b/src/drivers/nulldrv/main.s @@ -7,35 +7,6 @@ extern exit section .text -%macro SYSCALL 2 - global %1 - %1: - push rbp - mov rbp, rsp - - ; address of args should already be in rdi, etc - mov rax, %2 - syscall - ; result is now already in rax, so just return - - pop rbp - ret -%endmacro - -SYSCALL system_log, 0x00 -SYSCALL object_wait, 0x09 -SYSCALL object_signal, 0x0a -SYSCALL process_koid, 0x10 -SYSCALL thread_koid, 0x18 -SYSCALL thread_create, 0x19 -SYSCALL thread_exit, 0x1a -SYSCALL thread_pause, 0x1b -SYSCALL thread_sleep, 0x1c -SYSCALL channel_create, 0x20 -SYSCALL channel_close, 0x21 -SYSCALL channel_send, 0x22 -SYSCALL channel_receive, 0x23 - global _start _start: xor rbp, rbp ; Sentinel rbp diff --git a/src/kernel/syscalls.inc b/src/include/syscalls.inc similarity index 100% rename from src/kernel/syscalls.inc rename to src/include/syscalls.inc diff --git a/src/libraries/libc/arch/x86_64/syscalls.s b/src/libraries/libc/arch/x86_64/syscalls.s new file mode 100644 index 0000000..cf90182 --- /dev/null +++ b/src/libraries/libc/arch/x86_64/syscalls.s @@ -0,0 +1,21 @@ +%macro SYSCALL 2 + global _syscall_%1 + _syscall_%1: + push rbp + mov rbp, rsp + + ; address of args should already be in rdi, etc + mov rax, %2 + syscall + ; result is now already in rax, so just return + + pop rbp + ret +%endmacro + +%define SYSCALL(n, name) SYSCALL name, n +%define SYSCALL(n, name, a) SYSCALL name, n +%define SYSCALL(n, name, a, b) SYSCALL name, n +%define SYSCALL(n, name, a, b, c) SYSCALL name, n + +%include "syscalls.inc" diff --git a/src/libraries/libc/include/j6libc/syscalls.h b/src/libraries/libc/include/j6libc/syscalls.h new file mode 100644 index 0000000..15f3072 --- /dev/null +++ b/src/libraries/libc/include/j6libc/syscalls.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#define SYSCALL(n, name, ...) j6_status_t _syscall_ ## name (__VA_ARGS__); +#include "syscalls.inc" +#undef SYSCALL + +#ifdef __cplusplus +} +#endif