diff --git a/arch/user/include/mango/machine/init.h b/arch/user/include/mango/machine/init.h index cf16b97..a5364bb 100644 --- a/arch/user/include/mango/machine/init.h +++ b/arch/user/include/mango/machine/init.h @@ -1,6 +1,7 @@ #ifndef MANGO_X86_64_INIT_H_ #define MANGO_X86_64_INIT_H_ +#include #include #ifdef __cplusplus diff --git a/arch/user/include/mango/machine/pmap.h b/arch/user/include/mango/machine/pmap.h index b973528..3f084ee 100644 --- a/arch/user/include/mango/machine/pmap.h +++ b/arch/user/include/mango/machine/pmap.h @@ -1,6 +1,8 @@ #ifndef MANGO_USER_PMAP_H_ #define MANGO_USER_PMAP_H_ +#include + typedef uintptr_t ml_pmap_t; typedef uint64_t ml_pfn_t; diff --git a/arch/x86_64/irq.c b/arch/x86_64/irq.c index d613aef..261f695 100644 --- a/arch/x86_64/irq.c +++ b/arch/x86_64/irq.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #define MAX_ISR_HANDLERS 16 @@ -151,6 +152,8 @@ int idt_init(struct idt_ptr *ptr) init_global_idt(); } + set_syscall_gate((uintptr_t)syscall_gate); + ptr->i_limit = sizeof(idt) - 1; ptr->i_base = (uintptr_t)&idt; @@ -203,7 +206,7 @@ void irq_dispatch(struct ml_cpu_context *regs) void syscall_dispatch(struct ml_cpu_context *regs) { unsigned int sysid = regs->rax; - virt_addr_t syscall_impl = 0; // TODO + virt_addr_t syscall_impl = syscall_get_func(sysid); if (syscall_impl == 0) { regs->rax = KERN_UNSUPPORTED; diff --git a/include/mango/syscall.h b/include/mango/syscall.h new file mode 100644 index 0000000..a645143 --- /dev/null +++ b/include/mango/syscall.h @@ -0,0 +1,20 @@ +#ifndef MANGO_SYSCALL_H_ +#define MANGO_SYSCALL_H_ + +#include +#include +#include + +#define SYS_EXIT 1 +#define SYS_VM_OBJECT_CREATE 2 + +extern kern_status_t sys_exit(int status); +extern kern_status_t sys_vm_object_create( + const char *name, + size_t len, + enum vm_prot prot, + kern_handle_t *out_handle); + +extern virt_addr_t syscall_get_func(unsigned int sysid); + +#endif diff --git a/kernel/syscall.c b/kernel/syscall.c new file mode 100644 index 0000000..1f1c1eb --- /dev/null +++ b/kernel/syscall.c @@ -0,0 +1,40 @@ +#include +#include +#include + +kern_status_t sys_exit(int status) +{ + printk("sys_exit(%d)", status); + while (1) { + ml_cpu_pause(); + } + return KERN_UNIMPLEMENTED; +} + +kern_status_t sys_vm_object_create( + const char *name, + size_t len, + enum vm_prot prot, + kern_handle_t *out_handle) +{ + printk("sys_vm_object_create()"); + return KERN_UNIMPLEMENTED; +} + +#define SYSCALL_TABLE_ENTRY(id, p) [SYS_##id] = (virt_addr_t)(sys_##p) + +static const virt_addr_t syscall_table[] = { + SYSCALL_TABLE_ENTRY(EXIT, exit), + SYSCALL_TABLE_ENTRY(VM_OBJECT_CREATE, vm_object_create), +}; +static const size_t syscall_table_count + = sizeof syscall_table / sizeof syscall_table[0]; + +virt_addr_t syscall_get_func(unsigned int sysid) +{ + if (sysid >= syscall_table_count) { + return 0; + } + + return syscall_table[sysid]; +}