关于THREAD_START_SP
2017-02-23
1. 问题引入
https://awakening-fong.github.io/posts/arm/arm_qemu_02 中说到 startkernel前设置sp为 initthreadunion + THREADSTART_SP
#define THREAD_START_SP (THREAD_SIZE - 8)
为何要-8?
2. 解
static inline struct thread_info *current_thread_info(void)
{
register unsigned long sp asm ("sp");
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}
(图示中A点到B点 大小是8字节)
如果sp是SP0, 那么,(sp & ~(THREADSIZE - 1)) 后还是指向SP0 (A点);
如果sp是SP1, 那么, (sp & ~(THREADSIZE - 1)) 后指向的是thread_info (C点).
所以, 需要-8.
SP0 ----> +.------------+ --.-- 高地址
| | A | |
8 | | | ^
| | | |
SP1 ----> |.B | THREAD_SIZE |
| | . |
| | | |
| | | |
| | | |
thread_info ---> |.C | ------ |
| | |
| | |
| | |
| |
+-------------+ 低地址
本文地址: https://awakening-fong.github.io/posts/arm/thread_start_sp
转载请注明出处: https://awakening-fong.github.io
若无法评论, 请打开JavaScript, 并通过proxy.
blog comments powered by Disqus