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 ...
随机推荐
- 增加eclipse启动的Tomcat内存的方法 tomcat内存增加
增加eclipse启动的Tomcat内存的方法 Tomcat一般默认情况下最大最优内存设置为2G 这种情况下,修改Tomcat\bin\catalina.bat,添加如下内容 set JAVA_OPT ...
- 使用Hadoop打造私有云盘之API操作
项目介绍:使用hadoop实现云盘的增删读获取列表功能,hadoop不支持数据修改,特性是一次写入多次读取.主流的网盘也不支持该功能.今天我们用hdfs的FileSystem实现这些操作. 1.上传功 ...
- 学习Windows Azure 视频集合大全
Windows Azure 入门系列课程视频Windows Azure 入门系列课程(1):Windows Azure 概述http://www.aboutyun.com/thread-5777-1- ...
- mysql均衡负载
一.利用mysql 复制分流查询操作: 利用mysql的主从复制可以有效的分流更新操作和查询操作,具体的实现是一个主服务器,承担更新操作,多台从服务器,承担查询操作,主从之间通过复制实现数据的同步.多 ...
- PC-飞起来!我的Windows XP——五步快速优化Windows XP
虽然Microsoft的 Vista已经发售了快一年,但国内大部分系统用户仍使用着目前堪称完美的Windows XP.与以往的Windows操作系统一样,新安装的Windows XP可能还不在最佳状态 ...
- 有关gcc的扩展__attribute__((unused))
================================ Author: taoyuetao Email: tao_yuetao@yahoo.com.cn Blog: taoyuetao.cu ...
- 从CR线下活动学到的:如何组织一个小的线下活动
作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf 周末在腾讯组织了GR,活动达到了预期的收获,从这次活动我主 ...
- 换种眼光看Spring之bean是怎么诞生的(一)
Java的世界里处处存在了对象,有时候换一种眼光往往会给自己带来与之前大不一样的理解. 一个对象的出现离不开字节码,拿classforname来讲,classforname("...&quo ...
- 获取datagrid中编辑列combobox的value值与text值
var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'}); var productname = $(ed ...
- TransactionScope 对该事务的状态无效 和一些注意事项
使用TransactionScope 的时候要操作同一种数据库操作方式,不能一个方法用ado.net ,另外一个方法用EF,那样会报 "该事务管理器已经禁止了它对远程/网络事务的支持&quo ...