一言不合就是上代码。。。。。。。。。。。。。。。。。。。。。。。面对这个汇编反正我是一脸懵逼,于是我就一个个的差了汇编指令,但是我还是没能弄懂,具体的操作流程,
首先得疑问就是,我们在创建任务的时候会分配给任务一个堆栈空间,例如 CPU_STK TASK1_TASK[START_TASK_SIZE]; 这就意味着我们在保护现场的时候,会把寄存器的值保存到这个堆栈对吧?但是我在汇编的函数里并没有看到 ,系统把堆栈保存的时候用到 CPU_STK TASK1_TASK[START_TASK_SIZE]; 这个东东啊
希望懂的童鞋,大虾,当然还有原子哥,看到了及时帮我解释一下。您的回答决定了我痛苦地时间长短。。。。。。。。
提前说声谢谢!!!!
CPSID I ; Prevent interrup
tion during context switch
MRS R0, PSP ; PSP is process stack pointer
CBZ R0, PendSVHandler_nosave ; Skip register save the first time
;Is the task using the FPU context? If so, push high vfp registers.
TST R14, #0X10
IT EQ
VSTMDBEQ R0!,{S16-S31}
SUBS R0, R0, #0x20 ; Save remaining regs r4-11 on process stack
STM R0, {R4-R11}
LDR R1, =OSTCBCurPtr ; OSTCBCurPtr->OSTCBStkPtr = SP;
LDR R1, [R1]
STR R0, [R1] ; R0 is SP of process being switched out
; At this point, entire context of process has been saved
PendSVHandler_nosave
PUSH {R14} ; Save LR exc_return value
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, =OSPrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, =OSPrioHighRdy
LDRB R2, [R1]
STRB R2, [R0]
LDR R0, =OSTCBCurPtr ; OSTCBCurPtr = OSTCBHighRdyPtr;
LDR R1, =OSTCBHighRdyPtr
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdyPtr->StkPtr;
LDM R0, {R4-R11} ; Restore r4-11 from new process stack
ADDS R0, R0, #0x20 ;Is the task using the FPU context? If so, push high vfp registers.
TST R14, #0x10
IT EQ
VLDMIAEQ R0!, {S16-S31}
MSR PSP, R0 ; Load PSP with new process SP
ORR LR, LR, #0x04 ; Ensure exception return uses process stack
CPSIE I
BX LR ; Exception return will restore remaining context
END