diff options
Diffstat (limited to 'src/core/paging.c')
| -rw-r--r-- | src/core/paging.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/core/paging.c b/src/core/paging.c index 0ab5498..cf5b951 100644 --- a/src/core/paging.c +++ b/src/core/paging.c @@ -89,42 +89,36 @@ char* paging_allocate_next_page(){ asm("hlt"); } -// TODO: Take p into account int *paging_allocate(int p){ - // ----- Allow kernel access during interruption + // ----- Populate kernel adresses (to be able to execute interrupts codes) int *page_dir=(int*)paging_allocate_next_page(); int *k_page_table=(int*)paging_allocate_next_page(); - // Init page directory + // Kernel is located in the first 4Mb (page dir entry 0) page_dir[0]=(int)k_page_table|3; - // Init page table 0 int addr_offset=0; for(int i=0;i<1024;i++){ k_page_table[i]=addr_offset; - k_page_table[i]|=3; // Permission + k_page_table[i]|=3; // Permissions addr_offset+=PAGING_PAGE_SIZE; // 4Ko pages } - // ----- Task table - int *u_page_table=(int*)paging_allocate_next_page(); + // ----- Populate task adresses + int *u_page_table=(int)paging_allocate_next_page(); 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; - - int dir_entry=1; - int pt_entry=3; + 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 while(p_current!=0){ + u_page_table[pt_entry]=(int)paging_allocate_next_page()|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; } - u_page_table[pt_entry]=(int)paging_allocate_next_page()|7; - p_current--; } - return page_dir; } |
