Linux Kernel Code view
http://androidxref.com/
Interrupt: An event that is defined to change the order in which the processor executes instructions. It corresponds to the electrical signals generated by the circuitry of the hardware (CPU, other hardware devices). Synchronous interrupts: The CPU control unit is generated when the instruction is executed, which is called synchronization because the CPU does not emit interrupts until one instruction terminates execution. is also known as an exception
Asynchronous interrupts: Other hardware devices are randomly generated according to the CPU clock signal. also by abbreviation interrupted
Interrupt constraint: 1, interrupt must be completed as soon as possible; interrupts are typically performed in two parts: critical and urgent, the kernel executes immediately, and the rest of the kernel executes later;
2, the processing of interrupts must be able to meet the nesting, that is, when an interrupt is being processed, another interrupt has occurred, you must try to support
3, the interruption can be banned, but must be as limited as possible to use
Interrupt: Shielded interrupt, unshielded interrupt
Exception: Processor detection exception (fault, Trap, abort), programming exception
The motive for introducing the signal:
How IRQ (Interrupt Request) causes interrupts:
IRQ: A hardware device that can make an interrupt request is also called an IRQ for the output line;
IRQ Line: Connected to the input pin of the hardware circuit of the programmable interrupt controller.
Programmable Interrupt Controller (IPC):
1, monitor the IRQ line, if two or more IRQ line generated signal, select the PIN number is small
2, if only one trigger signal a, convert it to the corresponding vector, B, the vector is stored in the interrupt controller's IO port, allowing the CPU to read through the data bus, C, send the trigger signal to the processor's INTR pin, which generates an interrupt
D, wait until the CPU passes. This interrupt signal is written to a i\o port of the programmable interrupt controller to confirm it and clear the Intr line;
3, return to the first step.
I/o APIC (I/O Advanced Programmable Interrupt Controller):
How the 80x86 microprocessor handles interrupts and exceptions at the hardware level:
Structure of the exception handler:
1. Save the contents of most registers in the kernel stack
2. Handling exceptions with advanced C functions
3. Exit from the exception handler through the Ret_from_exception () function.
If the interrupt structure must be initialized with a data structure:
Before the kernel enables interrupts, the initial address of the IDT (interrupt descriptor) must be loaded into the IDTR register and each of them is initialized. It needs to be completed when the system is initialized.
The initialization of IDT:
1, when the computer is still running in real mode, IDT is initialized, used by the BIOS routines,
2. After the Linux takeover, IDT is moved to an area of RAM and is initialized two times.
During kernel initialization, an interrupt gate is used to populate the IDT 256 table entries, and then replace it with a meaningful trap and interrupt handler.
Once the initialization is complete, there is a dedicated interrupt gate for each pic-confirmed Irq,idt.
How to process interrupt signals at the software level:
Interrupt Processing Flow:
1. Hardware notify pic via IRQ line
2. pic puts the interrupt vector into the register
3, the processor read registers, such as RAM. By interrupt handling routine processing (ISR)
4. Notify pic
Note: Before the kernel is enabled for interrupts, you must know the correspondence between the IRQ number and the I/O device, otherwise the kernel does not know which device the vector corresponds to, if it is processed.
The corresponding relationship between the IRQ number and the device is established when the device driver is initialized.
Deep understanding of the Linux kernel-interrupts and exceptions