邵贝贝的书上说,任务开始调度时,(1)首先执行一条类似中断功能的指令,(2)接着保存CPU的所有寄存器的值,即压到当前任务的堆栈中;(3)然后获得新任务的堆栈指针,(4)并把堆栈内的CPU寄存器的值弹出来,传给CPU各寄存器,(5)最后执行一条中断返回指令,即完成了任务切换。
但我在网上找了一段任务切换的代码,发现上述介绍的过程没有(1)这个步骤,只有后面的四步。不知道为什么?下面是那段代码,请各位指点一下:
EXPORT OSCtxSw
IMPORT OSPrioCur
IMPORT OSPrioHighRdy
IMPORT OSTCBCur
IMPORT OSTaskSwHook
IMPORT OSTCBHighRdy
OSCtxSw
STMFD sp!, {lr} ; push pc (lr is actually be pushed in place of PC)
STMFD sp!, {r0-r12,lr} ; push lr & register file
MRS r4, cpsr
STMFD sp!, {r4} ; push current psr
LDR r4, =OSTCBCur ; Get current task TCB address
LDR r5, [r4]
STR sp, [r5] ; store sp in preempted tasks s TCB
IMPORT OSTaskSwHook
OSIntCtxSw
BL OSTaskSwHook
LDR r4, =OSTCBHighRdy
LDR r4, [r4]
LDR r5, =OSTCBCur
STR r4, [r5] ; OSTCBCur = OSTCBHighRdy
LDR r6, =OSPrioHighRdy
LDRB r6, [r6]
LDR r5, =OSPrioCur
STRB r6, [r5] ; OSPrioCur = OSPrioHighRdy
LDR sp, [r4]
LDMFD sp!, {r4} ; pop new task cpsr
MSR cpsr_cxsf, r4
LDMFD sp!, {r0-r12,lr,pc} ; pop new task r0-r12,lr & pc
谢谢~~~~~~~~