How do I create/load a GDT when I am in PMode as opposed to Real Mode? What are the differences? In my gdt.s, do I specify bits 16 or bits 32? Do I switch back into real mode, load the GDT, and switch into Pmode? Or what?
The reason I am asking is because I am using the GRUB2 bootloader, which (I understand) puts you into Pmode, and I have not yet set up any GDT.
How do I create/load a GDT when I am in PMode?
- BenjiWiebe
- Posts: 20
- Joined: Thu Feb 07, 2013 9:47 pm
- Location: Durham, Kansas
- Contact:
Re: How do I create/load a GDT when I am in PMode?
It's exactly the same.
Re: How do I create/load a GDT when I am in PMode?
One difference, in RMode, LGDT takes 24 bit linear address; in PMode, LGDT takes 32 bit linear address. The same is true for SGDT, LIDT/SIDT.
Always give a difficult task to a lazy person. He will find an easy way to do it.
- 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: How do I create/load a GDT when I am in PMode?
Utter nonsense. Even if you never heard of operand sizes and prefixes there's no way you're going to explain how you established the above.trinopoty wrote:One difference, in RMode, LGDT takes 24 bit linear address; in PMode, LGDT takes 32 bit linear address. The same is true for SGDT, LIDT/SIDT.
Re: How do I create/load a GDT when I am in PMode?
What pointer are you talking about?trinopoty wrote:One difference, in RMode, LGDT takes 24 bit linear address; in PMode, LGDT takes 32 bit linear address. The same is true for SGDT, LIDT/SIDT.
The GDTP itself, which is size:linear base, thus 48-bit in realmode/pmode, and 80-bit in long mode.
Or the pointer to the GDTP, which is the argument of lgdt. This pointer is an ordinary offset within the current segment (not a linear adress), thus the size depends on the current segment size (unless overridden with a prefix).
Either way, you are wrong.
Re: How do I create/load a GDT when I am in PMode?
I got the result on my own Core 2 Duo machine.Combuster wrote:Utter nonsense. Even if you never heard of operand sizes and prefixes there's no way you're going to explain how you established the above.trinopoty wrote:One difference, in RMode, LGDT takes 24 bit linear address; in PMode, LGDT takes 32 bit linear address. The same is true for SGDT, LIDT/SIDT.
Even using prefix did not help in the case.
Always give a difficult task to a lazy person. He will find an easy way to do it.
- 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: How do I create/load a GDT when I am in PMode?
Proof wanted. At least it gives us an opportunity to point out the bugs that must be present in your code (or brain cells)trinopoty wrote:I got the result on my own Core 2 Duo machine.
Re: How do I create/load a GDT when I am in PMode?
Hi,
Of course in real mode or 16-bit protected mode code you can use an operand size override prefix to get a full 32-bit GDT base address (unless the CPU is an 80286), and in 32-bit protected mode code you can use an operand size override to limit the base address to 24-bit.
Also note that the reason for this "unusual" behaviour is backward compatibility - the 80286 only supported 24-bit addressing, so to make 32-bit CPUs work the same...
Cheers,
Brendan
He's mostly right (although the difference is in operand size, not real mode vs. protected mode). Basically, for LGDT if the operand size is 16-bit the CPU loads a 32-bit base address then masks it so that the upper 8 bits are zero/unused and you end up with a 24-bit GDT base address being loaded, and if the operand size is 32-bit then no masking occurs and a full 32-bit GDT base address is loaded.Combuster wrote:Proof wanted. At least it gives us an opportunity to point out the bugs that must be present in your code (or brain cells)trinopoty wrote:I got the result on my own Core 2 Duo machine.
Of course in real mode or 16-bit protected mode code you can use an operand size override prefix to get a full 32-bit GDT base address (unless the CPU is an 80286), and in 32-bit protected mode code you can use an operand size override to limit the base address to 24-bit.
Also note that the reason for this "unusual" behaviour is backward compatibility - the 80286 only supported 24-bit addressing, so to make 32-bit CPUs work the same...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: How do I create/load a GDT when I am in PMode?
An operand size difference is possible as I tend to not specify any operand size explicitly.
To be honest, I just write the code and let the assembler/compiler generate whatever they want, given that it works as I expect.
When I first saw the problem, I did not care as I knew the kernel will change the GDT later anyway.
To be honest, I just write the code and let the assembler/compiler generate whatever they want, given that it works as I expect.
When I first saw the problem, I did not care as I knew the kernel will change the GDT later anyway.
Always give a difficult task to a lazy person. He will find an easy way to do it.