blob: 72bc9241f6a7c8d1f3ace454d70a53ed75a8bb85 [file] [log] [blame]
Rick Chen72157872018-05-29 14:10:06 +08001/* SPDX-License-Identifier: GPL-2.0+ */
Alexander Grafa7f99e52018-04-23 07:59:43 +02002/*
3 * (C) 2018 Alexander Graf <agraf@suse.de>
Alexander Grafa7f99e52018-04-23 07:59:43 +02004 */
5
6#include <config.h>
7#include <linux/linkage.h>
8
Lukas Auer862e2e72018-11-22 11:26:12 +01009#ifdef CONFIG_ARCH_RV64I
Alexander Grafa7f99e52018-04-23 07:59:43 +020010#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"
18ENTRY(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
36ENDPROC(setjmp)
37.popsection
38
39.pushsection .text.longjmp, "ax"
40ENTRY(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. */
57 beq a1, zero, longjmp_1
58 mv a0, a1
59 ret
60
61 longjmp_1:
62 li a0, 1
63 ret
64ENDPROC(longjmp)
65.popsection