Hi,
Warrior wrote:Also: Is there any recommended way to make use of the GDT?
I'd recommend using the GDT in a way that suits the overall design of the OS (without knowing the overall design of the OS I can't be more specific).
Warrior wrote:I was thinking of writing it in assembly just with the hardcoded descriptors.
Warrior wrote:Or something of the sorts but then again, what about writing it in C with an ASM stublet for the lgdt instruction but with the ability to dynamicly add descriptors with permissions, etc etc..? I'm not sure what advantages one has over the other :p .
Will your OS design require the ability to dynamically create GDT entries? If you're using flat segments and doing everything with paging, then possibly not. You could have a different descriptor for each process' CS (so that they can't execute their data), or have an OS that uses segmentation (with or without paging). Perhaps your OS compiles everything from a strict/secure language during boot, and doesn't need privilege levels, paging or segmentation (in this case you wouldn't need any GDT after boot)?
My OS uses paging for almost everything, a single GDT (and no LDTs). GDT entries below 0x800 are created statically, while the rest are created dynamically (but remain unchanged after the GDT is created). The GDT is initialized/created by boot code (third stage) before the kernel is started.
My GDT goes like this:
[tt]0x0000 NULL descriptor
0x0008 System code descriptor, base = 0, limit = 0xC01FF000
0x0010 System data descriptor, base = 0, limit =4GB
0x0018 User code descriptor, base = 0, limit = 0xC0000000
0x0020 User data descriptor, base = 0, limit = 4GB
0x0028 System code descriptor, base = 0, limit = 0xC01FF000 (for SYSCALL only)
0x0030 System data descriptor, base = 0, limit = 4GB (for SYSCALL only)
0x0038 User data descriptor, base = 0, limit = 4GB (for SYSCALL only)
0x0040 Kernel API call gate
0x0048 to 0x07F8 Unused (reserved for future use)
0x0800 First CPU's data, base = list entry address, limit = entry structure size (used by GS only)
0x0808 to 0x0FF8 Reserved for more CPU's data (up to 256 CPUs supported)
0x1000 First CPU's TSS descriptor
0x1008 to 0x17F8 Reserved for more CPU's TSSs (one TSS per CPU)
0x17FF GDT limit (8 KB only)[/tt]
Warrior wrote:One last question: Just for my sanity, is it okay to think as a GDT as a roadmap ?
I'm neither a therapist nor a judge, so it's ok with me if you choose to think of the GDT as anything you like
. Whether or not I'd consider it appropriate to use the term "roadmap" within documentation intended for other developers is another matter entirely, and would depend on the answer to following question: In what way is the GDT like a roadmap for your OS?
Cheers,
Brendan