然后我们再浏览一下ARM9的上下文切换函数 packages\hal\arm\arch\current\src\context.S [plain] view plaincopy
- // ----------------------------------------------------------------------------
- // hal_thread_switch_context
- // Switch thread contexts
- // R0 = address of sp of next thread to execute
- // R1 = address of sp save location of current thread
-
- // Need to save/restore R4..R12, R13 (sp), R14 (lr)
-
- // Note: this is a little wasteful since r0..r3 don't need to be saved.
- // They are saved here though so that the information can match the
- // HAL_SavedRegisters
-
- FUNC_START_ARM(hal_thread_switch_context, r2)
- mov ip,sp
- sub sp,sp,#(ARMREG_SIZE - armreg_lr - 4) // skip svc_sp, svc_lr, vector, cpsr, and pc
- stmfd sp!,{ip,lr}
- stmfd sp!,{r0-r10,fp,ip}
- mrs r2,cpsr
- str r2,[sp,#armreg_cpsr]
- str sp,[r1] // return new stack pointer
- #ifdef __thumb__
- b hal_thread_load_context_ARM // skip mode switch stuff
- #endif
-
- # Now load the destination thread by dropping through
- # to hal_thread_load_context
-
- // ----------------------------------------------------------------------------
- // hal_thread_load_context
- // Load thread context
- // R0 = address of sp of next thread to execute
- // Note that this function is also the second half of
- // hal_thread_switch_context and is simply dropped into from it.
-
- FUNC_START_ARM(hal_thread_load_context, r2)
- ldr fp,[r0] // get context to restore
- mrs r0,cpsr // disable IRQ's
- orr r0,r0,#CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE
- msr cpsr,r0
- ldr r0,[fp,#armreg_cpsr]
- msr spsr,r0
- ldmfd fp,{r0-r10,fp,ip,sp,lr}
- #ifdef __thumb__
- mrs r1,spsr // r1 is scratch
- // [r0 holds initial thread arg]
- msr cpsr,r1 // hopefully no mode switch here!
- bx lr
- #else
- movs pc,lr // also restores saved PSR
- #endif
|