1. Introduction of bss clearing (why we need to clear bss) Let’s give an example first:
#include "s3c2440_soc.h"
#include "uart.h"
char g_Char = 'A'; //.data
char g_Char3 = 'a';
const char g_Char2 = 'B'; //.rodata
int g_A = 0; //bss
int g_B; //bss
int main(void)
{
uart0_init();
puts("nrg_A = ");
printHex(g_A);
puts("nr");
while (1)
{
putchar(g_Char);
g_Char++; /* When nor starts, this code is invalid and will be valid after relocating to the baseaddr of sdram*/
putchar(g_Char3);
g_Char3++;
delay(1000000);
}
return 0;
}
We burned the program in and printed g_A, but found that the value of g_A was not 0, but a random value. why?
At this time, we have completed the relocation and copied the code to sdram, and then the address immediately following sdram is the base address of .bss. At this time, the memory in the bss segment has not been processed in any way, so it is random.
Then after relocating the code, we need to clear the data in the .bss section on the sdram, because we know that bss is a global variable that is not initialized and has an initial value of 0.
2.How to clear bss
Of course, you only need to write all 0s to the bss section. We write the link script as follows:
SECTIONS
{
. = 0x30000000;
. = ALIGN(4);
.text :
{
*(.text)
}
. = ALIGN(4);
.rodata : { *(.rodata) }
. = ALIGN(4);
.data : { *(.data) }
. = ALIGN(4);
__bss_start = .;
.bss : { *(.bss) *(.COMMON) }
_end = .;
}
Then write start.s, and the code to clear the bss section is as follows:
/* Clear BSS segment*/
ldr r1, =__bss_start
ldr r2, =_end
mov r3, #0
clean:
strb r3, [r1]
add r1, r1, #1
cmp r1, r2
ble clean
bl main
halt:
b stop
We burned the program again and printed g_A, but found that the value of g_A was 0. Essentially, it is to clear the relocated bss segment data to 0.
Previous article:s3c2440 bare metal - code relocation, bss clearing optimization and position-independent code
Next article:s3c2440 bare metal-code relocation (2. Programming to implement code relocation)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Let me ask, what are the most cutting-edge energy storage technologies currently?
- Review summary: Free review: The cheapest Hongmeng development board Neptune is here
- Has anyone used the software every circuit?
- Excuse me, is there any tutorial for assembling MCS-51 microcontroller?
- [Hardcore Science] What is a bipolar four-quadrant power supply? Is the power amplifier also a bipolar four-quadrant power supply?
- Nonvolatile MRAM and its cell structure
- FPGA controls DSP power-on reset procedure
- Sampling period
- Ask for help, recommendation, keywords
- It's holiday time, but we're still working overtime every day