[zion] Handle syscall cases by macro as well.
This commit is contained in:
parent
5fc7296b20
commit
76107b7db7
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -65,6 +65,15 @@ z_err_t ValidateCap(const RefPtr<Capability>& 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<Z##name##Req*>(req));
|
||||
|
||||
extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req, void* resp) {
|
||||
RefPtr<Thread> thread = gScheduler->CurrentThread();
|
||||
switch (call_id) {
|
||||
case Z_PROCESS_EXIT:
|
||||
// FIXME: kill process here.
|
||||
dbgln("Exiting: %m", req);
|
||||
dbgln("Exit code: %x", reinterpret_cast<ZProcessExitReq*>(req)->code);
|
||||
thread->Exit();
|
||||
panic("Returned from thread exit");
|
||||
break;
|
||||
CASE(ProcessExit);
|
||||
CASE(ThreadCreate);
|
||||
case Z_PROCESS_SPAWN:
|
||||
return ProcessSpawn(reinterpret_cast<ZProcessSpawnReq*>(req),
|
||||
reinterpret_cast<ZProcessSpawnResp*>(resp));
|
||||
case Z_THREAD_CREATE:
|
||||
return ThreadCreate(reinterpret_cast<ZThreadCreateReq*>(req));
|
||||
case Z_THREAD_START:
|
||||
return ThreadStart(reinterpret_cast<ZThreadStartReq*>(req));
|
||||
case Z_THREAD_EXIT:
|
||||
|
|
Loading…
Reference in New Issue