Setting a new GDT when kernel is mapped to 4 mb

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
deathangel
Member
Member
Posts: 31
Joined: Thu Apr 14, 2005 11:00 pm
Location: Planet Earth
Contact:

Setting a new GDT when kernel is mapped to 4 mb

Post 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
User avatar
bubach
Member
Member
Posts: 1224
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Setting a new GDT when kernel is mapped to 4 mb

Post by bubach »

Can you show some code/bochs debug logs?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
deathangel
Member
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

Post 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
User avatar
carbonBased
Member
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

Post 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
deathangel
Member
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

Post by deathangel »

I am using microsoft Visual C++ compiler 7.10, and Visual C++ Linker 7.10. That is an interesting notion though.

deathangel
deathangel
Member
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

Post by deathangel »

I forgot to mention that this is in C++, NOT C ;-)

deathangel
Post Reply