COMP3221 lec40-exception-review.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 40: Review of Exception

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

ECE 353 Introduction to Microprocessor Systems
Lab III Real-Time Embedded Operating System for a SoC System.
1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
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.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
CS61C L26 Interrupt Review © UC Regents 1 CS61C - Machine Structures Lecture 26 - Review of Interrupts December 6, 2000 David Patterson
Chapter 12: Software interrupts (SWI) and exceptions
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: 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.
Exception Processing ECE511: Digital System & Microprocessor.
OS Spring’03 Introduction Operating Systems Spring 2003.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II
COMP3221 lec27-exception-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 27: Exceptions & Interrupts - I
Exceptions, Interrupts & Traps
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
The ARM Programmer’s Model
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Exception and Interrupt Handling
Introduction to Embedded Systems
System Calls 1.
Exceptions and Interrupts 2
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Protection and the Kernel: Mode, Space, and Context.
MICROPROCESSOR INPUT/OUTPUT
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
Introduction to Embedded Systems Rabie A. Ramadan 6.
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.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 1: Review of Computer Organization
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
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.
Introduction to ARM processor. Intro.. ARM founded in November 1990 Advanced RISC Machines Company headquarters in Cambridge, UK Processor design centers.
ARM7 TDMI INTRODUCTION.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 12: Software interrupts (SWI) and exceptions
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.
Anton Burtsev February, 2017
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 27: Exceptions & Interrupts - I
Chapter 12: Software interrupts (SWI) and exceptions
Exceptions Control Flow
Architectural Support for OS
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.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Interrupts and exceptions
May, 2004 Modified from notes by Saeid Nooshabadi
Presentation transcript:

COMP3221 lec40-exception-review.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 40: Review of Exception November, 2003 Saeid Nooshabadi

COMP3221 lec40-exception-review.2 Saeid Nooshabadi Outline °Instruction Set Support for Exception °Prioritized Exceptions °Re-entrant Exception Routine

COMP3221 lec40-exception-review.3 Saeid Nooshabadi Crossing the System Boundary °System loads user program into memory and ‘gives’ it use of the processor °Switch back SWI -request service -I/O TRAP (page Fault) Interrupt Proc Mem I/O Bus status reg. data reg. System User

COMP3221 lec40-exception-review.4 Saeid Nooshabadi Reasons for Exceptions/Interrupts °Hardware errors: memory parity error °External I/O Event High Priority and Low Priority I/O events °Illegal instruction °Virtual memory Write protection violation Page fault - page is on disk Invalid Address - outside of address range °Arithmetic overflow Floating Point Exceptions °Software Interrupts (invoke Op Sys routine)

COMP3221 lec40-exception-review.5 Saeid Nooshabadi SWI °How does user invoke the OS? swi instruction: invoke the OS code (Go to 0x , change to privileged mode) By software convention,number xxx in swi xxx has system service requested: OS performs request

COMP3221 lec40-exception-review.6 Saeid Nooshabadi Software/Hardware Resources for Exceptions °Registers to use in exception routine All modes of operation have registers lr_mode and sp_mode in their bank for use; don’t have to be saved Registers r8 – r12 are also available in fiq bank. °Enable/Disable Interrupt & Fast Interrupt Bits °Privileged/User mode to protect when can Disable Interrupts °PC address of instruction causing the exception or the return address saved in lr_mode. °Exception priority in case of multiple simultaneous exceptions °Jump to Exception vectors at 0x x C °Mode bits in CPSR to show the cause of exception °Priority levels hardware/software to take multiple interrupts °Possible register showing cause of interrupts

COMP3221 lec40-exception-review.7 Saeid Nooshabadi Support for ARM Modes of Operations

COMP3221 lec40-exception-review.8 Saeid Nooshabadi CPSR Encoding for Operating Modes & Interrupts mode Mode of Operation TARM vs Thumb State (We only use ARM in COMP3221 F FIQ Fast interrupts Disable bit I IRQ Normal interrupt Disable bit NZCV Condition Flags CPSR Changing mode bits is only possible in privileged modes

COMP3221 lec40-exception-review.9 Saeid Nooshabadi Switching between Modes (User to FIQ Mode) FIQ EXCEPTION User mode CPSR copied to FIQ mode SPSR cpsr r15 (pc) r14 (lr) r13 (sp) r12 r10 r11 r9 r8 r7 r4 r5 r2 r1 r0 r3 r6 r14_fiq r13_fiq r12_fiq r10_fiq r11_fiq r9_fiq r8_fiq Registers in use User Mode spsr_fiq cpsr r7 r4 r5 r2 r1 r0 r3 r6 r15 (pc) r14_fiq r13_fiq r12_fiq r10_fiq r11_fiq r9_fiq r8_fiq r14 (lr) r13 (sp) r12 r10 r11 r9 r8 Registers in use FIQ Mode spsr_fiq Return address calculated from User mode PC value and stored in FIQ mode LR

COMP3221 lec40-exception-review.10 Saeid Nooshabadi °When an exception occurs, the ARM 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 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

COMP3221 lec40-exception-review.11 Saeid Nooshabadi ARM Modes of Operations °10000 User Normal user code °10001 FIQ Processing fast interrupts °10010 IRQ Processing standard interrupts °10011 SVCProcessing software interrupts (SWIs) °10111 Abort Processing memory faults °11011 Undef Handling undefined instruction traps °11111 System Running privileged operating system tasks CPSR Privileged Modes Non-Privileged Mode

COMP3221 lec40-exception-review.12 Saeid Nooshabadi Future of Wireless Embedded Devices °The future will see smart technologies that will allow devices to be connected to any network that is available, while automatically collecting the information users want. Technically, the new wireless is also predicted to be smarter in size and power as traditional chips have been power hungry. This change will see tiny, inexpensive, embedded networks being integrated into almost any manufactured object. These embedded networks could also be tied to sensors that could monitor everything from environmental conditions to peak-hour traffic. °Interestingly, speech recognition is predicted to boom as people prefer to talk rather than type commands or text on small key pads that are crammed into mobile phones and personal digital assistants Gerry Purdy - wireless analyst Silicon Valley 4.0 Conference

COMP3221 lec40-exception-review.13 Saeid Nooshabadi Multiple Exceptions/Interrupts °Problem: What if multiple exceptions and interrupts come simultaneously °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) Handle them one by one in order of priority: sounds good

