ARM processor modes and on-chip registers, ARM exceptions and interrupts

Publisher:古通闲人Latest update time:2016-06-30 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The difference between interrupts and exceptions: interrupts are from the outside to the inside, while exceptions are from the inside.


1. Memory format (word alignment):

The Arm architecture treats memory as a linear combination of bytes starting from address zero. The first stored word (32-bit) data is placed from byte zero to byte three, and the second stored word data is placed from byte four to byte seven, arranged one by one. As a 32-bit microprocessor, the maximum addressing space supported by the Arm architecture is 4GB.

 

Storage format

        1. Big-endian format: high byte at low address, low byte at high address;

        2. Little-endian format: high byte at high address, low byte at low address;

Instruction length:

The instruction length of the Arm microprocessor is 32 bits, and can also be 16 bits (in thumb mode). The Arm microprocessor supports three data types: byte (8 bits), halfword (16 bits), and word (32 bits). Among them, words need to be aligned to 4 bytes, and halfwords need to be aligned to 2 bytes.

Note: The so-called instruction length is the length of a complete instruction, not just the length of the three letters mov.

2. The ARM system CPU has two working states

   1. ARM state: the processor executes 32-bit word-aligned ARM instructions;

         2. Thumb state: The processor executes 16-bit, half-word aligned Thumb instructions;

During the program execution, the two states can be switched accordingly. The change of the processor working state does not affect the processor's working mode and the contents of the corresponding registers.

CPU is powered on in ARM state

 

3. The ARM system CPU has the following 7 working modes:

        1. User mode (Usr): used for normal program execution;

        2. Fast interrupt mode (FIQ): used for high-speed data transmission;

        3. External interrupt mode (IRQ): used for normal interrupt processing;

        4. Management mode (svc): protection mode used by the operating system;

        5. Data access termination mode (abt): This mode is entered when data or instruction prefetching is terminated. It can be used for virtual storage and storage protection.

        6. System mode (sys): runs privileged operating system tasks;

        7. Undefined instruction abort mode (und): This mode is entered when an undefined instruction is executed and can be used to support hardware;

ARM Context-A* architecture has 8 modes

The on-chip registers referred to here are the registers inside the CPU, while the registers that control GPIO belong to peripherals.

Reference: http://infocenter.arm.com/help/index.jsp Corresponding series of documents on the arm official website

 ARM processor modes and on-chip registers, ARM exceptions and interrupts

There are two ways to switch the working mode of Arm:

Passive switching: some exceptions or interrupts are generated when the arm is running to automatically switch modes

Active switching: through software changes, that is, the software sets the register to perform arm mode switching, because the arm's working mode can be switched by assigning values ​​to the corresponding registers.

Tips: When the processor runs in user mode, certain protected system resources cannot be accessed.

 

Except for the user mode, the other six working modes are privileged modes;

The other five modes in the privileged mode except the system mode are called exception modes;

Most programs run in user mode;

Entering privileged mode is to handle interrupts, exceptions, or access protected system resources;

4. Register

ARM has 31 general 32-bit registers and 6 program status registers, which are divided into 7 groups. Some registers are shared by all working modes, and some registers are specific to each working mode.

R13 - Stack pointer register, used to save the stack pointer;

R14 - Program connection register. When the BL subroutine call instruction is executed, R14 gets the backup of R15. When an interrupt or exception occurs, R14 saves the return value of R15.

R15——Program counter;

The fast interrupt mode has 7 backup registers R8-R14, which makes it unnecessary to save any registers when entering the fast interrupt mode to execute a large part of the program;

Other privileged modes have two independent copies of registers, R13 and R14, so that each mode can have its own stack pointer and connection registers;

 

5. Current Program Status Register (CPSR)

The meaning of each bit in CPSR is as follows:

T bit: 1——CPU is in Thumb state, 0——CPU is in ARM state;

I, F (interrupt disable bit): 1-disable interrupt, 0-enable interrupt;

Working mode bits: These bits can be changed to switch modes;

6. Program Status Save Register (SPSR)

When switching to a privileged mode, the SPSR saves the CPSR value of the previous working mode, so that when returning to the previous working mode, the value of the SPSR can be restored to the CPSR;

ARM processor modes and on-chip registers, ARM exceptions and interrupts

7. Mode Switching

When an exception occurs and the CPU enters the corresponding exception mode, the following tasks are automatically completed by the CPU:

1. Save the address of the next instruction to be executed in the previous working mode in R14 of the exception mode;

2. The value of CPSR is transferred to the SPSR of the abnormal mode;

3. Set the working mode of CPSR to the working mode corresponding to the abnormal mode;

4. Set the PC value to the address of this exception mode in the exception vector table, that is, jump to execute the corresponding instruction in the exception vector table;

When returning from an abnormal working mode to the previous working mode, the software needs to complete the following tasks:

1. Subtract an appropriate value (4 or 8) from R14 in the exception mode and assign it to the PC register;

2. Assign the value of the exception mode SPSR to the CPSR;

 

 

 

ARM has seven exceptions. When an exception occurs, the ARM core will automatically execute the instructions in the Vector Table.

ARM's seven exceptions and their offsets in the Vector Table:   

 

abnormal

model

Vector table offset

Reset

SVC

+0x00

Undefined instruction

UND

+0x04

Software Interrupt (SWI)

SVC

+0x08

Prefetch Abort

ABT

+0x0c

Data Termination

