summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/hal/paging.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/hal/paging.c')
-rw-r--r--arch/x86_64/hal/paging.c34
1 files changed, 22 insertions, 12 deletions
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*);