Add another page for kernel stack

This commit is contained in:
Loic Guegan 2021-04-17 16:51:08 +02:00
parent 3259715b0e
commit a46c6dc2cc

View file

@ -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;