ABT

+0x10

Unassigned

--

+0x14

IRQ

IRQ

+0x18

FIQ    

FIQ

+0x1c

 

The address of the Vector Table of ARM versions below V4 is 0x00000000. The address of the Vector Table of versions above V4 can be selected between 0x00000000 and 0xFFFF0000.

In the ARM architecture, interrupts are a type of exception. Taking interrupts as an example, when an interrupt is received, the ARM core first saves the CPSR and PC registers in the current mode to the SPSR and LR registers in the exception mode, and then sets the PC register value of the target mode to address 0x00000018 (or 0xFFFF0018), and finally switches to the target mode, that is, the IRQ mode. The first instruction executed after switching to the target mode is the instruction at address 0x00000018 (or 0xFFFF0018). This is generally a jump instruction, which is used to jump to the interrupt processing function. Other exception handling methods are similar.

S3C6410 has a 32KB IROM (internel ROM) with a program embedded in it. The beginning of the program is a Vector Table. When booting in IROM mode, IROM is mapped to 0x00000000, so the first instruction executed is the Reset exception jump instruction in the Vector Table (the first instruction is taken at address 0 when the ARM core is powered on). We can use the exception vector table of this IROM to implement interrupt processing under u-boot.

Just after power-on, the interrupt is initialized so that S3C6410 can receive and process interrupts. After an interrupt occurs, the exception jump in 0x00000018 is executed first, and then the interrupt processing function in IROM is executed. This processing function is very simple: the value at 0x0C001FF8 (which falls within the SRAM address range) is assigned to PC. Therefore, we can store the entry address of our own interrupt processing function at 0x0C001FF8, and when an interrupt occurs, our interrupt processing function will be automatically called. The implementation method of other exceptions is similar, except that 0x0C001FF8 needs to be changed to another value. The specific value needs to be analyzed in the code in IROM.

The disassembled code of S3C6410 IROM can be searched on the Internet, or you can extract and disassemble it yourself.

 
Keywords:ARM Reference address:ARM processor modes and on-chip registers, ARM exceptions and interrupts

Previous article:ARM processor program status register (CPSR, SPSR) access instructions
Next article:Registers in different processor modes

Recommended ReadingLatest update time:2024-11-15 16:25

In-depth understanding of ARM architecture (S3C6410) --- S3C6410 system clock
The system clock control logic generates the required system clock signals in S3C6410, ARMCLK for CPU, HCLK for AXI/AHB bus peripherals and PCLK for APB bus peripherals. There are three PLLs in S3C6410. One is only for ARMCLK, one is for HCLK and PCLK, and the last one is for peripheral, especially for audio related cl
[Microcontroller]
In-depth understanding of ARM architecture (S3C6410) --- S3C6410 system clock
ARM assembly syntax under Linux
Part 1 ARM assembly syntax under Linux Although it is convenient to write programs in C or C++ under Linux, the assembly source program is used for the most basic initialization of the system, such as initializing the stack pointer, setting up the page table, operating the ARM coprocessor, etc. After the initializatio
[Microcontroller]
Design of digital microwave monitoring system based on ARM chip LPC2214 and μC/OS-II
With the popularization and deepening of embedded system development, traditional software development methods are difficult to meet the needs of more complex applications. Embedded operating systems play an increasingly important role in development and have been widely used in mobile phones and mobile computers. Equ
[Microcontroller]
Design of digital microwave monitoring system based on ARM chip LPC2214 and μC/OS-II
Why are PC=PC+8 in both ARM3-stage and 5-stage pipelines?
First, let's introduce the prerequisite knowledge ARM7 uses a three-stage pipeline (1) Fetch: The task of the fetch stage is to read instructions from the program memory. (2) Decode: The decode stage completes the analysis of the instruction and prepares the control signals required by the data path for the next c
[Microcontroller]
Why are PC=PC+8 in both ARM3-stage and 5-stage pipelines?
Configuration functions of ARM common functions---key accumulation
//Author: "Tears and Sweat" //Data: 2011-November //Function: Accumulate programming ideas and routines The configuration functions included in this page are: void SysTick_Configuration(void); void GPIO_Configuration(void);  //Configure the port pin function void EXTI_Configuration(void); //Configure the extern
[Microcontroller]
tq2440-arm9 transplantation (problems encountered)
1. Kernel compilation error (different compiler versions used) ARM-Linux-ld: ERROR: drivers/media/video/tq2440/built-in.o is compiled for EABI version 5, whereas drivers/media/video/built-in.o is compiled for version 0 When compiling the kernel, this error occurred. According to the error message, it can be identifie
[Microcontroller]
Efficient exception handling solution based on ARM processor
Embedded systems require fast responses to exceptions and interrupt handlers. This paper analyzes the characteristics of exception handling under the ARM architecture, proposes an efficient exception handling solution based on the ARM processor, and designs and implements the solution based on the LPC3250 hardware pla
[Microcontroller]
Efficient exception handling solution based on ARM processor
Preliminary creation of makefile, detailed explanation of arm-linux- (gcc/ld/objcopy/objdump)
Enter vi Makefile in linux to create a Makefile file Note: You must add the TAB key before the command line For example: assemble two files led.c and crt0.S to create a Makefile 1 1 led.bin : crt0.S led.c 2 2 arm-linux-gcc -c -o crt0.o crt0.c 3 3 arm-linux-gcc -c -o led.o l
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号