refactor (syscalls): refactored syscalls to match the documented SysABI
This commit is contained in:
parent
3fbc9dc274
commit
4070959736
|
@ -7,50 +7,40 @@
|
|||
#include "utils/status.h"
|
||||
|
||||
typedef enum {
|
||||
SYSCALLS_FILES = 0x01,
|
||||
SYSCALLS_MEMORY = 0x02,
|
||||
SYSCALLS_PROC = 0x03,
|
||||
SYSCALLS_RUNTIME_LINKER = 0x04,
|
||||
SYSCALLS_COMPATABILITY = 0x05,
|
||||
SYSCALLS_FILES = 0x00,
|
||||
SYSCALLS_MEMORY = 0x01,
|
||||
SYSCALLS_PROC = 0x02,
|
||||
SYSCALLS_DRIVERS = 0x03,
|
||||
|
||||
SYSCALLS_KERNEL = 0xFF
|
||||
}syscall_group_E;
|
||||
|
||||
typedef enum {
|
||||
SYSCALL_FILES_OPEN = 0x0101,
|
||||
SYSCALL_FILES_CLOSE = 0x0102,
|
||||
SYSCALL_FILES_READ = 0x0103,
|
||||
SYSCALL_FILES_WRITE = 0x0104,
|
||||
SYSCALL_FILES_DELETE = 0x0105,
|
||||
SYSCALL_FILES_LIST = 0x0106,
|
||||
SYSCALL_FILES_INFO = 0x0107,
|
||||
SYSCALL_NX_FS_OPEN = 0x0001,
|
||||
SYSCALL_NX_FS_CLOSE = 0x0002,
|
||||
SYSCALL_NX_FS_READ = 0x0003,
|
||||
SYSCALL_NX_FS_WRITE = 0x0004,
|
||||
SYSCALL_NX_FS_DELETE = 0x0005,
|
||||
SYSCALL_NX_FS_LIST = 0x0006,
|
||||
SYSCALL_NX_FS_INFO = 0x0007,
|
||||
|
||||
SYSCALL_MEMORY_MAP = 0x0201,
|
||||
SYSCALL_MEMORY_UNMAP = 0x0202,
|
||||
SYSCALL_MEMORY_LABEL = 0x0203,
|
||||
SYSCALL_MEMORY_RANGE = 0x0204,
|
||||
SYSCALL_MEMORY_ACCESS = 0x0205,
|
||||
SYSCALL_NX_MEM_ALLOC = 0x0101,
|
||||
SYSCALL_NX_MEM_FREE = 0x0102,
|
||||
SYSCALL_NX_MEM_LABEL = 0x0103,
|
||||
SYSCALL_NX_MEM_UNLABEL = 0x0104,
|
||||
|
||||
SYSCALL_PROCESS_CREATE = 0x0301,
|
||||
SYSCALL_PROCESS_ENV = 0x0302,
|
||||
SYSCALL_PROCESS_SIGNAL = 0x0303,
|
||||
SYSCALL_PROCESS_THREAD_CREATE = 0x0304,
|
||||
SYSCALL_PROCESS_THREAD_START = 0x0305,
|
||||
SYSCALL_PROCESS_THREAD_PAUSE = 0x0306,
|
||||
SYSCALL_PROCESS_THREAD_KILL = 0x0307,
|
||||
SYSCALL_NX_PROC_CREATE = 0x0201,
|
||||
SYSCALL_NX_PROC_SIGNAL_SEND = 0x0202,
|
||||
SYSCALL_NX_PROC_SIGNAL_SET_HANDLER = 0x0203,
|
||||
SYSCALL_NX_PROC_THREAD_CREATE = 0x0204,
|
||||
SYSCALL_NX_PROC_THREAD_START = 0x0205,
|
||||
SYSCALL_NX_PROC_THREAD_PAUSE = 0x0206,
|
||||
SYSCALL_NX_PROC_THREAD_KILL = 0x0207,
|
||||
|
||||
SYSCALL_RUNTIME_LINKER_OPEN = 0x0401,
|
||||
SYSCALL_RUNTIME_LINKER_CLOSE = 0x0402,
|
||||
SYSCALL_RUNTIME_LINKER_LOAD_SYMBOL = 0x0403,
|
||||
SYSCALL_RUNTIME_LINKER_STATUS = 0x0404,
|
||||
SYSCALL_RUNTIME_LINKER_STANDARD_MOD = 0x0405,
|
||||
SYSCALL_NX_DRV_REGISTER = 0x0301,
|
||||
|
||||
SYSCALL_COMPATABILITY_ABI_TYPE = 0x0501,
|
||||
SYSCALL_COMPATABILITY_ABI_VERSION = 0x0502,
|
||||
SYSCALL_COMPATABILITY_ACTION = 0x0503,
|
||||
|
||||
SYSCALL_KERNEL_SCHEDULER_START = 0xFF00,
|
||||
SYSCALL_KERNEL_PANIC = 0xFF01
|
||||
SYSCALL_NX_KERNEL_SCHEDULER_START = 0xFF00,
|
||||
SYSCALL_NX_KERNEL_PANIC = 0xFF01
|
||||
} syscall_E;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "mm/page_frame.h"
|
||||
#include "mm/region.h"
|
||||
|
||||
void syscall_handle_nx_fopen(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_open(cpu_state_T* state) {
|
||||
string_t path = (string_t)state->rdi; // arg1
|
||||
uint64_t len = state->rsi; // arg2
|
||||
file_descriptor_t* fd_ptr = (file_descriptor_t*)state->rdx; // arg3
|
||||
|
@ -23,7 +23,7 @@ void syscall_handle_nx_fopen(cpu_state_T* state) {
|
|||
*fd_ptr = file_descriptor_request(scheduler_get_current_process()->fd_array, node);
|
||||
}
|
||||
|
||||
void syscall_handle_nx_fclose(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_close(cpu_state_T* state) {
|
||||
file_descriptor_t fd = (file_descriptor_t)state->rdi; // arg1
|
||||
|
||||
file_descriptor_free(scheduler_get_current_process()->fd_array, fd);
|
||||
|
@ -31,7 +31,7 @@ void syscall_handle_nx_fclose(cpu_state_T* state) {
|
|||
state->rax = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_fread(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_read(cpu_state_T* state) {
|
||||
file_descriptor_t fd = (file_descriptor_t)state->rdi; // arg1
|
||||
uint64_t offset = state->rsi; // arg2
|
||||
uint8_t* mem = (uint8_t*)state->rdx; // arg3
|
||||
|
@ -63,7 +63,7 @@ void syscall_handle_nx_fread(cpu_state_T* state) {
|
|||
state->rax = read_bytes;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_write(cpu_state_T* state) {
|
||||
file_descriptor_t fd = (file_descriptor_t)state->rdi; // arg1
|
||||
uint64_t offset = state->rsi; // arg2
|
||||
uint8_t* mem = (uint8_t*)state->rdx; // arg3
|
||||
|
@ -103,9 +103,9 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
|||
state->rax = written_bytes;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_delete(cpu_state_T* state) {
|
||||
string_t path = (string_t)state->rdi; // arg1
|
||||
string_t len = (string_t)state->rsi; // arg2
|
||||
string_t len = (string_t)state->rsi; // arg2
|
||||
|
||||
vfs_node_T* node = vfs_resolve_path(&g_root_fs, path);
|
||||
if (node == NULL) {
|
||||
|
@ -118,7 +118,7 @@ void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
|||
state->rax = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_flist(cpu_state_T* state) {
|
||||
void syscall_handle_nx_fs_list(cpu_state_T* state) {
|
||||
string_t path = (string_t)state->rdi; // arg1
|
||||
uint64_t len = state->rsi; // arg2
|
||||
uint8_t* mem = (uint8_t*)state->rdx; // arg3
|
||||
|
@ -153,7 +153,7 @@ void syscall_handle_nx_flist(cpu_state_T* state) {
|
|||
}
|
||||
|
||||
|
||||
void syscall_handle_nx_mmap(cpu_state_T* state) {
|
||||
void syscall_handle_nx_mem_alloc(cpu_state_T* state) {
|
||||
uint8_t* addr = (uint8_t*)state->rdi; // arg1
|
||||
uint64_t n = state->rsi; // arg2
|
||||
uint64_t flags = (uint64_t)state->rdx; // arg3
|
||||
|
@ -187,7 +187,7 @@ void syscall_handle_nx_mmap(cpu_state_T* state) {
|
|||
state->rax = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_munmap(cpu_state_T* state) {
|
||||
void syscall_handle_nx_mem_free(cpu_state_T* state) {
|
||||
void* addr = (void*)state->rdi; // arg1
|
||||
uint64_t n = state->rsi; // arg2
|
||||
|
||||
|
@ -207,7 +207,8 @@ void syscall_handle_nx_munmap(cpu_state_T* state) {
|
|||
state->rax = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_pcreate(cpu_state_T* state) {
|
||||
|
||||
void syscall_handle_nx_proc_create(cpu_state_T* state) {
|
||||
string_t path = (string_t)state->rdi; // arg1
|
||||
uint64_t len = state->rsi; // arg2
|
||||
pid_t* pid = (pid_t*)state->rdx; // arg3
|
||||
|
@ -245,7 +246,7 @@ void syscall_handle_nx_pcreate(cpu_state_T* state) {
|
|||
state->rax = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void syscall_handle_nx_psignal(cpu_state_T* state) {
|
||||
void syscall_handle_nx_proc_signal_send(cpu_state_T* state) {
|
||||
pid_t pid = (pid_t)state->rdi; // arg1
|
||||
uint64_t signal = state->rsi; // arg2
|
||||
|
||||
|
@ -273,28 +274,28 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
|
|||
case SYSCALLS_FILES: {
|
||||
|
||||
switch (state->rax) {
|
||||
case SYSCALL_FILES_OPEN: {
|
||||
syscall_handle_nx_fopen(state);
|
||||
case SYSCALL_NX_FS_OPEN: {
|
||||
syscall_handle_nx_fs_open(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_FILES_CLOSE: {
|
||||
syscall_handle_nx_fclose(state);
|
||||
case SYSCALL_NX_FS_CLOSE: {
|
||||
syscall_handle_nx_fs_close(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_FILES_READ: {
|
||||
syscall_handle_nx_fread(state);
|
||||
case SYSCALL_NX_FS_READ: {
|
||||
syscall_handle_nx_fs_read(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_FILES_WRITE: {
|
||||
syscall_handle_nx_fwrite(state);
|
||||
case SYSCALL_NX_FS_WRITE: {
|
||||
syscall_handle_nx_fs_write(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_FILES_DELETE: {
|
||||
syscall_handle_nx_fdelete(state);
|
||||
case SYSCALL_NX_FS_DELETE: {
|
||||
syscall_handle_nx_fs_delete(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_FILES_LIST: {
|
||||
syscall_handle_nx_flist(state);
|
||||
case SYSCALL_NX_FS_LIST: {
|
||||
syscall_handle_nx_fs_list(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -303,12 +304,12 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
|
|||
|
||||
case SYSCALLS_MEMORY: {
|
||||
switch (state->rax) {
|
||||
case SYSCALL_MEMORY_MAP: {
|
||||
syscall_handle_nx_mmap(state);
|
||||
case SYSCALL_NX_MEM_ALLOC: {
|
||||
syscall_handle_nx_mem_alloc(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_MEMORY_UNMAP: {
|
||||
syscall_handle_nx_munmap(state);
|
||||
case SYSCALL_NX_MEM_FREE: {
|
||||
syscall_handle_nx_mem_free(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -317,23 +318,19 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
|
|||
|
||||
case SYSCALLS_PROC: {
|
||||
switch (state->rax) {
|
||||
case SYSCALL_PROCESS_CREATE: {
|
||||
syscall_handle_nx_pcreate(state);
|
||||
case SYSCALL_NX_PROC_CREATE: {
|
||||
syscall_handle_nx_proc_create(state);
|
||||
break;
|
||||
}
|
||||
case SYSCALL_PROCESS_SIGNAL: {
|
||||
syscall_handle_nx_psignal(state);
|
||||
case SYSCALL_NX_PROC_SIGNAL_SEND: {
|
||||
syscall_handle_nx_proc_signal_send(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SYSCALLS_RUNTIME_LINKER: {
|
||||
break;
|
||||
}
|
||||
|
||||
case SYSCALLS_COMPATABILITY: {
|
||||
case SYSCALLS_DRIVERS: {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -349,12 +346,12 @@ cpu_state_T* syscall_handle(cpu_state_T* state) {
|
|||
}
|
||||
|
||||
switch (state->rax) {
|
||||
case SYSCALL_KERNEL_SCHEDULER_START: {
|
||||
case SYSCALL_NX_KERNEL_SCHEDULER_START: {
|
||||
return_state = scheduler_start(state);
|
||||
break;
|
||||
}
|
||||
|
||||
case SYSCALL_KERNEL_PANIC: {
|
||||
case SYSCALL_NX_KERNEL_PANIC: {
|
||||
panic(state, (string_t)arg1);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue