TQ2440 uboot---6.start.S in relocate part analysis, adr and ldr difference

Publisher:WhisperingWaveLatest update time:2018-04-15 Source: eefocusKeywords:TQ2440  uboot Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:TQ2440  uboot Reference address:TQ2440 uboot---6.start.S in relocate part analysis, adr and ldr difference

Previous article:LED Bare Program
Next article:ARM assembly pseudo-instructions MACRO and MEND

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号