1 | //===-- Implementation of setjmp ------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/__support/common.h" |
10 | #include "src/setjmp/setjmp_impl.h" |
11 | |
12 | #include <setjmp.h> |
13 | |
14 | #if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) |
15 | #error "Invalid file include" |
16 | #endif |
17 | |
18 | #define STORE_IMPL(insns, reg, val) \ |
19 | LIBC_INLINE_ASM(#insns " " #reg ", %0\n\t" : : "m"(val) :) |
20 | |
21 | #ifdef LIBC_TARGET_ARCH_IS_RISCV32 |
22 | #define STORE(reg, val) STORE_IMPL(sw, reg, val) |
23 | #define STORE_FP(reg, val) STORE_IMPL(fsw, reg, val) |
24 | #else |
25 | #define STORE(reg, val) STORE_IMPL(sd, reg, val) |
26 | #define STORE_FP(reg, val) STORE_IMPL(fsd, reg, val) |
27 | #endif |
28 | |
29 | namespace LIBC_NAMESPACE { |
30 | |
31 | LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) { |
32 | STORE(ra, buf->__pc); |
33 | STORE(s0, buf->__regs[0]); |
34 | STORE(s1, buf->__regs[1]); |
35 | STORE(s2, buf->__regs[2]); |
36 | STORE(s3, buf->__regs[3]); |
37 | STORE(s4, buf->__regs[4]); |
38 | STORE(s5, buf->__regs[5]); |
39 | STORE(s6, buf->__regs[6]); |
40 | STORE(s7, buf->__regs[7]); |
41 | STORE(s8, buf->__regs[8]); |
42 | STORE(s9, buf->__regs[9]); |
43 | STORE(s10, buf->__regs[10]); |
44 | STORE(s11, buf->__regs[11]); |
45 | STORE(sp, buf->__sp); |
46 | |
47 | #if __riscv_float_abi_double |
48 | STORE_FP(fs0, buf->__fpregs[0]); |
49 | STORE_FP(fs1, buf->__fpregs[1]); |
50 | STORE_FP(fs2, buf->__fpregs[2]); |
51 | STORE_FP(fs3, buf->__fpregs[3]); |
52 | STORE_FP(fs4, buf->__fpregs[4]); |
53 | STORE_FP(fs5, buf->__fpregs[5]); |
54 | STORE_FP(fs6, buf->__fpregs[6]); |
55 | STORE_FP(fs7, buf->__fpregs[7]); |
56 | STORE_FP(fs8, buf->__fpregs[8]); |
57 | STORE_FP(fs9, buf->__fpregs[9]); |
58 | STORE_FP(fs10, buf->__fpregs[10]); |
59 | STORE_FP(fs11, buf->__fpregs[11]); |
60 | #elif defined(__riscv_float_abi_single) |
61 | #error "setjmp implementation not available for the target architecture." |
62 | #endif |
63 | |
64 | return 0; |
65 | } |
66 | |
67 | } // namespace LIBC_NAMESPACE |
68 | |