Early ARM cores had state (ARM or Thumb) switching (using BX and other instructions to modify the T control bit in the CPSR register (current program status register, which stores condition code flags, interrupt disable bits, current processor mode, and other status and control information) to complete the program state switching), and now ARM only uses Thumb state. Therefore, we will not discuss state switching.
1. Seven ARM working modes and their application scenarios (Linux operating system uses USR and SVC modes, and may also switch to Linux kernel mode by entering other modes when an exception occurs)
Set the M[4:0] bits in the CPSR register to correspond to the following seven modes (Note: User mode and system mode only have read access to CPSR, so these two modes cannot enter other modes by directly setting CPSR (except SWI assembly instructions)):
1. User mode (USR): used for normal program execution. In the Linux operating system, user space processes run in this mode. The CPSR register M[4:0] is set to 10000.
2. System mode (SYS): runs privileged operating system tasks. CPSR register M[4:0] is set to 11011.
This mode and user mode share the value of R15-pc (program counter, which stores the address of the unit where the next instruction is located), so there is no need for ARM to force the value.
After ARM enters the following modes, it is necessary to reassign the R15-PC register, that is, start executing new instructions.
3. Supervisor mode (SVC): The protection mode (high privilege) used by the operating system. In the Linux operating system, the kernel space runs in this mode. The CPSR register M[4:0] is set to 10011.
When ARM is just powered on or reset, it enters this mode and forces the PC to fetch instructions from 0x0000 0000; when the system soft interrupt (such as system call, calling ARM's SWI assembly instruction) occurs, it enters this mode and forces the PC to fetch instructions from 0x0000 0008 - this is also the only way for ARM to actively switch from user mode to management mode (Linux actively enters kernel mode from user mode). The following chapters will analyze it in detail.
Chapter 3 of "Some Problems with ARM and Linux": How Linux Enters Kernel State from User State
Chapter 4 of "Some Problems with ARM and Linux": Analysis of the Principles of System Calls on the ARM Platform
When an abnormal situation occurs, Linux may also run in the following ARM modes; such as hardware interrupts, exceptions caused by program problems, etc.
4. Fast interrupt mode (FIQ): used for high-speed data transmission. CPSR register M[4:0] is set to 10001.
After entering this mode, ARM forces PC to fetch instructions from 0x0000 001C.
5. External interrupt mode (IRQ): used for normal interrupt processing. CPSR register M[4:0] is set to 10010.
After entering this mode, ARM forces the PC to fetch instructions from 0x0000 0018.
6. Data access termination mode (ABT): This mode is entered when data or instruction prefetching is terminated. It can be used for virtual memory and storage protection. The CPSR register M[4:0] is set to 10111.
When instruction fetching is terminated, this mode is entered and the PC is forced to fetch instructions from 0x0000 000C; when data fetching is terminated, this mode is entered and the PC is forced to fetch instructions from 0x0000 0010.
7. Undefined instruction termination mode (UND): This mode is entered when an undefined instruction is executed and can be used to support hardware. The CPSR register M[4:0] is set to 11111.
When an undefined instruction appears in the program, enter this mode and force the PC to fetch instructions from 0x0000 0004.
The other 6 modes in non-user mode, including SVC, FIQ, IRQ, ABT, UND, and SYS, can modify the CPSR register to control the switching of ARM working modes.
In the Linux operating system, when the CPU is in privileged mode (Linux is in kernel mode), it can enter user mode at will. When the CPU is in user mode (Linux is in user mode), Linux switches from user mode to kernel mode (ARM switches from user mode to other privileged modes) only in two cases: system call and interrupt (interrupt enters IRQ mode, and can also operate the kernel). Generally, the program runs in user mode at the beginning. When the program needs to use system resources, it must enter kernel mode by calling soft interrupt.
R13-SP (stack pointer register, used in stack operations) is independent for each working mode. Therefore, a stack address must be defined for SP for each mode needed in the program. The method is to change the status bit in the status register (CPSR) to switch the processor to a different state, and then assign a value to SP. Note: Do not switch to User mode to set the stack for User mode, because after entering User mode, you can no longer operate CPSR to return to other modes, which may affect the execution of the next program.
After power-on or reset, ARM enters SVC management mode and starts fetching instructions from 0x0000 0000; both the bootloader and Linux Kernel work in this mode.
2. Two methods of switching ARM working mode
1. Passive switching: refers to the passive switching of ARM in the current working mode without requiring mode switching. When ARM is running, some exceptions (including soft interrupts) or interrupts (hard interrupts) are generated to switch modes. For example, the Linux operating system mentioned above switches from user mode to kernel mode, such as hardware interrupts or program exceptions. Kernel mode will not switch to user mode passively.
2. Active switching: refers to the ARM in the current working mode, through some autonomous operations, actively request to switch the working mode. ARM changes through software, that is, the software sets the register to switch the ARM mode, because the ARM working mode can be switched through the assignment of the corresponding register. As mentioned above, the Linux operating system switches from kernel state to user state; there is a special case here: Linux user state can be switched to kernel state through system call.
Later, I will focus on the switch from Linux user mode to kernel mode. See Chapter 3 of "Some Problems with ARM and Linux": How Linux Enters Kernel Mode from User Mode
================================================== ================================================== ================================
Summary of ARM main registers:
CPSR and SPSR: current program status register and saved program status register;
R15-PC and R14-LR: connection registers between the program counter and the user-saved PC;
R13-SP: Stack pointer.
Previous article:"Some Problems with ARM and Linux" Chapter 2: Linux operating system and ARM working mode
Next article:ARM registers' 7 operating modes and several addressing modes
Recommended ReadingLatest update time:2024-11-17 02:52
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- 【Tuya BK7231N】In-depth analysis of sample code
- The sipeed team will provide developers with free MAXI development boards
- CircuitPython-enabled electronic cat (MeowMeow)
- Please give me some advice!
- Combined amplifier circuit
- Analysis of the switch input circuit composed of four diodes
- Analysis of common problems in TMS320C2000 projects?
- Clock chip problem
- 18 Ways to Draw PCB Routes
- Be careful with the FPGA's JTAG port (power-on and power-off sequence)