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