2023-05-29 00:32:54 -07:00
|
|
|
#include "include/zcall.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-06-07 00:04:53 -07:00
|
|
|
#include "usr/zcall_internal.h"
|
|
|
|
|
2023-06-06 16:24:03 -07:00
|
|
|
uint64_t SysCall0(uint64_t number) {
|
|
|
|
uint64_t return_code;
|
|
|
|
asm("syscall" : "=a"(return_code) : "D"(number));
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2023-05-29 00:32:54 -07:00
|
|
|
uint64_t SysCall1(uint64_t number, const void* first) {
|
|
|
|
uint64_t return_code;
|
|
|
|
asm("syscall" : "=a"(return_code) : "D"(number), "S"(first) : "rcx", "r11");
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:24:03 -07:00
|
|
|
uint64_t SysCall2(uint64_t number, const void* first, const void* second) {
|
|
|
|
uint64_t return_code;
|
|
|
|
asm("syscall"
|
|
|
|
: "=a"(return_code)
|
|
|
|
: "D"(number), "S"(first), "d"(second)
|
|
|
|
: "rcx", "r11");
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2023-06-07 00:04:53 -07:00
|
|
|
void ZProcessExit(uint64_t code) {
|
|
|
|
SysCall1(Z_PROCESS_EXIT, reinterpret_cast<void*>(code));
|
2023-05-29 00:32:54 -07:00
|
|
|
}
|
2023-05-30 20:55:03 -07:00
|
|
|
|
2023-06-07 00:04:53 -07:00
|
|
|
uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
|
|
|
|
uint64_t* new_as_cap) {
|
|
|
|
ZProcessSpawnReq req{
|
|
|
|
.proc_cap = proc_cap,
|
2023-05-30 20:55:03 -07:00
|
|
|
};
|
2023-06-07 00:04:53 -07:00
|
|
|
ZProcessSpawnResp resp;
|
|
|
|
uint64_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
|
|
|
|
*new_proc_cap = resp.proc_cap;
|
|
|
|
*new_as_cap = resp.as_cap;
|
|
|
|
return ret;
|
2023-05-30 20:55:03 -07:00
|
|
|
}
|
2023-06-06 16:24:03 -07:00
|
|
|
|
|
|
|
uint64_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap) {
|
|
|
|
ZThreadCreateReq req{
|
|
|
|
.proc_cap = proc_cap,
|
|
|
|
};
|
|
|
|
ZThreadCreateResp resp;
|
|
|
|
uint64_t ret = SysCall2(Z_THREAD_CREATE, &req, &resp);
|
|
|
|
*thread_cap = resp.thread_cap;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
|
|
|
uint64_t arg2) {
|
|
|
|
ZThreadStartReq req{
|
|
|
|
.thread_cap = thread_cap,
|
|
|
|
.entry = entry,
|
|
|
|
.arg1 = arg1,
|
|
|
|
.arg2 = arg2,
|
|
|
|
};
|
|
|
|
return SysCall1(Z_THREAD_START, &req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZThreadExit() { SysCall0(Z_THREAD_EXIT); }
|
2023-06-07 00:04:53 -07:00
|
|
|
|
|
|
|
uint64_t ZAddressSpaceMap(uint64_t as_cap, uint64_t offset, uint64_t mem_cap,
|
|
|
|
uint64_t* vaddr) {
|
|
|
|
ZAddressSpaceMapReq req{
|
|
|
|
.as_cap = as_cap,
|
|
|
|
.offset = offset,
|
|
|
|
.mem_cap = mem_cap,
|
|
|
|
};
|
|
|
|
ZAddressSpaceMapResp resp;
|
|
|
|
uint64_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
|
|
|
|
*vaddr = resp.vaddr;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* mem_cap) {
|
|
|
|
ZMemoryObjectCreateReq req{
|
|
|
|
.size = size,
|
|
|
|
};
|
|
|
|
ZMemoryObjectCreateResp resp;
|
|
|
|
uint64_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
|
|
|
|
*mem_cap = resp.mem_cap;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ZDebug(const char* message) {
|
|
|
|
return SysCall1(Z_DEBUG_PRINT, message);
|
|
|
|
}
|