我是一个新手。开始是这样的,在移植eCos时遇到一个编译错误,代码如下
- //=========================================================================
- // State switch VSR
- //
- // This is called from the init code to switch execution from the main
- // stack to the process stack. We also take the opportunity to do some
- // other things that are best done in asm code such as disabling interrupts
- // and setting the control register.
- //
- // The adjustment to MSP by 1/2 interrupt stack size allows code to
- // throw exceptions without corrupting the execution stack. This is
- // only necessary for non-kernel configurations (e.g. RedBoot, Stubs)
- // since kernel configurations will switch to a thread stack before
- // they should throw an exception.
-
- .global hal_switch_state_vsr
- .thumb
- .thumb_func
- .type hal_switch_state_vsr, %function
- hal_switch_state_vsr:
- mov r0,#CYGNUM_HAL_CORTEXM_PRIORITY_MAX
- msr basepri,r0
-
- mov r0,#2 // Set CONTROL register to 2
- msr control,r0
- isb // Insert a barrier
-
- msr psp,sp // Copy SP to PSP
- #if !defined(CYGPKG_KERNEL)
- sub sp,#(CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE/2)
- #endif
-
- orr lr,#0xD // Adjust return link
- bx lr // Return to init code on PSP now
- #endif
这段代码编译的时候报错,Error:r13 not allowed here--'msr psp,sp'。
然后我就去找原因了:
1.R13寄存器可以保存两个指针MSP和PSP。
2.M3有两个等级,一个是用户级和特权级,这个好理解,为了安全嘛。
3.M3有两种模式,线程模式和handler模式,线程模式运行主应用程序代码,handler模式运行异常和中断的代码,而且在handler模式下,只能用MSP指针。
然后我就猜想,错误的原因是不是在handler模式下执行的msr psp,sp这条指令所以报错了,然而我并不知道这个想法对不对。
其实我的问题是,处于什么考虑需要两个堆栈指针,而且要这样应用呢,希望大神给我讲讲嘛,感激不尽。如果顺便能帮我找找代码出错的原因俺都愿意以身相许了。
|