[c5cbc099] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 3 | // |
---|
[8ec4a52] | 4 | // CtxSwitch-arm64.S -- |
---|
[c5cbc099] | 5 | // |
---|
| 6 | // Author : Peter A. Buhr |
---|
| 7 | // Created On : Sun Aug 16 07:50:13 2020 |
---|
| 8 | // Last Modified By : Peter A. Buhr |
---|
[8ec4a52] | 9 | // Last Modified On : Wed Aug 26 16:24:59 2020 |
---|
| 10 | // Update Count : 25 |
---|
[c5cbc099] | 11 | // |
---|
[ccbf683] | 12 | |
---|
[c5cbc099] | 13 | // The context switch routine requires the initial the stack of a thread to |
---|
| 14 | // look like the thread has saved its context in the normal manner. |
---|
[ccbf683] | 15 | |
---|
[c5cbc099] | 16 | // Offsets must synchronized with the __stack_context_t in invoke.h. |
---|
[ccbf683] | 17 | |
---|
[c5cbc099] | 18 | #define PTR_BYTE 8 |
---|
| 19 | #define SP_OFFSET ( 0 * PTR_BYTE ) |
---|
| 20 | #define FP_OFFSET ( 1 * PTR_BYTE ) |
---|
| 21 | |
---|
| 22 | // Context switch between coroutines/tasks. |
---|
| 23 | // void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) ; |
---|
| 24 | // Arguments "from" in register x0, "to" in register x1. |
---|
| 25 | |
---|
| 26 | #define SAVE 20 * 8 |
---|
| 27 | |
---|
[8ec4a52] | 28 | .file "CtxSwitch-arm64.S" |
---|
[ccbf683] | 29 | .text |
---|
[c5cbc099] | 30 | .align 2 |
---|
[c7a900a] | 31 | .global __cfactx_switch |
---|
[8ec4a52] | 32 | .type __cfactx_switch, %function |
---|
[c7a900a] | 33 | __cfactx_switch: |
---|
[c5cbc099] | 34 | |
---|
| 35 | sub sp, sp, #SAVE // push stack |
---|
| 36 | |
---|
| 37 | // Save volatile GP registers x19-x30 on the stack. |
---|
| 38 | |
---|
| 39 | stp x19, x20, [sp, #0x00] |
---|
| 40 | stp x21, x22, [sp, #0x10] |
---|
| 41 | stp x23, x24, [sp, #0x20] |
---|
| 42 | stp x25, x26, [sp, #0x30] |
---|
| 43 | stp x27, x28, [sp, #0x40] |
---|
| 44 | stp x29, x30, [sp, #0x50] // x29 => fp |
---|
| 45 | |
---|
| 46 | // Save volatile SIMD/FPU registers d8-d15 on the stack. |
---|
| 47 | |
---|
| 48 | stp d8, d9, [sp, #0x60] |
---|
| 49 | stp d10, d11, [sp, #0x70] |
---|
| 50 | stp d12, d13, [sp, #0x80] |
---|
| 51 | stp d14, d15, [sp, #0x90] |
---|
| 52 | |
---|
| 53 | // Save old context in the "from" area. |
---|
| 54 | |
---|
| 55 | mov x4, sp // cannot store sp directly |
---|
| 56 | str x4, [x0, #SP_OFFSET] |
---|
| 57 | str fp, [x0, #FP_OFFSET] |
---|
| 58 | |
---|
| 59 | // Load new context from the "to" area. |
---|
| 60 | |
---|
| 61 | ldr fp, [x1, #FP_OFFSET] |
---|
| 62 | ldr x4, [x1, #SP_OFFSET] |
---|
| 63 | mov sp, x4 // cannot store sp directly |
---|
| 64 | |
---|
| 65 | // Load volatile GP registers x19-x30 from the stack. |
---|
| 66 | |
---|
| 67 | ldp x19, x20, [sp, #0x00] |
---|
| 68 | ldp x21, x22, [sp, #0x10] |
---|
| 69 | ldp x23, x24, [sp, #0x20] |
---|
| 70 | ldp x25, x26, [sp, #0x30] |
---|
| 71 | ldp x27, x28, [sp, #0x40] |
---|
| 72 | ldp x29, x30, [sp, #0x50] |
---|
| 73 | |
---|
| 74 | // Load volatile SIMD/FPU registers d8-d15 from the stack. |
---|
| 75 | |
---|
| 76 | ldp d8, d9, [sp, #0x60] |
---|
| 77 | ldp d10, d11, [sp, #0x70] |
---|
| 78 | ldp d12, d13, [sp, #0x80] |
---|
| 79 | ldp d14, d15, [sp, #0x90] |
---|
| 80 | |
---|
| 81 | add sp, sp, #SAVE // pop stack |
---|
| 82 | ret // return to new thread (mov pc, x30) |
---|
| 83 | |
---|
| 84 | .size __cfactx_switch, .-__cfactx_switch |
---|
| 85 | .section .note.GNU-stack,"",%progbits // mark no executable stack needed |
---|
| 86 | |
---|
| 87 | // Stub to create new stacks which can be context switched to |
---|
| 88 | // void __cfactx_invoke_stub( void ); |
---|
[c7a900a] | 89 | |
---|
[ccbf683] | 90 | .text |
---|
[c5cbc099] | 91 | .align 2 |
---|
[c7a900a] | 92 | .global __cfactx_invoke_stub |
---|
[8ec4a52] | 93 | .type __cfactx_invoke_stub, %function |
---|
[c7a900a] | 94 | __cfactx_invoke_stub: |
---|
[c5cbc099] | 95 | mov x0, x19 // load main as parameter 0 |
---|
| 96 | mov x1, x20 // load this as parameter 1 |
---|
| 97 | mov x30, x21 // load coroutine invoke routine |
---|
| 98 | ret // and jmp to it (mov pc, x30) |
---|
| 99 | .size __cfactx_invoke_stub, .-__cfactx_invoke_stub |
---|
| 100 | |
---|
| 101 | // Local Variables: // |
---|
| 102 | // mode: c // |
---|
| 103 | // tab-width: 4 // |
---|
| 104 | // End: // |
---|