OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: IRQ1 is not triggered when button is pressed
PostPosted: Sat Oct 02, 2021 4:54 pm 
Offline

Joined: Sat Oct 02, 2021 4:12 pm
Posts: 2
Hi, I'm new here and I'm also a newbie hobbyist OS developer.

I'm stuck at the IDT setup, the keyboard IRQ is not triggered when i press some keyboard button, I tried to fix it for a couple of days, had to understand a bit more about the PIC and why we need to remap the PIC IRQ lines to another offset in the IDT.

The weird thing is: the timer driver gets triggered (I don't know if it's being triggered once or more times, I did not manage to test it), but the keyboard driver routine is not being triggered (when I press some button). Both routines were loaded into an array of interrupt_handlers and the interruptions are being routed by a common irq_handler function, link to the code: https://github.com/ifest1/osdev/blob/main/cpu/idt.c

This common irq_handler is being called by the ISR routines in ASM inside a isr_common_stub which enables us to use a common irq_handler triggered by every interrupt. The ISR routines are created using three ASM macros, one for ISR with no error code pushed onto the stack, one for ISR's that the CPU pushes the error code onto the stack and the last one is for the devices IRQ's lines, 32 up to 47.
This is done here: https://github.com/ifest1/osdev/blob/ma ... errupt.asm

Back to the idt.c file, function idt_init the flow is:
- set_idt_gate for each ISR routine imported from interrupt.asm
- initialize the two PIC's master and slave, set cascade on master IRQ 2 and pass the identity to the second PIC, code: https://github.com/ifest1/osdev/blob/main/cpu/pic.c#L5
- set the idt pointer
- pass the idt pointer to the CPU
- init IRQ lines (masking the PIC's bits in the data port of each PIC)
- enable interrupts (asm sti)

Does anybody knows how can I debug this?


Top
 Profile  
 
 Post subject: Re: IRQ1 is not triggered when button is pressed
PostPosted: Sun Oct 03, 2021 8:29 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
The most useful way to debug is to use a debugger (e.g. gdb) in conjunction with a virtual machine (e.g. emu). This will let you single-step through code, set breakpoints and examine variables and any other RAM. The qemu monitor is also a useful source of information.

Common causes of interrupts not functioning are improper masking in the PIC and failure to acknowledge the interrupt. I do wonder if the line
Code:
if (irq_line >= 7)
is what you intended as it make the code
Code:
else if (8 <= irq_line <= 15) {
        pic_data_port = PIC2_PORT_A + 1;
        irq_line -= 8;
    }
redundant.


Top
 Profile  
 
 Post subject: Re: IRQ1 is not triggered when button is pressed
PostPosted: Sun Oct 03, 2021 1:23 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Do you flush the keyboard controller's output buffer? You'll only receive IRQ1 when the keyboard controller's output buffer is filled. If the output buffer is already full when you initialize the interrupt controllers and you never empty it, you'll never receive IRQ1.


Top
 Profile  
 
 Post subject: Re: IRQ1 is not triggered when button is pressed
PostPosted: Mon Oct 04, 2021 9:27 am 
Offline

Joined: Sat Oct 02, 2021 4:12 pm
Posts: 2
Hey I found the issue... I forgot to implement the EOI PIC signaling after get the interruption handler fired. I also fixed the redundant conditionals, thank you folks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Amazonbot [bot], DotBot [Bot], SemrushBot [Bot] and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group