Understanding of ARM load and run-time addresses

Publisher:糖三角Latest update time:2016-07-25 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Just understanding it this way makes sense for some processes, and it is consistent with what is said in some materials.

The download address and runtime address in the scatter file are used in the compilation and linking stages.
For example, there is the following scatter file, taking the jump from assembly to c file as an example.
LOAD 0x0
{
    JMAIN +0
    {
        jmain.o(jmain,+first)
    }
    TEST 0x200
    {
        test.o
        *(+RO,+RW,+ZI)
    }
}
jmain.s is just a jump,
b __main,
main is defined in test.c.
void main(){}

The 0x0 at LOAD in the scatter file represents the download address, which means that all .o files generated in the entire project file

are arranged from 0x0 from front to back when compiled (jmian.o starts at 0x0, test.o follows jmain.o), of course, there may be some processing in the middle

, but generally speaking, it is like this. For example, it can be understood that the generated .bin file starts from 0x0, jmain.o and test.o

and others. There is no gap between them.

The runtime address in scatter, such as 0x200, is used to guide the compiler to compile instructions. There is a situation:
if 0x200 is changed to 0x100, the compiled binary code is: 0xea00003e, when it is 0x200, the instruction is 0xea00007e.

The difference here shows that the compiler generates the binary code of the instruction according to the runtime address.

Therefore, I think the download address can be regarded as the first address of a memory segment. The instructions stored at this address need to be compiled and generated

when generating binary code .

The CPU will jump to the instruction at 0x200 when it runs . In this way, it

is consistent with the address at run time and download time mentioned in general materials.

But there is still a problem. In the above example, if the .bin file is downloaded to the 0x0 address of the board, the CPU will run 0xea00007e after starting to run from 0x0

, but there is no instruction we want to run at 0x200, such as main(). Therefore, there is a copy process that needs to be

performed before jumping to main().

When compiling and linking, the linker will save the address 0x200 to a certain address. After __main, 0x200 will be taken out from the address

, and test.o and the following things will be copied from the address at the time of downloading (behind jmain.o, that is, the address mentioned above)

to the address 0x200 through the loop, and arranged in sequence. After copying, jump to 0x200, that is, running 0xea00007e will be normal.

This copy process can be done by the compiler, or we can write code ourselves.


Back to the ro base setting in ads, it is the download address in scatter = the runtime address of the root region. In ads, set ro 

base=0x10000, and download the generated .bin to the board's ram, such as mx 0x8000, g 0x8000, the program can run normally. This is because

.bin is placed at 0x8000 on the board. The reason for running from 0x8000 is that the CPU's PC is always +4. The instructions before the jump

do not involve absolute addresses, relative addresses, and their binary codes do not involve these addresses. So it can run normally. When running to b 

__main, the copy is completed using the loop automatically generated by ads. 0x10000 is involved in the copy. It is this copy and the subsequent

b __rt_entry that enable the program to run normally.

In this way, the load address in the scatter file is not so important.
Reference address:Understanding of ARM load and run-time addresses

Previous article:Analysis of the startup process of ARM multi-core processor
Next article:About the interrupt call of 44b0

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号