Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interrupts and exceptions

Tags:

I've seen several question on here about exceptions, and some of them hint at interrupts as exceptions, but none make the connection clear.

  • What is an interrupt?

  • What is an exception? (please explain what exceptions are for each language you know, as there are some differences)

  • When is an exception an interrupt and vice-versa?

like image 976
Adam Davis Avatar asked Sep 24 '08 04:09

Adam Davis


People also ask

What is the difference of interrupt and exception in arm?

One way to distinguish between the two is that an exception is an event (other than branch or jump instructions) that causes the normal sequential execution of instructions to be modified. An interrupt is an exception that is not caused directly by program execution.

What is the main difference between a trap exception and an interrupt?

The difference between a trap and an interrupt is that a trap is triggered by a user program to invoke OS functionality. Still, an interrupt is triggered by a hardware device to allow the processor to execute the corresponding interrupt handler routine.

How is interrupt handled in exception?

When an exception or interrupt occurs, your processor may perform the following actions: move the current PC into another register, call the EPC. record the reason for the exception in the Cause register. automatically disable further interrupts or execptions from occuring, by left-shifting the Status register.


1 Answers

Your processor is going to have a number of external interrupt pins. Typically these pins are connected to hardware and are used to indicate when some external event occurs. For example, if you are using a serial port the UART will raise raise a pin that is connected to one of the interrupt pins on the processor to indicate that a byte has been received.

Other peripherals like timers, usb controllers, etc. will also generate interrupts on the basis of some external event.

When the processor receives a signal on one of it's external interrupt pins it will immediately jump to some nominated location in memory and start executing. The code executed is typically called an ISR, or interrupt service routine. Unless you're implementing drivers or doing embedded software of some sort it's unlikely that you'll ever come across ISRs.

Unfortunately the answer to the question about exceptions is a little less clear - there have been 3 different meanings listed in other answers on this page.

Ron Savage's answer refers to the software construct. This is purely an application level exception, where a piece of code is able to indicate an error that can be detected by some other piece of code. There is no hardware involvement here at all.

Then there is the exception as seen by a task. This is an operating system level construct that is used to kill a task when it does something illegal - like divide by 0, illegally accessing memory etc.

And thirdly, there is the hardware exception. In terms of behaviour it is identical to an interrupt in that the processor will immediately jump to some nominated memory location and start executing. Where an exception differs from an interrupt is that an exception is caused by some illegal activity that the processor has detected. For example the MMU on the processor will detect illegal memory accesses and cause an exception. These hardware exceptions are the initial trigger for the operating system to perform it's cleanup tasks (as described in the paragraph above).

like image 84
Andrew Edgecombe Avatar answered Sep 28 '22 18:09

Andrew Edgecombe