分享

对stm32启动代码DCD sfe(CSTACK)的理解

 月光下的幽会 2014-04-29

复位序列:
在离开复位状态后,CM3做的第一件事就是读取下列两个32位整数的值:
1、从地址0x0000 0000 处取出MSP的初始值。(也就是 stm32启动代码DCD     sfe(CSTACK)设置的栈顶指针值)
    PS:至于MSP的真实地址是多少我还不清楚,如果哪位大侠知道请告诉我。可以确定的是它是在0x2000 0000--0x2002 0000之间的一个值,貌似是在0x20020000。


 

2、从地址0x0000 0004 处取出PC的初始值 也就是复位向量的值。
相关知识:
IAR汇编指令SFB和SFE
SFB Segment begin 段开始
语法格式
SFB(segment [{+|-} offset])

参数
segment: 可重定位段的段名, 必须在SFB使用前已定义
offset : 从开始地址的偏移, 是一个可选参数, 当偏移量省略时, 可以不添加小括号

描述
SFB 右边可以接受一个操作数, 而且这个操作数必须是一个可重位段的段名.
这个操作符计算段的首字节地址. 这个操作发生在连接时.
The operator evaluates to the absolute address of the first byte of that segment. This evaluation takes place at linking time.


NAME demo
RSEG CODE
start: DC16 SFB(CODE)
即使上面的代码和多个其他的模块进行连接, start标号处仍被置为段的首字节地址. Even if the above code is linked with many other modules, start will still be set to the address of the first byte of the segment.

 


SFE Segment end

语法格式
SFE (segment [{+|-} offset])

参数
segment: 可重定位段的段名, 必须在SFB使用前已定义
offset : 从开始地址的偏移, 是一个可选参数, 当偏移量省略时, 可以不添加小括号

描述
SFE在其右边接收一个操作数. 操作数必须是一个可重定位段的段名. SFE操作符将段起始地址和段大小相加. 这个操作在连接时发生.
SFE accepts a single operand to its right. The operand must be the name of a relocatable segment. The operator evaluates to the segment start address plus the segment size. This evaluation takes place at linking time.


NAME demo
RSEG CODE
end: DC16 SFE(CODE)
即使当上面的代码被和多个模块连接时, end标号仍然会被置为段最后一个字节的地址. Even if the above code is linked with many other modules, end will still be set to the address of the last byte of the segment.

段MY_SEGMENT的大小可以通过以下方式计算而得:
SFE(MY_SEGMENT)-SFB(MY_SEGMENT)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多