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-07 08:50:08 -07:00
|
|
|
z_err_t SysCall2(uint64_t number, const void* first, const void* second) {
|
|
|
|
z_err_t return_code;
|
2023-06-06 16:24:03 -07:00
|
|
|
asm("syscall"
|
|
|
|
: "=a"(return_code)
|
|
|
|
: "D"(number), "S"(first), "d"(second)
|
|
|
|
: "rcx", "r11");
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t SysCall0(uint64_t number) { return SysCall2(number, 0, 0); }
|
2023-06-07 08:24:10 -07:00
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t SysCall1(uint64_t number, const void* first) {
|
2023-06-07 08:24:10 -07:00
|
|
|
return SysCall2(number, first, 0);
|
|
|
|
}
|
|
|
|
|
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 08:50:08 -07:00
|
|
|
z_err_t ZProcessSpawn(uint64_t proc_cap, uint64_t bootstrap_cap,
|
|
|
|
uint64_t* new_proc_cap, uint64_t* new_vmas_cap,
|
|
|
|
uint64_t* new_bootstrap_cap) {
|
2023-06-07 00:04:53 -07:00
|
|
|
ZProcessSpawnReq req{
|
|
|
|
.proc_cap = proc_cap,
|
2023-06-07 08:24:10 -07:00
|
|
|
.bootstrap_cap = bootstrap_cap,
|
2023-05-30 20:55:03 -07:00
|
|
|
};
|
2023-06-07 00:04:53 -07:00
|
|
|
ZProcessSpawnResp resp;
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
|
2023-06-07 00:04:53 -07:00
|
|
|
*new_proc_cap = resp.proc_cap;
|
2023-06-07 00:30:26 -07:00
|
|
|
*new_vmas_cap = resp.vmas_cap;
|
2023-06-07 08:24:10 -07:00
|
|
|
*new_bootstrap_cap = resp.bootstrap_cap;
|
2023-06-07 00:04:53 -07:00
|
|
|
return ret;
|
2023-05-30 20:55:03 -07:00
|
|
|
}
|
2023-06-06 16:24:03 -07:00
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZThreadCreate(uint64_t proc_cap, uint64_t* thread_cap) {
|
2023-06-06 16:24:03 -07:00
|
|
|
ZThreadCreateReq req{
|
|
|
|
.proc_cap = proc_cap,
|
|
|
|
};
|
|
|
|
ZThreadCreateResp resp;
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall2(Z_THREAD_CREATE, &req, &resp);
|
2023-06-06 16:24:03 -07:00
|
|
|
*thread_cap = resp.thread_cap;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
|
|
|
uint64_t arg2) {
|
2023-06-06 16:24:03 -07:00
|
|
|
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
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
|
|
|
uint64_t vmmo_cap, uint64_t* vaddr) {
|
2023-06-07 00:04:53 -07:00
|
|
|
ZAddressSpaceMapReq req{
|
2023-06-07 00:30:26 -07:00
|
|
|
.vmas_cap = vmas_cap,
|
|
|
|
.vmas_offset = vmas_offset,
|
|
|
|
.vmmo_cap = vmmo_cap,
|
2023-06-07 00:04:53 -07:00
|
|
|
};
|
|
|
|
ZAddressSpaceMapResp resp;
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
|
2023-06-07 00:04:53 -07:00
|
|
|
*vaddr = resp.vaddr;
|
|
|
|
return ret;
|
|
|
|
}
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap) {
|
2023-06-07 00:04:53 -07:00
|
|
|
ZMemoryObjectCreateReq req{
|
|
|
|
.size = size,
|
|
|
|
};
|
|
|
|
ZMemoryObjectCreateResp resp;
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
|
2023-06-07 00:30:26 -07:00
|
|
|
*vmmo_cap = resp.vmmo_cap;
|
2023-06-07 00:04:53 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZChannelCreate(uint64_t* channel1, uint64_t* channel2) {
|
2023-06-07 08:24:10 -07:00
|
|
|
ZChannelCreateResp resp;
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall2(Z_CHANNEL_CREATE, 0, &resp);
|
2023-06-07 08:24:10 -07:00
|
|
|
*channel1 = resp.chan_cap1;
|
|
|
|
*channel2 = resp.chan_cap2;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZChannelSend(uint64_t chan_cap, uint64_t type, uint64_t num_bytes,
|
|
|
|
const uint8_t* bytes, uint64_t num_caps,
|
|
|
|
const uint64_t* caps) {
|
2023-06-07 08:24:10 -07:00
|
|
|
ZChannelSendReq req{
|
|
|
|
.chan_cap = chan_cap,
|
|
|
|
.message =
|
|
|
|
{
|
|
|
|
.type = type,
|
|
|
|
.num_bytes = num_bytes,
|
|
|
|
.bytes = const_cast<uint8_t*>(bytes),
|
|
|
|
.num_caps = num_caps,
|
|
|
|
.caps = const_cast<uint64_t*>(caps),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return SysCall1(Z_CHANNEL_SEND, &req);
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZChannelRecv(uint64_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
|
|
|
uint64_t num_caps, uint64_t* caps, uint64_t* type,
|
|
|
|
uint64_t* actual_bytes, uint64_t* actual_caps) {
|
2023-06-07 08:24:10 -07:00
|
|
|
ZChannelRecvReq req{
|
|
|
|
.chan_cap = chan_cap,
|
|
|
|
.message =
|
|
|
|
{
|
|
|
|
.type = 0,
|
|
|
|
.num_bytes = num_bytes,
|
|
|
|
.bytes = bytes,
|
|
|
|
.num_caps = num_caps,
|
|
|
|
.caps = caps,
|
|
|
|
},
|
|
|
|
};
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ret = SysCall1(Z_CHANNEL_RECV, &req);
|
2023-06-07 08:24:10 -07:00
|
|
|
*type = req.message.type;
|
|
|
|
*actual_bytes = req.message.num_bytes;
|
|
|
|
*actual_caps = req.message.num_caps;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:50:08 -07:00
|
|
|
z_err_t ZDebug(const char* message) { return SysCall1(Z_DEBUG_PRINT, message); }
|