switch_context_arm32_sysv_elf.s 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	.arm
	.text
	.global	__cs_switch_context
	.type	__cs_switch_context, %function

__cs_switch_context:
        /* Parameter List (in order)
        * r0 = pointer to continuation (should hold value of target stack will be filled with this continuation)
        *
        * Return
        * r0 = continuation that returned control back to the caller (null if fallthrough)
        *
        * Variables
        * r1 = temporary for the old stack pointer */

        /* ========== Save State ========== */
        /* store programm counter for later return */
        push {lr}
        /* store callee saved registers */
        push {r4-r12,lr}
        /* store floating point extension registers */
        #if (defined(__VFP_FP__) && !defined(__SOFTFP__))
        sub sp, sp, #64
        vstmia sp, {d8-d15}
        #endif
        /* ========== Save State ========== */

        /* Perform change to new stack */
        /* Keep old stack as result from this function. */
        mov r1, sp
        /* Switch to new stack pointer. */
        mov sp, r0


        /* ========== Restore State ========== */
        /* restore floating point extension registers */
        #if (defined(__VFP_FP__) && !defined(__SOFTFP__))
        vldmia sp, {d8-d15}
        add sp, sp, #64
        #endif
        /* restore callee saved registers */
        pop {r4-r12,lr}
        /* ========== Restore State ========== */

        /* Just return back from the call. */
        /* This is the end of a fiber, so we have no continuation. */
        mov r0, r1
        pop {pc}