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