.globl _start
_start: b
From this we can see that ARM supports 7 exceptions. The question is how does ARM respond after an exception occurs? The first reset exception is good.
Understand, it is placed at 0x0, it is executed as soon as the power is turned on, and our program always starts from the reset exception handler, so
This reset exception handler does not need to return. So how did it execute to the following exception handlers?
After reading the book, I understood the ARM response process to exceptions, so I was able to answer this question.
When an exception occurs, ARM will automatically perform the following steps:
(1) Put the address of the next instruction into the link register LR (usually R14), so that it can return from the correct position when handling the exception.
Continue execution.
(2) Copy the corresponding CPSR (Current Program Status Register) to the SPSR (Backup Program Status Register).
(3) According to the exception type, the operating mode bit of CPSR is forced to be set. (
4) The PC (program counter) is forced to fetch the next instruction from the relevant exception vector address and execute it, thereby jumping to the corresponding exception handling procedure .
As
for what these exception types represent, I didn't go into it. Because I usually care about reset, there is no need to figure it out.
ARM specifies the address of the exception vector:
ldr pc, _undefined_instruction; undefined instruction exception 0x4
It is very simple to understand this code. When an exception occurs, the PC will be forced to be set to the corresponding exception vector, thereby jumping to the corresponding
The interrupt vectors of these boot
programs are only used by the boot program itself. Once the boot program has finished booting the Linux kernel, it will use
Own interrupt vector.
Oh, this is a problem. For example, when an ARM interrupt (irq) occurs, it will always run to 0x18 for execution. How about the Linux kernel?
How can you use your own interrupt vector? The reason is that the Linux kernel uses paged memory management. After the MMU page mapping is enabled, the CPU
The address sent is a virtual address rather than a physical address. As far as the Linux kernel is concerned, the physical address after the virtual address 0x18 is mapped is
That is 0xc000 0018. So Linux just puts the interrupt vector at 0xc000 0018.
The two main functions of MMU are:
(1) Security: specify access rights
(2) Provide address space: convert discontinuous space into continuous space.
Does the second point mean to implement paged storage?
.globl _start ; System reset position
_start: b reset ; Jump code corresponding to each exception vector
ldr pc, _undefined_instruction ; Undefined instruction exception
……
_undefined_instruction :
.word undefined_instruction
Some people may wonder, for the same jump instruction, why does the first sentence use b reset,
while the following ones all use ldr?
To understand this problem, let's take the undefined instruction exception as an example.
When this exception occurs, the CPU always jumps to 0x4, which is a virtual address. The physical address it maps
to depends on the specific mapping.
ldr pc, _undefined_instruction
relative addressing, jumps to the label _undefined_instruction, but the actual jump address is actually _undefined_instruction
The content is undefined_instruction. The .word equivalent is:
_undefined_instruction dw undefined_instruction (see Graduation Notes 3 for details).
It is hard to say how far this address undefined_instruction is. It may be in the same
The page may be far away. However, except for reset, other exceptions may only occur after the MMU starts working, so
The address of undefined_instruction is also mapped by the MMU.
When the power is just turned on, the CPU starts executing from 0x0, and the MMU has not started working yet. At this time, the virtual address and the physical address are the same; on the other hand,
On the other hand, restart may also happen after MMU starts working. If reset also uses ldr, there will be problems because the virtual address and physical address are different at this time.
The address is completely different.
Therefore, the reason why reset uses b is because reset can occur before or after the MMU is established, while other exceptions can only occur after the MMU is established.
Use b reset, the reset subroutine and reset vector are on the same page, so there will be no problem (b is a relative jump)
If the two are too far apart, the compiler will report an error.
Previous article:ARM interrupt state and SVC state stack switching (exceptions)
Next article:About align in arm assembly
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What do you think of my fingerprint lock?
- Please advise how to deal with EMC test problems.
- Signal gain and noise gain of op amp
- How to check the number of bytes occupied by the written code, memory usage, and stack overflow when using IAR for MSP430
- AUTOSAR software development learning complete set of materials
- Pay attention to these aspects when making PCB samples
- Today’s award-winning live broadcast at 10 a.m.: Getting started with ADI’s software-defined radio ADALM-Pluto
- 【TGF4042 signal generator】+ resolution test
- Transplantation of μC/OS-II Real-time Operating System to 51 Single-Chip Microcomputer
- Free download of "A Brief Introduction to Special and General Relativity"