Lecture 10 Exceptions and Interrupts. How are exceptions generated?

Similar documents
October, Saeid Nooshabadi. Overview COMP 3221

Input/Output. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

The ARM instruction set

Systems Architecture The ARM Processor

18-349: Embedded Real-Time Systems Lecture 2: ARM Architecture

ARM ARCHITECTURE. Contents at a glance:

Samsung S3C4510B. Hsung-Pin Chang Department of Computer Science National Chung Hsing University

18-349: Introduction to Embedded Real-Time Systems

CISC RISC. Compiler. Compiler. Processor. Processor

Hercules ARM Cortex -R4 System Architecture. Processor Overview

ARM Architecture (1A) Young Won Lim 3/20/18

William Stallings Computer Organization and Architecture 10 th Edition Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Processor Structure and Function

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 12 Processor Structure and Function

Agenda. ARM Core Data Flow Model Registers Program Status Register Pipeline Exceptions Core Extensions ARM Architecture Revision

ECE 598 Advanced Operating Systems Lecture 7

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

CPU Structure and Function

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

ARM Processors ARM ISA. ARM 1 in 1985 By 2001, more than 1 billion ARM processors shipped Widely used in many successful 32-bit embedded systems

ECE 598 Advanced Operating Systems Lecture 8

ARM Programmer s Model

There are different characteristics for exceptions. They are as follows:

18-349: Introduction to Embedded Real- Time Systems Lecture 3: ARM ASM

ARM Accredited Engineer Certification

Returning from an Exception. ARM Exception(Interrupt) Processing. Exception Vector Table (Assembly code) Exception Handlers (and Vectors) in C code

ARM and the ARM Powered logo are trademarks of Advanced RISC Machines Ltd.

Interrupt/Timer/DMA 1

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

Project 2: Vectored Interrupts (4%)

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

Chapter 4. Enhancing ARM7 architecture by embedding RTOS

Embedded System Design

ECE 598 Advanced Operating Systems Lecture 8

15CS44: MICROPROCESSORS AND MICROCONTROLLERS. QUESTION BANK with SOLUTIONS MODULE-4

Embedded Operating Systems

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

ARM Processors for Embedded Applications

CPU Structure and Function. Chapter 12, William Stallings Computer Organization and Architecture 7 th Edition

UNIT- 5. Chapter 12 Processor Structure and Function

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

ARM Processor. Dr. P. T. Karule. Professor. Department of Electronics Engineering, Yeshwantrao Chavan College of Engineering, Nagpur

Job Posting (Aug. 19) ECE 425. ARM7 Block Diagram. ARM Programming. Assembly Language Programming. ARM Architecture 9/7/2017. Microprocessor Systems

ARM processor organization

Arm Assembly Language programming. 7. Non-user modes

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 6

I expect you to understand everything discussed prior to this page. In particular:

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

MICROPROCESSORS AND MICROCONTROLLERS 15CS44 MODULE 4 ARM EMBEDDED SYSTEMS & ARM PROCESSOR FUNDAMENTALS ARM EMBEDDED SYSTEMS

Operating System Control Structures

ECE 598 Advanced Operating Systems Lecture 11

ARM Assembly Language

ARM, the ARM Powered logo, BlackICE and ICEbreaker are trademarks of Advanced RISC Machines Ltd.

Sneha Rajguru & Prajwal Panchmahalkar

ARM Embedded Systems: ARM Design philosophy, Embedded System Hardware, Embedded System Software

William Stallings Computer Organization and Architecture. Chapter 11 CPU Structure and Function

The ARM processor. Morgan Kaufman ed Overheads for Computers as Components

EE4144: ARM Cortex-M Processor

Migrating ARM7 Code to a Cortex-M3 MCU By Todd Hixon, Atmel

CISC 662 Graduate Computer Architecture Lecture 7 - Multi-cycles. Interrupts and Exceptions. Device Interrupt (Say, arrival of network message)

Introduction to the ARM Processor Using Intel FPGA Toolchain. 1 Introduction. For Quartus Prime 16.1

CISC 662 Graduate Computer Architecture Lecture 7 - Multi-cycles

What are Exceptions? EE 457 Unit 8. Exception Processing. Exception Examples 1. Exceptions What Happens When Things Go Wrong

Freescale Semiconductor

Introduction to the ARM Processor Using Altera Toolchain. 1 Introduction. For Quartus II 14.0

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

CPU Structure and Function

CSE 153 Design of Operating Systems

Chapter 12. CPU Structure and Function. Yonsei University

To read more. CS 6354: Homework 1 Related / Precise Interrupts. Homework 1. On paper reviews

ZYNQ/ARM Interrupt Controller

Module Introduction. PURPOSE: The intent of this module is to explain MCU processing of reset and interrupt exception events.

Interrupts (Exceptions) Gary J. Minden September 11, 2014

POLITECNICO DI MILANO. Exception handling. Donatella Sciuto:

Instruction Set Architecture of MIPS Processor

COMPUTER ORGANIZATION AND DESI

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

Hardware and Software Architecture. Chapter 2

Arm Architecture. Enrique Secanechia Santos, Kevin Mesolella

ECE251: Thursday September 27

Interrupts (Exceptions) (From LM3S1968) Gary J. Minden August 29, 2016

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

Address spaces and memory management

ARM968E-S. Technical Reference Manual. Revision: r0p1. Copyright 2004, 2006 ARM Limited. All rights reserved. ARM DDI 0311D

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Input/Output Programming

