Control not returning after Context Switch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Control not returning after Context Switch

497 Views
ajmalali
Contributor III

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

Labels (2)
0 Kudos
1 Reply

334 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Ajeesh,

writing your own operating system is a huge task and this is out of our free support scope. I can recommend this nice reference Real-Time Concepts for Embedded Systems by Qing Li and Carolyn or you may also o aquire our NXP professional support and services here Professional Support and Service Resources|NXP 


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos