diff options
Diffstat (limited to 'src/core/paging.c')
| -rw-r--r-- | src/core/paging.c | 20 |
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; } |
