aboutsummaryrefslogtreecommitdiff
path: root/lib/arch/arm/yield.s
blob: de9d60408da9030e841dcc68878673e2731f6c1f (plain) (blame)
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
# Copyright (c) 2021 Johannes Stoelp

    .arch armv7-a
    .section .text, "ax", %progbits

    # extern "C" void yield(const void* new_stack, void** old_stack);
    #                                   ^^^^^^^^^         ^^^^^^^^^
    #                                   x0                x1
    .global yield
    .type   yield, %function
yield:
    .cfi_startproc
    // prologue
    push {fp, lr}
    mov fp, sp

    // push callee saved registers
    push {r4-r11}

    // arg0: r0 holds new stack
    // arg1: r1 holds addr to location current stack must be saved
    mov r2, sp
    str r2, [r1]  // save current stack ptr
    mov sp, r0    // switch to new stack ptr

    // pop callee saved registers
    pop {r4-r11}

    // epilogue
    pop {fp, pc}
    .cfi_endproc
    .size yield, .-yield