Octocontrabass wrote:
All you have is the interrupt number? That's not enough information to figure out what's wrong. Shouldn't your exception handlers tell you more than that?
Since you're using QEMU, you can run it with "-d int" (and maybe also "-no-reboot") to log detailed information about every interrupt.
Here are some other problems I saw in your code:
I fixed a few of these issues, and as per your suggestion I ran qemu with "-d int". The last exception I got gave the following:
Code:
check_exception old: 0xffffffff new 0xd
1: v=0d e=0102 i=0 cpl=0 IP=0008:00200057 pc=00200057 SP=0010:00207000 env->regs[R_EAX]=00000000
EAX=00000000 EBX=00009500 ECX=000003d5 EDX=000003d5
ESI=00000000 EDI=00002000 EBP=00000000 ESP=00207000
EIP=00200057 EFL=00000202 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 002016c7 00000017
IDT= 00207010 00003fff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00206fe0 CCO=EFLAGS
EFER=0000000000000000
I'm in the process of deciphering this all, but if you spot anything immediately wrong with it, that would be super helpful. If I'm correct, it looks like the error code (e=0x0102 -> 0000100000010) indicates that it's referencing an index in the GDT and originated from within the processor?
I'm working on disassembling the OS image, and looking at the addresses around where the exception occurred (0x00200057 + 0x0008), but I'm kind of at a loss at this point.
Edit: I've done some digging, and I traced the problem back to where I call the `lgdt` command:
Code:
Dump of assembler code from 0x200028 to 0x200060:
0x00200028: sbb %eax,(%eax)
0x0020002a: add %al,(%eax)
0x0020002c: add %al,(%eax)
0x0020002e: add %al,(%eax)
0x00200030 <_start+0>: mov $0x207000,%esp
=> 0x00200035 <_start+5>: lgdtl 0x2016df
0x0020003c <_start+12>: mov $0x10,%ax
0x00200040 <_start+16>: mov %eax,%ds
0x00200042 <_start+18>: mov %eax,%es
0x00200044 <_start+20>: mov %eax,%fs
0x00200046 <_start+22>: mov %eax,%gs
0x00200048 <_start+24>: mov %eax,%ss
0x0020004a <_start+26>: ljmp $0x8,$0x200051
0x00200051 <_start+33>: call 0x2016b0 <main>
0x00200056 <_start+38>: hlt
0x00200057 <_start+39>: jmp 0x200056 <_start+38>
0x00200059 <_start.end+0>: xchg %ax,%ax
0x0020005b <_start.end+2>: xchg %ax,%ax
0x0020005d <_start.end+4>: xchg %ax,%ax
0x0020005f <_start.end+6>: nop
End of assembler dump.
I find this weird, since before I added interrupt / exception handling, my program ran completely fine, and the GDT looks like it's been set up correctly (although that might just be from GRUB). I thought my GDT was fine, I don't know what's wrong with it.