Page 1 of 1

Questions on implementing paging

Posted: Tue Sep 30, 2003 6:33 pm
by beyondsociety
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?

Re:Questions on implementing paging

Posted: Wed Oct 01, 2003 1:41 am
by Pype.Clicker
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 ?

Re:Questions on implementing paging

Posted: Wed Oct 01, 2003 8:16 am
by Tim
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.

Re:Questions on implementing paging

Posted: Wed Oct 01, 2003 10:53 am
by beyondsociety
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.
I would like to take a look at this code, would you be kind to post it?

Re:Questions on implementing paging

Posted: Wed Oct 01, 2003 4:09 pm
by Tim
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]