From 4dddb5f5f8611f6df6d2ce2f019cca67a5598cdb Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 27 Sep 2019 23:52:33 +0200 Subject: Added some paging functionality --- src/kernel/paging/paging.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/kernel/paging/paging.c (limited to 'src/kernel/paging/paging.c') 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 + +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 -- cgit v1.2.3