"Some Problems with ARM and Linux" Chapter 1: ARM Working Mode

Publisher:lambda21Latest update time:2016-06-24 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
================================================== ================================================== ================================

    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.

Keywords:ARM Reference address:"Some Problems with ARM and Linux" Chapter 1: ARM Working Mode

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

ARM assembly instruction MCR/MRC learning
The MCR instruction transfers the data in the register of the ARM processor to the register of the coprocessor. If the coprocessor cannot successfully perform the operation, an undefined instruction exception interrupt will be generated. The syntax format of the command is: MCR{} p15, 0, , , {,} MCR2 p15, 0, , , {
[Microcontroller]
Research on Wandboard Development Board Based on ARM Cortex-A9
  1 Overview   Freescale's i.MX 6 series multi-core application processors use the ARM Cortex-A9 architecture, including single-core, dual-core and quad-core series, with operating frequencies up to 1.2GHz, support ARMv7, Neon, VFPv3 and Trustzone, integrate 32kB instruction and data L1 cache and 256kB~1MB L2 cache,
[Microcontroller]
Research on Wandboard Development Board Based on ARM Cortex-A9
How to access user mode registers in arm privileged mode
After ARM enters the exception mode, it accesses the registers of each mode. The access between modes (excluding user mode) is done by modifying CPSR and entering another mode. The CPY SET between each other is done through unbanked regs (R0 - R7). So how does privileged mode access user mode registers?
[Microcontroller]
s3c2440 ARM9 bare metal driver first article - GPIO driver (C)
This article is a supplement to LED drivers: Without further ado, let's get to the code. start.s .text .global _start _start: ldr r0 ,= 0x53000000 @WATCHDOG ADD mov r1 ,#0x0 str r1 , @r1 data is written to r0 to turn off the watchdog ldr sp ,=1024*4 @Set up the stack bl main @jump to main e
[Microcontroller]
ARM11 and DSP Collaborative Video Stream Processing Technology 3G Video Safety Helmet Design
  This paper designs a 3G video helmet based on ARM11 and DSP dual-core video processing technology. After local efficient compression processing of the audio and video signals at the work site, it transmits them to the remote server in real time through the 3G network, realizing remote command and monitoring and two-
[Embedded]
ARM11 and DSP Collaborative Video Stream Processing Technology 3G Video Safety Helmet Design
How to use printf in IAR for ARM
1. Add a line _DLIB_FILE_DESCRIPTOR under option- C/C++ compiler--- defined symbols 2. Add the following function in the file using printf  int fputc(int ch, FILE *f) {       USART_SendData(USART1, (u8) ch);      while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)   {   }   return ch; } 
[Microcontroller]
Wireless network card device driver solution designed by ARM
With the access of wireless LAN in embedded systems, wireless control and data transmission of embedded systems can be realized, and some special application occasions can be met. Here, through the in-depth understanding and analysis of the Linux device driver of the USB wireless network card, it was successfully
[Microcontroller]
Wireless network card device driver solution designed by ARM
Install arm-linux-gnueabi-xxx compiler in Ubuntu
Installing the ARM-Linux-GCC toolchain Assuming your Ubuntu system is up to date, you only need to execute the following command to successfully install it: sudo apt-get install gcc-arm-linux-gnueabi After the installation is complete, type directly in the terminal arm-linux-guneabi-gcc -v
[Microcontroller]
Install arm-linux-gnueabi-xxx compiler in Ubuntu
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号