From 5a9a57177f730d1c00ab2b47f91e5ea2660a4f77 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 13 Apr 2021 15:31:45 +0200 Subject: Enable .bss zeroing and improve paging --- src/core/paging.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-) (limited to 'src/core/paging.c') diff --git a/src/core/paging.c b/src/core/paging.c index b1f462f..c32a3bc 100644 --- a/src/core/paging.c +++ b/src/core/paging.c @@ -1,21 +1,43 @@ #include "paging.h" +#include "libc/stdio.h" + +/// Use a bitmap to keep track of allocated pages +char pages_status[PAGING_MAX_PAGES/8]; +/// Kernel page directory (ATTENTION need to be 4096) +u32 k_pd[PAGING_MAX_DIR_ENTRY] __attribute__((aligned(4096))); +/// Kernel page table +u32 k_pt[PAGING_MAX_DIR_ENTRY][1024] __attribute__((aligned(4096))); void paging_enable(){ - int *page_dir=(int*)PAGING_DIR_LOCATION; - int *page_table=(int*)PAGING_TABLE_LOCATION; + // Init pages status + for(int i=0;i>j)&0x1; + if((i*8+j)>=min){ + if((i*8+j)>j)&1; + if(state!=1){ + int page_id=i*8+j; + int page_addr=PAGING_PAGE_SIZE*page_id; + paging_set_usage(page_addr,1); + return((char*)page_addr); + } + } + } + print("Could not allocate anymore pages! Stopping..."); + asm("hlt"); +} + +char *paging_allocate(int p){ + int *page_dir=(int*)paging_allocate_next_page(); + int *page_table; + int current_page_entry=0; + int current_dir_entry=0; + while(current_page_entry