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