Interrupt/IRQ problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Whatever5k

Interrupt/IRQ problem

Post 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
Whatever5k

Re:Interrupt/IRQ problem

Post 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...
PlayOS

Re:Interrupt/IRQ problem

Post 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. :(
Whatever5k

Re:Interrupt/IRQ problem

Post by Whatever5k »

[attachment deleted by admin]
Whatever5k

Re:Interrupt/IRQ problem

Post by Whatever5k »

[attachment deleted by admin]
Whatever5k

Re:Interrupt/IRQ problem

Post 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
PlayOS

Re:Interrupt/IRQ problem

Post by PlayOS »

I will look over your code as soon as I can, but now I must go to bed.
Slasher

Re:Interrupt/IRQ problem

Post by Slasher »

try add esp,8
Whatever5k

Re:Interrupt/IRQ problem

Post 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?
Post Reply