ARM processor ~ interrupts and exceptions

Publisher:老卫Latest update time:2020-04-23 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Interrupts and exceptions

definition

Except for User and System, all working modes in ARM are exception modes. The exceptions here are broad and include the following three situations:


External Interrupt (External Interrupt)

Changing the program execution flow due to reasons external to the CPU is an asynchronous event and can be blocked


Software interrupt (traps)

The processor has software instructions that can predictably change the execution flow of the program being executed to execute a specific program.

Explicit events, unconditional execution

It is a synchronous event and cannot be blocked.

For example, the Trap instruction in the Motorola 68000 series, the SWI in ARM, the INT in Intel 8086

abnormal

Events caused by internal CPU reasons (such as illegal instructions) or external reasons (such as memory access errors)

There is no corresponding processor instruction

When an exception occurs, the processor unconditionally suspends the currently running program to execute a specific handler.

It is a synchronous event and cannot be blocked.

ARM processors handle the above three events in exception mode and respond through exception vectors. Each exception vector of ARM stores an instruction (usually a jump instruction). When an exception occurs, the CPU automatically goes to the specified vector address to read the instruction and execute it.


Exception Vector Table

ARM's exception vector is generally the instruction that completes the program jump


In ARM720T, ARM9 series and later kernels, the exception vector table can be placed in the high address space starting at 0xFFFF0000

Exception Vector Table

details

Exception vector table contents

If the starting address of the exception handler is within the 32MB range, the jump can be completed directly using the branch instruction

If the starting address of the exception handler is a legal ARM instruction immediate value (which can be obtained by rotating a number between 0 and 255 by an even number of bits), the address can be loaded into the PC using a data transfer instruction.


In other cases, the LDR instruction is required to load the PC.


Exception event types caused by ARM

comprehensive

Abnormal response process

When an exception occurs, the processor core will

Copy the contents of CPSR to the SPSR_ register in the corresponding mode

Set the relevant bits of the CPSR (change to ARM state, change to exception mode, disable interrupts (if appropriate))

Save the return address in the LR_ register in the corresponding mode

Set PC to the exception vector table address

To return from an exception, the exception handler needs to

Restore CPSR from SPSR_

Set PC to the address pointed to by LR_ (the return address is loaded into PC)

The above can only be done in ARM state

Reset exception

When Reset is triggered, the CPU enters Supervisor mode and disables FIQ and IRQ


R14_svc = Unknown value

SPSR_svc = CPSR

CPSR[4:0] = 0b10011; Enter management mode

CPSR[5] = 0; Execute in ARM state

CPSR[6] = 1; Disable fast interrupt FIQ

CPSR[7] = 1; Disable normal interrupt IRQ


Undefined instruction exception

There are two situations that trigger this exception.


The CPU executes a coprocessor instruction without waiting for a response from any coprocessor.

When the CPU executes an undefined instruction

Once this exception occurs, the CPU will complete the following actions


R14_und = the address of the next instruction of the undefined instruction

SPSR_und = CPSR

CPSR[4:0] = 0b11011 ; enter undefined mode

CPSR[5] = 0; Execute in ARM state

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods


MOVS PC, R14 ; Skip the instruction where the exception occurred

SUBS PC, R14, #4 ; Re-execute the instruction where the exception occurred


Software interrupt exception

Triggered when the SWI instruction is executed, mainly used to enter the OS system call

Soft interrupt

R14_svc = the address of the next instruction after the SWI instruction

SPSR_svc = CPSR

CPSR[4:0] = 0b10011; Enter management mode

CPSR[5] = 0; Execute in ARM state

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods: MOVS PC, R14


Instruction prefetch exception

When a memory read error occurs while reading an instruction, it is marked as aborted. This exception is triggered when the instruction is to be executed. If it is not executed, this exception is not triggered.


That is, when the CPU attempts to execute an instruction that has been marked as invalid, this exception is triggered.


R14_abt = the address of the instruction next to the abort instruction

SPSR_abt = CPSR

CPSR[4:0] = 0b10111 ; Enter the abort mode

CPSR[5] = 0; Execute in ARM state

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods: SUBS PC, R14, #4


Data Abort Exception

When loading/storing data between the CPU and the storage system, if an error occurs, this exception is triggered. There are two cases:


Internal Abort Exception

Caused by the CPU core itself, such as an MMU/MPU error, which means that corrective actions need to be taken and the appropriate instructions need to be re-executed


External abort exception

Caused by the storage system, possibly a hardware error or the memory address does not exist


R14_abt = the address of the instruction next to the abort instruction

SPSR_abt = CPSR

CPSR[4:0] = 0b10111 ; Enter the abort mode

CPSR[5] = 0; Execute in ARM state

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods


SUBS PC, R14, #4 ; Skip the instruction where the exception occurred

SUBS PC, R14, #8 ; Return to the instruction where the exception occurred


IRQ

This exception is triggered when an external IRQ input request occurs and the IRQ interrupt response has been enabled.


R14_irq = next instruction address

SPSR_irq = CPSR

CPSR[4:0] = 0b10010; Enter IRQ mode

CPSR[5] = 0; Execute in ARM state

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods: SUBS PC, R14, #4


FIQ

This exception is triggered when an external FIQ input request occurs and the FIQ interrupt response has been enabled.


Usually used to transfer data quickly


R14_fiq = next instruction address

SPSR_fiq = CPSR

CPSR[4:0] = 0b10001; Enter FIQ mode

CPSR[5] = 0; Execute in ARM state

CPSR[6] = 1; Disable fast interrupt FIQ

CPSR[7] = 1; Disable normal interrupt IRQ


