I've finally been able to get a recursive paging setup working. I want to change the page directory now, though.
This is my init function where I want to set a new pd:
Code: Select all
void vmm_init() {
uint32_t eflags = interrupt_save_disable();
uint32_t *pd_p __attribute__((aligned(4096))) = pAllocPage();
uint32_t *pd_v = 0xAAAAAA000;
vMapPage(pd_p, pd_v, BIT_PD_PT_RW | BIT_PD_PT_PRESENT);
// recursive mapping
uint32_t *self_pde_v = 0xAAEAA000;
uint32_t *self_pde_p __attribute__((aligned(4096))) = (uint32_t)pAllocPage();
vMapPage(self_pde_p, self_pde_v, BIT_PD_PT_RW | BIT_PD_PT_PRESENT);
memset(self_pde_v, 0, sizeof(self_pde_v));
self_pde_v = (uint32_t)pd_p | BIT_PD_PT_PRESENT | BIT_PD_PT_RW;
pd_v[PAGE_DIRECTORY_INDEX(PD_VADDR)] = self_pde_v;
// 4MB page for the kernel
uint32_t *kernel_pde_v = 0xAB2AA000;
uint32_t *kernel_pde_p __attribute__((aligned(4096))) = (uint32_t)pAllocPage();
vMapPage(kernel_pde_p, kernel_pde_v, BIT_PD_PT_RW | BIT_PD_PT_PRESENT);
memset(kernel_pde_v, 0, sizeof(kernel_pde_v));
kernel_pde_v = _start_addr_phys | BIT_PD_PAGE_SIZE | BIT_PD_PT_PRESENT | BIT_PD_PT_RW;
pd_v[PAGE_DIRECTORY_INDEX(KERNEL_VIRTUAL_BASE)] = kernel_pde_v;
set_cr3(pd_p);
interrupt_restore(eflags);
}
set_cr3() is just:
Code: Select all
set_cr3:
mov eax, [esp + 4]
and eax, 0xFFFFF000
mov cr3, eax
ret
Do I have to identity map kinda like I had to do when initially enable paging?
Thanks in advance.