Temporary GDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tm-

Temporary GDT

Post by tm- »

Why do most people set up temporary GDT in the bootloader and then in the kernel set up new GDT? What's the reason for that? Why can't I just set it up in bootloader well? ???

And what descriptors are necessary? I mean code segment descriptor is probably necessary, and data (and null descriptor) but what about bss? Should I have to create descriptor for that too?
AR

Re:Temporary GDT

Post by AR »

You could, I would believe most people prefer remapping the GDT in the Kernel just so that it's "under it's control" [in a known state, in a known location, incase the bootloader is changed or something] or because they actually use it (ie. Segmentation and/or Hardware task switching so having to create a new TSS for every thread)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Temporary GDT

Post by Pype.Clicker »

if you ever had to _modify_ the content of the GDT once loaded, you'll realise that it's easier to re-define a new GDT at the kernel than trying to have the kernel know what sort of weird location the bootloader has used.

The reason is that you'll try to avoid excessive knowledge of the bootloader in your kernel. Moreover, most of us do use GRUB as their bootloader and GRUB doesn't really give you the choice: it doesn't guarantee the GDT can safely be kept (since it doesn't tell you where it is, what is around it, etc. in the Multiboot specs) so you have to set up your own. That's not that a big deal, btw.
B.E

Re:Temporary GDT

Post by B.E »

Pype.Clicker wrote: if you ever had to _modify_ the content of the GDT once loaded, you'll realise that it's easier to re-define a new GDT at the kernel than trying to have the kernel know what sort of weird location the bootloader has used.
You can use SGDT to find the location of the gdt.
another way is get the bootloader to store the address somewhere in memory and pass the address of that memory to the kernal
DruG5t0r3

Re:Temporary GDT

Post by DruG5t0r3 »

It is correct that SGDT will give you it's address. Problem is, Grub might place that GDT right in the middle of something you'd like to have access to. And I find that the GDT is far more "usable" if you reload a fresh new one from your C kernel.
Warrior

Re:Temporary GDT

Post by Warrior »

Ah, so it only loads the GDT so it can enter protected mode and it's recommended you flush out the old GDT and setup your own. (How would I flush out the old GDT) ?
DruG5t0r3

Re:Temporary GDT

Post by DruG5t0r3 »

Ah, so it only loads the GDT so it can enter protected mode and it's recommended you flush out the old GDT and setup your own. (How would I flush out the old GDT) ?
By loading a new one ;D
Post Reply