Page 1 of 1
Setting a new GDT when kernel is mapped to 4 mb
Posted: Wed Apr 20, 2005 11:00 pm
by deathangel
My kernel is in PE format and loaded at the 4mb mark. When I load a new GDT and jump to the new CS, it triple-faults the CPU. I am in the understanding that this is not possible, as I have tried everything I can think of to get this to work. Does anybody have any suggestions?
Thanks, deathangel
Re: Setting a new GDT when kernel is mapped to 4 mb
Posted: Thu Apr 21, 2005 11:00 pm
by bubach
Can you show some code/bochs debug logs?
Re: Setting a new GDT when kernel is mapped to 4 mb
Posted: Thu Apr 21, 2005 11:00 pm
by deathangel
Sorry, I put it in assembler and it worked seamlessly. But here is the code anyway:
Code: Select all
USHORT GDT[7 * 4] =
{
0x0000, 0x0000, 0x0000, 0x0000,
0xFFFF, 0x0000, 0x9A00, 0x00CF,
0xFFFF, 0x0000, 0x9200, 0x00CF,
0xFFFF, 0x0000, 0xFA00, 0x00CC,
0xFFFF, 0x0000, 0xF200, 0x00CC,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000
};
struct GDTDescriptor
{
USHORT Size;
ULONG Base;
};
VOID InitializeGDT()
{
GDTDescriptor Desc;
Desc.Size = 7 * 8 - 1;
Desc.Base = (ULONG)&GDT;
__asm
{
lgdt Desc;
push 0x08;
push offset l4;
retf
l4:
mov ax, 0x10;
mov ds, ax;
mov es, ax;
mov fs, ax;
mov gs, ax;
};
}
deathangel
Re: Setting a new GDT when kernel is mapped to 4 mb
Posted: Fri Apr 22, 2005 11:00 pm
by carbonBased
What compiler were you using?
I'm guessing the problem may have been with alignment:
struct GDTDescriptor
{
USHORT Size;
ULONG Base;
};
Could get transformed into:
struct GDTDescriptor
{
USHORT Size;
USHORT padding;
ULONG Base;
};
For alignment purposes on optimizing 32-bit compilers.
But, hey, if it's working in assembly... prob'ly not a big deal
Cheers,
Jeff
Re: Setting a new GDT when kernel is mapped to 4 mb
Posted: Wed Apr 27, 2005 11:00 pm
by deathangel
I am using microsoft Visual C++ compiler 7.10, and Visual C++ Linker 7.10. That is an interesting notion though.
deathangel
Re: Setting a new GDT when kernel is mapped to 4 mb
Posted: Wed Apr 27, 2005 11:00 pm
by deathangel
I forgot to mention that this is in C++, NOT C
deathangel