Understanding of ARM load domain and run domain

Publisher:晴天7777Latest update time:2016-03-01 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
        Generally speaking, a program includes a read-only code segment and a readable and writable data segment. In the ARM integrated development environment, the read-only code segment and constants are called RO segments (ReadOnly); readable and writable global variables and static variables are called RW segments (ReadWrite); and variables in the RW segment that are to be initialized to zero are called ZI segments (ZeroInit). For embedded systems, program images are stored in some non-volatile devices such as Flash memory, and at runtime, the RW segment in the program must be reloaded into the readable and writable RAM. This involves the program's loading domain and runtime domain. Simply put, the program's loading domain refers to the state of the program burned into the Flash, and the runtime domain refers to the state of the program when it is executed. For simpler cases, you can specify RO BASE and RW BASE in the ARM LINKER option of the ADS integrated development environment to inform the connector of the connection base addresses of RO and RW. For complex cases, such as when the RO segment is divided into several parts and mapped to multiple places in the storage space, you need to create a text file called a "distributed loading description file" to notify the connector to connect a certain part of the program to a certain address space in the memory. It should be pointed out that the definition in the distribution loading description file should be carried out according to the memory distribution after the system is redirected. After the boot program completes the initialization task, the main program should be transferred to RAM to run in order to speed up the system operation.


        What is an arm image file? An arm image file is actually an executable file, including bin or hex formats, which can be directly burned into rom for execution. During the axd debugging process, we debugged the axf file, which is actually also an image file. It just adds a file header and some debugging information to the bin file. An image file is generally composed of domains, which are composed of up to three output segments (RO, RW, ZI), and the output segment is composed of input segments. The so-called domain refers to the area where the entire bin image file is located, which is divided into a loading domain and a running domain. The loading domain is the working area where the image file is statically stored. Generally speaking, the address space where the entire bin file in Flash is located is the loading domain. Of course, programs are generally not placed in Flash for execution, but are generally moved to SDRAM for operation. The address space where they are moved to SDRAM for operation is the running domain. The code we input generally has a code part and a data part, which is the so-called input segment. After compilation, it becomes the RO segment and RW segment in the bin file, as well as the so-called ZI segment, which is the output segment. For the output segments in the load domain, generally speaking, the RO segment is followed by the RW segment, and the RW segment is followed by the ZI segment. In the run domain, these output segments are not continuous, but RW and ZI must be connected. The data in the ZI segment and RW segment can actually be RW attributes. 
| Image

RO
Base| |Image
RO
Limit| |Image
R
Base| |Image
ZI
Base| |Image
ZI
Limit|These variables are notified by the compiler, and we can see their values ​​in the makefile. They indicate the address space where each output segment is located in the runtime domain.| Image
RO
Base| is the starting address of the ro segment in the running domain, |Image
RO
Limit| is the end address of the ro segment in the running domain, and so on. We can specify it in the linker output. In simple mode, ro base corresponds to | Image
RO
Base|, RW Base corresponds to |Image
R
Base|, since rw and zi are connected, |Image
ZI
Base| is equal to |Image
R
limit|. The other values ​​are calculated automatically by the compiler.
Below is the ported part of the 2410 startup code, with my comments:
BaseOfROM DCD |Image
RO
Base|
TopOfROM DCD | Image
RO
Limit|
BaseOfBSS DCD |Image
R
Base|
BaseOfZero DCD |Image
ZI
Base|
EndOfBSS DCD |Image
ZI
Limit|
adr r0, ResetEntry; ResetEntry is the starting address of the reset runtime domain, which is usually 0 in boot nand
ldr r2, BaseOfROM;
cmp r0, r2
ldreq r0, TopOfROM; TopOfROM=0x30001de0, the end of the code segment address
beq InitRam 
ldr r3, TopOfROM
; part 1, by comparison, move ro to sdram, and move to the destination address from | Image
RO
Base| Start, To|Image
RO
Limit|End

ldmia r0!, {r4-r7}; Transfer the value of r0 as the 4 consecutive 32-bit numbers at the address (ResetEntry) to r4, r5, r6, r7 in turn; at the same time, r0 increases.
stmia r2!, {r4-r7}; Store the values ​​of r4, r5, r6, r7 in |Image
RO
Base| address; at the same time r2 increases.
cmp r2, r3
bcc %B0;
; part 2, move rw segment to sdram, the destination address is |Image
R
Base| Start, To|Image
ZI
Base|Endsub
r2, r2, r3;r2=0 ;When copying above, 4 double words (32 bits) are copied each time, but the RO segment size is not necessarily an integer multiple of 4, so several double words may be copied more, r2-r3 gets the number of copiessub
r0, r0, r2 ;r0-(r2-r3) can make r0 point to the end address of RO in boot nandInitRam
;carry rw to baseofBSS
ldr r2, BaseOfBSS ;TopOfROM=0x30001de0,baseofrw
​​ldr r3, BaseOfZero ;BaseOfZero=0x30001de0
0
cmp r2, r3
ldrcc r1, [r0], #4
strcc r1, [r2], #4
bcc %B0 
;part 3, initialize sdram zi to 0, address from|Image
ZI
Base|To|Image
ZI
Limit|
mov r0, #0;init 0
ldr r3, EndOfBSS;EndOfBSS=30001e40

