|
| 1 | +//===-- Implementation of longjmp -----------------------------------------===// |
| 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/setjmp/longjmp.h" |
| 10 | +#include "src/__support/common.h" |
| 11 | +#include "src/__support/macros/properties/architectures.h" |
| 12 | + |
| 13 | +#include <setjmp.h> |
| 14 | + |
| 15 | +#if !defined(LIBC_TARGET_ARCH_IS_RISCV64) |
| 16 | +#error "Invalid file include" |
| 17 | +#endif |
| 18 | + |
| 19 | +namespace __llvm_libc { |
| 20 | + |
| 21 | +LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) { |
| 22 | + LIBC_INLINE_ASM("ld ra, %0\n\t" : : "m"(buf->__pc) :); |
| 23 | + LIBC_INLINE_ASM("ld s0, %0\n\t" : : "m"(buf->__regs[0]) :); |
| 24 | + LIBC_INLINE_ASM("ld s1, %0\n\t" : : "m"(buf->__regs[1]) :); |
| 25 | + LIBC_INLINE_ASM("ld s2, %0\n\t" : : "m"(buf->__regs[2]) :); |
| 26 | + LIBC_INLINE_ASM("ld s3, %0\n\t" : : "m"(buf->__regs[3]) :); |
| 27 | + LIBC_INLINE_ASM("ld s4, %0\n\t" : : "m"(buf->__regs[4]) :); |
| 28 | + LIBC_INLINE_ASM("ld s5, %0\n\t" : : "m"(buf->__regs[5]) :); |
| 29 | + LIBC_INLINE_ASM("ld s6, %0\n\t" : : "m"(buf->__regs[6]) :); |
| 30 | + LIBC_INLINE_ASM("ld s7, %0\n\t" : : "m"(buf->__regs[7]) :); |
| 31 | + LIBC_INLINE_ASM("ld s8, %0\n\t" : : "m"(buf->__regs[8]) :); |
| 32 | + LIBC_INLINE_ASM("ld s9, %0\n\t" : : "m"(buf->__regs[9]) :); |
| 33 | + LIBC_INLINE_ASM("ld s10, %0\n\t" : : "m"(buf->__regs[10]) :); |
| 34 | + LIBC_INLINE_ASM("ld s11, %0\n\t" : : "m"(buf->__regs[11]) :); |
| 35 | + LIBC_INLINE_ASM("ld sp, %0\n\t" : : "m"(buf->__sp) :); |
| 36 | + |
| 37 | +#if __riscv_float_abi_double |
| 38 | + LIBC_INLINE_ASM("fld fs0, %0\n\t" : : "m"(buf->__fpregs[0]) :); |
| 39 | + LIBC_INLINE_ASM("fld fs1, %0\n\t" : : "m"(buf->__fpregs[1]) :); |
| 40 | + LIBC_INLINE_ASM("fld fs2, %0\n\t" : : "m"(buf->__fpregs[2]) :); |
| 41 | + LIBC_INLINE_ASM("fld fs3, %0\n\t" : : "m"(buf->__fpregs[3]) :); |
| 42 | + LIBC_INLINE_ASM("fld fs4, %0\n\t" : : "m"(buf->__fpregs[4]) :); |
| 43 | + LIBC_INLINE_ASM("fld fs5, %0\n\t" : : "m"(buf->__fpregs[5]) :); |
| 44 | + LIBC_INLINE_ASM("fld fs6, %0\n\t" : : "m"(buf->__fpregs[6]) :); |
| 45 | + LIBC_INLINE_ASM("fld fs7, %0\n\t" : : "m"(buf->__fpregs[7]) :); |
| 46 | + LIBC_INLINE_ASM("fld fs8, %0\n\t" : : "m"(buf->__fpregs[8]) :); |
| 47 | + LIBC_INLINE_ASM("fld fs9, %0\n\t" : : "m"(buf->__fpregs[9]) :); |
| 48 | + LIBC_INLINE_ASM("fld fs10, %0\n\t" : : "m"(buf->__fpregs[10]) :); |
| 49 | + LIBC_INLINE_ASM("fld fs11, %0\n\t" : : "m"(buf->__fpregs[11]) :); |
| 50 | +#elif defined(__riscv_float_abi_single) |
| 51 | +#error "longjmp implementation not available for the target architecture." |
| 52 | +#endif |
| 53 | + |
| 54 | + val = val == 0 ? 1 : val; |
| 55 | + LIBC_INLINE_ASM("add a0, %0, zero\n\t" : : "r"(val) :); |
| 56 | +} |
| 57 | + |
| 58 | +} // namespace __llvm_libc |
0 commit comments