COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II

Slides:



Advertisements
Similar presentations
Lab III Real-Time Embedded Operating System for a SoC System.
Advertisements

Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
I/O Unit.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Interrupts (contd..) Multiple I/O devices may be connected to the processor and the memory via a bus. Some or all of these devices may be capable of generating.
COMP3221 lec31-mem-bus-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 31: Memory and Bus Organisation - I
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Chapter 7 Interupts DMA Channels Context Switching.
CS61C L14 Interrupts © UC Regents 1 CS61C - Machine Structures Lecture 14 - Operating System Support and Prioritized Interrupts October (Friday the) 13(th),
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
COMP3221 lec27-exception-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 27: Exceptions & Interrupts - I
COMP3221 lec40-exception-review.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 40: Review of Exception
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
COMP3221 lec31-mem-bus-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 32: Memory and Bus Organisation - II
The ARM Programmer’s Model
Exception and Interrupt Handling
Introduction to Embedded Systems
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Introduction to Embedded Systems Rabie A. Ramadan 6.
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
Interrupts By Ryan Morris. Overview ● I/O Paradigm ● Synchronization ● Polling ● Control and Status Registers ● Interrupt Driven I/O ● Importance of Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Copyright © 2007 by Curt Hill Interrupts How the system responds.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
ARM7 TDMI INTRODUCTION.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Microprocessor Systems Design I
Timer and Interrupts.
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 27: Exceptions & Interrupts - I
Computer System Overview
Module 2: Computer-System Structures
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 30: Memory and Bus Organisation - I
Operating Systems Chapter 5: Input/Output Management
Architectural Support for OS
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
ARM Introduction.
Modified from notes by Saeid Nooshabadi
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Module 2: Computer-System Structures
May, 2004 Modified from notes by Saeid Nooshabadi
Presentation transcript:

COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II October, 2003 Saeid Nooshabadi

COMP3221 lec28-exception-II.2 Saeid Nooshabadi Overview °Instruction Set Support for Exceptions °Role of O/S in Handling Exceptions °Prioritized Exceptions °Re-entrant Exception Routine

COMP3221 lec28-exception-II.3 Saeid Nooshabadi Review: Support for ARM Modes of Operations

COMP3221 lec28-exception-II.4 Saeid Nooshabadi °When an exception occurs, the core: Copies CPSR into SPSR_ Sets appropriate CPSR bits  Interrupt disable flags if appropriate. Maps in appropriate banked registers Stores the “return address” in LR_ Sets PC to vector address Review: Exception Handling and the Vector Table 0x x C 0x x x x C 0x x Reset Undefined Instr FIQ IRQ Reserved Data Abort Prefetch Abort SWI °To return, exception handler needs to: Restore CPSR from SPSR_ Restore PC from LR_ via movs pc, lr or subs pc, lr, #4 °Single instruction stored at these locations should be a branch to a handler

COMP3221 lec28-exception-II.5 Saeid Nooshabadi Review: Privileged vs User Mode °Privileged Modes vs. User Mode: OS can provide security and fairness °swi : provides a way for a programmer to avoid having to know details of each I/O device. °To be acceptable, Exception handler must: service all Exceptions (no drops) service by priority make all users believe that no Exception has occurred

COMP3221 lec28-exception-II.6 Saeid Nooshabadi Review: OS: I/O Requirements °The OS must be able to prevent: The user program from communicating with the I/O device directly °If user programs could perform I/O directly: No protection to the shared I/O resources °3 types of communication are required: The OS must be able to give commands to the I/O devices The I/O device notify OS when the I/O device has completed an operation or an error Data transfers between memory and I/O device

COMP3221 lec28-exception-II.7 Saeid Nooshabadi Review: Crossing the System Boundary °System loads user program into memory and ‘gives’ it use of the processor °Switch back swi -request service -I/O exception (und. Inst) Interrupt Proc Mem I/O Bus status reg. data reg. System User

