diff options
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/hal/obj.c | 16 | ||||
| -rw-r--r-- | arch/x86_64/hal/obj.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/paging.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/process.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/serial_com.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/smp.c | 4 | ||||
| -rw-r--r-- | arch/x86_64/lib/printf.c | 5 | ||||
| -rw-r--r-- | arch/x86_64/sys/init.c | 4 | ||||
| -rw-r--r-- | arch/x86_64/sys/syscall.c | 58 |
9 files changed, 78 insertions, 17 deletions
diff --git a/arch/x86_64/hal/obj.c b/arch/x86_64/hal/obj.c index 783d2f4..8011347 100644 --- a/arch/x86_64/hal/obj.c +++ b/arch/x86_64/hal/obj.c @@ -1,11 +1,15 @@ #include "obj.h" #include "arch/x86_64/lock.h" +#include "paging.h" #include "hal/obj.h" #include "jove.h" jove_owned_obj_t* obj_take(jove_obj_t *obj) { + if((uintptr_t)obj < IDENT_VIRT_BASE) { + reterr(EBADOBJ); + } take_mutex(&obj->lock); return (jove_owned_obj_t*)obj; } @@ -13,6 +17,9 @@ obj_take(jove_obj_t *obj) jove_obj_t* obj_release(jove_owned_obj_t *obj) { + if((uintptr_t)obj < IDENT_VIRT_BASE) { + reterr(EBADOBJ); + } release_mutex((atomic_flag*)&obj->lock); return (jove_obj_t*)obj; } @@ -47,7 +54,7 @@ obj_setvalue(jove_owned_obj_t *obj, uintmax_t value) obj->value = value & 0x00007FFFFFFFFFFFULL; } -jove_obj_t* +jove_owned_obj_t* objdir_getlocal( jove_owned_obj_t *objdir_obj, uint16_t entry) @@ -60,7 +67,7 @@ objdir_getlocal( } jove_objdir_t *objtab = obj_deref(objdir_obj); - return &objtab->entries[entry]; + return obj_take(&objtab->entries[entry]); } jove_owned_obj_t* @@ -73,12 +80,11 @@ objdir_getobj( return objdir_obj; } { - jove_obj_t *child_locked_objdir = objdir_getlocal(objdir_obj, path[0]); - if(child_locked_objdir == NULL) { + jove_owned_obj_t *child_objdir = objdir_getlocal(objdir_obj, path[0]); + if(child_objdir == 0) { return 0; } - jove_owned_obj_t *child_objdir = obj_take(child_locked_objdir); jove_owned_obj_t *target_obj = objdir_getobj(child_objdir, path + 1, path_len - 1); obj_release(child_objdir); return target_obj; diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h index 9569a8a..f7d7711 100644 --- a/arch/x86_64/hal/obj.h +++ b/arch/x86_64/hal/obj.h @@ -63,7 +63,7 @@ void obj_setvalue(jove_owned_obj_t *obj, uintmax_t value); /*Returns the n'th entry of the object directory passed. * If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ. * If the passed entry index is out of bounds, returns NULL and sets errno to EOOB.*/ -jove_obj_t *objdir_getlocal(jove_owned_obj_t *objdir_obj, uint16_t entry); +jove_owned_obj_t *objdir_getlocal(jove_owned_obj_t *objdir_obj, uint16_t entry); /*Recursively seeks through an object directory for an object following the passed * path variable. diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c index 5887e79..fb6dea7 100644 --- a/arch/x86_64/hal/paging.c +++ b/arch/x86_64/hal/paging.c @@ -171,7 +171,7 @@ paging_pml4_init(void) paging_pml4_switch(kernel_pml4_pptr); { - jove_owned_obj_t *pgdir_o = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I)); + jove_owned_obj_t *pgdir_o = objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I); obj_settype(pgdir_o, JOVE_OBJ_PAGEDIR); obj_setvalue(pgdir_o, kernel_pml4_pptr); obj_release(pgdir_o); diff --git a/arch/x86_64/hal/process.c b/arch/x86_64/hal/process.c index fb295c0..5c91238 100644 --- a/arch/x86_64/hal/process.c +++ b/arch/x86_64/hal/process.c @@ -21,7 +21,7 @@ processing_setup(void (*process_main)) proc->tss.rsp[0] = (uintptr_t)s_init_pcb->ksp; { - jove_owned_obj_t *process_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_PCB_I)); + jove_owned_obj_t *process_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_PCB_I); obj_settype(process_obj, JOVE_OBJ_PROCESS); obj_setvalue(process_obj, (uintptr_t)s_init_pcb); obj_release(process_obj); diff --git a/arch/x86_64/hal/serial_com.c b/arch/x86_64/hal/serial_com.c index 3967cd7..22682fd 100644 --- a/arch/x86_64/hal/serial_com.c +++ b/arch/x86_64/hal/serial_com.c @@ -68,7 +68,7 @@ serial_com_init(void) } { - jove_owned_obj_t *com_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_SERIAL_COM_I)); + jove_owned_obj_t *com_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_SERIAL_COM_I); obj_settype(com_obj, JOVE_OBJ_SERIAL_COM); obj_setvalue(com_obj, SERIAL_COM1); obj_release(com_obj); diff --git a/arch/x86_64/hal/smp.c b/arch/x86_64/hal/smp.c index 0b1ed9d..e0945c1 100644 --- a/arch/x86_64/hal/smp.c +++ b/arch/x86_64/hal/smp.c @@ -43,11 +43,11 @@ smp_init_bsp(void) kprintf("%p\n", _rootdir_obj); processor_t *bsp = &s_processors[0]; { - jove_owned_obj_t *processor_objdir_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_PROCESSORS_I)); + jove_owned_obj_t *processor_objdir_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_PROCESSORS_I); obj_settype(processor_objdir_obj, JOVE_OBJ_OBJDIR); obj_setvalue(processor_objdir_obj, (uintptr_t)&s_processor_objdir); - jove_owned_obj_t *bsp_obj = obj_take(objdir_getlocal(processor_objdir_obj, 0)); + jove_owned_obj_t *bsp_obj = objdir_getlocal(processor_objdir_obj, 0); init_processor(bsp, bsp_obj); obj_release(bsp_obj); diff --git a/arch/x86_64/lib/printf.c b/arch/x86_64/lib/printf.c index 42ee568..f60b943 100644 --- a/arch/x86_64/lib/printf.c +++ b/arch/x86_64/lib/printf.c @@ -11,13 +11,12 @@ kvprintf(const char *fmt, va_list ap) int wlen = (r > 256 ? 256 : r); { - jove_owned_obj_t *serial_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_SERIAL_COM_I)); + jove_owned_obj_t *serial_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_SERIAL_COM_I); serial_com_write(serial_obj, buffer, wlen); obj_release(serial_obj); - jove_owned_obj_t *vt_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_VIRTTERM_I)); + jove_owned_obj_t *vt_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_VIRTTERM_I); vt_write(vt_obj, buffer, wlen); - obj_release(vt_obj); } diff --git a/arch/x86_64/sys/init.c b/arch/x86_64/sys/init.c index 2bd86d5..26eefde 100644 --- a/arch/x86_64/sys/init.c +++ b/arch/x86_64/sys/init.c @@ -77,7 +77,7 @@ init_setup(void) kpanic("Kernel commandline is missing 'init' arg.\n"); } - jove_owned_obj_t *initrd_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_INITRD_I)); + jove_owned_obj_t *initrd_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_INITRD_I); jove_owned_obj_t *init_obj = initrd_seek(initrd_obj, init_path); if(init_obj == NULL) { kpanic("init: Cannot find file '%s' in initrd.\n", init_path); @@ -96,7 +96,7 @@ init_setup(void) kpanic("init: Either passed file '%s' is not an ELF file or is not loadable.\n", init_path); } - jove_owned_obj_t *init_pagedir = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I)); + jove_owned_obj_t *init_pagedir = objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I); page_t *pml4 = obj_deref(init_pagedir); //Load the init ELF diff --git a/arch/x86_64/sys/syscall.c b/arch/x86_64/sys/syscall.c index 8cc58bf..4e95225 100644 --- a/arch/x86_64/sys/syscall.c +++ b/arch/x86_64/sys/syscall.c @@ -1,7 +1,63 @@ +#include "arch/x86_64/hal/process.h" +#include "arch/x86_64/hal/smp.h" +#include "hal/smp.h" +#include "jove.h" +int +syscall_handler_arch(uint64_t message_path_raw, uint64_t message_pathlen) +{ + uint16_t *message_path = (uint16_t*)&message_path_raw; + if(message_pathlen > 4) { + return EBADPATH; + } + processor_t *proc = processor_current(); + jove_owned_obj_t *objdir = obj_take(proc->pcb->rootdir); + jove_owned_obj_t *message_obj = objdir_getobj(objdir, message_path, message_pathlen); + if(message_obj == 0) { + obj_release(objdir); + return errno; + } + + return 0; +} __attribute__((naked)) void _syscall_entry(void) { - + __asm__ volatile(" \ + swapgs; \ + movq %%gs:%c[pcb], %%rax; \ + movq %%rsp, %%rdx; \ + movq %c[ksp](%%rax), %%rsp; \ + pushq %%rdx; \ + pushq %%r11; \ + pushq %%rbx; \ + pushq %%rcx; \ + pushq %%rbp; \ + pushq %%r12; \ + pushq %%r13; \ + pushq %%r14; \ + pushq %%r15; \ + callq syscall_handler_arch; \ + swapgs; \ + popq %%r15; \ + popq %%r14; \ + popq %%r13; \ + popq %%r12; \ + popq %%rbp; \ + popq %%rcx; \ + popq %%rbx; \ + xorq %%rdx, %%rdx; \ + xorq %%rsi, %%rsi; \ + xorq %%rdi, %%rdi; \ + xorq %%r8, %%r8; \ + xorq %%r9, %%r9; \ + xorq %%r10, %%r10; \ + popq %%rcx; \ + popq %%r11; \ + popq %%rsp; \ + sysretq;" + :: + [pcb] "i"(offsetof(processor_t, pcb)), + [ksp] "i"(offsetof(pcb_t, ksp))); } |
