Page 1 of 1

GDT and IDT

Posted: Fri Oct 24, 2008 4:35 am
by kmtdk
well
i have thought about one thing:
after you execute the command "LIDT", and "LGDT", does the cpu refeeere to the mem where the tables are, or does it loads them into its own memory, so i for an example can overwrite the tables ???


KMT Dk

Re: GDT and IDT

Posted: Fri Oct 24, 2008 4:58 am
by Combuster
Yes and no.

When an entry is used, it is taken from memory. Since this would for segment registers imply that upon each use (memory access) they'd need to re-read the GDT, they have optimized things a bit. The segment registers have a hidden part that hold the GDT contents. When a segment register is loaded (even with the same value) the values from the GDT or LDT are copied and stored together with the selector, and it will keep using those values even if the GDT changes.

IDT entries are never cached. CS/DS/ES/FS/GS/SS keep a copy of the GDT entry that is associated to them. The remaining caches are the ones that come with TR and IDTR.

Re: GDT and IDT

Posted: Fri Oct 24, 2008 5:00 am
by JackScott
So if you've guaranteed that code will never reload segment registers, the kernel should be able to survive a corrupt GDT?

Re: GDT and IDT

Posted: Fri Oct 24, 2008 5:01 am
by CodeCat
Most likely, yes. But remember that user space processes can change segment registers as well. You don't want them to be able to crash your kernel...

Re: GDT and IDT

Posted: Sat Oct 25, 2008 7:20 am
by Combuster
As well as interrupts and privilege changes - They implicitly load CS and also SS for the latter