Exception and Interrupt Handling in ARM

Similar documents
Exception and Interrupt Handling in ARM

Interrupt handling. Andrew N. Sloss

An Introduction to the ARM 7 Architecture

StrongARM** SA-110 Microprocessor Instruction Timing

A Choices Hypervisor on the ARM architecture

UNIT 4 Software Development Flow

The ARM Architecture. With a focus on v7a and Cortex-A8

Overview of the Cortex-M3

ARM VIRTUALIZATION FOR THE MASSES. Christoffer Dall

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

ARM Architecture. ARM history. Why ARM? ARM Ltd developed by Acorn computers. Computer Organization and Assembly Languages Yung-Yu Chuang

Cortex-A9 MPCore Software Development

ARM Microprocessor and ARM-Based Microcontrollers

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

THUMB Instruction Set

Keil C51 Cross Compiler

Application Note 195. ARM11 performance monitor unit. Document number: ARM DAI 195B Issued: 15th February, 2008 Copyright ARM Limited 2007

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

Operating Systems. Lecture 03. February 11, 2013

Microprocessor & Assembly Language

Chapter 1 Computer System Overview

Lesson-16: Real time clock DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK

How To Port From The Ark7Tdmi To The Corporum3 Processor

ARM Accredited Engineer AAE Syllabus. Document number: ARM AEG 0052C Copyright ARM Limited 2012

Towards A Unified Hardware Abstraction Layer Architecture for Embedded Systems

SYSTEM ecos Embedded Configurable Operating System

Virtualization in the ARMv7 Architecture Lecture for the Embedded Systems Course CSD, University of Crete (May 20, 2014)

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Hardware accelerated Virtualization in the ARM Cortex Processors

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

ARM Virtualization: CPU & MMU Issues

RTOS Debugger for ecos

Traditional IBM Mainframe Operating Principles

Application Note 179. Cortex -M3 Embedded Software Development. Released on: March Copyright All rights reserved.

Software based Finite State Machine (FSM) with general purpose processors

Cortex -M0 Devices. Generic User Guide. Copyright 2009 ARM Limited. All rights reserved. ARM DUI 0497A (ID112109)

RTAI. Antonio Barbalace (modified by M.Moro 2011) RTAI

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Developer Suite ARM. Assembler Guide. Version 1.2. Copyright 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B

Instruction Set Architecture

Performance Comparison of RTOS

INPUT/OUTPUT ORGANIZATION

RTEMS Porting Guide. On-Line Applications Research Corporation. Edition , for RTEMS July 2015

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

PROBLEMS (Cap. 4 - Istruzioni macchina)

EECE 276 Embedded Systems

Chapter 2: OS Overview

COS 318: Operating Systems

Hardware Assisted Virtualization

FRONT FLYLEAF PAGE. This page has been intentionally left blank

ARMv8 Technology Preview. By Richard Grisenthwaite Lead Architect and Fellow. ARM

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Intel Xeon Phi Coprocessor (codename: Knights Corner) Performance Monitoring Units

Timer, Interrupt, Exception in ARM

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

CSC 2405: Computer Systems II

Programming Guide. Intel Microarchitecture Codename Nehalem Performance Monitoring Unit Programming Guide (Nehalem Core PMU)

Lecture 6: Interrupts. CSC 469H1F Fall 2006 Angela Demke Brown

Research on System Virtualization using Xen Hypervisor for ARM based secure mobile phones

Introduction to Embedded Systems. Software Update Problem

Virtual machines and operating systems

(Refer Slide Time: 00:01:16 min)

Special FEATURE. By Heinrich Munz

CHAPTER 7: The CPU and Memory

CHAPTER 6 TASK MANAGEMENT

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

1. Computer System Structure and Components

How to design and implement firmware for embedded systems

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

CS161: Operating Systems

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

Chapter 02: Computer Organization. Lesson 04: Functional units and components in a computer organization Part 3 Bus Structures

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

ARM7TDMI-S. Technical Reference Manual. (Rev 3) Copyright ARM Limited All rights reserved. ARM DDI 0084F

Keil Debugger Tutorial

Freescale Semiconductor, I

AVR Butterfly Training. Atmel Norway, AVR Applications Group

An Implementation Of Multiprocessor Linux

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

