diff options
Diffstat (limited to 'arch/x86_64/hal')
| -rw-r--r-- | arch/x86_64/hal/obj.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/paging.c | 34 | ||||
| -rw-r--r-- | arch/x86_64/hal/paging.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/process.c | 2 |
4 files changed, 24 insertions, 16 deletions
diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h index 645727d..9569a8a 100644 --- a/arch/x86_64/hal/obj.h +++ b/arch/x86_64/hal/obj.h @@ -8,8 +8,6 @@ enum { JOVE_OBJ_SERIAL_COM = 0x81, - JOVE_OBJ_PAGE_FRAME, - JOVE_OBJ_PAGE_MAPPING, }; /*Represents a locked kernel object pointer inside of a object directory.*/ diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c index c1a22a2..9ef67ab 100644 --- a/arch/x86_64/hal/paging.c +++ b/arch/x86_64/hal/paging.c @@ -1,8 +1,10 @@ #include "paging.h" #include "arch/x86_64/x86_64.h" #include "jove.h" +#include "init.h" #include "config.h" #include "smp.h" +#include "hal/obj.h" #include "lib/string.h" #include "lib/printf.h" #include "lib/panic.h" @@ -13,11 +15,11 @@ PAGEALIGN page_t _kernel_pml3[512]; PAGEALIGN page_t _kernel_pml2[512]; PAGEALIGN page_t _kernel_pml1[512]; -#define IDENT_HUGEPAGES ((PHYS_BIGPAGES_MAX + 511) / 512) -#define IDENT_GIANTPAGES ((IDENT_HUGEPAGES + 511) / 512) +#define IDENT_GIANTPAGES ((PHYS_HUGEPAGES_MAX + 511) / 512) +#define IDENT_MASSIVEPAGES ((IDENT_GIANTPAGES + 511) / 512) -PAGEALIGN static page_t ident_pml3[IDENT_GIANTPAGES][512]; -PAGEALIGN static page_t ident_pml2[IDENT_HUGEPAGES][512]; +PAGEALIGN static page_t ident_pml3[IDENT_MASSIVEPAGES][512]; +PAGEALIGN static page_t ident_pml2[IDENT_GIANTPAGES][512]; void* phys_tovirt(uintptr_t phys) @@ -80,6 +82,9 @@ paging_pml4_init(void) memset(_kernel_pml2, 0, 0x1000); memset(_kernel_pml1, 0, 0x1000); + memset(ident_pml3, 0, 0x1000 * IDENT_MASSIVEPAGES); + memset(ident_pml2, 0, 0x1000 * IDENT_GIANTPAGES); + /*Paging entries depend on physical addresses to properly map. * Since the virtual kernel address differs from the physical memory address, * we need to convert the pointers using the physical memory pointer passed @@ -140,24 +145,22 @@ paging_pml4_init(void) /*Identity pages are mapped as huge pages starting at the 256'th PML3 entry. *We want to support any range of physical memory up to several TiB, so *the mapper has to consider multiple heirarchies of huge pages.*/ - for(size_t l3 = 0; l3 < IDENT_GIANTPAGES; l3++) { - memset(ident_pml3[l3], 0, 0x1000); - uintptr_t ident_pml3_pptr = KPTR_TOPHYS((uintptr_t)ident_pml3[l3]); + + for(size_t l3 = 0; l3 < IDENT_MASSIVEPAGES; l3++) { + uintptr_t ident_pml3_pptr = KPTR_TOPHYS(&ident_pml3[l3]); _kernel_pml4[256 + l3].value = ident_pml3_pptr | PAGE_PRESENT | PAGE_WRITEABLE | PAGE_GLOBAL; } - for(size_t l2 = 0; l2 < IDENT_HUGEPAGES; l2++) { + for(size_t l2 = 0; l2 < IDENT_GIANTPAGES; l2++) { size_t l3 = l2 / 512; size_t l2_mod = l2 % 512; - memset(ident_pml2[l2], 0, 0x1000); - uintptr_t ident_pml2_pptr = KPTR_TOPHYS((uintptr_t)ident_pml2[l2]); - + uintptr_t ident_pml2_pptr = KPTR_TOPHYS(&ident_pml2[l2]); ident_pml3[l3][l2_mod].value = ident_pml2_pptr | PAGE_PRESENT | PAGE_WRITEABLE | PAGE_GLOBAL; } - for(size_t l1 = 0; l1 < PHYS_BIGPAGES_MAX; l1++) { + for(size_t l1 = 0; l1 < PHYS_HUGEPAGES_MAX; l1++) { size_t l2 = l1 / 512; size_t l1_mod = l1 % 512; @@ -167,6 +170,13 @@ 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)); + obj_settype(pgdir_o, JOVE_OBJ_PAGEDIR); + obj_setvalue(pgdir_o, kernel_pml4_pptr); + obj_release(pgdir_o); + } + /*Before tasking, if the kernel has a bug and crashes we need some * information about what happened.*/ extern struct int_stackframe *(*__int_handles[])(struct int_stackframe*); diff --git a/arch/x86_64/hal/paging.h b/arch/x86_64/hal/paging.h index 54df1eb..eb916a3 100644 --- a/arch/x86_64/hal/paging.h +++ b/arch/x86_64/hal/paging.h @@ -44,7 +44,7 @@ extern void *_kernel_physptr; #define IDENT_VIRT_BASE 0xFFFF800000000000ULL #define KERNEL_VIRT_BASE 0xFFFFFFFF80000000ULL -#define KPTR_TOPHYS(v) (v - KERNEL_VIRT_BASE + (uintptr_t)_kernel_physptr) +#define KPTR_TOPHYS(v) ((uintptr_t)v - KERNEL_VIRT_BASE + (uintptr_t)_kernel_physptr) uintptr_t paging_get_pml4(void); void paging_pml4_init(void); diff --git a/arch/x86_64/hal/process.c b/arch/x86_64/hal/process.c index dd49456..fb295c0 100644 --- a/arch/x86_64/hal/process.c +++ b/arch/x86_64/hal/process.c @@ -12,7 +12,7 @@ static pcb_t *s_init_pcb = (pcb_t*)&s_init_pcb_bytes; void processing_setup(void (*process_main)) { - uintptr_t ksp = (uintptr_t)&s_init_pcb_bytes + 8; + uintptr_t ksp = ((uintptr_t)&s_init_pcb_bytes) + 0xFF0; s_init_pcb->ksp = (void*)ksp; s_init_pcb->pml4 = paging_get_pml4(); |