cmp r2, r3
strcc r0, [r2], #4
bcc %B1
So far, the copying and initialization of the three output segments (RO, RW, ZI) are completed.

 

*************************************************** **********

RO segment, RW segment and ZI segment--Image

??
Limit Meaning

 

Composition of ARM programs

            The "ARM program" mentioned here refers to the program being executed in the ARM system, not the bin image file saved in ROM. Please pay attention to the difference.
            An ARM program consists of 3 parts: RO, RW and ZI.
            RO is the instruction and constant in the program .
            RW is the initialized variable in the program.
            ZI is the uninitialized variable in the program.
            The above 3 points can be understood as:
            RO is readonly,
            RW is read/write, and
            ZI is zero.

Composition of ARM image file
            The so-called ARM image file refers to the bin file burned into ROM, also known as image file. It is called Image file below.
            Image file contains RO and RW data.
            The reason why Image file does not contain ZI data is that ZI data is all 0, so there is no need to include it. Just clear the area where ZI data is located before running the program. Including it will waste storage space.
            Q: Why must RO and RW be included in Image?
            A: Because the instructions and constants in RO and the initialized variables in RW cannot be "created out of nothing" like ZI.

ARM program execution process

            From the above two points, we can know that the image file burned into ROM is not exactly the same as the ARM program in actual operation. Therefore, it is necessary to understand how the ARM program reaches the actual operation state from the image in ROM.
            In fact, the instructions in ROM should at least have the following functions:
            1. Move RW from ROM to RAM, because RW is a variable and variables cannot exist in ROM.
            2. Clear all RAM areas where ZI is located, because the ZI area is not in the Image, so the program needs to clear the corresponding RAM area according to the ZI address and size given by the compiler. ZI is also a variable, and similarly: variables cannot exist in ROM. In the initial stage of program running, the C program can access variables normally only after the instructions in RO complete these two tasks. Otherwise, only code without variables can be run.

Note: If a variable is initialized to 0, it will be placed in the ZI area in the same way as an uninitialized variable. That is, in an ARM C program, all uninitialized variables will be automatically initialized to 0. RO contains two types of data: Code and RO Data.

Summary:
            1; Instructions and constants in C are compiled as RO data.
            2; Uninitialized or initialized to 0 variables in C are compiled as ZI data.
            3; Variables initialized to non-zero values ​​in C are compiled as RW data.

Keywords:ARM Reference address:Understanding of ARM load domain and run domain

Previous article:S3C2440 abnormal entry and exit
Next article:S3C2440 startup code interrupt analysis

Recommended ReadingLatest update time:2024-11-15 07:29

ARM exception handler
Experimental purpose: Master the ARM exception handling process. Understand the structure of the SWI program. Master the method of calling SWI exceptions from the application.   Experiment 1: Design a string output program using SWI exceptions This experiment uses SWI exceptions to output the string "hello world!
[Microcontroller]
ARM exception handler
ARM boot process
Most ARM-based chips are complex on-chip systems. Most hardware modules in such complex systems are configurable and need to be set to their required working states by software. Therefore, before the user's application program, a special piece of code is required to complete the initialization of the system. Since this
[Microcontroller]
After the failed acquisition deal with Nvidia, Arm decided to lay off 12% to 15% of its employees
Arm told Reuters in an email on Monday that it plans to cut 12% to 15% of its workforce. The company said the main areas of job cuts would be the UK and the US. Arm also claimed in the email: "Like any business, Arm is constantly reviewing its business plans to ensure the company strikes the right balance between op
[Mobile phone portable]
ARM Linux startup one: assembly startup to start_kernel
Describe the general process of arm linux startup, taking S5PV210 (Cortex A8) as an example, this article describes the first stage.        1. ARM Linux boot        After uboot boots arm linux (uImage image) to SDRAM, it interprets the 64-byte header of the uImage image through the bootm command, obtains the entry a
[Microcontroller]
Overview of the instruction set of ARM microprocessors (I) - Detailed notes on ARM application system development
Overview of the ARM microprocessor instruction set The ARM instruction set is of load/store type, which means that the instruction set can only process data in registers, and the processing results must be placed back in the registers, while access to system memory must be completed through special load/store instruct
[Microcontroller]
ARM LCD and LCD controller
Since we mentioned LCD, the first thing we must understand is its types. CD (liquid crystal display) is a display that uses liquid crystal to control transmittance counting to achieve color. Compared with traditional CRT displays, it has many advantages: light and thin, low energy consumption, low radiation, etc., and
[Microcontroller]
ARM LCD and LCD controller
ARM exception and vector table
ARM has 7 exceptions, namely: 1. Reset 2. Undefined instructions 3. Soft interrupt 4. Prefetch instruction termination 5. Data Termination 6. Interrupt Request (IRQ) 7. Fast Interrupt Request (FIQ) To put it simply, ARM will always run in one of the above 7 abnormal situations. When you first learn abo
[Microcontroller]
ARM GIC Introduction 1
GIC is a very important part of ARM architecture. This article is based on the public ARM corresponding data and the MTK development board. I record it after my personal understanding to consolidate and deepen my understanding. That's all. If there are any mistakes, please point them out. 1. Overview of GIC
[Microcontroller]
ARM GIC Introduction 1
Latest Microcontroller Articles
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号