[Reprinted] use of arm linker-initialization of the application program running environment

Source: Internet
Author: User

General executableProgramBoth includeCodeSegment and data segment. It can also be viewed as composed of the RO and RW segments. The RO section generally contains code segments and constants, which are read-only during running. The RW segment includes some global and static variables that can be changed during running (read/write ). If some global variables are initialized to zero, the RW segment also contains the Zi segment.
RO: Read Only code segment
RW: Read Write the initialized global variable
Zi: Zero init uninitialized global variables

The RO segment is read-only and cannot be changed during running, the RO segment can reside in Flash (of course it can also be in SDRAM or SRAM ). The RW segment can be read and written. Therefore, it must be loaded into the SDRAM or SRAM during operation.
When compiling with ads, you need to set Ro base and RW base. If you have used ads, you should be clear about this. By setting Ro base and RW base, the linker is notified of the start running address (RO base) and RW segment address (RW base) of the program ). If a program only has Ro segments and has no RW segments, the program can be run in Flash completely without the need for SDRAM or SRAM. If the RW and Ro segments are included, the RW segments of the program must be copied to the SDRAM or SRAM before being accessed to ensure that the program runs properly. The following figure shows the status of a program before (load view) and execute view. We can see that the entire program is placed in the ROM before execution. During execution, the RW segment is copied to a proper location in Ram.

At the beginning, the program is always stored in ROM/flash. Its Ro part can be executed in ROM/flash or transferred to a faster RAM; RW and Zi must be transferred to writable Ram.The initialization of the application execution environment is to complete the necessary data transmission and content clearing from Rom to ram.

Different tool chains provide different mechanisms and methods to help you complete this step, mainly related to the linker. The following is a direct implementation of a common memory model in the arm development tool environment ads:

LDR r0, = | image $ Ro $ limit |; get the address of the next byte at the end of the RO segment, and the start address of RW in the Rom.
LDR R1, = | image $ RW $ base |; obtain the initial address of the RW segment in Ram.
LDR R3, = | image $ Zi $ base |; initial address of the global variable
CMP r0, R1;
Beq loop1
Loop0
CMP R1, R3; whether it is the last address of the RW segment in Ram. If it is not, it will always copy the ROM (flash variation and Data Segment to ram)
Ldrcc R2, [R0], #4; [R0] = [R1]
Strcc R2, [R1], #4;
BCC loop0
Loop1
LDR R1, = | image $ Zi $ limit |; execute loop1 and loop2 to initialize Zi to 0
MoV R2, #0
Loop2
CMP R3, r1
Strcc R2, [R3], #4;
BCC loop2

In ads, some pre-defined variables can be used (linker defined symbol ). In the following implementation, several predefined variables are used:
Image $ Ro $ base this variable specifies the base of the RO segment
Image $ Ro $ limit this variable specifies the limit of the RO segment
Image $ RW $ base this variable specifies the base of the RW segment
Image $ RW $ limit this variable specifies the limit of the RW segment
Image $ Zi $ base this variable specifies the base of the Zi segment
Image $ Zi $ limit this variable specifies the limit of the Zi segment
Note: For more information, see ads linker guide.
Image $ Ro $ limit minus image $ Ro $ base equals the size of the RO segment
Image $ RW $ limit minus image $ RW $ base equals the size of RW segments
Image $ Zi $ limit minus image $ Zi $ base equals the size of the Zi segment
(Image $ Ro $ limit minus image $ Ro $ base)
+ (Image $ RW $ limit minus image $ RW $ base)
= Equal to the size of the entire program
Note: The Zi segment is included in the RW segment.

 

From: http://zhanglicn.blog.sohu.com/72551452.html

 

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.