What is Interrupt
-
Interrupt is event/signals generated by H/W(Eg: clock, keyboard) or S/W which is sent to CPU by Interrupt Controller.
Interrupts are used to handle asynchronous events, CPU pauses the current execution, address the event, and then resume its previous activity.
CPU is asked to perform some high priority task wrt what its doing.
Interrupts can be triggered by hardware devices (hardware interrupts) or by software instructions (software interrupts).
Information from interrupt is converted to character and stored in buffer to be later used by ISR.
Interrupt Flow/Hardware Interrupt reaching CPU
@startuml
participant User as u
participant KeyBoardController as kc
participant pic as "Programmable\nInterruptController"
participant cpu as "CPU\nINTR PIN"
participant RAM as ram
participant pcb as "Process\nControl Block" #Aqua
participant ivt as "Interrupt\nVector Table"
participant isr as "Interrupt\nService Routine"
note over u #Cyan
User playing movie
pressed key on
keyboard
end note
u -> kc: Key pressed
kc -> pic: h/w interrupt
note over pic #LightPink
Decide priority
Assign interrupt id
end note
pic -> cpu: hw interrupt
note over cpu #Gold
pause movie play
end note
note over cpu #Gold
Save PC to PCB
end note
cpu -> pcb: Save data on PCB
note over pcb
Data saved on PCB
- PC(program counter)
- Status Register
end note
cpu -> ivt: Find isr using id
ivt -> cpu: IST address
note over cpu #Gold
Load new ISR to PC
end note
note over cpu #Gold
Check which registers
Are needed by ISR
end note
cpu -> pcb: Save register on PCB
note over pcb
Save present registers
on PCB
end note
cpu -> ram: Create new stack for ISR
cpu -> ram: Load New\nISR address
cpu -> ram: jump to isr address
note over ram #Beige
read data from keyboard
ISR execution complete
end note
note over cpu #Gold
Restores PCB data
Movie playback resume
end note
@enduml
|
|
IVT(Interrupt Vector Table) / (IDT) Interrupt Descriptor Table
-
Contains ISR(Interrupt service routine)/Handler Address to which CPU jumps at occurrence of interrupt.
Present in 1st 1K of physical memory.
Starting address of IVT is stored in dedicated register (IDTR).
IVT is created when the system initially boots and reflects the specific system configuration.
IVT is filled using Probing
Interrupt number is used as index in IVT. CPU goes to IVT's index, gets Instruction Pointer/Program counter and starts Interrupt service procedure. Once CPU starts ISP, Device Acks Interrupt controller
| 0x420932 ISR of Int0 | | | |
Interrupt No> 0 1 2 3
CPU Hardware_Device
<- Interrupt3=signal-
Find & runs ISR3 for Intr3
isr3(){..}
Probing
-
Finding which Interrupt line Hardware Device is going to use?
Device driver tells the Hardware device to generate interrupts and watches the IRQ line and finds which line device is using.
unsigned long probe_irq_on(void);
This function returns a bit maskof unassigned interrupts.The driver must preserve the returned bit mask, and pass it to probe_irq_off later.
Other Method? The interrupt handler can be installed either at driver initialization or when the device is first opened. Installing isr at device initialization causes interrupt line to be occupied even device is not used.