ARM compile space attributes

Publisher:andyliow1980Latest update time:2016-04-12 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Spatial properties of the program

Generally speaking, a program is essentially composed of three segments: bss segment, data segment, and text segment. This concept is a very important basic concept in current computer programming. It is also very important in the design of embedded systems, involving the memory size allocation and the space occupied by storage units when the embedded system is running.

BSS segment: BSS segment (bss segment) usually refers to a memory area used to store uninitialized global variables in the program. BSS is the abbreviation of Block Started by Symbol. BSS segment belongs to static memory allocation.

Data segment: A data segment is usually a memory area used to store initialized global variables in a program. The data segment belongs to static memory allocation.

Code segment: A code segment (code segment/text segment) usually refers to a memory area used to store program execution code. The size of this area is determined before the program runs, and the memory area is usually read-only. Some architectures also allow the code segment to be writable, that is, to allow the program to be modified. The code segment may also contain some read-only constant variables, such as string constants.

Heap: The heap is used to store memory segments that are dynamically allocated during process operation. Its size is not fixed and can be dynamically expanded or reduced. When a process calls functions such as malloc to allocate memory, the newly allocated memory is dynamically added to the heap (the heap is expanded); when using functions such as free to release memory, the released memory is removed from the heap (the heap is reduced).

       Stack: Stack is also called stack, which is where users store local variables temporarily created by the program, that is, the variables defined in the function brackets "{}" (but not including the variables declared statically, static means storing variables in the data segment). In addition, when a function is called, its parameters will also be pushed into the stack of the process that initiated the call, and after the call ends, the return value of the function will also be stored back in the stack. Due to the first-in-first-out feature of the stack, the stack is particularly convenient for saving/restoring the call site. In this sense, we can regard the stack as a memory area for storing and exchanging temporary data.

The text and data segments are both in the executable file (usually solidified in the image file in embedded systems) and are loaded from the executable file by the system. The bss segment is not in the executable file and is initialized by the system.

The bss segment (data that is not manually initialized) does not allocate space for the data in this segment, but only records the size of the space required for the data. The data segment (data that has been manually initialized) allocates space for the data, and the data is stored in the target file. The DATA segment contains initialized global variables and their values. The size of the BSS segment is obtained from the executable file, and then the linker obtains a memory block of this size, which follows the data segment. When this memory area enters the address space of the program, all are cleared. The entire segment containing the DATA and BSS segments is usually called the data area at this time.

2. ARM image properties

 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 image file contains RO and RW data. But it does not contain ZI data because ZI data is all 0, so there is no need to include it. Just clear the area where ZI data is before running the program. Including it will waste storage space.

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 RO 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 operation, 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. Instructions and constants in
ARM  C are compiled as RO type data . Variables that are not initialized or initialized to 0 in ARM  C are compiled as ZI type data. Variables that have been initialized to non-zero values ​​in ARM  C are compiled as RW type data.

 

The .text segment is the code segment. It is used to store program code. It is usually read-only (program code is finalized after compilation and cannot be changed).

The .data segment is the data segment. It is used to store initialized global variables (global) and initialized static variables (static). It is readable and writable.

The .bss segment is the global variable data segment. It is used to store uninitialized global variables (global) and uninitialized static variables (static). It is also readable and writable. bss is the abbreviation of Block Started by Symbol. The reason why bss is separated from data is that the system will clear the initial values ​​of the variables in these bss segments to zero.

The .constdata segment is the constant data segment. It is used to store constants (const). It is also read-only.

 

The memory allocated by malloc in the source program is bss. Its size is not determined by the size of data, but mainly by the maximum value of memory allocated simultaneously in the program. However, if it exceeds the range, that is, the allocation fails, you can wait until the space is released before allocating it again.

For the above segments, users can flexibly define their first address and size. But for most users, the program code area is in ROM or FLASH, and the read-write area is in SRAM or DRAM. Consider the size of your program, the size of function calls, and the size of memory usage, and then refer to a link location file and make a slight modification.

The stack is what we usually call a stack. It is used to store the local variables and parameters of a function. Its operation is similar to the stack in the data structure, which is a "Last In First Out" (LIFO) data structure. This means that the last data put on the stack will be the first data removed from the stack. For information that is temporarily stored and does not need to be saved for a long time, the LIFO data structure is ideal. After calling a function or procedure, the system usually clears the local variables, function call information and other information saved on the stack. The top of the stack is usually at the end of the readable and writable RAM area, and its address space usually "decreases downward", that is, the more data is saved on the stack, the smaller the address of the stack.

 

