1 / 3
文档名称:

为什么要加preserve8栈的8字节对齐.docx

格式:docx   大小:29KB   页数:3页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

为什么要加preserve8栈的8字节对齐.docx

上传人:liwenfei1314 2018/10/20 文件大小:29 KB

下载得到文件列表

为什么要加preserve8栈的8字节对齐.docx

文档介绍

文档介绍:为什么要加 REQUIRE8 and PRESERVE8? 栈的 8 字节对齐
标签: c 处理器
2015-02-16 23:15 339 人阅读 评论 (0) 收藏 举报
分类:
arm( 22) C/C++ ( 91)
目录 (?)[+]
REQUIRE8 and PRESERVE8
The REQUIRE8 and PRESERVE8 directives specify that the current file requires or preserves
eight-byte alignment of the stack.
The REQUIRE8 directive sets the REQ8 build attribute to inform the linker.
The PRESERVE8 directive sets the PRES8 build attribute to inform the linker.
The linker checks that any code that requires eight-byte alignment of the stack is only called,
directly or indirectly, by code that preserves eight-byte alignment of the stack.
解释 :
cortex-m3 栈的 8 字节对齐
一、什么是栈对齐?
栈的字节对齐,实际是指栈顶指针须是某字节的整数倍。因此下边对系统栈与 MSP,任务
栈与 PSP,栈对齐与 SP 对齐 这三对概念不做区分。 另外下文提到编译器的时候, 实际上是
对编译器汇编器连接器的统称。
之前对栈的 8 字节对齐理解的不透, 就在网上查了好多有关栈字节对齐、还有一些 ARM 对
齐伪指令的资料信息, 又做了一些实验, 把这些零碎的信息拼接在一起, 总觉得理解透这个
问题的话得长篇大论了。结果昨天看了 AAPCS 手册、然后查到了没有使用 PRESERVE8 伪
指令出现错误的实例,突然觉得长篇大论不存在了,半篇小论这问题就能理顺了。
二、 AAPCS 栈使用规约
在 ARM 上编程,但凡涉及到调用, 就需要遵循一套规约 AAPCS:《 Procedure Call Standard for
the ARM Architecture 》。这套规约里面对栈使用的约定如下:

Universal stack constraints
At all times the following basic constraints must hold:
Stack-limit < SP <= stack-base. The stack pointer must lie within the extent of the stack.
SP mod 4 = 0. The stack must at all times be aligned to a word boundary.
A process may only access (for reading or writing) the closed interval of th