Acknowledging ISR's
Acknowledging ISR's
I've been wondering about this for a while. Is there any need to 'acknowledge' CPU interrupts handled by ISR's? When I receive a CPU interrupt (and only a CPU interrupt, so interrupts ranging from 0 - 31), the interrupt keeps repeating itself, causing the handler to be called over and over again, hogging up the entire operating system (IRQ's can still be received though). This makes me think there is something wrong with my ISR handler, but I've checked the documentation and read a few websites (like JamesM's, Bran's, the wiki) to see if I did something wrong, alas. The IRQ handlers work fine (probably because master and slave are acknowledged properly).
Any idea's what could cause an infinitely looping CPU interrupt handler? My apologies if this is a stupid question .
Thanks in advance,
Creature
Any idea's what could cause an infinitely looping CPU interrupt handler? My apologies if this is a stupid question .
Thanks in advance,
Creature
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Acknowledging ISR's
If the return IP == the offending code, then if you IRET, the handler will call again since it returns to the bad code.
I'm having a problem with my IRQs, hehe, and it's pissing me off. The timer interrupt won't call!
I'm having a problem with my IRQs, hehe, and it's pissing me off. The timer interrupt won't call!
-
- 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:
Re: Acknowledging ISR's
It depends - are the ISRs exceptions?
If so, depending on the type (trap or fault) the return EIP on the stack is the faulting EIP or the EIP of the next instruction. If it's the faulting EIP then you'll get an exception loop.
If so, depending on the type (trap or fault) the return EIP on the stack is the faulting EIP or the EIP of the next instruction. If it's the faulting EIP then you'll get an exception loop.
Re: Acknowledging ISR's
Yes, like division-by-zero exceptions, page-faults (which is more of a fault), GPF's, ... they all infinitely loop. The IRQ's work fine, however.pcmattman wrote:It depends - are the ISRs exceptions?
If so, depending on the type (trap or fault) the return EIP on the stack is the faulting EIP or the EIP of the next instruction. If it's the faulting EIP then you'll get an exception loop.
So basically, if a process throws an exception, the best thing to do is let the user of the OS know the process 'crashed' somewhere and then shut that process down? In my case there is only one process, and that is the kernel itself, so if it page-faults, my iret will keep bringing me back to the moment before it crashed, where it will just crash again?
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
-
- 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:
Re: Acknowledging ISR's
Things like a division by zero exception are a fault (see Volume 3A of the Intel Manuals - section 5). This means for all intents and purposes the error is unrecoverable.
A page fault is an exception to the rule - you can map in the faulting page - this is how things like copy-on-write work.
A trap may return (for instance, interrupt 3 - Breakpoint exception, which returns to the next instruction after the instruction triggering the breakpoint).
A page fault is an exception to the rule - you can map in the faulting page - this is how things like copy-on-write work.
A fault is a killed process - except for the special page fault case.So basically, if a process throws an exception, the best thing to do is let the user of the OS know the process 'crashed' somewhere and then shut that process down?
A trap may return (for instance, interrupt 3 - Breakpoint exception, which returns to the next instruction after the instruction triggering the breakpoint).
Re: Acknowledging ISR's
So basically I shouldn't try to recover from a division-by-zero exception? What would be the best thing to do when it occurs? Let the user know about it, shutdown the kernel, disable interrupts and halt the processor (something like panic?).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: Acknowledging ISR's
well
you are outh to ( depending on what operation you are doing(if it is a calc the user does))
however i had always thougt about; why not detect what register is the DIV with 0, and change the destance register to 0, and continue execution ?( if it is the os handling the divide by zero error)
KMT dk
you are outh to ( depending on what operation you are doing(if it is a calc the user does))
however i had always thougt about; why not detect what register is the DIV with 0, and change the destance register to 0, and continue execution ?( if it is the os handling the divide by zero error)
KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
Re: Acknowledging ISR's
Best to start with anyway is to dump debug info to screen (exception, regs etc) and halt.
Your own blue screen of death.
Your own blue screen of death.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Acknowledging ISR's
Print your error messages in haiku form!
EDIT: one more post till 1000!
EDIT: one more post till 1000!
-
- 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:
Re: Acknowledging ISR's
Tell me one case where dividing by zero is behavior you expect. There's a reason you get the fault, and that's because there's a bug in the code somewhere. Also, continuing execution means you need to jump to the next instruction, which means you'll need to keep the sizes of all relevant instructions stored somewhere. Not to mention you'll hinder your own debugging if your exception handlers try to fix the problem for you.however i had always thougt about; why not detect what register is the DIV with 0, and change the destance register to 0, and continue execution ?( if it is the os handling the divide by zero error)
I know it sounds really nice to have exception handlers that try to fix the problem (I have thought about it myself), but the error is too context-sensitive to be able to restore an appropriate state.
It's easy enough to just dump the registers, kill the faulting thread(/process) and continue. For extra debugging help you could even do a backtrace
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Acknowledging ISR's
You may also want to report the error to the program using signals or some similar construct. That way if the program can retry whatever that thread was doing before it caused the exception, it can.
Re: Acknowledging ISR's
You could just kill the process that caused it. (Unless it was in the kernel of course.)JohnnyTheDon wrote:You may also want to report the error to the program using signals or some similar construct. That way if the program can retry whatever that thread was doing before it caused the exception, it can.
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Acknowledging ISR's
I know, but you may want to allow the program to try to recover if it can. If it can't recover, or if it chooses not to attempt to recover, then the process will be killed.
-
- 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:
Re: Acknowledging ISR's
I personally feel that's a step you take once you're ready to release to the public, rather than during development when you are trying to debug stuff.I know, but you may want to allow the program to try to recover if it can
But, @Creature: it's up to you how you choose to go about this, we can only give our own opinions (or quote the manuals)
Re: Acknowledging ISR's
Yes, you are right. But it does sound kind of lame to have to panic the entire kernel just because a divide-by-zero exception occurred. But then again, they don't occur in the kernel process or shouldn't occur as I'm the only one programming that process . If someone else (accidentally) causes a division-by-zero exception, I should probably best kill the process that caused it, possibly giving a debug dump with the registers and such.pcmattman wrote:I personally feel that's a step you take once you're ready to release to the public, rather than during development when you are trying to debug stuff.I know, but you may want to allow the program to try to recover if it can
But, @Creature: it's up to you how you choose to go about this, we can only give our own opinions (or quote the manuals)
Thanks for the information .
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.