Micro-Operations. execution of a sequence of steps, i.e., cycles

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

Interrupts. Table 1, Interrupt priorities if external handler is used, 0 - highest. coprocessor number 2 exception/interrupt

32-bit Embedded Core Peripheral. Advanced Interrupt Controller (AIC)

CS 3330 Exam 3 Fall 2017 Computing ID:

William Stallings Computer Organization and Architecture

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

Arm Assembly Language programming. 2. Inside the ARM

Lecture 5: Computer Organization Instruction Execution. Computer Organization Block Diagram. Components. General Purpose Registers.

EE458 - Embedded Systems Exceptions and Interrupts

Transcription:

Lecture 10 Exceptions and Interrupts The ARM processor can work in one of many operating modes. So far we have only considered user mode, which is the "normal" mode of operation. The processor can also enter "privileged" operating modes which are used to handle exceptions and SWIs The Current Processor Status Register CPSR has 5 bits [bit4:0] to indicate which mode the processor is in:- Lecture 10-1 How are exceptions generated? By default, the processor is usually in user mode It enters one of the exception modes when unexpected events occurs. There are three different types of exceptions (some are called interrupts):- 1. As a direct result of executing an instruction, such as: Software Interrupt Instruction (SWI) Undefined or illegal instruction Memory error during fetching an instruction 2. As a side-effect of an instruction, such as: Memory fault during data read/write from memory Arithmetic error (e.g. divide by zero) 3. As a result of external hardware signals, such as: Reset Fast Interrupt (FIQ) Normal Interrupt (IRQ) Lecture 10-2

Shadow Registers As the processor enters an exception mode, some new registers are automatically switched in:- Lecture 10-3 Shadow Registers (con't) For example, an external event (such as movement of the mouse) occurs that generates a Fast Interrupt (on the FIQ pin), the processor enters FIQ operating mode. It sees the same r0 - r7 as before, but sees a new set of r8 - r14, and in addition, an extra register called the Saved Processor Status Register (SPSR) stores the value of the CPSR. By swapping to some new registers, it makes it easier for the programmer to preserve the state of the processor. For example, during FIQ mode, r8 - r14 can be used freely. On returning back to user mode, the original values of r8 - r14 will be automatically restored. Lecture 10-4

What happens when an exception occurs? ARM completes current instruction as best it can. It departs from current instruction sequence to handle the exception by performing the following steps:- 1. It changes the operating mode corresponding to the particular exception. 2. It saves the current PC in the r14 corresponding to the new mode. For example, if FIQ occurs, the PC value is stored in r14(fiq). 3. It saves the old value of CPSR in the Saved Processor Status Register of the new mode. 4. It disables exceptions of lower priority (to be considered later). 5. It forces the PC to a new value corresponding to the exception. This is effectively a forced jump to the Exception Handler or Interrupt Service Routine. Lecture 10-5 Where is the exception handler routine? Exceptions can be viewed as "forced" subroutine calls. When and if an exception occurs is not predictable (unless it is a SWI exception). A unique address is pre-defined for each exception handler (IRQ, FIQ, etc), and a branch is made to this address. The address to which the processor is forced to branch to is called the exception/interrupt vector. Lecture 10-6

Exception vector addresses Each vector (except FIQ) is 4 bytes long (i.e. one instruction) You put a branch instruction at this address: B exception_handler FIQ is special in two ways:- 1. You can put the actual FIQ handler (also called Fast Interrupt Service Routine) at 0x0000001C onwards, because FIQ vector occupies the highest address 2. FIQ has many more shadow registers. So you don t have to save as many registers on the stack as other exceptions - faster. Lecture 10-7 Exception Return Once the exception has been handled (by the exception handler), the user task is resumed. The handler program (or Interrupt Service Routine) must restore the user state exactly as it was before the exception occurred: 1. Any modified user registers must be restored from the handler s stack 2. The CPSR must be restored from the appropriate SPSR 3. PC must be changed back to the instruction address in the user instruction stream Steps 1 and 3 are done by user, step 2 by the processor Restoring registers from the stack would be the same as in the case of subroutines Restoring PC value is more complicated. The exact way to do it depends on which exception you are returning from. Lecture 10-8

Exception Return (con t) Remember that the return address was saved in r14 before entering the exception handler. To return from a SWI or undefined instruction trap, use: MOVS pc, r14 To return from an IRQ, FIQ or prefetch abort, use: SUBS pc, r14, #4 To return from a data abort to retry the data access, use: SUBS pc, r14, #8 If the destination register is the PC, the S modifier does NOT mean set the flags, but restore the CPSR The differences between these three methods of return is due to the pipeline architecture of the ARM processor. The PC value stored in r14 can be one or two instructions ahead due to the instruction prefetch pipeline. Lecture 10-9 Exception Priorities Since exceptions can arise at the same time, a priority order has to be clearly defined. For the ARM processor this is: Reset (highest priority) Data abort (i.e. Memory fault in read/write data) Fast Interrupt Request (FIQ) Normal Interrupt Request (IRQ) Prefetch abort Software Interrupt (SWI), undefined instruction Consider the case of a FIQ and an IRQ occurring at the same time. The processor will process the FIQ handler first and remember that there is IRQ pending. On return from FIQ, the process will immediately go to the IRQ handler. Lecture 10-10