From 4f08ba2b1d0ad7ea90d4d97a483b56b891b9c902 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 1 May 2021 11:37:52 +0200 Subject: Creating scheduler, debug paging --- src/core/paging.cc | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/core/paging.cc') diff --git a/src/core/paging.cc b/src/core/paging.cc index bad776f..7231352 100644 --- a/src/core/paging.cc +++ b/src/core/paging.cc @@ -7,6 +7,7 @@ char paging_status[PAGING_MAX_PAGE / 8]; u64 kpages[MAX_TABLES][512] __attribute__((aligned(4096))); int kpages_next=1; // First page is for the pml4 +u64* kpml4; u64* paging_allocate_table(){ u64 addr=(u64)kpages[kpages_next]; @@ -18,6 +19,12 @@ u64* paging_allocate_table(){ } return allocated; } +u64* paging_allocate_utable(){ + u64 *table=PAGE_ALLOCATE(); + for(u32 i=0;i<512;i++) + table[i]=0; + return table; +} void paging_enable() { // Init status @@ -38,17 +45,17 @@ void paging_enable() { // Setting up new kernel address space for(u64 i=0;i<=0x10000000;i+=4096){ // Higher half mapping - PAGE_MAP(i); + PAGE_VIRT_MAP(i,PAGING_OPT_DEFAULTS); // Allow access to RAM: - paging_allocate_addr(kpages[0], i, i, PAGING_OPT_P|PAGING_OPT_RW, 1); + paging_allocate_addr(kpages[0], i, i, PAGING_OPT_DEFAULTS, 1); } // 4096 bytes stack - PAGE_MAP_PHY(-4096, kvar_stack_pma); + PAGE_MAP(kvar_kernel_vma-4096, kvar_stack_pma,PAGING_OPT_DEFAULTS); // Load new pml4 - u64 kpage_phy=((u64)kpages[0]-kvar_kernel_vma); - lpml4(kpage_phy); + kpml4=(u64*)((u64)kpages[0]-kvar_kernel_vma); + lpml4(kpml4); } u64* paging_allocate_contiguous(int npages){ @@ -146,7 +153,7 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char // Solve pdp if(pml4_table[pml4] == 0){ - pml4_table[pml4]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE()); + pml4_table[pml4]=(u64)(useKernelTables ? paging_allocate_table() : paging_allocate_utable()); pml4_table[pml4]|=options; paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables); return; @@ -156,7 +163,7 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char u64* pdp_table=(u64*)(PAGE(pml4_table[pml4])); pdp_table=useKernelTables ? VIRT(pdp_table) : pdp_table; if(pdp_table[pdp] == 0){ - pdp_table[pdp]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE()); + pdp_table[pdp]=(u64)(useKernelTables ? paging_allocate_table() : paging_allocate_utable()); pdp_table[pdp]|=options; paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables); return; @@ -166,7 +173,7 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char u64* pd_table=(u64*)(PAGE(pdp_table[pdp])); pd_table=useKernelTables ? VIRT(pd_table) : pd_table; if(pd_table[pd] == 0){ - pd_table[pd]=(u64)(useKernelTables ? paging_allocate_table() : PAGE_ALLOCATE()); + pd_table[pd]=(u64)(useKernelTables ? paging_allocate_table() : paging_allocate_utable()); pd_table[pd]|=options; paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables); return; @@ -175,19 +182,17 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char // Solve address u64* pt_table=(u64*)(PAGE(pd_table[pd])); pt_table=useKernelTables ? VIRT(pt_table) : pt_table; - if(pt_table[pt] == 0){ - pt_table[pt]=PAGE(phy); - pt_table[pt]|=options; - return; - } - + pt_table[pt]=PAGE(phy); + pt_table[pt]|=options; + return; } u64* paging_create_task(int npages){ - u64 *pml4=PAGE_ALLOCATE(); + u64 *pml4=paging_allocate_utable(); - for(int i=0;i>39&0x1FF; -- cgit v1.2.3