From 6edeba8fe208fb019aec00fdc72b97407a8078d3 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 11 Apr 2021 20:53:06 +0200 Subject: Enable paging --- src/utils/paging.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/utils/paging.c (limited to 'src/utils/paging.c') diff --git a/src/utils/paging.c b/src/utils/paging.c new file mode 100644 index 0000000..b1f462f --- /dev/null +++ b/src/utils/paging.c @@ -0,0 +1,31 @@ +#include "paging.h" + +void paging_enable(){ + int *page_dir=(int*)PAGING_DIR_LOCATION; + int *page_table=(int*)PAGING_TABLE_LOCATION; + + // Init page directory + for(int i=0;i<1024;i++) + page_dir[i]=0; + page_dir[0]=(int)page_table; + page_dir[0] |=7; // Permissions + + // Init page table 0 + int addr_offset=0; + for(int i=0;i<1024;i++){ + page_table[i]=addr_offset; + page_table[i]|=7; // Permission + addr_offset+=4096; // 4Ko pages + } + + // Turns on paging + asm( + "movl %0, %%eax \n\t" + "movl %%eax, %%cr3 \n\t" // Configure page table location + "movl %%cr0, %%eax \n\t" + "orl %1, %%eax \n\t" + "movl %%eax, %%cr0 \n\t" // Turn on paging + :: "i" (PAGING_DIR_LOCATION), "i" (PAGING_CR0_BIT) + ); + +} \ No newline at end of file -- cgit v1.2.3