xref: /freebsd/sys/contrib/openzfs/module/lua/setjmp/setjmp_rv64g.S (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
1*eda14cbcSMatt Macy/*-
2*eda14cbcSMatt Macy * Copyright (c) 2015-2016 Ruslan Bukin <br@bsdpad.com>
3*eda14cbcSMatt Macy * All rights reserved.
4*eda14cbcSMatt Macy *
5*eda14cbcSMatt Macy * Portions of this software were developed by SRI International and the
6*eda14cbcSMatt Macy * University of Cambridge Computer Laboratory under DARPA/AFRL contract
7*eda14cbcSMatt Macy * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
8*eda14cbcSMatt Macy *
9*eda14cbcSMatt Macy * Portions of this software were developed by the University of Cambridge
10*eda14cbcSMatt Macy * Computer Laboratory as part of the CTSRD Project, with support from the
11*eda14cbcSMatt Macy * UK Higher Education Innovation Fund (HEIF).
12*eda14cbcSMatt Macy *
13*eda14cbcSMatt Macy * Redistribution and use in source and binary forms, with or without
14*eda14cbcSMatt Macy * modification, are permitted provided that the following conditions
15*eda14cbcSMatt Macy * are met:
16*eda14cbcSMatt Macy * 1. Redistributions of source code must retain the above copyright
17*eda14cbcSMatt Macy *    notice, this list of conditions and the following disclaimer.
18*eda14cbcSMatt Macy * 2. Redistributions in binary form must reproduce the above copyright
19*eda14cbcSMatt Macy *    notice, this list of conditions and the following disclaimer in the
20*eda14cbcSMatt Macy *    documentation and/or other materials provided with the distribution.
21*eda14cbcSMatt Macy *
22*eda14cbcSMatt Macy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23*eda14cbcSMatt Macy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*eda14cbcSMatt Macy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*eda14cbcSMatt Macy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26*eda14cbcSMatt Macy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*eda14cbcSMatt Macy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*eda14cbcSMatt Macy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*eda14cbcSMatt Macy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*eda14cbcSMatt Macy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*eda14cbcSMatt Macy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*eda14cbcSMatt Macy * SUCH DAMAGE.
33*eda14cbcSMatt Macy */
34*eda14cbcSMatt Macy
35*eda14cbcSMatt Macy#define ENTRY(sym)                                              \
36*eda14cbcSMatt Macy        .text; .globl sym; .type sym,@function; sym:
37*eda14cbcSMatt Macy#define END(sym) .size sym, . - sym
38*eda14cbcSMatt Macy
39*eda14cbcSMatt Macy
40*eda14cbcSMatt MacyENTRY(setjmp)
41*eda14cbcSMatt Macy	/* Store the stack pointer */
42*eda14cbcSMatt Macy	sd	sp, (0 * 8)(a0)
43*eda14cbcSMatt Macy	addi	a0, a0, (1 * 8)
44*eda14cbcSMatt Macy
45*eda14cbcSMatt Macy	/* Store the general purpose registers and ra */
46*eda14cbcSMatt Macy	sd	s0, (0 * 8)(a0)
47*eda14cbcSMatt Macy	sd	s1, (1 * 8)(a0)
48*eda14cbcSMatt Macy	sd	s2, (2 * 8)(a0)
49*eda14cbcSMatt Macy	sd	s3, (3 * 8)(a0)
50*eda14cbcSMatt Macy	sd	s4, (4 * 8)(a0)
51*eda14cbcSMatt Macy	sd	s5, (5 * 8)(a0)
52*eda14cbcSMatt Macy	sd	s6, (6 * 8)(a0)
53*eda14cbcSMatt Macy	sd	s7, (7 * 8)(a0)
54*eda14cbcSMatt Macy	sd	s8, (8 * 8)(a0)
55*eda14cbcSMatt Macy	sd	s9, (9 * 8)(a0)
56*eda14cbcSMatt Macy	sd	s10, (10 * 8)(a0)
57*eda14cbcSMatt Macy	sd	s11, (11 * 8)(a0)
58*eda14cbcSMatt Macy	sd	ra, (12 * 8)(a0)
59*eda14cbcSMatt Macy	addi	a0, a0, (13 * 8)
60*eda14cbcSMatt Macy
61*eda14cbcSMatt Macy	/* Return value */
62*eda14cbcSMatt Macy	li	a0, 0
63*eda14cbcSMatt Macy	ret
64*eda14cbcSMatt MacyEND(setjmp)
65*eda14cbcSMatt Macy
66*eda14cbcSMatt MacyENTRY(longjmp)
67*eda14cbcSMatt Macy	/* Restore the stack pointer */
68*eda14cbcSMatt Macy	ld	t0, 0(a0)
69*eda14cbcSMatt Macy	mv	sp, t0
70*eda14cbcSMatt Macy	addi	a0, a0, (1 * 8)
71*eda14cbcSMatt Macy
72*eda14cbcSMatt Macy	/* Restore the general purpose registers and ra */
73*eda14cbcSMatt Macy	ld	s0, (0 * 8)(a0)
74*eda14cbcSMatt Macy	ld	s1, (1 * 8)(a0)
75*eda14cbcSMatt Macy	ld	s2, (2 * 8)(a0)
76*eda14cbcSMatt Macy	ld	s3, (3 * 8)(a0)
77*eda14cbcSMatt Macy	ld	s4, (4 * 8)(a0)
78*eda14cbcSMatt Macy	ld	s5, (5 * 8)(a0)
79*eda14cbcSMatt Macy	ld	s6, (6 * 8)(a0)
80*eda14cbcSMatt Macy	ld	s7, (7 * 8)(a0)
81*eda14cbcSMatt Macy	ld	s8, (8 * 8)(a0)
82*eda14cbcSMatt Macy	ld	s9, (9 * 8)(a0)
83*eda14cbcSMatt Macy	ld	s10, (10 * 8)(a0)
84*eda14cbcSMatt Macy	ld	s11, (11 * 8)(a0)
85*eda14cbcSMatt Macy	ld	ra, (12 * 8)(a0)
86*eda14cbcSMatt Macy	addi	a0, a0, (13 * 8)
87*eda14cbcSMatt Macy
88*eda14cbcSMatt Macy	/* Load the return value */
89*eda14cbcSMatt Macy	mv	a0, a1
90*eda14cbcSMatt Macy	ret
91*eda14cbcSMatt MacyEND(longjmp)
92