Error enabling paging?
Posted: Wed Nov 07, 2007 12:02 am
Hi guys,
I've been trying to get paging working, but I haven't had much success. I've got a working physical page (de)allocator, and everything seems to be fine up to setting CR0. I haven't been able to figure out what I've been doing wrong from the tutorials I've read. I'd be much obliged if someone could point me in the right direction. Here's the pertinent code:
This assembly code is pretty straight forward - SetPageDirectory works fine, but EnablePaging fails at mov cr0, eax. I haven't tested DisablePaging.
Here's the code that calls enable paging:
There's not much to this either - MapPages maps continuous sets of pages, but isn't implemented yet. In fact, the only mapping that gets done is to map the page directory into itself. I don't think that would prevent me from enabling paging.
I haven't yet written an interrupt handler - I want to get some memory management done first - so I can't get details on the failure. Any help would be greatly appreciated!
I've been trying to get paging working, but I haven't had much success. I've got a working physical page (de)allocator, and everything seems to be fine up to setting CR0. I haven't been able to figure out what I've been doing wrong from the tutorials I've read. I'd be much obliged if someone could point me in the right direction. Here's the pertinent code:
This assembly code is pretty straight forward - SetPageDirectory works fine, but EnablePaging fails at mov cr0, eax. I haven't tested DisablePaging.
Code: Select all
global _SetPageDirectory
_SetPageDirectory:
push ebp ;stack stuff
mov ebp, esp
mov eax, [ebp + 8] ;"pop" the directory
and eax, 0xFFFFF000
mov cr3, eax
pop ebp
ret
global _EnablePaging
_EnablePaging:
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
ret
global _DisablePaging
_DisablePaging:
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
ret
Code: Select all
KernelPageDirectoryAddress = AllocatePage();
memset(KernelPageDirectoryAddress, 0, 4096); //clear the page directory
KernelPageDirectoryAddress[1023] = ((unsigned int)KernelPageDirectoryAddress & 0xFFFFF000) | 0x3; //maps the page directory's last entries into itself
//map the pages we've claimed
PrintString("\nMapping Pages");
MapPages(0xC0000000, 0x100000, kernelPages); //map our kernel to its virtual location
MapPages(0xD0000000, 0x100000 + kernelPages * 4096, kernelHeapPages); //map the currently used heap pages
SetPageDirectory(KernelPageDirectoryAddress);
EnablePaging(); //problem here
I haven't yet written an interrupt handler - I want to get some memory management done first - so I can't get details on the failure. Any help would be greatly appreciated!