初级会员
- 积分
- 183
- 金钱
- 183
- 注册时间
- 2018-6-10
- 在线时间
- 31 小时
|
5金钱
[mw_shl_code=applescript,true]/* 初始化线程栈 */
rt_uint8_t *rt_hw_stack_init(void *tentry,
void *parameter,
rt_uint8_t *stack_addr)
{
struct stack_frame *stack_frame;
rt_uint8_t *stk;
unsigned long i;
/* 获取栈顶指针 rt_hw_stack_init 在调用时,传给stack_addr的是(栈顶指针-4)*/
stk = stack_addr + sizeof(rt_uint32_t);
/*让stk指针向下8字节对齐*/
stk = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stk,8);
/*stk指针继续向下移动sizeof(struct stack_frame)个偏移*/
stk -=sizeof(struct stack_frame);
/* 将stk指针强制转换为 stack_frame类型后存到stack_frame*/
stack_frame =(struct stack_frame *)stk;
/*以stack_frame 为起始地址,将栈空间里面的sizeof(struct stack_frame)个内存初始化为0xdeadbeef */
for(i=0; i<sizeof(struct stack_frame)/sizeof(rt_uint32_t); i++)
{
((rt_uint32_t *)stack_frame) = 0xdeadbeef;
}
/*初始化异常发生时自动保存的寄存器*/
stack_frame->exception_stack_frame.r0 =(unsigned long)parameter;
stack_frame->exception_stack_frame.r1 = 0; /* r1 */
stack_frame->exception_stack_frame.r2 = 0; /* r2 */
stack_frame->exception_stack_frame.r3 = 0; /* r3 */
stack_frame->exception_stack_frame.r12 = 0; /* r12 */
stack_frame->exception_stack_frame.lr = 0; /* lr */
stack_frame->exception_stack_frame.pc = (unsigned long)tentry; /* entry point, pc */
stack_frame->exception_stack_frame.psr = 0x01000000L; /* PSR */
/* 返回线程指针 */
return stk;
}
[/mw_shl_code]
|
|