Page 1 of 1

basics

Posted: Sat Apr 01, 2006 2:35 am
by LongHorn
In what order should i do things if i load my kernel from Grubs to enable paging?
1.load idt and gdt
2.enable paging
3.mm and so on
Do i need to load gdt here?
Could i enable paging straight away? If i am doing so when should i load idt. After paging means should i store virtual address or physical address?

Re:basics

Posted: Sat Apr 01, 2006 3:26 am
by JoeKayzA
If you want to use a higher half kernel, you might want to enable paging first, like Colonel Kernel described in another thread recently. From this point on, all addresses will be virtual addresses of course.

After that, I'd say you should enable the memory manager (and get a set of 'real' page tables), and then load the gdt and idt. Since you are doing quite a lot of work (initializing paging and mm) without interrupts, you should test them quite well beforehand, since any exception will lead to a triple fault. ;)

cheers Joe

Re:basics

Posted: Sat Apr 01, 2006 12:59 pm
by Colonel Kernel
JoeKayzA wrote: Since you are doing quite a lot of work (initializing paging and mm) without interrupts, you should test them quite well beforehand, since any exception will lead to a triple fault. ;)
Actually, that's why I set up the IDT and GDT immediately after enabling paging. The order in which I initialize things is like so:
  • Enable paging.
  • Set up the kernel's initial stack
  • Set up the GDT and IDT
  • Copy GRUB's memory map into one of the kernel's buffers and wrap it in my own architecture-independent "object" (BootLoaderInfo)
  • Call kmain(), passing it a pointer to the BootLoaderInfo
kmain() itself initializes things in this order:
  • Initializes the "kernel display" (my own VGA text mode & font)
  • Initializes the subsystem responsible for sanely shutting down or rebooting the system when a fatal exception occurs
  • Sets up all exception and interrupt handlers and re-maps the PIC
  • Initializes the physical memory manager
That's as far as I've implemented it. As someone else said recently, it's all about the chicken & egg problem. I can't wait until it actually *does* something... :P

Re:basics

Posted: Sat Apr 01, 2006 1:29 pm
by paulbarker
Reminds me of a certain sketch...

"Bring me the maching that goes 'ping'".

Re:basics

Posted: Sat Apr 01, 2006 1:57 pm
by Colonel Kernel
And get the most expensive machine, in case the administrator comes!

Re:basics

Posted: Mon Apr 03, 2006 12:50 am
by LongHorn
@ Colonel Kernel : you are saying that i have to enable gdt and idt after enable paging. Then are you suggesting me to set idt and gdt in asm itslef then call kmain?
What should be loaded in gdtr and idtr then virtual or physical?

Re:basics

Posted: Mon Apr 03, 2006 1:46 am
by Colonel Kernel
LongHorn wrote: @ Colonel Kernel : you are saying that i have to enable gdt and idt after enable paging. Then are you suggesting me to set idt and gdt in asm itslef then call kmain?
You don't have to initialize the GDT and IDT after initializing paging just because I do it that way. I think it makes mapping the kernel into the "higher half" a lot easier though. My GDT and IDT initialization code is a mixture of C and asm, but you could write it all in asm if you want.
What should be loaded in gdtr and idtr then virtual or physical?
Virtual.

Re:basics

Posted: Mon Apr 03, 2006 3:12 am
by paulbarker
What should be loaded in gdtr and idtr then virtual or physical?
It's actually linear, not virtual. Just to tidy up the confusion, GDTR wants a linear address that will go thru the normal page translation. CR3 (for paging) wants a physical address.

My problem is I can't find anywhere in the manual whether IDTR goes thru segment translation (via GDT) or not. I'm assuming it will go thru page translation (I can't see any reason for the IDTR to be a physical address). So what is it, linear or virtual?

Re:basics

Posted: Mon Apr 03, 2006 4:25 am
by JoeKayzA
My problem is I can't find anywhere in the manual whether IDTR goes thru segment translation (via GDT) or not.
To my knowledge, it doesn't, it's a linear address just like the GDT's. Remember, for a logical address (that goes through segment translation and then through paging), you need a segment selector (16bit) and an offset (32bit). The IDT pointer that you load into the IDTR doesn't contain a segment selector, so it can only be a linear address.

And btw, AFAIK linear and virtual addresses are pretty much the same.

cheers Joe

Re:basics

Posted: Mon Apr 03, 2006 4:39 am
by paulbarker
The words linear, logical and virtual are used to mean different things by different people. I don't know what the words used in the manual are, but you should be able to understand what I meant.

Re:basics

Posted: Mon Apr 03, 2006 2:09 pm
by LongHorn
Fine
I enabled paging, now what should i do?
->createpagetable
->pagebind
->pageunbind
(before mm)
Is there any need of creating further page tables? if so what are they? and where should be my pagedir and pagetable present? Its at 0x9C000 onwards for now. Where will it be created in a professional OS?

Re:basics

Posted: Tue Apr 04, 2006 3:34 am
by YeXo
Is there any need of creating further page tables? if so what are they? and where should be my pagedir and pagetable present? Its at 0x9C000 onwards for now. Where will it be created in a professional OS?
That depends on the amount of physical memory you want to use. You need at least 1 page table for every 4mb physical memory you want to use. The pagedirectory(s) and pagetable(s) will always be located at whatever location is free at that particular moment. Therefore you need to write a pmm (physical memory manager) before you write a vmm (virtual memory manager.).