SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What are the exceptions in ARM architecture?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What are the exceptions in ARM architecture?

Scott Allen
Last updated: September 11, 2023 6:41 am
Scott Allen 5 Min Read
Share
SHARE

The ARM architecture defines a set of exceptions that can occur during program execution. These exceptions, also known as interrupts, allow the processor to handle events and transfer control to specific software routines to deal with these events. Some key things to know about exceptions in ARM architecture:

Contents
Types of ExceptionsException VectorsProcessor States on Exception EntryReturn From ExceptionEnabling and Disabling InterruptsNested ExceptionsPrioritizing ExceptionsSecure and Non-secure ExceptionsSummary

Types of Exceptions

There are several different types of exceptions defined in the ARM architecture:

  • Reset – This exception occurs when the processor is reset. It causes the program counter to jump to the reset vector address.
  • Undefined instruction – Triggered when an undefined or unimplemented instruction is executed.
  • Software interrupt – This is a program-triggered exception by executing the SWI instruction.
  • Prefetch abort – An instruction prefetch resulted in an abort, such as an invalid memory access.
  • Data abort – An data memory access operation resulted in an abort, such as invalid memory access.
  • IRQ – Standard interrupt request triggered by an external device or event.
  • FIQ – Fast interrupt request which has higher priority than IRQ.

Exception Vectors

Each exception type has a corresponding vector – an address pointing to the exception handler routine. The processor jumps to this address when the exception is triggered.

The exception vector addresses are defined by the ARM architecture. For example, the reset vector is 0x00000000, the undefined instruction vector is 0x00000004, and so on.

Developers can implement custom exception handler routines at these vector addresses to respond to exceptions in the desired way.

Processor States on Exception Entry

When an exception occurs, the ARM processor automatically saves its state before jumping to the vector. This includes:

  • Saving the program counter (PC) to the link register (LR)
  • Switching to a new mode – e.g. from User mode to Supervisor mode
  • Saving the SPSR (Saved Program Status Register)

This preserves the state so that the main program can resume after the exception handler runs.

Return From Exception

Once the exception handler completes its work, it returns control back to the main program using the subs instruction. This restores the PC, CPSR and other registers from the stored values.

The exception return offsets are predefined for each exception type. This allows the handler to return to the instruction after the point where the exception occurred.

Enabling and Disabling Interrupts

The ARM processors provide mechanisms to enable and disable interrupts such as IRQ and FIQ. This is useful for critical sections of code where interrupts must be temporarily blocked.

Common ways to enable/disable interrupts include:

  • Setting or clearing the I and F bits in the CPSR using MRS/MSR instructions
  • Using CPS instructions to modify the interrupt disable flags
  • Storing and restoring CPSR during exception entry/exit

Disabling interrupts for long periods can impact real-time performance, so care must be taken.

Nested Exceptions

It is possible for an exception to occur while another exception handler is already running. This is called nested exceptions.

ARM processors include mechanisms to handle nested exceptions safely by stacking additional context during nested exception entry.

However, nested exceptions can make interrupt handling complex for developers. They should generally be avoided in application code if possible.

Prioritizing Exceptions

In ARM architecture, exceptions have a defined priority order. Higher priority exceptions can interrupt lower priority ones.

The exception priorities are, from highest to lowest:

  1. Reset
  2. Data abort
  3. FIQ
  4. IRQ
  5. Prefetch abort
  6. Undefined instruction
  7. Software interrupt

So for example, an FIQ interrupt will preempt a currently executing IRQ handler. But a lower priority Software Interrupt cannot preempt an FIQ.

Secure and Non-secure Exceptions

ARMv8 architectures introduce TrustZone and security extensions. This allows certain exceptions to be designated as “secure” while others are “non-secure”.

Secure exception handlers run with higher privileges and can access secure resources. Non-secure exceptions have limited access.

This exception model separation improves security in IT systems.

Summary

In summary, exceptions allow ARM processors to respond efficiently to events during program execution. The ARM architecture precisely defines various exceptions, their priorities, vector addresses, return mechanisms, and security models. Developers can leverage exceptions to build robust interrupt handling in their ARM-based systems.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What is the exception in the Cortex-M?
Next Article What is the exception handling of the ARM Cortex-M0?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Demystifying Arm’s Branch and Link Instructions (BL and BLX)

The Arm architecture includes two important branch and link instructions…

9 Min Read

Does cortex M series have MMU?

The short answer is yes, the Cortex-M series of ARM…

7 Min Read

Implementing a Round-Robin Scheduler on Cortex-M

A round-robin scheduler is a scheduling algorithm that sequentially cycles…

5 Min Read

SPI Memory Interfaces vs Memory Mapped Memories in Arm Cortex

SPI and memory mapped memories are two different ways to…

9 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account