I've looked through the thoroughly confusing AMD manual and managed to come up with this:
Code: Select all
// 64-bit GDT
GDT64:
GDTNull:
.word 0 // Limit (low)
.word 0 // Base (low)
.byte 0 // Base (middle)
.byte 0 // Access
.byte 0 // Granularity / Limit (high)
.byte 0 // Base (high)
GDTCode:
.word 0xFFFF // Limit (low)
.word 0 // Base (low)
.byte 0 // Base (middle)
.byte 0x9A // Access
.byte 0xAF // Granularity / Limit (high)
.byte 0 // Base (high)
GDTData:
.word 0xFFFF // Limit (low)
.word 0 // Base (low)
.byte 0 // Base (middle)
.byte 0x92 // Access
.byte 0xAF // Granularity / Limit (high)
.byte 0 // Base (high)
GDTCodeR3:
.word 0xFFFF // Limit (low)
.word 0 // Base (low)
.byte 0 // Base (middle)
.byte 0xFA // Access
.byte 0xAF // Granulariry / Limit (high)
.byte 0 // Base (high)
GDTDataR3:
.word 0xFFFF // Limit (low)
.word 0 // Base (low)
.byte 0 // Base (middle)
.byte 0xF2 // Access
.byte 0xAF // Granulariry / Limit (high)
.byte 0 // Base (high)
GDTTSS:
.word 0x0068 // Limit (low)
.word 0xF000 // Base (Addr of TSS)
.byte 0x00 // middle
.byte 0xE9
.byte 0x80
.byte 0x00
.long 0x00
.long 0x00
// Pointer
GDT64Pointer:
.word GDT64Pointer - GDT64 - 1 // Limit
.long GDT64 // Base
.long 0
Here's the code I use to load the TSS:
Code: Select all
Memory::Set32((uint8_t*)0xF004, 0x00008000, 1);
asm volatile("push %ax");
asm volatile("mov $0x33, %ax; ltr %ax");
asm volatile("pop %ax");
I'm in long mode btw. Any pointers?
Thanks