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 ++++++++++++++++++++++++++++++++++++++++++++++------ src/core/paging.h | 17 +++++++-- src/core/scheduler.c | 0 src/core/scheduler.h | 5 +++ 4 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 src/core/scheduler.c create mode 100644 src/core/scheduler.h (limited to 'src/core') 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_entry0 + #define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024+1 +#else + #define PAGING_MAX_DIR_ENTRY PAGING_MAX_PAGES/1024 +#endif /* * Configure and enable paging */ void paging_enable(); +char* paging_allocate_next_page(); +void paging_set_usage(int addr,char state); +/** + * Create a new page directory containing + * p pages. + */ +char *paging_allocate(int p); +void paging_dump(int min,int max); #endif \ No newline at end of file diff --git a/src/core/scheduler.c b/src/core/scheduler.c new file mode 100644 index 0000000..e69de29 diff --git a/src/core/scheduler.h b/src/core/scheduler.h new file mode 100644 index 0000000..f15168b --- /dev/null +++ b/src/core/scheduler.h @@ -0,0 +1,5 @@ +#ifndef SCHEDULER_H +#define SCHEDULER_H + + +#endif \ No newline at end of file -- cgit v1.2.3