I am working on trying to implement paging into my operating system. I was currently trying to use position independent code to relocate my kernel in the assembly stub and then initalize paging in c from the kernel.
I am having problems with trying to do this and was wondering if I can relocate my kernel in the setup of the paging code?
If this is possible, are there any problems to doing this. I have thought of using the GDT trick for reloating the kernel also, but I cannot figure out how to code it. Has anybody had any luck in setting up this method?
Questions on implementing paging
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Questions on implementing paging
why not simply enabling the paging at the assembly stub (which can be made position-independent quite easily, imho) so that you don't have to bother with relocation (as the run-time base address of the kernel will be known at compile-time
, nor with PIC in the kernel ?
-
Tim
Re:Questions on implementing paging
I agree with Pype on this one. In my 'big' Mobius kernel, I use the GDT trick to put the kernel image at C000_0000 even with paging disabled, then I enable paging and everything is normal. In some more recent experimental kernels I've been enabling paging right at the start, with assembler code to set up the initial mappings (0000_0000..0040_0000 and C000_0000..C040_0000). It's a bit nastier than doing it in C, but you only have to do it once, and you don't have to write position-independent C code.
-
beyondsociety
Re:Questions on implementing paging
I would like to take a look at this code, would you be kind to post it?I agree with Pype on this one. In my 'big' Mobius kernel, I use the GDT trick to put the kernel image at C000_0000 even with paging disabled, then I enable paging and everything is normal. In some more recent experimental kernels I've been enabling paging right at the start, with assembler code to set up the initial mappings (0000_0000..0040_0000 and C000_0000..C040_0000). It's a bit nastier than doing it in C, but you only have to do it once, and you don't have to write position-independent C code.
-
Tim
Re:Questions on implementing paging
See the attached startup code. It expects a Multiboot loader and should be fairly generic. Note that the initial page directory and the two initial page tables are put in a separate section in the executable, so that they can be page-aligned via the linker script.
[attachment deleted by admin]
[attachment deleted by admin]