1/* SPDX-License-Identifier: BSD-2-Clause */
2/*
3 * Copyright 2022-2023 NXP
4 */
5#include <asm.S>
6
7#ifdef RV32
8#define STR       sw
9#define LDR       lw
10#define REGOFF(x) ((x) * 4)
11#else
12#define STR       sd
13#define LDR       ld
14#define REGOFF(x) ((x) * 8)
15#endif /*RV32*/
16
17/* int setjmp (jmp_buf) */
18FUNC setjmp , :
19	STR	s0, REGOFF(0)(a0)
20	STR	s1, REGOFF(1)(a0)
21	STR	s2, REGOFF(2)(a0)
22	STR	s3, REGOFF(3)(a0)
23	STR	s4, REGOFF(4)(a0)
24	STR	s5, REGOFF(5)(a0)
25	STR	s6, REGOFF(6)(a0)
26	STR	s7, REGOFF(7)(a0)
27	STR	s8, REGOFF(8)(a0)
28	STR	s9, REGOFF(9)(a0)
29	STR	s10, REGOFF(10)(a0)
30	STR	s11, REGOFF(11)(a0)
31	STR	ra, REGOFF(12)(a0)
32	STR	sp, REGOFF(13)(a0)
33#ifdef CFG_FTRACE_SUPPORT
34	addi	sp, sp, -16
35	STR	ra, (sp)
36	mov	x29, sp
37	addi	a0, a0, REGOFF(12)
38	jal	ftrace_setjmp
39	LDR	ra, (sp)
40	addi	sp, sp, 16
41#endif
42	li 	a0, 0
43	ret
44END_FUNC setjmp
45
46/* void longjmp (jmp_buf, int) __attribute__ ((noreturn)) */
47FUNC longjmp , :
48#ifdef CFG_FTRACE_SUPPORT
49	addi	sp, sp, -16
50	STR	a0, REGOFF(0)(sp)
51	STR	a1, REGOFF(1)(sp)
52	STR	ra, REGOFF(2)(sp)
53	addi	a0, a0, REGOFF(12)
54	jal	ftrace_longjmp
55	LDR	a0, REGOFF(0)(sp)
56	LDR	a1, REGOFF(1)(sp)
57	LDR	ra, REGOFF(2)(sp)
58	addi	sp, sp, 16
59#endif
60	LDR	s0, REGOFF(0)(a0)
61	LDR	s1, REGOFF(1)(a0)
62	LDR	s2, REGOFF(2)(a0)
63	LDR	s3, REGOFF(3)(a0)
64	LDR	s4, REGOFF(4)(a0)
65	LDR	s5, REGOFF(5)(a0)
66	LDR	s6, REGOFF(6)(a0)
67	LDR	s7, REGOFF(7)(a0)
68	LDR	s8, REGOFF(8)(a0)
69	LDR	s9, REGOFF(9)(a0)
70	LDR	s10, REGOFF(10)(a0)
71	LDR	s11, REGOFF(11)(a0)
72	LDR	ra, REGOFF(12)(a0)
73	LDR	sp, REGOFF(13)(a0)
74	seqz	a0, a1
75	add	a0, a0, a1
76	ret
77END_FUNC longjmp
78