stm32中.bss和.data段是在哪里初始化的
https://segmentfault.com/q/1010000004829859/a-1020000004850311
Q:
STM32的启动文件startup_stm32f10x_hd.s中的描述是
This module performs:
Set the initial SP
Set the initial PC == Reset_Handler
Set the vector table entries with the exceptions ISR address
Configure the clock system and also configure the external SRAM mounted on STM3210E-EVAL board to be used as data memory (optional, to be enabled by user)
Branches to __main in the C library (which eventually calls main()).
我没有看到初始化.data和.bss段的描述
stm32应该是从中断向量Reset_Handler开始执行的
; Reset handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT __main
IMPORT SystemInit
LDR R0, =SystemInit
BLX R0 
LDR R0, =__main
BX R0
ENDP
SystemInit里面没有初始化代码,然后就到__main了,难道是在__main里进行的初始化?
因为上面说Branches to __main in the C library (which eventually calls main()),如果不在这里的话就进入C语言的main()函数了,我看到很多地方都说这个初始化在C语言运行之前。
如果是在__main里那具体是在哪里呢?
不同的编译器像gcc和Keil MDK都是在这里吗?
A:
.data和.bss是在__main里进行初始化的。
我是搜索的 “c library startup code”
对于ARM Compiler,__main主要执行以下函数
其中__scatterload会对.data和.bss进行初始化
Application code and data can be in a root region or a non-root region. Root regions
have the same load-time and execution-time addresses. Non-root regions
have different load-time and execution-time addresses. The root region
contains a region table output by the ARM linker. The region table
contains the addresses of the non-root code and data regions that
require initialization. The region table also contains a function
pointer that indicates what initialization is needed for the region,
for example a copying, zeroing, or decompressing function.__scatterload goes through the region table and initializes the various execution-time regions. The function:
Initializes the Zero Initialized (ZI) regions to zero
Copies or decompresses the non-root code and data region from their load-time locations to the execute-time regions.
__main always calls this function during startup before calling __rt_entry.
详细内容见:ARM Compiler C Library Startup and Initialization
对于gcc
汇编文件startup_stm32f10x_hd.s里面Reset_Handler已经对.data和.bss进行了初始化
Reset_Handler:  
/* Copy the data segment initializers from flash to SRAM */
  movs  r1, #0
  b  LoopCopyDataInit
CopyDataInit:
  ldr  r3, =_sidata
  ldr  r3, [r3, r1]
  str  r3, [r0, r1]
  adds  r1, r1, #4
LoopCopyDataInit:
  ldr  r0, =_sdata
  ldr  r3, =_edata
  adds  r2, r0, r1
  cmp  r2, r3
  bcc  CopyDataInit
  ldr  r2, =_sbss
  b  LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
  movs  r3, #0
  str  r3, [r2], #4
LoopFillZerobss:
  ldr  r3, = _ebss
  cmp  r2, r3
  bcc  FillZerobss
/* Call the clock system intitialization function.*/
  bl  SystemInit
/* Call the application's entry point.*/
  bl  main
  bx  lr 
 
stm32中.bss和.data段是在哪里初始化的的更多相关文章
- Linux中的段管理,bss段,data段,
		
Linux 的段管理, BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文Block Started by Symbol的简称.BSS段属于静态内存 ...
 - [转帖]浅谈程序中的text段、data段和bss段
		
作者:百问科技链接:https://zhuanlan.zhihu.com/p/28659560来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 一般情况,一个程序本质上都 ...
 - bss段和data段的区别
		
一般情况下,一个程序本质上都是由 bss段.data段.text段三个组成的——本概念是当前的计算机程序设计中是很重要的一个基本概念.而且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统运行时的内存大 ...
 - Linux段管理,BSS段,data段,.rodata段,text段
		
近期在解决一个编译问题时,一直在考虑一个问题,那就是Linux下可执行程序执行时内存是什么状态,是依照什么方式分配内存并执行的.查看了一下资料.就此总结一下,众所周知.linux下内存管理是通过虚存管 ...
 - (深入理解计算机系统) bss段,data段、text段、堆(heap)和栈(stack)
		
bss段: bss段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域. bss是英文Block Started by Symbol的简称. bss段属于静态内存分配. ...
 - 【转】(深入理解计算机系统) bss段,data段、text段、堆(heap)和栈(stack)
		
bss段: bss段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域. bss是英文Block Started by Symbol的简称. bss段属于静态内存分配. ...
 - 代码中函数、变量、常量 / bss段、data段、text段 /sct文件、.map文件的关系[实例分析arm代码(mdk)]
		
函数代码://demo.c #include<stdio.h> #include<stdlib.h> , global2 = , global3 = ; void functi ...
 - BSS段 data段 text段 堆heap 和 栈stack
		
BSS段:BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文Block Started by Symbol的简称.BSS段属于静态内存分配. 数 ...
 - 汇编中bss,data,text,rodata,heap,stack,意义
		
bss段: BSS段(bsssegment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文BlockStarted by Symbol的简称.BSS段属于静态内存分配. data ...
 
随机推荐
- NOIP2015 运输计划(二分+LCA+差分)
			
4326: NOIP2015 运输计划 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 308 Solved: 208[Submit][Status] ...
 - 【Java基础】List迭代并修改时出现的ConcurrentModificationException问题
			
现在有一个需求,要遍历一个List,假设List里面存储的是String对象,然后该需求事判断里面如果有某个对象,则添加一个新的对象进去.自然,我们得出下面的代码: import java.util. ...
 - ios 免书籍入门站点
			
http://www.raywenderlich.com/tutorials http://www.raywenderlich.com/ios-tutorials http://web.stanfor ...
 - HTTP状态码及其含义 503 500 401 200 301 302
			
下表显示了常见的HTTP 1.1状态代码以及它们对应的状态信息和含义. 应当谨慎地使用那些只有HTTP 1.1支持的状态代码,因为许多浏览器还只能够支持HTTP 1.0.如果你使用了HTTP 1.1特 ...
 - php&mysql
			
更新语句 $query='update num set num='.$counter.'where id=1'; ....................这个查询失败 $query='upd ...
 - A Tour of Go  Variables
			
The var statement declares a list of variables; as in function argument lists, the type is last. pac ...
 - poj 1273 Drainage Ditches【最大流入门】
			
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63924 Accepted: 2467 ...
 - 关于sqlite数据库
			
firedac数据引擎可以支持sqlite数据库,这种方式是纯绿色的,发布时不需要带上官方的sqlite.dll动态链接库文件. 当然调用该动态链接库的API方法也是可以操作sqlite数据库的,这样 ...
 - [三]JFreeChart实践二
			
功能: 1.设置带色彩的柱状图 2.可以设置多组数据的展示 3.可以设置图标的背景色 4.可以设置柱与柱之间的距离 5.可以设置柱子上边是否显示具体的数值
 - 【三支火把】---队列和栈的C程序实现
			
这几天总结了C语言的队列,栈的实现方法,在此总结一下:一.栈 首先从栈开始,诚然,相信学习过数据结构的你,肯定应该知道栈是什么东西了,如果不知道也没事每一句话我就可以帮你总结--数据只在栈顶进行插入和 ...