There is such a paragraph in u-boot's start.S
relocate: /*relocate U-Boot to RAM */
adr r0, _start /*r0 <- current position of code */
ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
cmp r0, r1 /* don't reloc duringdebug */
beq clear_bss
ldr r2, _armboot_start
ldr r3, _bss_start
sub r2, r3, r2 /*r2 <- size of armboot */
bl CopyCode2Ram /*r0: source, r1: dest, r2: size */
clear_bss:
…….
Compare r0 and r1, if they are not equal, copy the code from flash to ram. But the question is how can we determine that r0 and r1 are not equal just from the two instructions adr and ldr?
Since the assembly can't handle it, then disassemble it. By assembling the above code, you can see that there are differences between the two instructions.
33d800b0 :
33d800b0: e24f00b8 sub r0, pc, #184; 0xb8
33d800b4: e51f107c ldr r1, [pc, #-124] ;33d80040 <_text_base>
33d800b8: e1500001 cmp r0, r1
33d800bc: 0a000003 beq 33d800d0
adr r0, _start ==> 33d800b0: e24f00b8 sub r0, pc, #184; 0xb8
Get the address of the label at pc-184 and assign it to r0. _start changes with the load address, so r0 changes. When running from nandflash, it actually runs at address 0x0 of sram, and the address of _start is 0x0; when running from 0x33d80000, the value of _start is 0x33d80000.
ldr r1, _TEXT_BASE ==>800b4: e51f107c ldr r1, [pc, #-124]
The literal meaning is to get the value at the address [pc, #-124], that is, to get the value at the address _TEXT_BASE. No matter how the link is made, the address of _TEXT_BASE will change, but the value TEXT_BASE at the address _TEXT_BASE will not change. This instruction assigns the value of _TEXT_BASE, that is, .word TEXT_BASE, to r1, that is, r1=TEXT_BASE=0x33d80000. This instruction has nothing to do with where the program is running. As long as TEXT_BASE is defined, then r1=TEXT_BASE.
Previous article:LED Bare Program
Next article:ARM assembly pseudo-instructions MACRO and MEND
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Urgently looking for a test engineer based in Beijing (preferably with some network security experience)
- Some measures to prevent digital circuits from being disturbed in single chip microcomputers
- Wireless communication solution for HMI control of crane feeding in copper processing workshop
- ADC conversion chip hx711
- EEWORLD University ---- Getting Started Video of Gizwits Gokit3
- Read the information and fill out the questionnaire to win prizes: Keysight Technologies' automotive Ethernet test solution and IXIA automotive Ethernet technology white paper
- DSP generates hex file and bin file method
- [RT-Thread Reading Notes] Threads and Critical Protection
- [GD32F310 Review] Communication USART Configuration and ECHO Routine
- Help interpret the battery charging curve