COMP3221 lec27-exception-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 27: Exceptions & Interrupts - I

Slides:



Advertisements
Similar presentations
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 19: I/O, Interupsi 20 November 2002 Bobby Nazief Johny Moningka
Advertisements

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.
ECE 353 Introduction to Microprocessor Systems
Lab III Real-Time Embedded Operating System for a SoC System.
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
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 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.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Exception Processing ECE511: Digital System & Microprocessor.
Introduction To The ARM Microprocessor
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 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II
Exceptions, Interrupts & Traps
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.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.
Prardiva Mangilipally
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.
CHAPTER 2: ARM Processor fundamental
Exception and Interrupt Handling
Introduction to Embedded Systems
Exceptions and Interrupts 2
Protection and the Kernel: Mode, Space, and Context.
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.
Architecture Support for OS CSCI 444/544 Operating Systems Fall 2008.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Introduction to Embedded Systems Rabie A. Ramadan 6.
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
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.
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.
AT91 C-startup. 2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
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.
1 TM 1 Embedded Systems Lab./Honam University r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 (sp) r14 (lr) r15 (pc) cpsr r13 (sp) r14 (lr) spsr r13 (sp)
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
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
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.
ARM Introduction.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
Control Hazards Branches (conditional, unconditional, call-return)
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
Multiply Instructions
COMP3221: Microprocessors and Embedded Systems
Interrupts and exceptions
May, 2004 Modified from notes by Saeid Nooshabadi
Presentation transcript:

COMP3221 lec27-exception-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 27: Exceptions & Interrupts - I September, 2003 Saeid Nooshabadi

COMP3221 lec27-exception-I.2 Saeid Nooshabadi Overview °Instruction Set Support for Exceptions °Privileged vs User modes of operation. °Handling a Single Interrupt

COMP3221 lec27-exception-I.3 Saeid Nooshabadi Review °I/O gives computers their 5 senses °I/O speed range is million to one °Processor speed means must synchronize with I/O devices before use °Polling works, but expensive processor repeatedly queries devices °Interrupts works, more complex

COMP3221 lec27-exception-I.4 Saeid Nooshabadi Definitions for Clarification °Exception: signal marking that something “out of the ordinary” has happened and needs to be handled. Caused by internal and external sources °Interrupt: Externally asynchronous exception (by I/Os) °Software Interrupt (SWI): User defined synchronous exception °Trap: Processor’s diversion to a code to handle exception

COMP3221 lec27-exception-I.5 Saeid Nooshabadi Example of Exception Sources in ARM °Externally generated interrupts °An attempt by the processor to execute an undefined instruction °Accessing privileged operating system functions via software interrupts (SWI). Print Access Ethernet

COMP3221 lec27-exception-I.6 Saeid Nooshabadi I/O Interrupt °An I/O interrupt is like an undefined instruction exceptions except: An I/O interrupt is “asynchronous” More information needs to be conveyed °An I/O interrupt is asynchronous with respect to instruction execution: I/O interrupt is not associated with any instruction, but it can happen in the middle of any given instruction I/O interrupt does not prevent any instruction from completion

COMP3221 lec27-exception-I.7 Saeid Nooshabadi Architecture Support for Exceptions °Save the PC for return But where? °Where to go when Exception occurs? °How to determine the Cause of exception? °How to handle exceptions?

COMP3221 lec27-exception-I.8 Saeid Nooshabadi Exception Sources in ARM °Reset: Occurs when the processor reset pin is asserted. (Signalling power-up) °Undefined Instruction: Occurs if the processor, does not recognize the currently executing instruction. °Software Interrupt (SWI): This is a user-defined intentional synchronous interrupt instruction. °Prefetch Abort: Occurs when the processor attempts to execute an instruction that was not fetched, because the address was illegal. °Data Abort: Occurs when a data transfer instruction attempts to load or store data at an illegal address. °IRQ: Occurs when the processor external Interrupt ReQuest pin is asserted °FIQ: Occurs when the processor external Fast Interrupt reQuest pin is asserted

COMP3221 lec27-exception-I.9 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 lec27-exception-I.10 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 lec27-exception-I.11 Saeid Nooshabadi User Mode vs Privileged Modes °User Applications run in User Mode °Privileged modes, used to service interrupts exceptions access protected resources (via SWI Instruction) °Privileged modes  User mode OK °User mode  Privileged modes NOT OK Only possible through Controlled mechanisms: SWI, Exceptions, Interrupts

COMP3221 lec27-exception-I.12 Saeid Nooshabadi Rationale Privileged Modes °Privileged modes protect system from getting trashed by user. °Some Instructions can only be executed in privileged mode °Example: User can’t directly read/write information from disk I/Os. °Why not allow direct access to non- disk I/O devices in user mode? °Komodo on DSLMU runs in Privileged mode. Can access everything while running Komodo

COMP3221 lec27-exception-I.13 Saeid Nooshabadi I/O Requires Privileged Modes °Transmitter/receiver Status and Data words are in privileged data space; thus we must be in privileged mode to read or write them. °Device drivers run in privileged mode. °To access the I/O devices the user application has to make a Supervisor call to the OS via SWI instruction °Komodo on DSLMU Allows access to I/O ports in User mode! Security hole !