COMP3221 lec28-exception-II.8 Saeid Nooshabadi Instruction Set Support for OS (#1/2) °How to turn off interrupts during Exception routine? °Bits in CPSR determines whether or not interrupts disabled: Interrupt Request bit (I) (1  disabled, 0  enabled) Once an exception occurs (I) bit sets to to 1 automatically Return from exception restores the original value Fast Interrupt Request bit (F) only gets disabled if an fast Interrupt occurs

COMP3221 lec28-exception-II.9 Saeid Nooshabadi Instruction Set Support for OS (#2/2) °How to prevent user program from turning off interrupts (forever)? °Interrupt Request bit (I) and Fast Interrupt Request bit (F) bits can only be changed from the privileged modes

COMP3221 lec28-exception-II.10 Saeid Nooshabadi Multiple Simultaneous Exceptions/Interrupts °Problem: What if Data Abort exception and an I/O interrupt (printer ready, for example) come in both at the same time? °Options: drop any conflicting interrupts/ exceptions: unrealistic, they may be important simultaneously handle multiple interrupts exceptions: unrealistic, may not be able to synchronize them (such as with multiple I/O interrupts) queue them for later handling: sounds good

COMP3221 lec28-exception-II.11 Saeid Nooshabadi Exceptions Prioritization in ARM Exception Type Priority (1=High, 6=Low) Reset1 Data Abort 2 Fast Interrupt (FIQ) 3 Interrupt (IRQ)4 Prefetch Abort 5 Software Interrupt (SWI)6 Undefined Instruction6

COMP3221 lec28-exception-II.12 Saeid Nooshabadi FIQ Priority °Placing the Data Abort exception above the FIQ exception in the priority list ensures that the Data Abort is actually registered before the FIQ is handled. °The Data Abort handler is entered first but control is then passed immediately to the FIQ handler. °Once the FIQ has been handled, control returns to the Data Abort Handler. °This means that the data transfer error does not escape detection as it would if the FIQ were handled first.

COMP3221 lec28-exception-II.13 Saeid Nooshabadi Hardware support for FIQ °Extra register set r12_fiq – r8_fiq in FIQ bank would mean that they don’t need to be saved. °That means faster processing °FIQ vector address at 0x C is the last vector, and therefore can start executing immediately without a branch instruction 0x x C 0x x x x C 0x x Reset Undefined Instr FIQ IRQ Reserved Data Abort Prefetch Abort SWI

COMP3221 lec28-exception-II.14 Saeid Nooshabadi Preempting Exceptions by Interrupts °Question: Suppose we’re dealing with a computer running a nuclear facility. What if we’re handling an Floating Point Divide by 0 Exception and a Nuclear Meltdown Imminent interrupt comes in? °Answer: We need to categorize and allow some interrupts preempt other Exceptions so we can handle them in order of urgency: emergency vs. luxury.

COMP3221 lec28-exception-II.15 Saeid Nooshabadi ARM Support for Preempting Exceptions °ARM Architecture Support to simplify software: An Exception Process sets IRQ bits (disables it). No further IRQ interrupt is possible However, No exception can disable FIQ interrupt °If an FIQ interrupt comes while servicing an exception Take FIQ immediately Return to interrupted exception code as soon as no more FIQ Interrupt -State information for the preempted exception are saved on banked registers and as well as some internal registers

COMP3221 lec28-exception-II.16 Saeid Nooshabadi Reading Material °Experiment 5 Documentation °Steve Furber: ARM System On-Chip; 2nd Ed, Addison-Wesley, 2000, ISBN: Chapter 5. °ARM Architecture Reference Manual 2 nd Ed, Addison-Wesley, 2001, ISBN: , Part A, Exceptions, chapter A2 Section 6

COMP3221 lec28-exception-II.17 Saeid Nooshabadi So Many Devices One FIQ/IRQ ° Two interrupt request signals FIQ and IRQ never enough for all of the I/O devices ° Need a mechanism to attach multiple devices to the same IRQ pin. ° Solution: Use Interrupt Controller to attach multiple devices to the same IRQ pin. ARM Processor Core CPSR 7 IRQ Interrupt Controller controls how multiple peripherals can interrupt the ARM processor. Essentially, the interrupt controller acts as a large AND-OR gate In the event of an IRQ a combination of hardware and software techniques are required to detect the sources of interrupt and provide a system of priority and queuing.

COMP3221 lec28-exception-II.18 Saeid Nooshabadi Interrupt Controller in DSLMU/Komodo °IRQ Enable : Enables individual interrupts °IRQ Status: Indicates rasing interrupt. °Prioritization: in software (Ox C ) (Ox )

COMP3221 lec28-exception-II.19 Saeid Nooshabadi DSLMU/Komodo IRQ Status/Enable Regs Bit Mode Function 7R/WPush-button switch S2 on the Expansion Board 6R/WPush-button switch S3 on the Expansion Board 5R/W Serial port transmitter ready 4R/WSerial port receiver ready 3—(Reserved) 2R/WXilinx Virtex-E interrupt request 1R/WXilinx Spartan-XL interrupt request 0R/WTimer Compare interrupt request IRQ status reg. address = 0x IRQ Enable reg. address = 0x C

COMP3221 lec28-exception-II.20 Saeid Nooshabadi IRQ Interrupt Levels in ARM? °What are they? °It depends what the ARM chip is inside of: differ by app: GameBoy, Digital Set top Box, Digital Answering Machine, Digital Satellite Decoder, Pocket PC, Mobile Phone ° ARM architecture and Interrupt controller enables priorities for different I/O events

COMP3221 lec28-exception-II.21 Saeid Nooshabadi Improving Data Transfer Performance °Thus far: OS give commands to I/O, I/O device notify OS when the I/O device completed operation or an error °What about data transfer to I/O device? Processor busy doing loads/stores between memory and I/O Data Register °Ideal: specify the block of memory to be transferred, be notified on completion? Direct Memory Access (DMA) : a simple computer transfers a block of data to/from memory and I/O, interrupting upon done

COMP3221 lec28-exception-II.22 Saeid Nooshabadi Example: FIQ Code for DMA controller °DMA code from Disk Device to Memory.data Count:.word 4096 Start:.space 4096 °DMA “computer” in parallel with CPU.text Initial:ldr a1, =Count ldr a1, [a1] ; No. chars ldr a2, =Start ; next char Wait:ldr a3, DiskControl tst a3,1 ; select Ready beq Wait ; spinwait ldrb a4, DiskData ; get byte strb a4, [a2], #1 ; transfer, ; Start++ subs a1, a1,#1 ; Count-- bne Wait ;next char

COMP3221 lec28-exception-II.23 Saeid Nooshabadi Re-entrant Interrupt Routine? °Prioritization and queuing of interrupts attached to IRQ Interrupt controller requires one interrupt preempting another interrupt (reentrant interrupts) °All exceptions set IRQ disable interrupt bit (I) FIQ can interrupt IRQ and other exceptions °FIQ sets FIQ disable interrupt bit (F) as well °How allow one IRQ interrupt to interrupt another IRQ interrupt and and safely save registers? °Interrupt service Routine needs to save: Return address on lr_irq for the pre-empted IRQ handler on IRQ Mode Stack all registers that it is going to use on IRQ Mode Stack Reset the IRQ disable bit °Same thing for FIQ

COMP3221 lec28-exception-II.24 Saeid Nooshabadi Pre-empting Other Exceptions by IRQ? °All exceptions set IRQ disable interrupt bit (I) FIQ can interrupt IRQ and other exceptions °How allow IRQ interrupts to interrupt other exceptions (other than IRQ and FIQ exceptions)? °Interrupt service Routine needs to save: all registers that it is going to use on IRQ Mode Stack Reset the IRQ disable bit

COMP3221 lec28-exception-II.25 Saeid Nooshabadi IRQ Controller Support for Queuing and Priority °IRQ Controller Support to simplify software: An Interrupt Process cannot be preempted by Exception at same or lower "level" When an interrupt is handled, take the highest priority interrupt on the queue If a higher priority interrupt comes in while servicing a lower priority one -Preempt the lower priority one and take the higher priority one -current priority value is pushed onto a first-in last- out stack and the current priority is updated to the higher priority. -Return to interrupted code as soon as no more Interrupts at a higher level -On return the current interrupt level is updated with the last stored interrupt level from the stack.

COMP3221 lec28-exception-II.26 Saeid Nooshabadi Things to Remember °Privileged Mode v. User Mode: OS can provide security and fairness ° Exceptions prioritization in the case of multiple concurrent exceptions. °Multiple devices can be connected to single IRQ interrupt via an Interrupt Controller. °Re-entrant Interrupt: One interrupt preempting another interrupt. Prioritization and queuing of interrupts in hardware or software is required for this to work.