diff options
author | Marvin Borner | 2019-09-27 23:52:33 +0200 |
---|---|---|
committer | Marvin Borner | 2019-09-27 23:52:33 +0200 |
commit | 4dddb5f5f8611f6df6d2ce2f019cca67a5598cdb (patch) | |
tree | fe2047d2ac68bec2f4803f29c5a054ed59325511 /src | |
parent | 1d3ff04f2dd47c71aa0b2d7e7601f0d31b3eab60 (diff) |
Added some paging functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/paging/paging.c | 22 | ||||
-rw-r--r-- | src/kernel/paging/paging.h | 6 |
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 |