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