COMP3221 lec40-exception-review.14 Saeid Nooshabadi ARM Prioritized Exceptions 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 lec40-exception-review.15 Saeid Nooshabadi Taking New Exception While Handling Exception °Problem: What if we’re handling an Data Abort exception and need to make an SWI call? Each exception has its own version of registers lr_mode and sp_mode in their bank; so simply switch the supervisor mode Other registers need saving on the mode stack. °One SWI invoking another SWI ? Ok, provided SWI routine save lr_swi and sp_swi on the SWI stack on entry to routine as well.

COMP3221 lec40-exception-review.16 Saeid Nooshabadi Taking New Interrupt While Handling Exception °Problem: What if we’re handling an Data Abort exception and an I/O interrupt (printer ready, for example) comes in? It is ignored since all exceptions disable IRQ (I bit = 1) We can take interrupts by re-enabling them setting IRQ bit (I bit = 0); re-entrant interrupts FIQ interrupt can be disabled (F bit = 1) only by FIQ interrupt.

COMP3221 lec40-exception-review.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 lec40-exception-review.18 Saeid Nooshabadi Nested Interrupt Support °If going to support nested interrupts from multiple sources by re-enabling IRQ (I bit = 0), what must be saved/ restored on entry/exit of nested interrupt? Save/restore all things associated with current interrupt: interrupt PC in lr_irq, lr_sp, spsr, Any registers used beyond lr_irq and sp_irq °Problem: How many levels of recursion can we allow in interrupts i.e. how deep the stack can grow? °Solution: Prioritization and Priority levels

COMP3221 lec40-exception-review.19 Saeid Nooshabadi Prioritized Interrupts (#1/2) °Interrupt Controller support to simplify software: Set priority levels for interrupts Process cannot be preempted by interrupt at same or lower "level" When an interrupt is handled, take the highest priority interrupt -The handler may need to save the state of the preempted program Return to interrupted code as soon as no more interrupts at a higher level

COMP3221 lec40-exception-review.20 Saeid Nooshabadi Prioritized Interrupts (#2/2) °To implement, we need an IRQ Stack: portion of address space allocated for stack of “IRQ Frames” each frame represents one interrupt: contains enough info to restart handling the preempted interrupt if necessary. °In addition we need to keep the priority levels information it is kept in a First-In Last-Out (FILO) stack in the Interrupt Controller (IC) hardware current priority value is pushed onto a FILO stack and the current priority is updated to the higher priority. on return the current interrupt level is updated with the last stored interrupt level from the stack. °The priority levels information can be kept in IRQ stack if Interrupt controller does not support it.

COMP3221 lec40-exception-review.21 Saeid Nooshabadi Modified Interrupt Handler (#1/2) °Problem: When an interrupt comes in while handling another interrupt, lr_irq and spsr_irq get overwritten immediately by hardware. Lost lr_irq means loss of user program. °Solution: Modify interrupt handler. When first interrupt comes in: disable interrupts (Done by hardware) save lr_irq, sp_irq and spsr_irq, and any registers it may use on IRQ Stack mask out the lower or same priority interrupts (Done via Interrupt controller hardware, when supports it) re-enable interrupts continue handling current interrupt at the end disable the interrupts, unmask the lower or same priority interrupts, restore lr_irq, sp_irq, and spsr_irq, and any registers it has used from IRQ Stack and return to user code.

COMP3221 lec40-exception-review.22 Saeid Nooshabadi Modified Interrupt Handler (#2/2) °When next (or any later) of higher priority interrupt comes in: interrupt the first onedisable interrupts (Done by hardware) save lr_irq, sp_irq and spsr_irq, and any registers it may use on IRQ Stack mask out the lower or same priority interrupts (Done via Interrupt controller hardware, when supports it) re-enable interrupts continue handling current interrupt at the end disable the interrupts, unmask the same priority interrupts, restore lr_irq, sp_irq, and spsr_irq, and any registers it has used from IRQ Stack and return to lower priority interrupt.

COMP3221 lec40-exception-review.23 Saeid Nooshabadi Re-entrant Interrupt Routine Review? °How allow interrupt of interrupts and safely save registers? °Stack? Resources consumed by each interrupt, so cannot tolerate arbitrary deep nesting of exceptions/interrupts °With priority level system only interrupted by higher priority interrupt, so cannot be recursive °Only need one save area (“interrupt frame”) per priority level

COMP3221 lec40-exception-review.24 Saeid Nooshabadi Supporting Multiple Interrupts in Software °Exception/Interrupt behavior determined by combination of hardware mechanisms and operating system strategies °same hardware with different OS acts differently °A popular software model for multiple interrupts/exceptions, often used in Unix OS, is to set priority levels This is an OS concept, not a HW concept HW just needs mechanisms to support it

COMP3221 lec40-exception-review.25 Saeid Nooshabadi Things to Remember °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, interrupt handler must: service all interrupts (no drops) service by priority make all users believe that no interrupt has occurred