Rick Chen | 7215787 | 2018-05-29 14:10:06 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Alexander Graf | a7f99e5 | 2018-04-23 07:59:43 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) 2018 Alexander Graf <agraf@suse.de> |
Alexander Graf | a7f99e5 | 2018-04-23 07:59:43 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <config.h> |
| 7 | #include <linux/linkage.h> |
| 8 | |
Lukas Auer | 862e2e7 | 2018-11-22 11:26:12 +0100 | [diff] [blame] | 9 | #ifdef CONFIG_ARCH_RV64I |
Alexander Graf | a7f99e5 | 2018-04-23 07:59:43 +0200 | [diff] [blame] | 10 | #define STORE_IDX(reg, idx) sd reg, (idx*8)(a0) |
| 11 | #define LOAD_IDX(reg, idx) ld reg, (idx*8)(a0) |
| 12 | #else |
| 13 | #define STORE_IDX(reg, idx) sw reg, (idx*4)(a0) |
| 14 | #define LOAD_IDX(reg, idx) lw reg, (idx*4)(a0) |
| 15 | #endif |
| 16 | |
| 17 | .pushsection .text.setjmp, "ax" |
| 18 | ENTRY(setjmp) |
| 19 | /* Preserve all callee-saved registers and the SP */ |
| 20 | STORE_IDX(s0, 0) |
| 21 | STORE_IDX(s1, 1) |
| 22 | STORE_IDX(s2, 2) |
| 23 | STORE_IDX(s3, 3) |
| 24 | STORE_IDX(s4, 4) |
| 25 | STORE_IDX(s5, 5) |
| 26 | STORE_IDX(s6, 6) |
| 27 | STORE_IDX(s7, 7) |
| 28 | STORE_IDX(s8, 8) |
| 29 | STORE_IDX(s9, 9) |
| 30 | STORE_IDX(s10, 10) |
| 31 | STORE_IDX(s11, 11) |
| 32 | STORE_IDX(ra, 12) |
| 33 | STORE_IDX(sp, 13) |
| 34 | li a0, 0 |
| 35 | ret |
| 36 | ENDPROC(setjmp) |
| 37 | .popsection |
| 38 | |
| 39 | .pushsection .text.longjmp, "ax" |
| 40 | ENTRY(longjmp) |
| 41 | LOAD_IDX(s0, 0) |
| 42 | LOAD_IDX(s1, 1) |
| 43 | LOAD_IDX(s2, 2) |
| 44 | LOAD_IDX(s3, 3) |
| 45 | LOAD_IDX(s4, 4) |
| 46 | LOAD_IDX(s5, 5) |
| 47 | LOAD_IDX(s6, 6) |
| 48 | LOAD_IDX(s7, 7) |
| 49 | LOAD_IDX(s8, 8) |
| 50 | LOAD_IDX(s9, 9) |
| 51 | LOAD_IDX(s10, 10) |
| 52 | LOAD_IDX(s11, 11) |
| 53 | LOAD_IDX(ra, 12) |
| 54 | LOAD_IDX(sp, 13) |
| 55 | |
| 56 | /* Move the return value in place, but return 1 if passed 0. */ |
Heinrich Schuchardt | a718e2a | 2021-03-23 19:11:26 +0100 | [diff] [blame] | 57 | seqz a0, a1 |
| 58 | add a0, a0, a1 |
Alexander Graf | a7f99e5 | 2018-04-23 07:59:43 +0200 | [diff] [blame] | 59 | ret |
| 60 | ENDPROC(longjmp) |
| 61 | .popsection |