aboutsummaryrefslogtreecommitdiff
path: root/src/core/paging.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/paging.c')
-rw-r--r--src/core/paging.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/core/paging.c b/src/core/paging.c
index cf5b951..243ed0b 100644
--- a/src/core/paging.c
+++ b/src/core/paging.c
@@ -108,15 +108,24 @@ int *paging_allocate(int p){
int dir_entry=1; // Entry point is at 1024*4096=4194304 (page dir entry 1 and page table entry 0)
int pt_entry=0;
int p_current=max(1,p); // Allocate at least 1 page
+ p_current++; // Allocated one more page for the kernel stack (one per task)
while(p_current!=0){
- u_page_table[pt_entry]=(int)paging_allocate_next_page()|7;
+ u_page_table[pt_entry]=(int)paging_allocate_next_page();
+ if(p_current==1) // Kernel stack is the last page
+ u_page_table[pt_entry]|=3;
+ else
+ u_page_table[pt_entry]|=7;
p_current--;
pt_entry++;
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;
+ page_dir[dir_entry]=(int)u_page_table;
+ if(p_current==1) // Kernel stack is the last page (and might be in the last page directory entry)
+ page_dir[dir_entry]|=3;
+ else
+ page_dir[dir_entry]|=7;
}
}
return page_dir;