[SOLVED] GPF when calling ISR
Posted: Sat Jun 28, 2014 6:49 am
UPDATE: This is solved. The initial long mode GDT had both size bit and long bit set to 1. The size bit has to be 0 for long mode to be valid.
I'm playing around with a x86_64 higher half kernel and trying to get interrupts working. The kernel enters long mode, installs an IDT successfully and busy waits. I registered an ISR for the keyboard but keep getting General Protection Fault when I press a key or manually generate an interrupt. The GPF was generated upon calling the ISR, not when returning from it.
I'm fairly new to x86_64 and am pretty confused on why segmentation still seems to have come into play.
Here's a consecutive snippet of QEMU log, generated using "-d int"
// This is the manual "int $1"
0: v=01 e=0000 i=1 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
// First GPF
check_exception old: 0xffffffff new 0xd
1: v=0d e=0012 i=0 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
// Second GPF
check_exception old: 0xd new 0xd
2: v=08 e=0000 i=0 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
check_exception old: 0x8 new 0xd
// Triple faults and resets
Any help would be appreciated, thanks!
I'm playing around with a x86_64 higher half kernel and trying to get interrupts working. The kernel enters long mode, installs an IDT successfully and busy waits. I registered an ISR for the keyboard but keep getting General Protection Fault when I press a key or manually generate an interrupt. The GPF was generated upon calling the ISR, not when returning from it.
I'm fairly new to x86_64 and am pretty confused on why segmentation still seems to have come into play.
Here's a consecutive snippet of QEMU log, generated using "-d int"
// This is the manual "int $1"
0: v=01 e=0000 i=1 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
// First GPF
check_exception old: 0xffffffff new 0xd
1: v=0d e=0012 i=0 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
// Second GPF
check_exception old: 0xd new 0xd
2: v=08 e=0000 i=0 cpl=0 IP=0008:ffffffff8010e730 pc=ffffffff8010e730 SP=0010:ffffffff8010bfb0 env->regs[R_EAX]=ffff801680000fff
RAX=ffff801680000fff RBX=0000000000000000 RCX=00000000001bfeb0 RDX=00000000ffff00a1
RSI=0000ffffffff8010 RDI=000000000000008b RBP=ffffffff8010bff0 RSP=ffffffff8010bfb0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=00000000001bfea0 R15=0000000000000008
RIP=ffffffff8010e730 RFL=00200246 [---Z-P-] CPL=0 II=1 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
CS =0008 0000000000000000 00000000 00609a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
DS =0010 0000000000000000 00000000 00609300 DPL=0 DS [-WA]
FS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0018 0000000000000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT= ffffffff801001b0 00000017
IDT= ffffffff80168000 00000fff
CR0=80000011 CR2=0000000000000000 CR3=0000000000101000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0001ffffffff0021 CCD=0000ffffffff8010 CCO=CLR
EFER=0000000000000500
check_exception old: 0x8 new 0xd
// Triple faults and resets
Any help would be appreciated, thanks!