Page 1 of 1
Will paging ruin my kernel code ?
Posted: Sat Nov 21, 2015 10:49 am
by matan
When I enable paging , will my code be broken because pointers will not point to correct adresses in physical RAM ?
How can I switch paging and continue to run normally ?
Re: Will paging ruin my kernel code ?
Posted: Sat Nov 21, 2015 11:11 am
by Boris
You need to "identity paging" so Physical=virtual for the whole area of your kernel (including your interrupts handlers).
I suggest you to map your pagination directory/tables also, so you can modify them.
If you need to have your kernel in the end of virtual memory address, i suggest you to read
http://wiki.osdev.org/Higher_Half_bare_bones
Re: Will paging ruin my kernel code ?
Posted: Tue Nov 24, 2015 11:48 am
by onlyonemac
To add to what Boris said, you don't need to keep your kernel (or bootloader or wherever you're enabling paging) identity mapped. Just identity map the code where you're enabling paging. So if you enter your kernel with paging enabled, identity map your bootloader, map your kernel wherever you want it, then get the kernel's entry point to unmap the bootloader. If you enter the kernel with paging disabled and want to enable it in your kernel's initialisation routines (although I don't see any advantage to doing this), then map the kernel so that it's both identity mapped *and* mapped where you ultimately want it (you can map more than one virtual page to the same physical page), enable paging, jump to the other "virtual" copy of the kernel, then unmap the identity mapped kernel.
EDIT: Sorry I see your question is about breaking your existing code by enabling paging. Short answer: yes, it may well break your kernel code if you use any absolute addresses in your kernel. Long answer: you should re-write your kernel to allow paging now rather than later when it's longer - most assemblers and any decent linkers have an option to specify the "load address" of code, which the assembler uses to calculate the absolute addresses of labels, and any manually-calculated absolute addresses should be recalculated.
Re: Will paging ruin my kernel code ?
Posted: Wed Nov 25, 2015 2:18 am
by Brendan
Hi,
matan wrote:When I enable paging , will my code be broken because pointers will not point to correct adresses in physical RAM ?
How can I switch paging and continue to run normally ?
In my opinion, your kernel is already ruined (because it wasn't designed to use paging); and fixing that (including fixing all the pointers, etc) will "un-ruin" the kernel.
Cheers,
Brendan