Page 1 of 1

qemu crashes upon interrupt

Posted: Sun Mar 10, 2013 11:14 am
by Xandaros
Hey there,
I have some problems getting interrupts to work properly.
Whenever an interrupt fires (I am using the int instruction to test this), qemu simply crashes with this message:

Code: Select all

qemu-system-i386 -kernel kernel.bin
KVM internal error. Suberror: 1
emulation failure
EAX=00101001 EBX=00009500 ECX=000b8000 EDX=000b801e
ESI=00000000 EDI=00108000 EBP=001069f8 ESP=001069e0
EIP=00100094 EFL=00000202 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     00106a08 00000017
IDT=     22000000 000007ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
EFER=0000000000000000
Code=ff ff ff e8 c2 00 00 00 c7 04 24 00 10 10 00 e8 91 00 00 00 <cc> c7 04 24 11 10 10 00 e8 84 00 00 00 eb 01 90 c9 c3 66 90 55 89 e5 83 ec 14 8b 45 08 88
I'm not exactly sure if this is a problem with my code or with my qemu, but for now I'll just assume that my code is not working properly.
I am hosting my kernel on github, so you can easily check it out: https://github.com/Xandaros/Geranium-Du ... ree/faulty
loader.S is the initial file, kmain resides in kernel.c.
The other relevant files are idt.c to setup the IDT; interrupt.c, which contains the interrupt handler(s) and isr.S, which contains the initial assembly handlers, before they get passed to the C handler.

Any idea what could be causing this?
I have tried to use bochs, too, but that doesn't even work properly if I take out the interrupts and just HLTs right away... (with enabled interrupts it triple-faults)

I hope you can help me with this.
If you need more information, please tell me.

Edit: Oh yes... I am using Linux (3.5.0-25-generic x86_64) and I am using a cross-compiler to generate 32bit elf files.

Re: qemu crashes upon interrupt

Posted: Sun Mar 10, 2013 2:05 pm
by Griwes
And what bochs' `info idt` tells you?

Re: qemu crashes upon interrupt

Posted: Sun Mar 10, 2013 3:16 pm
by benjii
Well, the first thing that could lead to crash is that you don't send EOI(End of Interrupt). The second reason is that I don't see where you handle interrupts. If it's software interrupt, you should halt the system or act appropriately, if it's hardware interrupt, just send the EOI. Also, make sure that IDT is loaded correctly.

--benjii

Re: qemu crashes upon interrupt

Posted: Sun Mar 10, 2013 3:21 pm
by Combuster
@Benji:
Forgetting to EOI means you're not getting any further interrupts, and the triple fault has been demonstrated to actually require an interrupt, so it's not a contributory factor here.

You might have prevented another bug from happening though :wink:

Re: qemu crashes upon interrupt

Posted: Mon Mar 11, 2013 5:43 am
by Xandaros
Thanks for the hint with the bochs debugger.
Took me an eternity to set it up and get used to it(I had bochs installed from repo, I recompiled it to have the debugger and the gui), but it showed me the problem.
The pointer to the IDT in the descriptor turned out to be wrong... I forgot to make that struct packed... -_-

Thanks for the help :)

I'm curious now, though: What is it with the EOI? I can have multiple software interrupts after each other without any problem...

Also, while I'm at it: bochs refuses to display anything on the screen. I clear the video RAM and print stuff on it, but in bochs, it just keeps the boot text. qemu on the other hand works flawlessly. I'd like to use bochs, though. That debugger is very useful...

Re: qemu crashes upon interrupt

Posted: Mon Mar 11, 2013 6:21 am
by Combuster
I'm curious now, though: What is it with the EOI?
I_Cant_Get_Interrupts_Working (Hurray for the FAQ - even your original problem is in there)

Re: qemu crashes upon interrupt

Posted: Mon Mar 11, 2013 10:57 am
by Xandaros
Yeah, I didn't set up my PIC at that point. I just did that and it all makes sense now :D

And yes, I knew it needed to be packed. I facepalmed quite a bit after I saw that missing. (Was looking that the actual entries, as that seems the most error-prone to me)

Still need to get my bochs to display some text, though :/