Page 1 of 1

Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 5:00 am
by Whatever5k
It seems I have big problems with interrupt handling (at least when using
Bochs).
I have built an IDT, and have a function that changes the ISR for a
certain interrupt number. And I remapped the PICs to 0x20.
Ok, so first of all, I disable interrupts (cli). I change the ISR for the
keyboard, enable the irq (by sending such message to PIC) and finally, I
enable interrupts (sti).
Ok, but if I press a key, sometimes nothing happens.
Still, sometimes I see the proprietage message. Look at my code, this is
the ISR:

Code: Select all

[global int_irq1]
int_irq1:
   EXTERN printk
   
   cli
   
   push eax
   mov eax, msg
   push eax

   call printk

   mov al,0x20
   out 0x20,al

   add esp,4
   pop eax

   sti
   iretd


msg dw "IRQ1", "0"

That's the interrupt handler. And here's the C code:

Code: Select all

   remap_pics(0x20, 0x28);
   printk("PICs remapped: IRQs starting at interrupt 0x20\n\n");
   
   printk("Enabling IRQ1\n");
   changeISR(0x21, (void*) int_irq1);
   enable_irq(1);
   printk("Enabling interrupts...\n");
   asm("sti");

Ok, should be clear. So, why doesn't it work always and correctly? It
might be, that the printk() function is bad. This function does a call to
my own vsprintf() and then to putc(). There is no mutex handling and no
interrupts enable/disable.

Please help me, I'm really stuck with that!
Thanks and regards,
A. Blessing

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 8:56 am
by Whatever5k
Come on..please help me...
There are certainly persons who are able to help...
The problem is: when I boot from the BIOS who loads GRUB, everything is fine...but not with Bochs...

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:09 am
by PlayOS
Whatever5k wrote: .....
???add esp,4
.....
What is this 'add esp, 4' here for? Also, have you tried using IRET instead of IRETD?

I cannot really see anything wrong with your code if these two things are not problems. sorry. :(

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:17 am
by Whatever5k
[attachment deleted by admin]

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:18 am
by Whatever5k
[attachment deleted by admin]

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:19 am
by Whatever5k
I think when processing printk(), an interrupt occurs. My interrupt handler also call printk(). So they may conflict...how to solve that?

And when I boot it with GRUB, it works - but not with Bochs...why?
Also, when I run it with Bochs and keep pressing the keys, when I have keeped pressing the keys for, say 9 seconds, there's a segmentation fault.
In bochsout.txt there's this here:

00031887030e[CPU ] prefetch: running in bogus memory

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:27 am
by PlayOS
I will look over your code as soon as I can, but now I must go to bed.

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:29 am
by Slasher
try add esp,8

Re:Interrupt/IRQ problem

Posted: Sat Sep 28, 2002 9:31 am
by Whatever5k
Hm, I have changed the code to:

Code: Select all

[global int_irq1]
int_irq1:
        EXTERN irq1
        cli     ; disable interrupts while processing

        pushad

        call irq1

        mov al,0x20
        out 0x20,al

        popad
        sti     ; reenable interrupts
        iretd
and the C-function:

Code: Select all

void irq1(void)
{
        int scan;
        
        scan = inb(0x60);
        printk("IRQ1\n");
}
I think this function is better...what do you think?