最近看了RL-ARM代码,在初始化调用了os_set_env ,有点不解:
/*--------------------------- os_set_env ------------------------------------*/
__asm void os_set_env (void) {
/* Switch to Unpriviliged/Priviliged Thread mode, use PSP. */
MOV R0,SP //; R0 = MSP
MSR PSP,R0
//; PSP = R0
LDR R0,=__cpp(&os_flags) //; R0 = &os_flags
LDRB R0,[R0]
//; R0 = *R0
LSLS R0,#31
//; R0 = R0 << 31逻辑左移
MOVNE R0,#0x02 //; Priviliged Thread mode, use PSP if(R != 0x02)
MOVEQ R0,#0x03 //; Unpriviliged Thread mode, use PSP
if(R == 0x03)
MSR CONTROL,R0
//; CONTROL = R0
BX LR
//; return
ALIGN
}
这个一段RL-ARM的代码,功能是根据os_flags来设定CM3的CONTROL寄存器,即改变模式和使用PSP
问题是:程序返回时,直接进了SVC_Handler ,难道对CONTROL写操作会引发异常?
/*-------------------------- SVC_Handler -----------------------------------*/
// 11# 异常服务,执行系统服务调用指令SVC引发的异常
__asm void SVC_Handler (void)
{
}
求高手签定,谢谢 |