Paging is not enabled
Posted: Mon Jun 08, 2020 4:52 am
Hi.
I'm trying to add paging to my system, I'm using this tutorial.
When calling enablePaging(), the system crashes.
Here's my code:
The addresses are aligned.
What's wrong?
I'm trying to add paging to my system, I'm using this tutorial.
When calling enablePaging(), the system crashes.
Here's my code:
Code: Select all
bool init_vm_paging() {
page_directory_table = (uint32_t*)kmalloc(sizeof(int) * 1024);
if ((uint32_t)page_directory_table % 4096) {
dprintf("page_directory_table address is not aligned!\n");
kfree(page_directory_table);
return false;
}
first_page_table = (uint32_t*)kmalloc(sizeof(int) * 1024);
if ((uint32_t)first_page_table % 4096) {
dprintf("first_page_table address is not aligned!\n");
kfree(first_page_table);
return false;
}
for(uint32_t i = 0; i < 1024; i++) {
// This sets the following flags to the pages:
// Supervisor: Only kernel-mode can access them
// Write Enabled: It can be both read from and written to
// Not Present: The page table is not present
page_directory_table[i] = 0x00000002;
}
for(uint32_t i = 0; i < 1024; i++)
{
// As the address is page aligned, it will always leave 12 bits zeroed.
// Those bits are used by the attributes ;)
first_page_table[i] = (i * 0x1000) | 3; // attributes: supervisor level, read/write, present.
}
// attributes: supervisor level, read/write, present
page_directory_table[0] = ((unsigned int)first_page_table) | 3;
loadPageDirectory(page_directory_table);
enablePaging();
return true;
}
What's wrong?