From 1e397041c255581b68dc4ba240b3267fd3d0dc8f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 16 Apr 2021 20:20:29 +0200 Subject: Cleaning code --- src/core/paging.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/core/paging.c') diff --git a/src/core/paging.c b/src/core/paging.c index ab853bb..0ab5498 100644 --- a/src/core/paging.c +++ b/src/core/paging.c @@ -1,5 +1,6 @@ #include "paging.h" #include "libc/stdio.h" +#include "libc/math.h" /// Use a bitmap to keep track of allocated pages char pages_status[PAGING_MAX_PAGES/8]; @@ -105,11 +106,24 @@ int *paging_allocate(int p){ // ----- Task table int *u_page_table=(int*)paging_allocate_next_page(); - page_dir[1]=(int)u_page_table|7; // 1024*1024*4096/4 - u_page_table[0]=(int)page_dir|7; + page_dir[1]=(int)u_page_table|7; + u_page_table[0]=(int)page_dir|7; // Virtual address is 1024*4096/4 u_page_table[1]=(int)k_page_table|7; u_page_table[2]=(int)u_page_table|7; - u_page_table[3]=(int)paging_allocate_next_page()|7; + + int dir_entry=1; + int pt_entry=3; + int p_current=max(1,p); // Allocate at least 1 page + while(p_current!=0){ + if(pt_entry%1024==0){ + dir_entry++; + pt_entry=0; + u_page_table=(int*)paging_allocate_next_page(); + page_dir[dir_entry]=(int)u_page_table|7; + } + u_page_table[pt_entry]=(int)paging_allocate_next_page()|7; + p_current--; + } return page_dir; } -- cgit v1.2.3