Page 1 of 1

IDT/IRQ problems

Posted: Sat Jul 02, 2016 4:04 am
by moondeck
So, i have made my IDT setup, tried to fill it with entries, and my ISR code contains an "iret" instruction.
when i run "qemu-system-i386 -kernel kernel.mkern -d in_asm -no-reboot" i see that it stops execution at iret, and then crashes. No such problem occurs when i replace it with "ret".
Could anyone please help me with this?
Code here (irq.c, idt.c and irq.asm files in the arch/i386/ directory):
https://github.com/m00nd3ck/hydrogen

sorry if this is something really stupid

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 4:57 am
by Octocontrabass
Have you tried running it in Bochs yet? The log will give you lots of information about what's going wrong, and you might even be able to figure it out just from that. Post it here if you can't figure it out.

Have you verified that the code you're copying from tutorials is actually correct? Most tutorials have bugs.

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:06 am
by moondeck
Octocontrabass wrote:Have you tried running it in Bochs yet? The log will give you lots of information about what's going wrong, and you might even be able to figure it out just from that. Post it here if you can't figure it out.

Have you verified that the code you're copying from tutorials is actually correct? Most tutorials have bugs.
I didnt try to run it in bochs, i could not figure it out, so i've used QEMU.
Also, yes, i did verify that, but most of my code is actually self-written, i've only used tutorials/manuals as starting points. The ISR code is not copied from anywhere.

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:07 am
by moondeck
last lines of the QEMU logs are:

Code: Select all

IN: idt_install
0x001001b7:  add    $0x10,%esp
0x001001ba:  call   0x100119

----------------
IN: 
0x00100119:  pusha  
0x0010011a:  cld    
0x0010011b:  call   0x100377

----------------
IN: isr
0x00100377:  push   %ebp
0x00100378:  mov    %esp,%ebp
0x0010037a:  sub    $0x8,%esp
0x0010037d:  sub    $0x8,%esp
0x00100380:  push   $0x20
0x00100382:  push   $0x20
0x00100384:  call   0x100493

----------------
IN: outb
0x00100493:  push   %ebp
0x00100494:  mov    %esp,%ebp
0x00100496:  sub    $0x8,%esp
0x00100499:  mov    0x8(%ebp),%edx
0x0010049c:  mov    0xc(%ebp),%eax
0x0010049f:  mov    %dx,-0x4(%ebp)
0x001004a3:  mov    %al,-0x8(%ebp)
0x001004a6:  movzwl -0x4(%ebp),%edx
0x001004aa:  movzbl -0x8(%ebp),%eax
0x001004ae:  out    %al,(%dx)
0x001004af:  nop    
0x001004b0:  leave  
0x001004b1:  ret    

----------------
IN: isr
0x00100389:  add    $0x10,%esp
0x0010038c:  nop    
0x0010038d:  leave  
0x0010038e:  ret    

----------------
IN: 
0x00100120:  popa   
0x00100121:  iret   

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:18 am
by Octocontrabass
moondeck wrote:

Code: Select all

IN: idt_install
0x001001b7:  add    $0x10,%esp
0x001001ba:  call   0x100119

----------------
IN: 
0x00100119:  pusha
You have one function that starts with the "pusha" instruction. What is it? Where is it referenced in idt_install? How is it supposed to be referenced in idt_install?

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:22 am
by moondeck
Octocontrabass wrote:
moondeck wrote:

Code: Select all

IN: idt_install
0x001001b7:  add    $0x10,%esp
0x001001ba:  call   0x100119

----------------
IN: 
0x00100119:  pusha
You have one function that starts with the "pusha" instruction. What is it? Where is it referenced in idt_install? How is it supposed to be referenced in idt_install?
The only instruction with "pusha" that is referenced in idt_install is:

Code: Select all

idt_set_gate(0x20,(unsigned)interrupt(),0x08,0x8E);
could it be that?

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:34 am
by Octocontrabass
Yes. What is that code supposed to do? What is it actually doing?

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:36 am
by moondeck
Octocontrabass wrote:Yes. What is that code supposed to do? What is it actually doing?
Its supposed to put the address of an ISR into an IDT entry, but now that i look at it, it does not do it :D
How can i do it then? I've tried :

Code: Select all

idt_set_gate(0x20,&nterrupt(),0x08,0x8E);
but it does not work, says that an lvalue is required.

Re: IDT/IRQ problems

Posted: Sat Jul 02, 2016 5:44 am
by Octocontrabass
That sounds like a question for Google.