aboutsummaryrefslogtreecommitdiff
path: root/src/core/paging.c
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-16 20:20:29 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-16 20:20:29 +0200
commit1e397041c255581b68dc4ba240b3267fd3d0dc8f (patch)
tree757467f9ac0d998963ee5d80560205286b482acb /src/core/paging.c
parent93c2975ea8096a391a242299e119c31844b8fcbf (diff)
Cleaning code
Diffstat (limited to 'src/core/paging.c')
-rw-r--r--src/core/paging.c20
1 files changed, 17 insertions, 3 deletions
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;
}