COMP3221 lec27-exception-I.14 Saeid Nooshabadi Support for ARM Modes of Operations

COMP3221 lec27-exception-I.15 Saeid Nooshabadi Switching between Modes (User to FIQ Mode) 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 lec27-exception-I.16 Saeid Nooshabadi Exception Handling Mechanism (#1/2) °The processor’s response to an exception Copies the Current Program Status Register (CPSR) into the appropriate mode Saved Program Status Register(SPSR) Sets the appropriate CPSR bits -Mode bits : set appropriately. maps in the appropriate banked registers for that mode. -I bit : to disable interrupts. IRQs are disabled once any other exception occurs -F bit: FIQs are also disabled when a FIQ occurs. Stores the address of the return instruction (generally PC – 4) in LR_. Sets the PC to the appropriate vector address.This forces the branch to the appropriate exception handler.

COMP3221 lec27-exception-I.17 Saeid Nooshabadi Exception Handling Mechanism (#2/2) °Returning from an exception handler Restore the CPSR from the SPSR_. Restore the PC using the return address stored in LR_. These can be achieved in a single instruction movs pc, lr or subs pc, lr, #4 Adding the S flag (update condition codes) to a data processing instruction when in a privileged mode with the PC as the destination register, also transfers the SPSR to CPSR Same thing for Load Multiple instruction (using the ^ qualifier) ldmfd sp! {r0-r12, pc}^

COMP3221 lec27-exception-I.18 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 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 lec27-exception-I.19 Saeid Nooshabadi Software Interrupt (SWI) °In effect, a SWI is a user-defined instruction, °A planned Exception from User Application to request privileged O/S services via SWI Supervisor call. °It causes: A switch to privileged Supervisor Mode. A branch to an exception trap to the SWI exception vector ( 0x ) a SWI exception handler to be called. °The handler can then examine the comment field of the instruction to decide what operation has been requested.

COMP3221 lec27-exception-I.20 Saeid Nooshabadi SWI Invocation °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 lec27-exception-I.21 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 exception (und. Inst) Interrupt Proc Mem I/O Bus status reg. data reg. System User

COMP3221 lec27-exception-I.22 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 lec27-exception-I.23 Saeid Nooshabadi SWI Example under GNU Debugging tools 7;Print to console a single char in R0 swi 0x0 ;Read a single char from Kboard into R0 swi 0x4 ;Print nul-terminated string prt_str to the console ldrr0,=prt_str swi0x2 Swi 0x11 ; Terminate the program.data prt_str:.asciz “Hello World:\n"

COMP3221 lec27-exception-I.24 Saeid Nooshabadi CPSR and SPSR Transfer Instructions °MRS and MSR transfer content CPSR/SPSR to /from a general purpose register. All of status register, or just the flags, can be transferred. mrs Rd, ; Rd  msr,Rm ;  Rm Where = CPSR, CPSR_all, SPSR or SPSR_all and = CPSR_flg or SPSR_flg °Also an immediate form msr,#Imm32 a 32-bit immediate, of which the 4 most significant bits are written to the flag bits. CPSR

COMP3221 lec27-exception-I.25 Saeid Nooshabadi Modifying CPSR °Unused reserved bits, may be used in future, therefore: they must be preserved when altering PSR the value they return must not be relied upon when testing other bits. °Thus read-modify-write strategy must be followed when modifying any PSR: Transfer PSR to register using MRS Modify relevant bits Transfer updated value back to PSR using MSR °Note: In User Mode, all bits can be read but only the flag bits can be written to. CPSR

COMP3221 lec27-exception-I.26 Saeid Nooshabadi Questions Raised about Interrupts °Which I/O device caused interrupt? Needs to convey the identity of the device generating the interrupt °Can avoid interrupts during the interrupt routine? What if more important interrupt occurs while servicing this interrupt? Allow interrupt routine to be entered again? °Who keeps track of status of all the devices, handle errors, know where to put/supply the I/O data?

COMP3221 lec27-exception-I.27 Saeid Nooshabadi 4 Responsibilities leading to OS °The I/O system is shared by multiple programs using the processor °Low-level control of I/O devices is complex because requires managing a set of concurrent events and because requirements for correct device control are often very detailed °I/O systems often use interrupts to communicate information about I/O operations °Would like I/O services for all user programs under safe control

COMP3221 lec27-exception-I.28 Saeid Nooshabadi 4 Functions OS must provide °OS guarantees that user’s program accesses only the portions of I/O device to which user has rights (e.g., file access) °OS provides abstractions for accessing devices by supplying routines that handle low-level device operations °OS handles the interrupts generated by I/O devices (and other exceptions generated by a program) °OS tries to provide equitable access to the shared I/O resources, as well as schedule accesses in order to enhance system performance

COMP3221 lec27-exception-I.29 Saeid Nooshabadi Things to Remember °Privileged Mode v. 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