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 ?
Will paging ruin my kernel code ?
Re: Will paging ruin my kernel code ?
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
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
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Will paging ruin my kernel code ?
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.
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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Will paging ruin my kernel code ?
Hi,
Cheers,
Brendan
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.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 ?
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.