From a46c6dc2cc21c7341c7f202879eefd8bfa5909c1 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 17 Apr 2021 16:51:08 +0200 Subject: [PATCH] Add another page for kernel stack --- src/core/paging.c | 13 +++++++++++-- 1 file 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;