diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-17 16:31:45 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-17 16:31:45 +0200 |
| commit | dcadede2d4d6f7b94e38412dfbb924ed8abea709 (patch) | |
| tree | d8b3a11269cd29dff7389163f5f4d4f876ae7099 /src/core | |
| parent | 1e397041c255581b68dc4ba240b3267fd3d0dc8f (diff) | |
Debug paging
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/paging.c | 26 | ||||
| -rw-r--r-- | src/core/paging.h | 4 |
2 files changed, 12 insertions, 18 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; } diff --git a/src/core/paging.h b/src/core/paging.h index 53014db..3ecb663 100644 --- a/src/core/paging.h +++ b/src/core/paging.h @@ -10,8 +10,8 @@ #define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024 #endif #define PAGING_PADDR(entry) ((int*)(((u32)entry)&0xFFFFF000)) -#define PAGING_ENTRY_POINT_VIRT (1024*PAGING_PAGE_SIZE+3*PAGING_PAGE_SIZE) -#define PAGING_ENTRY_POINT_PHY(page_dir) ((int*)(((int*)((((int*)page_dir)[1])&0xFFFFF000))[3]&0xFFFFF000)) +#define PAGING_ENTRY_POINT_VIRT (1024*PAGING_PAGE_SIZE) +#define PAGING_ENTRY_POINT_PHY(page_dir) ((int*)(((int*)((((int*)page_dir)[1])&0xFFFFF000))[0]&0xFFFFF000)) /** * Configure and enable paging |
