I'm not sure if this is really "OS Design & Theory".
My question is quite simple, but I can't find the answer to it.
I am making a new OS, where I really need to change segments at run-time.
I know that in Protected Mode all segments are stored in the GDT.
Is it possible to possible to change the GDT and then reload it?
Updating the GDT
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: Updating the GDT
Instead of having to change GDT entries at run-time, you could just add multiple entries, for instance, if you're doing a higher-half kernel.
Then all that is needed is to load the segment registers with the right selector offset. The intel manual says that you can have a maximum of 8192 (!) descriptors apparently. I don't think it would be a good idea to modify GDT entries once it's been loaded, especially for descriptors that are in use though.
Then all that is needed is to load the segment registers with the right selector offset. The intel manual says that you can have a maximum of 8192 (!) descriptors apparently. I don't think it would be a good idea to modify GDT entries once it's been loaded, especially for descriptors that are in use though.
Re: Updating the GDT
But the segments that I need to add (and delete) cannot be determined at boot-time (they are calculated later on...)
Anyway, can I change the segments that are not in use? e.g. modify the user-mode code segment when it is not being used at that specific moment???
BTW, I just tried changing an unused segment (which is within GDT limits), and it does not seem to cause any trouble... (at least oon qemu)
Anyway, can I change the segments that are not in use? e.g. modify the user-mode code segment when it is not being used at that specific moment???
BTW, I just tried changing an unused segment (which is within GDT limits), and it does not seem to cause any trouble... (at least oon qemu)
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Updating the GDT
Any time a segment register is written (not necessarily changed!), it reads the corresponding entry in the GDT or LDT. You don't need to reload GDTR for that to work, you just modify the GDT currently in use and reload the appropriate segment registers.
Live editing of the GDT is however prone to reentrancy issues and race conditions, so be careful.
Live editing of the GDT is however prone to reentrancy issues and race conditions, so be careful.
Re: Updating the GDT
Right. Thanks.Combuster wrote:Any time a segment register is written (not necessarily changed!), it reads the corresponding entry in the GDT or LDT. You don't need to reload GDTR for that to work, you just modify the GDT currently in use and reload the appropriate segment registers.
Live editing of the GDT is however prone to reentrancy issues and race conditions, so be careful.