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
Setting a new GDT when kernel is mapped to 4 mb
-
deathangel
- Member

- Posts: 31
- Joined: Thu Apr 14, 2005 11:00 pm
- Location: Planet Earth
- Contact:
Re: Setting a new GDT when kernel is mapped to 4 mb
Can you show some code/bochs debug logs?
-
deathangel
- Member

- Posts: 31
- Joined: Thu Apr 14, 2005 11:00 pm
- Location: Planet Earth
- Contact:
Re: Setting a new GDT when kernel is mapped to 4 mb
Sorry, I put it in assembler and it worked seamlessly. But here is the code anyway:
deathangel
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;
};
}
- carbonBased
- Member

- Posts: 389
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: Setting a new GDT when kernel is mapped to 4 mb
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
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
-
deathangel
- Member

- Posts: 31
- Joined: Thu Apr 14, 2005 11:00 pm
- Location: Planet Earth
- Contact:
Re: Setting a new GDT when kernel is mapped to 4 mb
I am using microsoft Visual C++ compiler 7.10, and Visual C++ Linker 7.10. That is an interesting notion though.
deathangel
deathangel
-
deathangel
- Member

- Posts: 31
- Joined: Thu Apr 14, 2005 11:00 pm
- Location: Planet Earth
- Contact:
Re: Setting a new GDT when kernel is mapped to 4 mb
I forgot to mention that this is in C++, NOT C 
deathangel
deathangel
