Created
May 1, 2020 18:31
-
-
Save dheeptuck/959a3457661a8113d1e9bd2b43b64315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__attribute__((naked)) void LaunchScheduler(void) | |
{ | |
/// R0 contains the address of currentPt | |
__asm("LDR R0, =pCurntTcb"); | |
/// R2 contains the address in currentPt(value of currentPt) | |
__asm("LDR R2, [R0]"); | |
/// Load the SP reg with the stacked SP value | |
__asm("LDR R4, [R2]"); | |
__asm("MOV SP, R4"); | |
/// Pop registers R8-R11(user saved context) | |
__asm("POP {R4-R7}"); | |
__asm("MOV R8, R4"); | |
__asm("MOV R9, R5"); | |
__asm("MOV R10, R6"); | |
__asm("MOV R11, R7"); | |
/// Pop registers R4-R7(user saved context) | |
__asm("POP {R4-R7}"); | |
/// Start poping the stacked exception frame. | |
__asm("POP {R0-R3}"); | |
__asm("POP {R4}"); | |
__asm("MOV R12, R4"); | |
/// Skip the saved LR | |
__asm("ADD SP,SP,#4"); | |
/// POP the saved PC into LR via R4, We do this to jump into the | |
/// first task when we execute the branch instruction to exit this routine. | |
__asm("POP {R4}"); | |
__asm("MOV LR, R4"); | |
__asm("ADD SP,SP,#4"); | |
/// Enable interrupts | |
__asm("CPSIE I "); | |
__asm("BX LR"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment