1 / 30

Interrupt handling

Interrupt handling. Hebah Kohari Rathnakar Reddy Bodhireddy Sheril Dhabriya. Interrupt : A change in execution caused by an external event. Have device tell OS/CPU it is ready. Requires hardware to support. OS/CPU can then interrupt what it is doing to:

Télécharger la présentation

Interrupt handling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Interrupt handling Hebah Kohari Rathnakar Reddy Bodhireddy Sheril Dhabriya

  2. Interrupt : A change in execution caused by an external event. • Have device tell OS/CPU it is ready. • Requires hardware to support. • OS/CPU can then interrupt what it is doing to: • Determine what device wants service • Perform or start the service. • Go back to what OS/CPU was doing. • Determine what service it wants.

  3. Examples of interrupts • Mouse moved. • Disk drive at sector/track position(old days). • Keyboard key pressed. • Printer out of paper. • Video card wants memory access. • Modem sending or receiving. • USB scanner has data.

  4. 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 .

  5. General flow Process in execution Returns Main Program Process requires I/O service I/O Interrupt Interrupt Service Routine

  6. When a program throws an interrupt a device searching routine is performed. The program is reentered after the interrupt is handled.

  7. Different types of interrupt systems • Single interrupt systems. • Multiple interrupt systems.

  8. Single interrupt system • Finish current instruction. • Save program counter in IRL. • Load program counter with content of IHL.

  9. Multiple interrupt system

  10. Single and multiple

  11. 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.

  12. Steps in handling interrupts • Disable further interrupts. • Store current state of program. • Execute appropriate interrupt handling routine. • Restore state of program. • Enable interrupts. • Resume program execution.

  13. Flowchart of basic interrupt mechanism Fetch Instruction Increment PC Decode and Execute instr. Int request line active Restore PC No Yes Interrupt service Routine Store PC

  14. 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.

  15. 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

  16. Interrupt handling – OS ISSUES • When an interrupt is serviced the processor must be able to execute without being interrupted. It must have the capability of temporarily disabling the interrupt atomically. • If an interrupt occurs while an interrupt service is ongoing, it is simply deferred and considered a pending interrupt. It is serviced after the current request terminates. • The MIPS RISC architecture does not allow user programs to access beyond 0x8000 0000 (the upper half of the memory). The exception handler is in this part of memory and only executed in kernel mode.

  17. 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

  18. 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

  19. 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.

  20. 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.

  21. Types of priority implementations • Software Priority : When the polled data is collected by the servicing routine the program will then assign an order of servicing. • Hardware Priority : This implementation selects the ordering and generates the vectored information that identifies the selected device. • Daisy Chain Priority Control : It distributes the priority selection so that each device has part of the ordering logic located with the device controller.

  22. Interrupt Service • Interrupt service is a procedure in which its address specifies the desired service and is typically called ISR (interrupt service routine). • Centralized dispatch: exception handler decodes the cause. (MIPS style) • Vectored dispatch: the hardware based on a vector number invokes the appropriate service. (Power PC)

  23. The MIPS has a special coprocessor CPO, that is dedicated to exception handling. Status register Cause register Entry hi Entry low Index register Context register EPC register TLB Random register BdAddr register PRid REGISTER

  24. 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.

  25. Status register 15 8 5 4 3 2 1 0 MASK K E K E K E • 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; • E = interrupt enable; 0 means disabled, 1 means enabled • Interrupt handler runs in kernel mode with interrupts disabled • When interrupt occurs 6 LSB shifts left 2 bits, sets 2 LSB to 0.

  26. Cause register 15 10 5 2 PendingCode • 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.

  27. Cause register details • 0 (INT) => external interrupt. • 4 (ADDRL) => address error exception (load or fetch) • 5 (ADDRS) => address error exception (store). • 6 (IBUS) => bus error on instruction fetch. • 7 (DBUS) => bus error on data fetch • 8 (Syscall) => Syscall exception • 9 (BKPT) => Breakpoint exception • 10 (RI) => Reserved Instruction exception • 12 (OVF) => Arithmetic overflow exception

  28. 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.

  29. 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.

  30. Thank you

More Related