Run address and load address

Source: Internet
Author: User
Run address and load address

When connecting the target code, the running address and loading address are mentioned. What is the difference between the two?

The load address is the address of the program, and the run address is the absolute address of the program positioning, that is, the address located at the compilation connection. If the program runs in flash, the running address and loading address are the same. If the program runs in Ram but the program is stored in flash, the run address points to ram, and the load address points to flash. The code is usually written in NAND, such as S3C2440.
If the 4 K code starts from NAND, it will be copied to 4 Kram in 2440 for key hardware initialization. At this time, the internal RAM is mapped to 0x0 address. If you start from nor, because nor supports on-chip running, the code can be run directly on nor. At this time, nor is mapped to 0x0, and the 4kram in S3C2440 is mapped to 0x40000000.

Next let's take a look at the link file.

For the. LDS file, it defines the connection process after the program is compiled, and determines the storage location of each segment of the executable program. Let's take a look at the complete description of the. LDS file format on the GNU Official Website:

SECTIONS {...secname start BLOCK(align) (NOLOAD) : AT ( ldadr )  { contents } >region :phdr =fill...}

Secname and contents are mandatory, and others are optional. Let's take a look at several common ones:

1. secname: segment name

2. Contents: determines which content is placed in this segment. It can be the entire target file or a segment in the target file (code segment, data segment, etc)

3. Start: the connection (run) Address of the current segment. If at (ldadr) is not used, the address stored in this segment is also start. On the GNU website, start can be described using any type of address description symbol.

4. At (ldadr): defines the address for storing (loading) This section.

Let's look at a simple example:

/* nand.lds */SECTIONS { firtst 0x00000000 : { head.o init.o } second 0x30000000 : AT(4096) { main.o } }

Above, head. O is placed at the beginning of 0x00000000 address, init. o put in head. o, their running address is also 0x00000000, that is, the connection and storage address are the same (not specified at); main. O is placed at the beginning of 4096 (0x1000, which is specified by at, the storage address), but its running address is 0x30000000. Before running, it must start from 0x1000 (loading location) copy to 0x30000000 (runtime), and read the NAND Flash. This is the difference between the storage address and the connection (run) Address, known as loading the time domain and running the time domain, which can be specified separately in the. LDS connection script file.

Compiled. LDS file, which is called and executed with-tfilename when you use the arm-Linux-LD connection command, such as arm-Linux-LD-tnand. lds x. o y. o-o xy. o. You can also use the-ttext parameter to directly specify the connection address, for example, arm-Linux-LD-ttext 0x30000000 X. o y. O-o xy. O.

In short:

Connection address <=> RUN address
Storage address <=> load address

Since the program has two types of addresses, there are some differences between jump commands. Let's take a look at these jump commands.

In arm assembly, there are two jump Methods: B jump command and LDR command assign value to PC.

(1) B Step1: The B jump command is relative to the current Pc value, and the offset is calculated by the bit [] of the command, this makes the program using the B command not dependent on the position of the Code to be jumped, only the instruction itself.

(2) ldr pc, = Step1: This command reads data from a location in the memory (Step1) and assigns it to the PC. It also depends on the value of the current PC, however, the offset is the connection address (runtime address) at that position (step 1), so you can use it to redirect from flash to ram.

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.