Page 1 of 1
GDT
Posted: Mon Aug 18, 2003 9:19 am
by Shalom
Hi. I'm new to OS programming. I wrote a multiboot compliant kernel and wrote a couple of funtions to write stuff to the screen and got it to load with GRUB (I use bochs, though on occasion I boot it up properly to make sure it looks normal). Now I want to set up some proper things (like a keyboard driver). I've been reading into it, and I can't figure out exactly what a GDT is. Does GRUB set one up? What does it do? What entries should I put in it? What is a selector? I've tried reading a few tutorials on the subject and I can't say I understood them. Thank you,
Shalom.
Re:GDT
Posted: Mon Aug 18, 2003 10:27 am
by Tim
Shalom wrote:Does GRUB set one up?
Yes, but you should set up a whole new GDT if you want to reload any segment registers.
What does it do?
It defines the segments used by the whole system. Each segment has a base address, which gets added to all addresses referenced through the segment, and a limit, which places an upper limit on the addresses you can use through the segment. Each segment also has several flags, which define the type of segment (code, data or system) and access permissions.
What entries should I put in it?
At a minimum: null, code and data.
What is a selector?
It's a number which references a segment. A selector contains a table indicator bit, which says whether it references the GDT or the LDT; a two-bit requested privilege level field, which allows you to 'ask' for a certain privilege level; and thirteen index bits, which point to the segment within the GDT or LDT.
I've tried reading a few tutorials on the subject and I can't say I understood them.
You should read the Intel manuals if you haven't already done do; they should be considered the ultimate reference for things relating to the processor. Other than that, just keep reading and re-reading -- and browse through other peoples' source code for practical examples of usage.
Re:GDT
Posted: Tue Aug 19, 2003 6:15 am
by Shalom
Thank you, that helped a lot. Just to get it a bit clearer, if I made a simple GDT and then I wanted to set up an IDT, how would I know what to put under selector and address in the IDT descriptor entry?
Re:GDT
Posted: Tue Aug 19, 2003 6:38 am
by Therx
The selector in a IDT entry is the segment that should be used for running the code when the ISR is entered. It should be your code selector. When you have ring0 and ring3 selectors it should be the ring0 code
Pete