Printed Exception strings - what do all

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Dr. Alexander Walsch IN 2244 Part V WS 2013/14 Technische Universität München

Operating System Overview. Otto J. Anshus

Chapter 13. PIC Family Microcontroller

An Overview of Stack Architecture and the PSC 1000 Microprocessor

Operating Systems. Virtual Memory

Instruction Set Design

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

AN UART/SPI/I 2 C code examples. Document information. Abstract Simple code examples are provided for UART0, SPI and I 2 C.

System Virtual Machines

Computer-System Architecture

Systems I: Computer Organization and Architecture

Timer Value IRQ IACK

Formal virtualization requirements for the ARM architecture

Transcription:

Exception and Interrupt Handling in ARM Seminar Course: Architectures and Design Methods for Embedded Systems Author: Ahmed Fathy Abdelrazek (Infotech Master Student) Advisor: Dominik Lücke 1

Contents Introducing ARM Exceptions Interrupts Interrupt handling schemes Summary 2

Introducing ARM Modes of operation ARM processor has 7 modes of operation. Switching between modes can be done manually through modifying the mode bits in the CPSR register. Most application programs execute in user mode Non user modes (called privileged modes) are entered to serve interrupts or exceptions The system mode is special mode for accessing protected resources. It don t use registers used by exception hanlders, so it can t be corrupted by any exception handler error!!! 3

Introducing ARM Modes of operation Switching between these modes requires saving/loading register values Processor Mode User (usr) FIQ (fiq) IRQ (irq) Supervisor (svc) Abort (abt) Undefined (und) System (sys) Description Normal program execution mode Fast data processing mode For general purpose interrupts A protected mode for the operating system When data or instruction fetch is aborted For undefined instructions Privileged mode for OS Tasks 4

Introducing ARM ARM register set ARM processor has 37 32-bit registers. 31 registers are general purpose registers. 6 registers are control registers Registers are named from R0 to R16 with some registers banked in different modes R13 is the stack pointer SP (Banked) R14 is subroutine link register LR (Banked) R15 is progrm counter PC R16 is current program status register CPSR (Banked) 5

Introducing ARM ARM register set More banked registers, so context switching is faster 6

Contents Introducing ARM Exceptions Interrupts Interrupt handling schemes Summary 7

Exceptions What is an exception? An exception is any condition that needs to halt normal execution of the instructions Examples Resetting ARM core Failure of fetching instructions HWI SWI 8

Exceptions Exceptions and modes Each exception causes the ARM core to enter a specific mode. Exception Mode Purpose Fast Interrupt Request FIQ Fast interrupt handling Interrupt Request SWI and RESET Pre-fetch or data abort Undefined Instruction IRQ SVC ABT UND Normal interrupt handling Protected mode for OS Memory protection handling SW emulation of HW coprocessors 9

