From 76107b7db797db15e3d525574a8164dbdc61c27d Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Tue, 20 Jun 2023 13:50:18 -0700 Subject: [PATCH] [zion] Handle syscall cases by macro as well. --- zion/include/zcall.h | 12 ++++++------ zion/include/ztypes.h | 4 ++-- zion/syscall/syscall.cpp | 24 +++++++++++++++--------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/zion/include/zcall.h b/zion/include/zcall.h index d4d4852..13b8980 100644 --- a/zion/include/zcall.h +++ b/zion/include/zcall.h @@ -4,7 +4,7 @@ #include "ztypes.h" -#define SYS1(name, num, t1, a1) \ +#define SYS1(name, t1, a1) \ struct Z##name##Req { \ t1 a1; \ }; \ @@ -12,10 +12,10 @@ Z##name##Req req{ \ .a1 = a1, \ }; \ - return SysCall1(num, &req); \ + return SysCall1(kZion##name, &req); \ } -#define SYS2(name, num, t1, a1, t2, a2) \ +#define SYS2(name, t1, a1, t2, a2) \ struct Z##name##Req { \ t1 a1; \ t2 a2; \ @@ -25,12 +25,12 @@ .a1 = a1, \ .a2 = a2, \ }; \ - return SysCall1(num, &req); \ + return SysCall1(kZion##name, &req); \ } z_err_t SysCall1(uint64_t code, const void* req); -SYS1(ProcessExit, Z_PROCESS_EXIT, uint64_t, code); +SYS1(ProcessExit, uint64_t, code); [[nodiscard]] z_err_t ZProcessSpawn(z_cap_t proc_cap, z_cap_t bootstrap_cap, z_cap_t* new_proc_cap, @@ -42,7 +42,7 @@ SYS1(ProcessExit, Z_PROCESS_EXIT, uint64_t, code); uint64_t entry, uint64_t arg1, uint64_t arg2); -SYS2(ThreadCreate, Z_THREAD_CREATE, z_cap_t, proc_cap, z_cap_t*, thread_cap); +SYS2(ThreadCreate, z_cap_t, proc_cap, z_cap_t*, thread_cap); [[nodiscard]] z_err_t ZThreadStart(z_cap_t thread_cap, uint64_t entry, uint64_t arg1, uint64_t arg2); diff --git a/zion/include/ztypes.h b/zion/include/ztypes.h index dd2b382..5ddf800 100644 --- a/zion/include/ztypes.h +++ b/zion/include/ztypes.h @@ -30,12 +30,12 @@ typedef uint64_t z_err_t; * ------------------------------*/ // Process Calls. -#define Z_PROCESS_EXIT 0x01 +const uint64_t kZionProcessExit = 0x1; #define Z_PROCESS_SPAWN 0x02 #define Z_PROCESS_START 0x03 // Thread Calls. -#define Z_THREAD_CREATE 0x10 +const uint64_t kZionThreadCreate = 0x10; #define Z_THREAD_START 0x11 #define Z_THREAD_EXIT 0x12 diff --git a/zion/syscall/syscall.cpp b/zion/syscall/syscall.cpp index cb22352..6effc3d 100644 --- a/zion/syscall/syscall.cpp +++ b/zion/syscall/syscall.cpp @@ -65,6 +65,15 @@ z_err_t ValidateCap(const RefPtr& cap, uint64_t permissions) { return Z_OK; } +z_err_t ProcessExit(ZProcessExitReq* req) { + auto curr_thread = gScheduler->CurrentThread(); + dbgln("Exit code: %x", req->code); + // FIXME: kill process here. + curr_thread->Exit(); + panic("Returned from thread exit"); + return Z_ERR_UNIMPLEMENTED; +} + z_err_t ProcessSpawn(ZProcessSpawnReq* req, ZProcessSpawnResp* resp) { auto& curr_proc = gScheduler->CurrentProcess(); auto cap = curr_proc.GetCapability(req->proc_cap); @@ -261,21 +270,18 @@ z_err_t CapDuplicate(ZCapDuplicateReq* req, ZCapDuplicateResp* resp) { return Z_OK; } +#define CASE(name) \ + case kZion##name: \ + return name(reinterpret_cast(req)); + extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) { RefPtr thread = gScheduler->CurrentThread(); switch (call_id) { - case Z_PROCESS_EXIT: - // FIXME: kill process here. - dbgln("Exiting: %m", req); - dbgln("Exit code: %x", reinterpret_cast(req)->code); - thread->Exit(); - panic("Returned from thread exit"); - break; + CASE(ProcessExit); + CASE(ThreadCreate); case Z_PROCESS_SPAWN: return ProcessSpawn(reinterpret_cast(req), reinterpret_cast(resp)); - case Z_THREAD_CREATE: - return ThreadCreate(reinterpret_cast(req)); case Z_THREAD_START: return ThreadStart(reinterpret_cast(req)); case Z_THREAD_EXIT: