One of the GNU LD LMA and VMA

Source: Internet
Author: User

MIPS Processor Memory Structure

The project is using a MIPS CPU, storage space is the standard MIPS memory allocation, memory is divided into several parts, summarized as follows:

Boot room, boot code storage;

Iram, code storage space;

Dram,data storage space;

This means that code and data have their own separate storage space, which is placed separately.

We usually use GCC and LD to generate an executable file, such as the command line input gcc-o test test.c, the resulting executable is a file oh, that is, code and data are in a copy of the executable file. We burn this executable file into Flash, and then the CPU takes instructions from Flash.

But in front, we clearly planned the code and data are separate storage space AH. The conscientious will ask, yes ah, you are right, but what is the matter?

Differences between the two processor architectures

Well, let's go back to the beginning, and start with the concept of why code and data each plan a piece of storage space. This actually starts with the structure of "von Neumann" and "Harvard".

"Von Neumann structure" means that the program and data storage space is not separate, but in a piece of memory inside, so the program and data access bit width is equal.

"Harvard structure" means that the program and data storage space is separate, each has a piece of memory, so the program and data access bit width can be unequal.

Now the processor basically belongs to the above 2 kinds of architectures, such as x86, ARM, MIPS and so on.

After saying this, everything is clear. By the same means, the MIPS I use happens to be the "Harvard structure"!

LMA and VMA

So the "Harvard structure" of the processor, clearly generated executable files, which is usually said bin file, only one Ah, so the program and data are in the same bin file, such as Test.bin. We burn the test.bin into Flash.

On the Harvard architecture processor, how does this executable file execute?

Good question.

We know that for a C program, when it compiles the link, the code is placed in the text segment, the constants are stored in the Rodata segment, the values of the initialized global variables or the initialized static variables are placed in the data segment, the uninitialized global variable or the static variable is placed in the BSS segment.

While a string pointer variable such as char *string = "ABCdef", the string "abcdef" is stored in the const segment, and the value of the pointer variable is the address of the string "ABCdef", which is an address in the Rodata segment.

Both the text and rodata segments are stored in the rooms, and data and BSS are initially stored in the bin file, but before the main function of the C program starts running, it needs to be transported to ram.

So we need in bootloader, in assembly language to write a piece of code, the bin file in the data section of the copy to RAM, BSS does not have to move, only need to be the BSS segment in the RAM address range of 0 to clear.

Then point the SP pointer to the maximum address of RAM.

In this process, the LMA and VMA are used.

The LMA is the load address;

VMA is the virtual address, which is the run.

What is the meaning of the concrete? For example, we just talked about the Test.bin, then the program and data will be stored sequentially in the AH, the order please refer to the "target file in its memory image file layout" in http://www.cnblogs.com/ironx/p/4954845.html.

In the corresponding section of that article, the LMA, which is the storage address of the program and data in the bin file, is described in VMA, which is the operating address of the data and BSS segments in RAM.

In the assembly code of bootloader, we need to copy the data section to ram and clear 0 BSS.

At this point, the assembly code will copy the data from its LMA to VMA, which is the copy from the bin file's storage address to the running address in RAM.

A typical bootloader handling code is as follows:

Since Bootloader will use LMA and VMA, where is the LMA and VMA defined, in the LD script, the LD script specifies what the program and data are stored in the bin file, and how it is stored in ROM and Ram at runtime.

Please refer to http://www.cnblogs.com/ironx/p/4954845.html

One of the GNU LD LMA and VMA

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.