Osctxsw ; Special optimised code below: 1. Press the stack separately based on the task stack structure to save the site of the old task Stmfd SP !, {LR}; push PC (LR shocould be pushed in place of PC) Stmfd SP !, {R0-r12, LR}; push LR & Register File Mrs R4, CPSR Stmfd SP !, {R4}; push current PSR Mrs R4, spsr Stmfd SP !, {R4}; push current spsr ; 2, Ospriocur = ospriohighrdy LDR R4, = ospriocur LDR R5, = ospriohighrdy Ldrb R6, [R5] Strb R6, [R4] ; 3, Get current task TCB address: R5 = Ostcbcur LDR R4, = ostcbcur; r4 = & ostcbcur LDR R5, [R4] ; 4. ostcbcur-> ostcbstkptr = sp; STR sp, [R5]; store SP in preempted tasks's TCB BL ostaskswhook; call Task Switch hook ; 5, Get highest priority task TCB address: R6 = Ostcbhighrdy LDR R6, = ostcbhighrdy LDR R6, [R6] ; 6. sp = ostcbhighrdy-> ostcbstkptr; LDR sp, [R6]; get new task's stack pointer ; 7, Ostcbcur = ostcbhighrdy STR R6, [R4]; set new current task TCB address 8. Release stacks separately based on the task stack structure to restore the site of the new task. Ldmfd SP !, {R4}; pop new task's spsr MSR spsr_cxsf, r4 Ldmfd SP !, {R4}; pop new task's SRS MSR cpsr_cxsf, r4 Ldmfd SP !, {R0-r12, LR, PC}; pop new task's r0-r12, LR & PC |