The heap is what we usually call dynamic memory allocation. It is used to manage dynamic memory. Its operation method is different from the heap in the data structure.

 

In ARM's integrated development environment,

1. The read-only code segment is called the Code segment, which is the .text segment mentioned above.

2. The read-only constant data segment is called the RO Data segment, which is the .constdata segment mentioned above.

The above two segments are collectively referred to as RO segments (Read Only), which are placed in non-volatile devices such as ROM or FLASH.

3. The segment of initialized global variables and static variables that can be read and written is called the RW Data segment (ReadWrite), which is the .bss segment mentioned above.

4. The segment for uninitialized global variables and static variables that can be read and written is called the ZI Data segment (Zero Init), which is the .data segment mentioned above. Because the variables in this segment must be initialized to zero, it is called the ZI segment.

The above two segments are collectively referred to as the RW segment, and at runtime, it must be reloaded into the readable and writable RAM.


Keywords:ARM Reference address:ARM compile space attributes

Previous article:Using STM32's SysTick to achieve precise delay
Next article:STM32 FSMC Learning Notes (I)

Recommended ReadingLatest update time:2024-11-16 15:57

Simple example of arm-Linux dynamic library compilation
This article tells a simple example and explains "compiling dynamic libraries" very well.  1. Preparation  1. Use oracle VM Virtualbox software to install the Ubuntu virtual machine  2. Download the relevant software and transfer it to the virtual machine, and install the cross compiler.  2. Compile and apply  This
[Microcontroller]
Simple example of arm-Linux dynamic library compilation
ARM connector error
When writing an ARM program with RVCT3.1, a connection error occurred: Error: L6915E: Library reports error: scatter-load file declares no heap or stack regions and __user_initial_stackheap is not defined. I found some information on the Internet and found that the compiler did not define Image after using the custom s
[Microcontroller]
ARM+llinux system transplantation 3G dial-up Internet access to send and receive text messages (Part 2)
1. Send SMS in text format Send a text message to China Unicom: ~ : microcom -s 115200 /dev/ttyUSB1 at OK Set the SMS format to Text mode: at+cmgf=1 OK at+cmgs="+861300711**** " Enter the content to send: hello (press ctrl + z to send after writing the content)                                       +CMGS: 48 OK
[Microcontroller]
ARM+llinux system transplantation 3G dial-up Internet access to send and receive text messages (Part 2)
【ARM】2410 bare metal series-ADC digital-to-analog conversion
Development Environment 1. Hardware platform: FS2410 2. Host: Ubuntu 12.04 ADC Register Configuration 1. Initialize ADC (ADCCON) Set the prescaler, prescaler factor, select the A/D conversion channel, select normal mode and start the conversion 2. Determine whether the conversion is completed (ADCCON ) 3. Read con
[Microcontroller]
【ARM】2410 bare metal series-ADC digital-to-analog conversion
ARM off-chip FIash memory IAP solution
introduction Embedded application systems with ARM chips as processor cores have gained more and more popularity due to their small size, low power consumption, low cost, high performance, rich on-chip resources and wide support for operating systems. In-Application Programming (IAP) is such a self-modifying pr
[Microcontroller]
ARM off-chip FIash memory IAP solution
Programmers' Model of ARM Processor
There are some Programmers' Model chapters in the ARM manual. So what is the Programmers' Model? The Programmers' Model is from the programmer's point of view, what features the processor provides to programmers. Here we introduce some basic models based on ARM7TDMI-S, which are also applicable to the latest kernels.
[Microcontroller]
Remote Video Monitoring System Based on ARM-Linux and CDMA
0 Introduction CDMA (Code Division Multiple Access) wireless network has the characteristics of wide coverage, high efficiency and low cost. The data transmission rate of CDMA network can reach 200kb/s. The embedded remote video monitoring system developed here is a data transmission system built by mak
[Security Electronics]
Remote Video Monitoring System Based on ARM-Linux and CDMA
ARM processor working status and mode
Two working states 1. ARM state: the processor executes 32-bit aligned ARM instructions; 2. Thumb state: The processor executes 16-bit aligned ARM instructions. The difference between them is that the Thumb instruction set is not a complete instruction set, it is a subset of the ARM instruction set. However, the Thu
[Microcontroller]
ARM processor working status and mode
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号