diff options
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/hal/obj.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/paging.c | 36 | ||||
| -rw-r--r-- | arch/x86_64/proc/init.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/proc/process.c | 39 | ||||
| -rw-r--r-- | arch/x86_64/proc/process.h | 7 | ||||
| -rw-r--r-- | arch/x86_64/sys/syscall.c | 2 |
6 files changed, 52 insertions, 36 deletions
diff --git a/arch/x86_64/hal/obj.c b/arch/x86_64/hal/obj.c index 103b53d..75cb0c0 100644 --- a/arch/x86_64/hal/obj.c +++ b/arch/x86_64/hal/obj.c @@ -41,7 +41,7 @@ obj_release(jove_owned_obj_t *obj) void* obj_deref(jove_owned_obj_t *obj) { - return (void*)(((uintptr_t)obj_getvalue(obj)) | 0xFFFF800000000000ULL); + return (void*)(((uintptr_t)obj_getvalue(obj)) | IDENT_VIRT_BASE); } uint8_t diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c index 770cdff..408b5d5 100644 --- a/arch/x86_64/hal/paging.c +++ b/arch/x86_64/hal/paging.c @@ -42,6 +42,11 @@ paging_pml4_switch(uintptr_t pml4) __asm__ volatile("movq %0, %%cr3":: "r"(pml4): "memory"); } +void pagedir_invlpg(uintptr_t vptr) +{ + __asm__ volatile("invlpg (%0)":: "r"(vptr)); +} + static struct int_stackframe* s_int_handle_pf_early(struct int_stackframe *frame) { @@ -101,6 +106,29 @@ s_pagedir_get_pml1(page_t *pml4, uintptr_t vptr) return PML_TBL(pml2, pml2i); } +uintptr_t *pagedir_get_mapping(jove_owned_obj_t *pagedir, uintptr_t vptr) +{ + page_t *pml4 = obj_deref(pagedir); + page_t *pml1 = s_pagedir_get_pml1(pml4, vptr); + if(!pml1) return 0; + + size_t pml1i = PML1I(vptr); + page_t *mapping = &pml1[pml1i]; + return (uintptr_t*)mapping; +} + +uintptr_t +pagedir_ident_from_mapping(uintptr_t *mapping) +{ + return (((page_t*)mapping)->paddr << 12) | IDENT_VIRT_BASE; +} + +void +pagedir_mapping_set_present(uintptr_t *mapping, bool present) +{ + ((page_t*)mapping)->p = present; +} + int pagedir_map_frame(page_t *pml4, uintptr_t pptr, uintptr_t vptr, uintmax_t flg) @@ -113,7 +141,7 @@ int pagedir_map_frame(page_t *pml4, if(pml1[pml1i].p) return EEXIST; pml1[pml1i].value = pptr | PAGE_PRESENT | flg; - __asm__ volatile("invlpg (%0)":: "r"(vptr): "memory"); + pagedir_invlpg(vptr); return 0; } @@ -184,7 +212,7 @@ map_table: PAGE_PRESENT | (pptr > IDENT_VIRT_BASE ? 0 : PAGE_USER) | PAGE_WRITEABLE; - __asm__ volatile("invlpg (%0)":: "r"(vptr): "memory"); + pagedir_invlpg(vptr); return 0; } @@ -241,7 +269,7 @@ int pagedir_unmap_untyped_frame( jove_untyped_t *untyped_data = obj_deref(dst); untyped_data->limit = 0x1000; - __asm__ volatile("invlpg (%0)":: "r"(vptr): "memory"); + pagedir_invlpg(vptr); return 0; } @@ -295,7 +323,7 @@ unmap_table: jove_untyped_t *untyped = obj_deref(dst); untyped->limit = 0x1000; - __asm__ volatile("invlpg (%0)":: "r"(vptr): "memory"); + pagedir_invlpg(vptr); return 0; } } diff --git a/arch/x86_64/proc/init.c b/arch/x86_64/proc/init.c index 4c86038..be1d556 100644 --- a/arch/x86_64/proc/init.c +++ b/arch/x86_64/proc/init.c @@ -144,7 +144,7 @@ init_setup(void) jove_owned_obj_t *message_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_MESSAGE_I); obj_settype(message_obj, JOVE_OBJ_MESSAGE); - obj_setvalue(message_obj, (message_pptr & ~0xFFF) | 1); + obj_setvalue(message_obj, last_base | 1); obj_release(message_obj); obj_release(init_pagedir); diff --git a/arch/x86_64/proc/process.c b/arch/x86_64/proc/process.c index 0c5c282..6165585 100644 --- a/arch/x86_64/proc/process.c +++ b/arch/x86_64/proc/process.c @@ -11,55 +11,46 @@ PAGEALIGN uint8_t s_init_iopb[0x2000]; PAGEALIGN char _init_pcb_bytes[0x1000] = { 0 }; -pcb_t *_init_pcb = (pcb_t*)&_init_pcb_bytes; - -pid_t -pcb_pid(pcb_t *pcb) -{ - return pcb->pid; -} - -jove_obj_t* -pcb_rootdir(pcb_t *pcb) -{ - return pcb->rootdir; -} +pcb_t *pcb_tree; void processing_setup(void (*process_main)) { + pcb_t *init_pcb = (pcb_t*)&_init_pcb_bytes; + pcb_tree = init_pcb; + memset(s_init_iopb, 0xFF, 0x2000); uintptr_t ksp = ((uintptr_t)&_init_pcb_bytes) + 0xFF8; - _init_pcb->tree_node.get_key = (void*)pcb_pid; - _init_pcb->tree_node.color = 1; + init_pcb->header.tree_node.get_key = (void*)pcb_getpid; + init_pcb->header.tree_node.color = 1; + init_pcb->header.rootdir = _rootdir_obj; + init_pcb->header.pagedir = obj_release(objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I)); - _init_pcb->pid = 1; - _init_pcb->ksp = (void*)ksp; - _init_pcb->pml4 = paging_get_pml4(); - _init_pcb->rootdir = _rootdir_obj; + init_pcb->header.pid = 1; + init_pcb->ksp = (void*)ksp; jove_owned_obj_t *iopb_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_IOPB_I); obj_settype(iopb_obj, JOVE_OBJ_IOPB); obj_setvalue(iopb_obj, (uintptr_t)s_init_iopb); - _init_pcb->iopb = iopb_obj; + init_pcb->iopb = obj_release(iopb_obj); processor_t *proc = processor_current(); - proc->tss.rsp[0] = (uintptr_t)_init_pcb->ksp; + proc->tss.rsp[0] = (uintptr_t)init_pcb->ksp; memcpy(proc->iopb, s_init_iopb, 0x2000); { jove_owned_obj_t *process_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_PCB_I); obj_settype(process_obj, JOVE_OBJ_PCB); - obj_setvalue(process_obj, (uintptr_t)_init_pcb); + obj_setvalue(process_obj, (uintptr_t)init_pcb); proc->pcb_obj = process_obj; - proc->pcb = _init_pcb; + proc->pcb = init_pcb; } __asm__ volatile("\ movq %0, %%rsp; \ xorq %%rbp, %%rbp; \ jmpq %1":: - "r"(_init_pcb->ksp), "r"(process_main)); + "r"(init_pcb->ksp), "r"(process_main)); } diff --git a/arch/x86_64/proc/process.h b/arch/x86_64/proc/process.h index cf4d8a8..534c8d5 100644 --- a/arch/x86_64/proc/process.h +++ b/arch/x86_64/proc/process.h @@ -7,13 +7,10 @@ typedef struct process_control_block { - struct rbtree_node tree_node; + struct pcb_expected_header header; struct process_control_block *sched_next; - pid_t pid; - jove_obj_t *rootdir; - jove_owned_obj_t *iopb; - uintptr_t pml4; + jove_obj_t *iopb; enum pcb_state state; int killed; diff --git a/arch/x86_64/sys/syscall.c b/arch/x86_64/sys/syscall.c index e3fa81b..b584756 100644 --- a/arch/x86_64/sys/syscall.c +++ b/arch/x86_64/sys/syscall.c @@ -16,7 +16,7 @@ _syscall_handle_arch(syscall_context_t *ctx) syscall_handle_t call_handle = s_arch_handles[target_type]; if(call_handle == NULL) { kprintf("syscall: Process %i tried to call syscall on object %P which doesn't support syscalls!\n", - pcb_pid(obj_deref(ctx->pcb)), ctx->header->path, ctx->header->pathlen); + pcb_getpid(obj_deref(ctx->pcb)), ctx->header->path, ctx->header->pathlen); return -EBADOBJ; } |