Exceptions Vector table It is a table of addresses that the ARM core branches to when an exception is raised and there is always branching instructions that direct the core to the ISR. At this place in memory, we find a branching instruction ldr pc, [pc, #_IRQ_handler_offset] 10

Exceptions Exception priorities decide which of the currently raised exceptions is more important Decide if the exception handler itself can be interrupted during execution or not? Exception Priority I bit F bit Reset 1 1 1 Both are caused by an instruction entering the execution stage of the ARM instruction pipeline Data Abort 2 1 - FIQ 3 1 1 IRQ 4 1 - Prefetch abort 5 1 - SWI 6 1 - Undefined instruction 6 1-11

Exceptions Link Register Offset This register is used to return the PC to the appropriate place in the interrupted task since this is not always the old PC value.it is modified depending on the type of exception. The PC has advanced beyond the instruction causing the exception. Upon exit of the prefetch abort exception handler, software must re-load the PC back one instruction from the PC saved at the time of the exception. Exception Reset Data Abort FIQ, IRQ, prefetch Abort SWI, Undefined Instruction Returning Address None LR-8 LR-4 LR 12

Exceptions Entering exception handler 1. Save the address of the next instruction in the appropriate Link Register LR. 2. Copy CPSR to the SPSR of new mode. 3. Change the mode by modifying bits in CPSR. 4. Fetch next instruction from the vector table. Leaving exception handler 1. Move the Link Register LR (minus an offset) to the PC. 2. Copy SPSR back to CPSR, this will automatically changes the mode back to the previous one. 3. Clear the interrupt disable flags (if they were set). 13

Contents Introducing ARM Exceptions Interrupts Interrupt handling schemes Summary 14

Interrupts Assigning interrupts It is up to the system designer who can decide which HW peripheral can produce which interrupt. But system designers have adopted a standard design for assigning interrupts: SWI are used to call privileged OS routines. IRQ are assigned to general purpose interrupts like periodic timers. FIQ is reserved for one single interrupt source that requires fast response time. 15

Interrupts Interrupt latency It is the interval of time from an external interrupt signal being raised to the first fetch of an instruction of the ISR of the raised interrupt signal. System architects try to achieve two main goals: To handle multiple interrupts simultaneously. To minimize the interrupt latency. And this can be done by 2 methods: allow nested interrupt handling give priorities to different interrupt sources 16

Interrupts Enabling and disabling Interrupt MRS BIC MSR This is done by modifying the CPSR, this is done using only 3 ARM instruction: MRS To read CPSR MSR To store in CPSR BIC Bit clear instruction ORR OR instruction Enabling an IRQ/FIQ Interrupt: r1, cpsr r1, r1, #0x80/0x40 cpsr_c, r1 Disabling an IRQ/FIQ Interrupt: MRS ORR MSR r1, cpsr r1, r1, #0x80/0x40 cpsr_c, r1 17

Interrupts Interrupt stack Stacks are needed extensively for context switching between different modes when interrupts are raised. The design of the exception stack depends on two factors: OS Requirements. Target hardware. A good stack design tries to avoid stack overflow because it cause instability in embedded systems. 18

Interrupts Interrupt stack Two design decisions need to be made for the stacks: The location The size User stack Interrupt stack Traditional memory layout Heap Code Interrupt stack Vector Table User stack Heap Code Vector Table The benefit of this layout is that the vector table remains untouched if a stack overflow occured!! 19

Contents Introducing ARM Exceptions Interrupts Interrupt handling schemes Summary 20

Interrupt handling schemes Non-nested interrupt handling scheme This is the simplest interrupt handler. Interrupts are disabled until control is returned back to the interrupted task. One interrupt can be served at a time. Not suitable for complex embedded systems. Interrupt Return to task Disable interrupts Enable interrupts Save context Restore context Interrupt handler ISR 21

Interrupt handling schemes Nested interrupt handling scheme(1) Handling more than one interrupt at a time is possible by enabling interrupts before fully serving the current interrupt. Interrupt Disable interrupts Save context Latency is improved. System is more complex. No difference between interrupts by priorities, so normal interrupts can block critical interrupts. Enable interrupts somewhere here Return to task Interrupt handler ISR Restore context 22

Interrupt handling schemes Nested interrupt handling scheme(2) The handler tests a flag that is updated by the ISR Handler Not complete Re enabling interrupts requires switching out of current interrupt mode to either SVC or system mode. Context switch involves emptying the IRQ stack into reserved blocks of memory on SVC stack called stack frames. Complete serving interrupt Prepare stack. Switch mode. Construct a frame. Enable interrupts. Interrupt Interrupt 23

Interrupt handling schemes Prioritized simple interrupt handling associate a priority level with a particular interrupt source. Handling prioritization can be done by means of software or hardware. When an interrupt signal is raised, a fixed amount of comparisons is done. So the interrupt latency is deterministic. But this could be considered a disadvantage!! 24

Interrupt handling schemes Other schemes There are some other schemes, which are actually modifications to the previous schemes as follows: Re-entrant interrupt handler : re-enable interrupts earlier and support priorities, so the latency is reduced. Prioritized standard interrupt handler : arranges priorities in a special way to reduce the time needed to decide on which interrupt will be handled. Prioritized grouped interrupt handler : groups some interrupts into subset which has a priority level, this is good for large amount of interrupt sources. 25

Contents Introducing ARM Exceptions Interrupts Interrupt handling schemes Summary 26

Summary Availability of different modes of operation in ARM helps in exception handling in a structured way. Context switching is one of the main issues affecting interrupt latency, and this is resolved in ARM FIQ mode by increasing number of banked registers. We can t decide on one interrupt handling scheme to be used as a standard in all systems, it depends on the nature of the system: What type of interrupts are there? How many interrupts are there? 27

Thanks For listening, Waiting for questions 28