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?
Temporary GDT
Re:Temporary GDT
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)
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Temporary GDT
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.
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.
Re:Temporary GDT
You can use SGDT to find the location of the gdt.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.
another way is get the bootloader to store the address somewhere in memory and pass the address of that memory to the kernal
Re:Temporary GDT
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.
Re:Temporary GDT
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) ?
Re:Temporary GDT
By loading a new one ;DAh, 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) ?