Running address and loading address of the GNU system

Source: Internet
Author: User
Tags linux

When you connect to the target code, you mention the running address and the load address. What is the difference between the two?

The load-time address is the address where the program is placed, and the running address is the absolute address that the program locates, or the address that is positioned when the connection is compiled. If the program is running in Flash, the running address and the load address are the same. If the program is running in RAM, but the program is stored in Flash, the running address points to RAM and the load address is to flash. Code is generally written in NAND, such as s3c2440 if the boot from NAND start its start 4K code will be copy to 2440 internal 4KRAM for initialization of critical hardware this time the internal RAM is mapped to the 0x0 address. If starting from nor, because the nor support on the run, the code can be run directly on the nor at this time nor is mapped into 0x0,s3c2440 internal 4KRAM is mapped to the 0x40000000.

Let's look at the link file below.

For. lds files, it defines the connection process after compilation of the entire program and determines where each segment of the executable program is stored. Let's take a look at the full description of the. lds file on the GNU official website:

SECTIONS {  
...  
.. Secname start block (align) (noload): at (Ldadr)  
  {contents} >region:p hdr =fill  
...  
}

Secname and contents are necessary, and the rest are optional. Let's look at a few common:

1, Secname: paragraph name

2, Contents: Decide which content in this paragraph, can be the entire target file, can also be the target file in a paragraph (code snippets, data segments, etc.)

3, Start: This section of the connection (running) address, if not using at (LDADR), the address of this section is also the start. The GNU website says that start can be described by any symbol that describes the address.

4. At (LDADR): Defines the address that this section stores (loads).

Look at a simple example:

<span style= "FONT-SIZE:18PX;" >/* nand.lds
/SECTIONS {   
    firtst 0x00000000: {head.o INIT.O}   
    second 0x30000000:at (4096) {MAIN.O}
  }</span>

Above The HEAD.O are placed at the beginning of the 0x00000000 address, INIT.O on the HEAD.O, and their running address is 0x00000000, that is, the connection and storage address are the same (no at specified), MAIN.O is placed at the beginning of 4096 (0x1000, the AT-specified, storage address), but it is shipped The line address is 0x30000000, and it needs to be copied from 0x1000 (at the loading place) to the 0x30000000 (the runtime), and this process is also used to read NAND flash. This is the difference between the storage address and the connection (run) address, called the load time domain and the run-time domain, which can be specified separately in the. LDS connection script file.

Write a good. lds file that invokes execution with-tfilename when using the ARM-LINUX-LD Connection command, such as Arm-linux-ld–tnand.lds X.O y.o–o xy.o. The connection address is also specified directly with the-ttext parameter, such as Arm-linux-ld–ttext 0x30000000 x.o y.o–o xy.o.

Anyway:

Connection address <==> running address

Store address <==> load address

Since the program has two kinds of addresses, it involves some of the difference between the jump instructions, the following to see the specific jump instructions.

ARM assembly, there are often two kinds of jump methods: B Jump instructions, LDR instructions to the PC assignment.

(1) b step1:b Jump instruction is relative jump, depending on the value of the current PC, offset by the instruction itself bit[23:0] calculated, which makes the program using the B directive does not depend on the location of the code to jump to, only look at the instructions themselves.

(2) Ldr pc, =STEP1: The instruction reads the data from a location in memory (STEP1) and assigns it to the PC, which also relies on the value of the current PC, but the offset is the connection address (the runtime address) of that location (STEP1). So you can use it to achieve the program from Flash to ram jump.

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.