I have been trying to debug it for 3 days now and I'm getting a little frustrated.
I think my gdt_ptr is broken. Bochs outputs the following:
Code: Select all
00022021485e[CPU0 ] load_seg_reg(DS, 0x0010): invalid segment
00022021485e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00022021485e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00022021485i[CPU0 ] CPU is in protected mode (active)
00022021485i[CPU0 ] CS.d_b = 32 bit
00022021485i[CPU0 ] SS.d_b = 32 bit
00022021485i[CPU0 ] EFER = 0x00000000
00022021485i[CPU0 ] | RAX=0000000000100010 RBX=0000000000002000
00022021485i[CPU0 ] | RCX=00000000000000c0 RDX=00000000000000f2
00022021485i[CPU0 ] | RSP=0000000007feff68 RBP=0000000007feff94
00022021485i[CPU0 ] | RSI=0000000000000000 RDI=0000000000000000
00022021485i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00022021485i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00022021485i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00022021485i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00022021485i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00022021485i[CPU0 ] | SEG selector base limit G D
00022021485i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00022021485i[CPU0 ] | CS:0020( 0004| 0| 0) 00000000 ffffffff 1 1
00022021485i[CPU0 ] | DS:0028( 0005| 0| 0) 00000000 ffffffff 1 1
00022021485i[CPU0 ] | SS:0028( 0005| 0| 0) 00000000 ffffffff 1 1
00022021485i[CPU0 ] | ES:0028( 0005| 0| 0) 00000000 ffffffff 1 1
00022021485i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 00000000 0 0
00022021485i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 00000000 0 0
00022021485i[CPU0 ] | MSR_FS_BASE:0000000000000000
00022021485i[CPU0 ] | MSR_GS_BASE:0000000000000000
00022021485i[CPU0 ] | RIP=0000000000100039 (0000000000100039)
00022021485i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
00022021485i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00022021485e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
GDT[0x00]=??? descriptor hi=0x00000000, lo=0x00000000
GDT[0x01]=??? descriptor hi=0xcf9a0000, lo=0x0000ffff
GDT[0x02]=??? descriptor hi=0xcf920000, lo=0x0000ffff
GDT[0x03]=??? descriptor hi=0xcffa0000, lo=0x0000ffff
GDT[0x04]=??? descriptor hi=0xcff20000, lo=0x0000ffff
Code: Select all
global gdt_flush
gdt_flush:
mov eax, [esp+4]
lgdt [eax]
mov ax, 0x10
mov ds, ax <--- triple fault here
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2
flush2:
ret
Code: Select all
void Gdt::install()
{
gdt_ptr.limit = (sizeof(gdt_entry_t) * 5) - 1;
gdt_ptr.base = (unsigned int) &gdt_entries;
set_gate(0, 0, 0, 0, 0);
set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
gdt_flush((unsigned int) &gdt_ptr);
}
Thanks in advance
dukedevon