aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/paging/paging.c22
-rw-r--r--src/kernel/paging/paging.h6
2 files changed, 28 insertions, 0 deletions
diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c
new file mode 100644
index 0000000..164372e
--- /dev/null
+++ b/src/kernel/paging/paging.c
@@ -0,0 +1,22 @@
+#include <stdint.h>
+
+uint64_t page_dir_ptr_tab[4] __attribute__((aligned(0x20)));
+uint64_t page_dir[512] __attribute__((aligned(0x1000)));
+uint64_t page_tab[512] __attribute__((aligned(0x1000)));
+
+void enable_paging() {
+ page_dir_ptr_tab[0] = (uint64_t) &page_dir | 1;
+ page_dir[0] = (uint64_t) &page_tab | 3;
+
+ unsigned int i, address = 0;
+ for (i = 0; i < 512; i++) {
+ page_tab[i] = address | 3;
+ address = address + 0x1000;
+ }
+
+ asm volatile ("cli");
+ asm volatile ("movl %cr4, %eax; bts $5, %eax; movl %eax, %cr4"); // CRASH
+ asm volatile ("movl %%eax, %%cr3"::"a" (&page_dir_ptr_tab));
+ asm volatile ("movl %cr0, %eax; orl $0x80000000, %eax; movl %eax, %cr0;");
+ asm volatile ("sti");
+} \ No newline at end of file
diff --git a/src/kernel/paging/paging.h b/src/kernel/paging/paging.h
new file mode 100644
index 0000000..e8c3bf4
--- /dev/null
+++ b/src/kernel/paging/paging.h
@@ -0,0 +1,6 @@
+#ifndef MELVIX_PAGING_H
+#define MELVIX_PAGING_H
+
+void enable_paging();
+
+#endif