1/*-
2 * Copyright 2022 Han Gao <gaohan@uniontech.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#if __loongarch_lp64
28
29#define ENTRY(symbol) \
30  .text; \
31  .globl symbol; \
32  .align 3; \
33  .type symbol, @function; \
34  symbol:
35
36#define END(function) \
37  .size function, .- function;
38
39ENTRY(setjmp)
40	st.d	$ra, $a0, 0*8
41	st.d	$sp, $a0, 1*8
42	st.d	$r21, $a0, 2*8
43	st.d	$fp, $a0, 3*8
44	st.d	$s0, $a0, 4*8
45	st.d	$s1, $a0, 5*8
46	st.d	$s2, $a0, 6*8
47	st.d	$s3, $a0, 7*8
48	st.d	$s4, $a0, 8*8
49	st.d	$s5, $a0, 9*8
50	st.d	$s6, $a0, 10*8
51	st.d	$s7, $a0, 11*8
52	st.d	$s8, $a0, 12*8
53
54	li.w	$a0, 0
55	jr	$ra
56END(setjmp)
57
58ENTRY(longjmp)
59	ld.d	$ra, $a0, 0*8
60	ld.d	$sp, $a0, 1*8
61	ld.d	$r21, $a0, 2*8
62	ld.d	$fp, $a0, 3*8
63	ld.d	$s0, $a0, 4*8
64	ld.d	$s1, $a0, 5*8
65	ld.d	$s2, $a0, 6*8
66	ld.d	$s3, $a0, 7*8
67	ld.d	$s4, $a0, 8*8
68	ld.d	$s5, $a0, 9*8
69	ld.d	$s6, $a0, 10*8
70	ld.d	$s7, $a0, 11*8
71	ld.d	$s8, $a0, 12*8
72
73	sltui	$a0, $a1, 1
74	add.d	$a0, $a0, $a1	// a0 = (a1 == 0) ? 1 : a1
75	jr	$ra
76END(longjmp)
77
78#ifdef __ELF__
79.section .note.GNU-stack,"",%progbits
80#endif
81
82#endif
83