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
Only the first IRQ is handled
-
- Posts: 15
- Joined: Sun Jan 28, 2007 8:45 am
- Location: Somewhere in the infinite dimension universe that my vast imagination is.
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 !
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
Followed by debugging
Coder's nicest thing ...
La programmation modulaire
Une si grande bouffée d'air
Tellement antilinéaire
-
- Member
- Posts: 62
- Joined: Tue Feb 13, 2007 10:46 am
- JackScott
- 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:
-
- Member
- Posts: 199
- Joined: Fri Jul 13, 2007 6:37 am
- Location: Stuttgart/Germany
- Contact:
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():
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!
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);
}
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!
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
So, I´ve just add 'volatile' to my Queue struct variables and it worked. Thank u all again.
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
So, I´ve just add 'volatile' to my Queue struct variables and it worked. Thank u all again.