⇤ ← Revision 1 as of 2006-09-18 14:36:11
Size: 6379
Comment:
|
Size: 6310
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
- Introduction - CPU Support for Handling Interrupts | 1. Introduction 1. CPU Support for Handling Interrupts 1. Details of Programmable Interrupt Controller 1. Hardware checks performed by CPU 1. Details of Interrupt Descriptor Table 1. Task Gates 1. Trap Gates 1. Interrupt Gates 1. Kernel Support for Handling Interrupts 1. Low Level Interrupt Stubs - Details of do_IRQ() function, core of Interrupt Handling |
Line 7: | Line 16: |
- Details of Programmable Interrupt Controller - Hardware checks performed by CPU - Details of Interrupt Descriptor Table - Task Gates - Trap Gates - Interrupt Gates - Kernel Support for Handling Interrupts - Low Level Interrupt Stubs - Details of do_IRQ() function, core of Inteuupt Handling __'''Introduction'''__ |
__'''1. Introduction'''__ |
Line 29: | Line 28: |
'''__CPU's support for handling interrupts__''' | '''__2. CPU's support for handling interrupts__''' |
Line 31: | Line 30: |
For handling interrupts there are few of the things which we expect theCPU to do on occurence of every interrupt. Whenever an interrupt occurs,CPU performs some of the hardware checks, which are very much needed tomake the system secure. Before explaining the hardware checks, we willunderstand how the interrupts are routed to the CPU from hardwaredevices. | For handling interrupts there are few of the things which we expecttheCPU to do on occurence of every interrupt. Whenever an interruptoccurs,CPU performs some of the hardware checks, which are very muchneeded tomake the system secure. Before explaining the hardware checks,we willunderstand how the interrupts are routed to the CPU fromhardwaredevices. |
Line 33: | Line 32: |
'''''Details of Programmable Interrupt Controller''''' On Intel architecture, system devices (device controllers) areconnected to a special device known as PIC (Programmable Interrupt Controller). CPU have two lines for receiving interrupt signals (NMIand INTR). NMI line is to recieve non-maskable interrupts; the interrupts which can not be masked, means which can not be blocked atany cost. These interrupts are of hightest priority and are rarelyused. INTR line is the line on which all the interrupts from system devices are received. These interrupts can be masked or blocked. As allthe interrupt signals need to be multiplxed on single CPU line, we needsome mechanisum through which interrupts from different device controllers can be routed to single line of CPU. This routing or multiplexing is done PIC (Programmable Interrupt Controller). PIC sits between system devices and CPU and have multiple input lines; each line connected to different divice contollers in system. On other hand IPC have only one output line which is connected to the CPU's INTR line on which it sends signal to CPU. |
'''''2a) Details of Programmable Interrupt Controller''''' |
Line 36: | Line 34: |
There are two PIC controllers joined together and the output of second PIC controller is connected tothe second input of first PCI. This setup allows maximum of 15 input lines on which different system device controllers can be connected. PIC have some programmable registers, through which CPU communicates with it (give command, mask/unmask interrup lines, read status). Both PICs have their own following registers: | On Intel architecture, system devices (devicecontrollers)areconnectedto a special device known as PIC (Programmable Interrupt Controller). CPU have two lines for receiving interrupt signals(NMIandINTR). NMIline is to recieve non-maskable interrupts; theinterruptswhich cannot be masked, means which can not be blocked atanycost.Theseinterrupts are of hightest priority and are rarelyused. INTRlineisthe line on which all the interrupts from system devicesarereceived.These interrupts can be masked or blocked. As alltheinterruptsignalsneed to be multiplxed on single CPU line, weneedsomemechanisumthrough which interrupts from different devicecontrollerscan berouted to single line of CPU. This routing ormultiplexing isdone PIC(Programmable Interrupt Controller). PIC sitsbetween systemdevicesand CPU and have multiple input lines; each lineconnected todifferentdivice contollers in system. On other hand IPChave only oneoutputline which is connected to the CPU's INTR line onwhich it sendssignalto CPU. There are two PIC controllers joinedtogether and theoutput ofsecond PIC controller is connected tothesecond input of firstPCI.This setup allows maximum of 15 input lines onwhich differentsystemdevice controllers can be connected. PIC havesomeprogrammableregisters, through which CPU communicates with it(givecommand,mask/unmask interrup lines, read status). Both PICs havetheirownfollowing registers: |
Line 38: | Line 36: |
- Mask Register - Status Register |
Mask Register |
Line 41: | Line 38: |
Mask register is used to mask/unmask a specific interrupt line. CPU can ask the PIC to mask (block) the specific interrupt by setting the corresponding bit in mask register. Unmasking can be done by clearing that bit. When a particular interrupt is being masked, PIC do receive the interrupts on its corresponding input line, but do not send the interrupt singnal to CPU in which case CPU keeps on doing what it was doing. When an interrupts are being masked, they are not lost, rather PIC remembers those and do send the interrupt to CPU when CPU unmasks that interrupt line. Masking is different from blocking all the interrupts toCPU. CPU can ignore all the interrupts coming on INTR line by clearing the IF (Interrupt Falg) flag in EFLAGS register of CPU. When this bit is cleared, interrupts coming on INTR line are simply ignored by CPU, we can consider it to be blocking of interrupts. So now we understand that masking is done at PIC level and individual interrupt lines can be masked or unmasked,where as blocking is done at CPU level and is done for all the interrupts coming to taht CPU except NMI (Non-Maskable Interrupt), which is received on NMI line of CPU and can not be blocked or ignored. | Status Register |
Line 43: | Line 40: |
Now days,interrupt architecture is not as simple as shown above. Now days machines uses the APIC (Advanced Programmable Interrupt Controller), which can support upto 256 interrupt lines. Along with APIC, every CPU also have inbuilt IO-APIC. I won't go into details of these right now. | Mask register is used to mask/unmask a specific interrupt line.CPUcanask the PIC to mask (block) the specific interrupt bysettingthecorresponding bit in mask register. Unmasking can be donebyclearingthat bit. When a particular interrupt is being masked, PICdoreceivethe interrupts on its corresponding input line, but do notsendtheinterrupt singnal to CPU in which case CPU keeps on doing whatitwasdoing. When an interrupts are being masked, they are notlost,ratherPIC remembers those and do send the interrupt to CPU whenCPUunmasksthat interrupt line. Masking is different from blockingalltheinterrupts toCPU. CPU can ignore all the interrupts coming onINTRlineby clearing the IF (Interrupt Falg) flag in EFLAGS registerofCPU.When this bit is cleared, interrupts coming on INTR linearesimplyignored by CPU, we can consider it to be blocking ofinterrupts.So nowwe understand that masking is done at PIC levelandindividualinterrupt lines can be masked or unmasked,where asblockingis done atCPU level and is done for all the interrupts comingto tahtCPU exceptNMI (Non-Maskable Interrupt), which is received on NMIlineof CPU andcan not be blocked or ignored. |
Line 45: | Line 42: |
'''''Hardware checks performed by CPU''''' | Now days,interrupt architecture is not as simple as shown above.Nowdaysmachines uses the APIC (Advanced Programmable Interrupt Controller),which can support upto 256 interrupt lines. AlongwithAPIC, every CPUalso have inbuilt IO-APIC. I won't go into detailsofthese right now. '''''2b) Hardware checks performed by CPU'''''''' ''' |
Line 48: | Line 48: |
__''''''__ | __''''''__''' ''' |
Line 50: | Line 50: |
__''''''__ | __''''''__''' ''' |
Line 52: | Line 52: |
__''''''__ | __''''''__''' ''' |
Line 54: | Line 54: |
__''''''__ | __''''''__''' ''' |
This Section will cover the internals of Interrupt Handling in Linux Kernel (all explaination is related to i386 platform). This section is under development and might be incomplete right now.
I will cover the following topics in this section, explaining thehardware as well as software part of it, from how the interrupts aregenerated, routed and then handled by the low level code of Linux Kernel.
- Introduction
- CPU Support for Handling Interrupts
- Details of Programmable Interrupt Controller
- Hardware checks performed by CPU
- Details of Interrupt Descriptor Table
- Task Gates
- Trap Gates
- Interrupt Gates
- Kernel Support for Handling Interrupts
- Low Level Interrupt Stubs - Details of do_IRQ() function, core of Interrupt Handling
1. Introduction
This section will discuss, the hardware prospective of interrupt handling fromCPU, Linux Kernel's Interrupt Routing subsystem, Device Drivers's rolein Interrupt handling.
Term Interrupt is self defined,Interrupts are signals sent to CPU on an INTR bus (connected to CPU) whenever any device want to get attention of CPU. As soon as theinterrupt signal occurs, CPU defer the current activity and service the interrupt by executing the interrupt handler corresponding to that interrupt number (also know as IRQ number).
One of the clasifications of Interrupts can be done as follows: - Synchronous Interrupts (also know on as software interrupts) - Asynchronous Interrupts (also know as hardware interrupts)
Basic difference between these is that, synchronous interrupts are generated by CPU's control unit on facing some abnormal condition; these are also know as exception in Intel's termenology. These are interrupts whihc are generated by CPU itself either when CPU detects an abnormal condition or CPU executes some of the special instructions like 'int'or 'int3' etc. on other hand, asynchronous interupts are those, which actually are generated by outside world (devices connected to CPU). As these interrupts can occur at any point of time, these are known asynchronous interrupts.
Its important to note that both synchornous and asynchronous interrupts are handled by CPU on the completion of insturction during which the interrupt occur. Execution of a machine instruction is not done in one single CPU cycle, it take somecycles to complete. Any interrupt occurs in between the execution of instruction, will not be handled imediately, rather CPU will check o finterrupts on the completion of instruction.
2. CPU's support for handling interrupts
For handling interrupts there are few of the things which we expecttheCPU to do on occurence of every interrupt. Whenever an interruptoccurs,CPU performs some of the hardware checks, which are very muchneeded tomake the system secure. Before explaining the hardware checks,we willunderstand how the interrupts are routed to the CPU fromhardwaredevices.
2a) Details of Programmable Interrupt Controller
On Intel architecture, system devices (devicecontrollers)areconnectedto a special device known as PIC (Programmable Interrupt Controller). CPU have two lines for receiving interrupt signals(NMIandINTR). NMIline is to recieve non-maskable interrupts; theinterruptswhich cannot be masked, means which can not be blocked atanycost.Theseinterrupts are of hightest priority and are rarelyused. INTRlineisthe line on which all the interrupts from system devicesarereceived.These interrupts can be masked or blocked. As alltheinterruptsignalsneed to be multiplxed on single CPU line, weneedsomemechanisumthrough which interrupts from different devicecontrollerscan berouted to single line of CPU. This routing ormultiplexing isdone PIC(Programmable Interrupt Controller). PIC sitsbetween systemdevicesand CPU and have multiple input lines; each lineconnected todifferentdivice contollers in system. On other hand IPChave only oneoutputline which is connected to the CPU's INTR line onwhich it sendssignalto CPU. There are two PIC controllers joinedtogether and theoutput ofsecond PIC controller is connected tothesecond input of firstPCI.This setup allows maximum of 15 input lines onwhich differentsystemdevice controllers can be connected. PIC havesomeprogrammableregisters, through which CPU communicates with it(givecommand,mask/unmask interrup lines, read status). Both PICs havetheirownfollowing registers:
Mask Register
Status Register
Mask register is used to mask/unmask a specific interrupt line.CPUcanask the PIC to mask (block) the specific interrupt bysettingthecorresponding bit in mask register. Unmasking can be donebyclearingthat bit. When a particular interrupt is being masked, PICdoreceivethe interrupts on its corresponding input line, but do notsendtheinterrupt singnal to CPU in which case CPU keeps on doing whatitwasdoing. When an interrupts are being masked, they are notlost,ratherPIC remembers those and do send the interrupt to CPU whenCPUunmasksthat interrupt line. Masking is different from blockingalltheinterrupts toCPU. CPU can ignore all the interrupts coming onINTRlineby clearing the IF (Interrupt Falg) flag in EFLAGS registerofCPU.When this bit is cleared, interrupts coming on INTR linearesimplyignored by CPU, we can consider it to be blocking ofinterrupts.So nowwe understand that masking is done at PIC levelandindividualinterrupt lines can be masked or unmasked,where asblockingis done atCPU level and is done for all the interrupts comingto tahtCPU exceptNMI (Non-Maskable Interrupt), which is received on NMIlineof CPU andcan not be blocked or ignored.
Now days,interrupt architecture is not as simple as shown above.Nowdaysmachines uses the APIC (Advanced Programmable Interrupt Controller),which can support upto 256 interrupt lines. AlongwithAPIC, every CPUalso have inbuilt IO-APIC. I won't go into detailsofthese right now.
2b) Hardware checks performed by CPU
Once the interrupt signal is received by CPU, CPU performs some hardware checks for which no software machine instructions are executed. Before looking into what these checks are, we need to understand some architecture spcific data structures maintained by kernel.