本人下载了UCOS官网cortex m0的移植例子,版本2.92- 08,发现任务切换保护现场时有些疑问:在任务切换时由于中断已经把xPSR,PC,LR,R12,R3,R2,R1,R0自动保存了,所以我只需要保存剩下的通用寄存器,
即R4-R11,但是我发现任务切换代码里却只保存了R4-R7,这样是不是做任务切换时有风险?万一某个任务用到了R8-R11呢,
还是keil里的ARM编译器默认是不使用R8-R11寄存器,代码如下:
SUBS R0, R0, #0x10 ; Adjust stack pointer to where memory needs to be stored to avoid overwriting
STM R0!, {R4-R7} ; Stores 4 4-byte registers, default increments SP after each storing
SUBS R0, R0, #0x10 ; STM does not automatically call back the SP to initial location so we must do this manually
LDR R1, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R1, [R1]
STR R0, [R1] ; R0 is SP of process being switched out