Interrupt Handling
Interrupt Handling
Interrupt Handling
Hebah Kohari
Rathnakar Reddy Bodhireddy
Sheril Dhabriya
Examples of interrupts
Mouse moved. Disk drive at sector/track position(old days).
Types of interrupts
Synchronous/Asynchronous: Synchronous if it occurs at the same place, every time the program is executed with the same data and memory allocation. Asynchronous interrupts are those that occur unexpectedly. Internal/External : Internal interrupts arise from illegal or erroneous use of an instruction or data , also called as traps. External interrupts arise from I/O devices, timing device, circuit generated by power supply. Software/Hardware : Software interrupts is initiated by executing an instruction .
General flow
Returns Process in execution
Main Program
I/O Interrupt
When a program throws an interrupt a device searching routine is performed. The program is reentered after the interrupt is handled.
Interrupt
RegPC+1
Finish current instruction. Save program counter in IRL. Load program counter with content of IHL.
2
Single-interrupt system:
inter rupt signal pro gram counte r
status control
interrupt lines
IHL1
Device CPU
Interrupt handlers
Interrupt handlers are the routines that are called when an interrupt is detected.
Interrupt handlers are usually short sections of code that are designed to handle the immediate needs of the device and return control to the operating system or user program.
Restore PC
Yes Interrupt
Store PC
service Routine
Masking interrupts
It is sometimes advantageous to disable interrupts while the processor is performing some critical operation (like handling another interrupt). On some systems there may be one or more high priority interrupts that cannot be masked.
Interrupt handling
Interrupt handling in a PC: On a PC there are 24 separate interrupt lines that can be asserted. The appropriate interrupt handler is invoked based on the interrupt number. Interrupt handling in MIMS: On a MIPS machine the Cause register is filled in with an appropriate code which allows the interrupt handler to figure out the cause of the interrupt
Changing the mode back to the mode before the exception occurs is accomplished via the instruction rfe (return from exception). The mode information is stored in the Status Register and can only be written in the kernel mode. It can be read in user mode. The Status Register contains a simple hardware stack that can hold up to three levels of information: old, previous, current. On exception: old previous current
On rfe: old previous current
A reentrant exception handler is written such that it is itself interruptible. Interrupts and traps are assigned priorities. A check is made for pending interrupt requests after every instruction. If there is a pending interrupt request, the priority is checked. If it has a higher priority than the currently running code, it serviced first, otherwise it is ignored
Enabling and disabling of interrupts can be done either by using an interrupt mask (IPM) applied to bits 8-15, or the IE (applied to bit 0) of the Status Register. The execution of rfe enables interrupts. rfe and jr must be executed atomically.
In the MIPS RISC architecture, jr is actually executed first and does not take effect until after rfe is executed.
Interrupt priority
When multiple I/O devices are present in an interrupt system, two difficulties must be resolved:
How to handle interrupt requets from more than one device at a time. Identification of the selected device.
Assigning priority levels to each device means that highest level priorities will be serviced before lower levels.
Interrupt Service
Interrupt service is a procedure in which its address specifies the desired service and is typically called ISR (interrupt service routine).
The MIPS has a special coprocessor CPO, that is dedicated to exception handling.
Status register Entry hi Entry low Index register Context register Random register TLB BdAddr register
Cause register
EPC register
PRid REGISTER
MIPS CPO
EPC: A 32 bit register used to hold the address of the affected instruction. Register 14 of coprocessor 0. Cause: A register used to record the cause of the exception. In the MIPS architecture this register is 32 bits, though some bits are currently unused. BadVAddr: Register contains memory address at which memory reference occurred. Register 8 of coprocessor 0. Status: interrupt mask and enable bits.
Status register
15 8 MASK 5 4 K 3 2 E 1 0 E K E K
Mask = 1 bit for each of 5 hardware and 3 software interrupt levels. 1 enables interrupts, 0 disables interrupts
K = kernel/user; 0 = was in the kernel when interrupt occurred 1 = was running user mode;
Cause register
15 10 5 2
Pending
Code
Pending interrupt 5 hardware levels: bit set if interrupt occurs but not yet serviced. Handles cases when more than one interrupt occurs at same time, or records interrupt requests when interrupts disabled. Exception Code encodes reasons for interrupt.
Summary
An interrupt is one class of exception. An interrupt can occur at any time. Hardware and software are needed to support interrupt handling. The hardware must choose the appropriate time in which to interrupt the executing program and transfers control to an exception handler. The current state of the interrupted program must be saved.
Summary
The exception handler also determines which event has caused the exception and decides what should be done based on it. It must also save register values being used by the interrupted program and restore them before returning control to the interrupted program.
Thank you