Interrupts and exceptions

Exceptions

From Exceptions at Wikipedia:

Exception handling in the IEEE 754 floating point hardware standard refers in general to exceptional conditions and defines an exception as “an event that occurs when an operation on some particular operands has no outcome suitable for every reasonable application. That operation might signal one or more exceptions by invoking the default or, if explicitly requested, a language-defined alternate handling.”

The IEEE 754 standard uses the term “trapping” to refer to the calling of a user-supplied exception-handling routine on exceptional conditions, and is an optional feature of the standard.

A trap, also known as an exception or a fault, is typically a type of synchronous interrupt caused by an exceptional condition (e.g., breakpoint, division by zero, invalid memory access).

Interrupts

From Interrupts page at Wikipedia

In digital computers, an interrupt is an input signal to the processor indicating an event that needs immediate attention. An interrupt signal alerts the processor and serves as a request for the processor to interrupt the currently executing code, so that the event can be processed in a timely manner. If the request is accepted, the processor responds by suspending its current activities, saving its state, and executing a function called an interrupt handler (or an interrupt service routine, ISR) to deal with the event. This interruption is temporary, and, unless the interrupt indicates a fatal error, the processor resumes normal activities after the interrupt handler finishes.

Interrupt handlers have a multitude of functions, which vary based on what triggered the interrupt and the speed at which the interrupt handler completes its task. For example, pressing a key on a computer keyboard, or moving the mouse, triggers interrupts that call interrupt handlers which read the key, or the mouse’s position, and copy the associated information into the computer’s memory.

Find here The Linux Kernel Module Programming Guide, Chapter 12. Interrupt Handlers and Linux Device Drivers, Chapter 10. Interrupt Handling deep information about how interrupts are handled in Linux.

Interrupt Descriptor Table (IDT)

Rather than using a hard-coded interrupt dispatch table at the hardware level, software interrupts are often implemented at the operating system level as a form of callback function.

The Interrupt Descriptor Table (IDT) is a data structure used by the x86 architecture to implement an interrupt vector table. The IDT is used by the processor to determine the correct response to interrupts and exceptions.

The Interrupt Descriptor Table (IDT), holds a list of descriptors (pointers) that point to the functions that handle the particular interrupt or exception. These functions are called the interrupt or exception handlers. When an interrupt or exception occurs, it has a particular value, called an identifier or vector. The next table contains a list of the defined interrupt vectors.

Identifier Description
0 Divide error
1 Debug exception
2 Non-maskable interrupt
3 Breakpoint
4 Overflow
5 Bounds check
6 Invalid opcode
7 Coprocessor not available
8 Double fault
9 (reserved)
10 Invalid TSS
11 Segment not present
12 Stack exception
13 General protection fault
14 Page fault
15 (reserved)
16 Coprocessor error
17 alignment error (80486)
18-31 (reserved)
32-255 External (HW) interrupts

In Linux, the IDT is informed in idt.c

Mapping exceptions to signals

Some of these hardware exceptions are mapped to signals in the Linux kernel code.

Find in traps.h how they are “named” in the Linux Kernel. Inside the file traps.c defines some handlers that map some signals to exceptions

When we follow the divide_error routine in file entry_32.S, we see it that it will junp to the do_divide_error in file traps_32.c. As we can see, the signal table (siginfo_t) is informed with the SIGFPE signal (info.si_signo = SIGFPE;)

Interrupts Exceptions and Traps
http://www.linux-tutorial.info/modules.php?name=MContent&pageid=86

What is the difference between Trap and Interrupt?
https://stackoverflow.com/questions/3149175/what-is-the-difference-between-trap-and-interrupt

https://en.wikipedia.org/wiki/Signal_(IPC)#Relationship_with_hardware_exceptions

Very old information…
http://cs-pub.bu.edu/fac/richwest/cs591_w1/notes/wk1.pdf#page=17