Hi,
I am using I.mx6q Sabre-sd board. I am trying to write my own custom OS. During the context switching process, the context switch happens accurately but the control doesn't return to the exact position. ie. when the context has to be switched, i call a function that is written in assembly. After the assembly has been executed the context gets switched but the control doesn't reach where the assembly function was actually called. But the next task is being executed accurately. What might be the problem. The assembly code i am using is,
.global _context_switch.func _context_switch//save required registers_context_switch: STMFD sp!,{r14} STMFD sp!,{r0-r12,r14} MRS r0,cpsr STMFD sp!,{r0} LDR r0,__userStackPtr2Ptr LDR r1,[r0] STR sp,[r1]// LDR r0,__newUserStackPtr2Ptr LDR r12,[r0] LDR sp ,[r12] LDMFD sp!,{r0} ORR r0,r0,#0xc0 MSR cpsr,r0 BIC r0,r0,#0xc0 MSR spsr,r0 LDR sp,[r12] ADD sp,sp,#4 LDMFD sp!,{r0-r12,lr} LDMFD sp!,{pc}^// sub lr, lr, #4;// bx lr .endfunc
Is this correct? Am i missing some steps ? I am not good with assembly. Please help.
Regards,
Ajeesh
Hi daith, Thanks for the reply. My original implementation had "sub lr,lr, #4" at the very beginning and the"bx lr" at the end. Even then the execution does not return to the call. It goes directly to the next task. Is context switch suppose to happen like this? Or should it wait till the scheduler gets finished? Regards, Ajeesh