General Protection Fault

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
Whodoo

General Protection Fault

Post by Whodoo »

I got exceptions and software interrupts working.. and I decided to try some IRQs..so I created a ISR and the stuff in the IDT..but when I unmask the keyboard IRQ (IRQ #1) I get "General Protection Fault".
Any ideas?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:General Protection Fault

Post by Solar »

...your interrupt handling is not working?
Every good solution is obvious once you've found it.
Whodoo

Re:General Protection Fault

Post by Whodoo »

well interrupthandling..isnt that the same thing as exceptions? (something like that)... Ive written a ISR and all that and Im setting up and IDT and all that.. is there something special I need to do when it comes to IRQs (thats different from exception), except of unmasking the IRQ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:General Protection Fault

Post by Solar »

Whatever you did set up to handle IRQ1 generates a General Protection Fault, which is successfully caught by the GPF exception handler. (Or you'd be triple-faulting.) So, yes, your exception handlers do work. Your interrupt handlers don't.

And without additional information, it is difficult to say more.
Every good solution is obvious once you've found it.
Whodoo

Re:General Protection Fault

Post by Whodoo »

My bad, it works better now..
but when an interrupt has occured..what should I do then? Cause the handler runs but then nothing?s happening..I want to return to the code and all that...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:General Protection Fault

Post by Pype.Clicker »

From Help? cannot get Interrupts working... in TroubleShooting category of the FAQ:
* pops everything you push, but no more

Another common source of error at this point comes from misimplementation of ISR in C. Check the InterruptServiceRoutines page for enlightenment ...
Things would be easier if you could provide the handler code. This is an ASM handler, right ? you're not trying to have IRQ directly dispatched to a C function, are you ?
Whodoo

Re:General Protection Fault

Post by Whodoo »

Here?s the code for the ISR
ASM ISR:

[extern _int_21]
[global _int21]
_int21:
pusha
push ds
push es
push fs
push gs
mov eax,0x10
mov ds,eax
mov es,eax

call _int_21 ; C function
pop gs
pop fs
pop es
pop ds
popa
iret

The C function:
void int_21(void)
{
print("A key has been pressed: ", WHITE_TXT);
out(0x20, 0x20);
}

When I hit a key, the message is displayed(wee).. but only once, I cant recieve more than one IRQ..when pressing a key the next time, nothing?s happening..
Curufir

Re:General Protection Fault

Post by Curufir »

I'd check your out(0x20,0x20) is actually doing what it's advertising.
Whodoo

Re:General Protection Fault

Post by Whodoo »

hmm I guess I also need to clear the interrupt at the deviice that caused it? Done by reading an I/O register? But how do I convert the scancode to ascii?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:General Protection Fault

Post by Pype.Clicker »

the keyboard controller has its own internal logic. It delivers an IRQ when a new character becomes available and then waits for the CPU to read the character out of its internal buffer.

If you handle IRQ1 without reading the available byte on port 0x60 (keyboard scancode), the keyboard controller cannot emit another IRQ for the next keystrike.
Post Reply