Commonly used exception return methods: SUBS PC, R14, #4


Exception return

Except for the reset exception, all other exceptions can be processed and returned to the program that was interrupted when the exception occurred to continue execution.

Usually a data transfer instruction is used at the end of the exception handler to complete

In exception mode, add the suffix 'S' to the instruction and use the PC as the destination register. This will not only update the value of the PC, but also load the contents of the SPSR register into the CPSR.

One of the main reasons for correcting the return address is the pipeline of the ARM processor

Notes on calculating return addresses

Whether the PC value has been updated when an exception occurs

Do the interrupted instructions need to be executed after the exception return?

LR = PC - 4


Exception Priority

Exceptions are assigned priorities, which determine the order in which they are responded to.

Exception Priority

At the entrance of all exceptions, the IRQ interrupt is masked and can only trigger kernel response (such as interrupt nesting processing) when it is re-enabled.


At the entry of FIQ and Reset exceptions, FIQ interrupts are masked


Register usage in exception handling

The mode switch that accompanies an exception means that the exception handler that is called will access

Its own stack pointer (SP_)

Its own link register (LR_)

Its own Backup Program Status Register (SPSR_)

If it is FIQ exception handling, 5 other general status registers (r8_FIQ to r12_FIQ)

The other registers are the same as the registers in the original mode

On the external interface, the stack pointer (SP_) must be kept 8-byte aligned

The exception handler must ensure that the other (corrupted registers) are reloaded before returning to restore the state before the exception occurred.

This can be done by pushing the contents of the working (i.e. corrupted) registers onto the stack and popping them before returning.

The application's initialization code will perform the necessary register initialization

Interrupt handling

ARM can respond to two external interrupt request signals, FIQ and IRQ


FIQ interrupts have higher priority than IRQ interrupts


When multiple interrupts occur, the FIQ is processed first

When responding to a FIQ interrupt, mask the IRQ interrupt (and the FIQ interrupt). The IRQ interrupt will not be processed until the FIQ interrupt handler is completed.

The following design enables IFQ to respond as quickly as possible


The FIQ vector is at the end of the exception vector table, so that the FIQ handler can start directly from the FIQ vector, saving the time of jumping.

There are five additional registers in FIQ mode (R8_FIQ to R12_FIQ) that do not need to be saved and restored when entering and exiting FIQ.

FIQ interrupts are masked at the entry of the FIQ interrupt handler and need to be re-enabled (there can be multiple FIQ interrupt sources, but nesting of FIQ interrupts should be avoided for best system performance)

Most ARM-based systems have more than two interrupt sources, so an interrupt controller (usually memory-mapped addressing) is needed to control how the interrupt signal enters the ARM chip.

Multi-level interrupt

Keywords:ARM Reference address:ARM processor ~ interrupts and exceptions

Previous article:Interruption of Arm architecture exception handling process
Next article:ARM exception and interrupt handling

Recommended ReadingLatest update time:2024-11-15 07:51

Application and optimization research of Gnuboy virtual machine technology in ARM Linux
Gnuboy has implemented some optimization work on i386 assembly code and can run well on Pentium machines. In addition, so far, the platforms it can run on are still very limited. With the development of embedded system design technology, the functions of embedded products such as PDA and Smartphone are constantly expa
[Microcontroller]
Application and optimization research of Gnuboy virtual machine technology in ARM Linux
Analysis of SDIO mode driver for SD card based on ARM with SD controller
The SD card was jointly developed by Japan's Panasonic , Toshiba and the United States ' SanDisk in August 1999. The structure of SD card can ensure the security of digital file transmission and it is also easy to reformat, so it is increasingly used in embedded systems. SD cards are very convenient to use. There ar
[Microcontroller]
Analysis of SDIO mode driver for SD card based on ARM with SD controller
Professional engineers explain the difference between ARM and MCU
Professional engineers explain the difference between ARM and MCU 1. Software This should be the biggest difference. The operating system is introduced. Why introduce the operating system? What are the benefits?   1) Convenience. It is mainly reflected in the later development, that is, developing applications di
[Microcontroller]
arm-linux-gcc4.4.3 compiles busybox-1.25.0
System environment: 1. Operating system: Ubuntu16.04 2. Cross-compilation tool chain: arm-linux-gcc4.4.3 3. busybox source code package: busybox-1.25.0   1. Modify Makefile configuration First unzip the source package: tar -jxvf busybox-1.25.0.tar.bz2 Enter the busybox-1.25.0 directory and modify the Makefile as follo
[Microcontroller]
ARM assembly special symbols assembly symbol reference
Special symbols ---- corresponding instructions ---- meaning ---- examples ^ ---- MAP ---- define structured memory table ---- MAP 4096; the first address of the memory table is 4096 # ---- FIELD ---- Define the data in the memory table, used in conjunction with the MAP instruction ----  MAP 4096 STACKSVC FIELD
[Microcontroller]
Porting net-snmp to ARM platform
Host environment Windows + vmware (redhat9.0) The IP allocation is as follows:       ARM development board: 192.168.4.151       Windows: 192.168.4.44       Redhat9.0: 192.168.4.150 Building a cross-compilation environment   Unzip the cross compiler to the /opt/ directory, and then add it to the /etc/profil
[Microcontroller]
Design of remote control system for ARM controller and home intelligence using ZigBee technology
As the pace of life continues to accelerate, people hope to be able to keep abreast of the situation at home and control various devices at home even when they are at work or out. The continuous development of various wireless communication technologies has made remote control of home intelligent systems a reality. Th
[Microcontroller]
Design of remote control system for ARM controller and home intelligence using ZigBee technology
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号