Programming idea: The data transfer instruction MRS/MSR between the status register and the general register is used to implement the modification. The three steps of "read-modify-write back" should be used to implement the modification. Each time, only the corresponding domain needs to be modified. For example, this program only modifies the C control domain. At the same time, it should be noted that the system mode and user mode share SP, and only one of them needs to be initialized.
The program code is as follows:
(1) Programming in the GNU ARM development environment:
.equ _ISR_STARTADDRESS, 0xC7FF000 @Set the memory base address of the stack
.equ UserStack, _ISR_STARTADDRESS @User mode stack address 0x7FF000
.equ SVCStack, _ISR_STARTADDRESS+256 @ management mode stack address 0x7FF100
.equ UndefStack, _ISR_STARTADDRESS+256*2
.equ AbortStack, _ISR_STARTADDRESS+256*3
.equ IRQStack, _ISR_STARTADDRESS+256*4
.equ FIQ Stack, _ISR_STARTADDRESS+256*5
.equ USERMODE, 0x10
.equ FIQMODE, 0x11
.equ IRQMODE, 0x12
.equ SVCMODE, 0x13
.equ ABORTMODE, 0x17
.equ UNDEFMODE, 0x1B
.equ SYSMODE, 0x1F
.equ MODEMASK, 0x1F
.global _start
.text
_start:
MRS R0, CPSR @Read the current CPSR
BIC R0, R0, #MODEMASK @ Clear mode bit
#Set SP in user mode
ORR R1, R0, #SYSMODE
MSR CPSR_c, R1
LDR SP, =UserStack
#Set SP in undefined mode
ORR R1, R0, #UNDEFMODE
MSR CPSR_c, R1
LDR SP, =UndefStack
#Set the SP in termination mode
ORR R1, R0, #ABORTMODE
MSR CPSR_c, R1
LDR SP, =AbortStack
#Set the SP in management mode
ORR R1, R0, #SVCMODE
MSR CPSR_c, R1
LDR SP, =SVCStack
#Set SP in IRQ mode
ORR R1, R0, #IRQMODE
MSR CPSR_c, R1
LDR SP, =IRQStack
#Set SP in FIQ mode
ORR R1, R0, #FIQMODE
MSR CPSR_c, R1
LDR SP, =FIQStack
Stop:
B Stop
.end
(2) The program execution results are as follows:
SP_usr=0xC7FF000
SP_svc=0xC7FF100
SP_und=0xC7FF200
SP_abt=0xC7FF300
SP_irq=0xC7FF400
SP_fiq=0xC7FF500
Previous article:About setting stack pointer sp register r13
Next article:ARM pointer register-program counter PC, stack pointer SP
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [Silicon Labs Development Kit Review] +Si7021 Temperature and Humidity Sensor Detection
- Talk to a VICOR engineer about your design and how to improve your AT equipment throughput and uptime.
- How to migrate SES project from GNU toolchain to Segger toolchain?
- Let’s talk about it: Why is 5G a revolution?
- Crossing your legs has so many harmful effects? Do you still dare to do it after reading this?
- RSL10 Bluetooth SoC Mobile Application Construction 2 - Reading Data
- Problems encountered during operation of itop4418 development board
- Points problem help
- Happy Dragon Boat Festival.
- Description of the performance characteristics of a bandpass RF filter