aboutsummaryrefslogtreecommitdiff
path: root/src/core/paging.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/paging.c')
-rw-r--r--src/core/paging.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/core/paging.c b/src/core/paging.c
new file mode 100644
index 0000000..b1f462f
--- /dev/null
+++ b/src/core/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