ARM-based hardware startup program design-initialization stack

Publisher:epsilon15Latest update time:2015-11-13 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
ARM has 7 operating states, and the stack pointer register (SP) of each state is independent. Therefore, for each processor mode needed in the program, a stack address must be defined for SP. The process is: modify the status bit in the status register to switch the processor to the required mode, and then assign a value to SP. It should be noted that: do not switch to User mode to set the stack in this mode, because after entering User mode, you can no longer operate CPSR to return to other modes.

First define the value of the CPSR register M[4:0] corresponding to each mode. This value determines which mode to enter. Please refer to the relevant data manual.

Mode_USR EQU 0x10
Mode_FIQ EQU 0x11
Mode_IRQ EQU 0x12
Mode_SVC EQU 0x13
Mode_ABT EQU 0x17
Mode_UND EQU 0x1B
Mode_SYS EQU 0x1F 
I_BIT EQU 0x80 ; when I bit is set (1), IRQ is disabled
F_BIT EQU 0x40 ; when F bit is set (1), FIQ is disabled

Here is the code snippet to initialize the stack:

InitStack    
        MOV R0, LR

; /* Set management mode stack*/
        MSR CPSR_c, #(Mode_SVC | I_BIT | F_BIT) ; 0xd3
        LDR SP, StackSvc
; /* Set interrupt mode stack*/
        MSR CPSR_c, #(Mode_IRQ | I_BIT | F_BIT) ; 0xd2
        LDR SP, StackIrq
; /* Set fast interrupt mode stack*/
        MSR CPSR_c, #(Mode_FIQ | I_BIT | F_BIT) ; 0xd1
        LDR SP, StackFiq
; /* Set abort mode stack*/
        MSR CPSR_c, #(Mode_ABT | I_BIT | F_BIT) ; 0xd7
        LDR SP, StackAbt
; /* Set undefined mode stack*/
        MSR CPSR_c, #(Mode_UND | I_BIT | F_BIT) ; 0xdb
        LDR SP, StackUnd
; /* Set system mode stack */
        MSR CPSR_c, #(Mode_SYS | I_BIT | F_BIT); 0xdf
        LDR SP, StackUsr

        MOV PC, R0


D CD AbtStackSpace + (
ABT_STACK_LEGTH - 1)* 4 StackUnd DCD UndtStackSpace + (UND_STACK_LEGTH - 1)* 4


; /* Allocate stack space*/
        AREA MyStacks, DATA, NOINIT, ALIGN=2
UsrStackSpace SPACE USR_STACK_LEGTH * 4 ;User (system) mode stack space
SvcStackSpace SPACE SVC_STACK_LEGTH * 4 ;Management mode stack space
IrqStackSpace SPACE IRQ_STACK_LEGTH * 4 ;Interrupt mode stack space
FiqStackSpace SPACE FIQ_STACK_LEGTH * 4 ;Fast interrupt mode stack space
AbtStackSpace SPACE ABT_STACK_LEGTH * 4 ;Abort mode stack space
UndtStackSpace SPACE UND_STACK_LEGTH * 4 ;Undefined mode stack

Let's take the management mode stack space as an example.

SVC_STACK_LEGTH is defined as 16, and the allocation results are: allocate 16 4-byte storage spaces, initialize the storage spaces to 0, and point SP to the bottom of the stack (high memory).

From the above memory content, we can see that the management mode stack allocates a total of 16*4 bytes from 0x00008080 to 0x00008044. The address 0x00008040 stores 0x00008080, which is the value of the pointer at the bottom of the stack.

That is, after the compilation, the 32-bit pseudo instruction StackSvc DCD SvcStackSpace + (SVC_STACK_LEGTH - 1)* 4 places the SvcStackSpace address value (0x00008080) at the address 0x00008040 (StackSvc). That is, 0x00008080 is assigned to SP.

Let's look at the contents at addresses 0x00008080~0x00008044. They are all andeq r0,r0,r0. Translated from the assembly instruction format, andeq r0,r0,r0 is exactly 0x000000000 after being translated into 16-disable code. Thus, the stack space is cleared to 0.

Keywords:ARM Reference address:ARM-based hardware startup program design-initialization stack

Previous article:Analyze ARM startup code and interrupt handling process
Next article:ARM embedded system initialization process

Recommended ReadingLatest update time:2024-11-16 13:24

The industry fission caused by ARM (Part 2)
Next: Embracing Industrial Change   The x86 server chip market is in the calm before the storm. With ARM entering from the low end with its low power consumption and IBM suppressing from the high end with the help of the OpenPOWER Alliance, the x86 server chip market is bound to be in turmoil. Perhaps, as the "big b
[Analog Electronics]
The industry fission caused by ARM (Part 2)
Implementation of the sending process for ARM embedded system development
When data is to be sent through the network card, the upper-layer protocol entity calls the function hard_start_xmit(). In our driver, this function is mapped to the DM9000_wait_to_send_packet() function. As the "wait" in its name indicates, this function only completes the work of waiting for sending. The actual send
[Microcontroller]
When TDC-GP22 meets ARM CortexM3
While smart meters are developing rapidly in the power system, water meters are also developing rapidly in the direction of intelligence and full electronicization. On the one hand, the global water shortage forces the government to pay attention to water conservation and water volume control, and on the other hand, t
[Industrial Control]
When TDC-GP22 meets ARM CortexM3
ARM Development: An Overview of ARM Microprocessors
1.1ARM-Advanced RISC Machines ARM (Advanced RISC Machines) can be considered as the name of a company, a general term for a type of microprocessor, or the name of a technology. ARM was founded in Cambridge, UK in 1991, mainly selling licenses for chip design technology. At present, microprocessors using ARM technolo
[Microcontroller]
ARM7 LPC2138 digital frequency meter design source code and report
1.1 Design Principle Frequency is the number of times a periodic signal changes within a unit time (1s). If the number of repeated changes of this periodic signal measured within a certain time interval T is N, then its frequency can be expressed as f=N/T. Among them, f is the frequency of the measured signal, N is t
[Microcontroller]
ARM7 LPC2138 digital frequency meter design source code and report
ARM embedded LINUX startup process (1)
Written by a master, you will regret it if you don't read it!!                              LINUX boot process First, when porting Linux, you need to plan the memory image. For example, my system has 64M SDRAM,  the address is from 0x 0800 0000 -0x0bff ffff, 32M flash, the address is from 0x0c00 0000-0x0dff ffff. 
[Microcontroller]
Socionext announces partnership with Arm and TSMC to develop 2nm multi-core CPU chips
Socionext Inc. (hereinafter "Socionext"), a leader in SoC design and application technology, announced that it is cooperating with Arm and TSMC to develop a low-power 32-core CPU . The chip is based on Chiplet technology and uses TSMC's 2nm process technology. It can be used for ultra-large scale The data center serve
[Semiconductor design/manufacturing]
Fire monitoring solution based on ARM
With the rapid development of microelectronics and computer technology, 32-bit high-performance, low-power embedded microprocessors have gradually replaced traditional 8-bit single-chip microcomputers, and the use of multi-threaded and multi-tasking embedded operating systems remains a development trend. At pres
[Microcontroller]
Fire monitoring solution based on ARM
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
Guess you like

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号