Only the first IRQ is handled

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
hstagni
Posts: 6
Joined: Sat Nov 03, 2007 12:52 pm

Only the first IRQ is handled

Post by hstagni »

OK.
I made the GDT and the IDT, and I´m already handling exceptions. Then, I was trying to test if IDT was working. After remapping the PIC, made something like:
---------------------------------------------------------------------
SetIDTGate(32, (unsigned long)Irq0, CODE_SEG, IS_PRESENT, 0);
SetIDTGate(33, (unsigned long)Irq1, CODE_SEG, IS_PRESENT, 0);

And function Irq0 and Irq1 are:
void Irq0{
puts("IRQ0 fired");
outportb(0x20, 0x20); /*END OF INTERRUPT master controller*/
}
void Irq1{
puts("IRQ1 fired");
outportb(0x20, 0x20); /*END OF INTERRUPT master controller*/
}
------------------------------------------------
I was running it and the only a single message "IRQ0 fired" was on the screen. This was expected, cause I didnt programmed the PIT, so I guess it fires just once(doesnt it?). But I tried to hit some keys and nothing happened.
I know I am missing something but everything seems quite logical to me: I hit a key-> CPU recieves an IRQ-> My IDT is checked and there is my Irq1 function address, but the function is never called.

What am I missing??????????????????????

sorry for my poor english
synthetix
Posts: 15
Joined: Sun Jan 28, 2007 8:45 am
Location: Somewhere in the infinite dimension universe that my vast imagination is.

Post by synthetix »

Hi hstagni, I had this error before and I may be able to help you solve it.

First, if your IRQ stubs are in assembly, look for parameter order inversion:

C handler:

void IRQHandler(unsigned char IRQNumber,unsigned char IRQErrorCode);

Assembly stub:

cli
push IRQNumber
push ErrorCode ; not to do if the irq returns one already
sti

This assembly code passes the parameters in the wrong order, if your dummy error code is 0.
My dummy error code was 32, and I was passing the ISR number (IRQNumber + 32) so that my C handler would substract 32 from it. As you can imagine, I was only getting IRQs for the timer.

It should be:

cli
push ErrorCode ; not to do if the irq returns one already
push IRQNumber
sti

If it still does not work, the sources of your os could be helping. I hope it helps you !
The joys of coding
Followed by debugging
Coder's nicest thing ...

La programmation modulaire
Une si grande bouffée d'air
Tellement antilinéaire
uglyoldbob
Member
Member
Posts: 62
Joined: Tue Feb 13, 2007 10:46 am

Post by uglyoldbob »

I thought all interrupt handlers had to return using "iret".
I have an 80386SX 20MHz 2MB RAM.
It is my testbed platform. Only has the 3.5" and 5.25" floppy drives.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Make sure you send the EOI to the controller (output 0x20 to port 0x20 for the first controller, and I can't rememeber what to do for the second one... :shock:).
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post by JackScott »

If it is IRQ 0-7, send to master controller only.
If it is IRQ 8-15, send to master and slave controllers.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

by the way, when you're writing an isr for the keyboard, also make sure you actually read the scancode, even if you're "sending it to /dev/null" :-)
hstagni
Posts: 6
Joined: Sat Nov 03, 2007 12:52 pm

Post by hstagni »

It Worked! I was missing iret, so I had to write an ASM function that calls the handler that is in an handler array.
Everything worked fine, I was typing, words appeared on screen and the screen was scrolling correctly.

But I have a problem with keyboard now. My ISR for keyboard is storing chars in a queue. Then I made a function getchar():

Code: Select all

int getchar()
{
       while(IsEmpty(&KeyBuffer)); /*while key queue is empty, waits*/
       return Dequeue(&KeyBuffer);
}
It doesnt work
I checked the code hundreds of time. I printed some lines, and I discovered the KeyBuffer queue is **NOT** empty, but my 'kernel' keeps stuck in "while(IsEmpty(&KeyBuffer));".
Then, I writed some putchars inside "while(IsEmpty(&KeyBuffer));" and it magicly worked. Why? Should I put some kind of delay inside this while? Is it normal?


Anyway, thanks a lot for helping me!
hstagni
Posts: 6
Joined: Sat Nov 03, 2007 12:52 pm

Post by hstagni »

Ok, I´ve just read this:
http://publications.gbdirect.co.uk/c_bo ... atile.html

This site has an section showing why keyword volatile was created, and it looks just like my getchar function :D

So, I´ve just add 'volatile' to my Queue struct variables and it worked. Thank u all again.
Post Reply