xref: /minix3/lib/libc/arch/riscv/gen/_setjmp.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: _setjmp.S,v 1.2 2015/03/27 06:44:28 matt Exp $	*/
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc/*-
4*0a6a1f1dSLionel Sambuc * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc * All rights reserved.
6*0a6a1f1dSLionel Sambuc *
7*0a6a1f1dSLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
8*0a6a1f1dSLionel Sambuc * by Matt Thomas of 3am Software Foundry.
9*0a6a1f1dSLionel Sambuc *
10*0a6a1f1dSLionel Sambuc * Redistribution and use in source and binary forms, with or without
11*0a6a1f1dSLionel Sambuc * modification, are permitted provided that the following conditions
12*0a6a1f1dSLionel Sambuc * are met:
13*0a6a1f1dSLionel Sambuc * 1. Redistributions of source code must retain the above copyright
14*0a6a1f1dSLionel Sambuc *    notice, this list of conditions and the following disclaimer.
15*0a6a1f1dSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16*0a6a1f1dSLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
17*0a6a1f1dSLionel Sambuc *    documentation and/or other materials provided with the distribution.
18*0a6a1f1dSLionel Sambuc *
19*0a6a1f1dSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*0a6a1f1dSLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*0a6a1f1dSLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*0a6a1f1dSLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*0a6a1f1dSLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*0a6a1f1dSLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*0a6a1f1dSLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*0a6a1f1dSLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*0a6a1f1dSLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*0a6a1f1dSLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*0a6a1f1dSLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
30*0a6a1f1dSLionel Sambuc */
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc#include <machine/asm.h>
33*0a6a1f1dSLionel Sambuc#include "assym.h"
34*0a6a1f1dSLionel Sambuc
35*0a6a1f1dSLionel Sambuc#if defined(LIBC_SCCS)
36*0a6a1f1dSLionel Sambuc__RCSID("$NetBSD: _setjmp.S,v 1.2 2015/03/27 06:44:28 matt Exp $")
37*0a6a1f1dSLionel Sambuc#endif
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel Sambuc/*
40*0a6a1f1dSLionel Sambuc * C library -- _setjmp, _longjmp
41*0a6a1f1dSLionel Sambuc *
42*0a6a1f1dSLionel Sambuc *	_longjmp(a,v)
43*0a6a1f1dSLionel Sambuc * will generate a "return(v?v:1)" from the last call to
44*0a6a1f1dSLionel Sambuc *	_setjmp(a)
45*0a6a1f1dSLionel Sambuc * by restoring registers from the stack.
46*0a6a1f1dSLionel Sambuc * The previous signal state is NOT restored.
47*0a6a1f1dSLionel Sambuc */
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel SambucENTRY(_setjmp)
50*0a6a1f1dSLionel Sambuc	REG_S	zero, JB_MAGIC(a0)	/* indicate no sigmask */
51*0a6a1f1dSLionel Sambuc	REG_S	ra, JB_RA(a0)		/* save return address */
52*0a6a1f1dSLionel Sambuc	REG_S	sp, JB_SP(a0)		/* save stack pointer */
53*0a6a1f1dSLionel Sambuc	REG_S	gp, JB_GP(a0)		/* save global pointer */
54*0a6a1f1dSLionel Sambuc	REG_S	tp, JB_TP(a0)		/* save thread pointer */
55*0a6a1f1dSLionel Sambuc	REG_S	s0, JB_S0(a0)		/* save callee saved register */
56*0a6a1f1dSLionel Sambuc	REG_S	s1, JB_S1(a0)		/* save callee saved register */
57*0a6a1f1dSLionel Sambuc	REG_S	s2, JB_S2(a0)		/* save callee saved register */
58*0a6a1f1dSLionel Sambuc	REG_S	s3, JB_S3(a0)		/* save callee saved register */
59*0a6a1f1dSLionel Sambuc	REG_S	s4, JB_S4(a0)		/* save callee saved register */
60*0a6a1f1dSLionel Sambuc	REG_S	s5, JB_S5(a0)		/* save callee saved register */
61*0a6a1f1dSLionel Sambuc	REG_S	s6, JB_S6(a0)		/* save callee saved register */
62*0a6a1f1dSLionel Sambuc	REG_S	s7, JB_S7(a0)		/* save callee saved register */
63*0a6a1f1dSLionel Sambuc	REG_S	s8, JB_S8(a0)		/* save callee saved register */
64*0a6a1f1dSLionel Sambuc	REG_S	s9, JB_S9(a0)		/* save callee saved register */
65*0a6a1f1dSLionel Sambuc	REG_S	s10, JB_S10(a0)		/* save callee saved register */
66*0a6a1f1dSLionel Sambuc	REG_S	s11, JB_S11(a0)		/* save callee saved register */
67*0a6a1f1dSLionel Sambuc#ifndef _SOFT_FLOAT
68*0a6a1f1dSLionel Sambuc	frcsr	t2			/* get FSCR */
69*0a6a1f1dSLionel Sambuc	REG_S	t2, JB_FCSR(a0)		/* save it */
70*0a6a1f1dSLionel Sambuc	fsd	fs0, JB_FS0(a0)		/* save callee saved register */
71*0a6a1f1dSLionel Sambuc	fsd	fs1, JB_FS1(a0)		/* save callee saved register */
72*0a6a1f1dSLionel Sambuc	fsd	fs2, JB_FS2(a0)		/* save callee saved register */
73*0a6a1f1dSLionel Sambuc	fsd	fs3, JB_FS3(a0)		/* save callee saved register */
74*0a6a1f1dSLionel Sambuc	fsd	fs4, JB_FS4(a0)		/* save callee saved register */
75*0a6a1f1dSLionel Sambuc	fsd	fs5, JB_FS5(a0)		/* save callee saved register */
76*0a6a1f1dSLionel Sambuc	fsd	fs6, JB_FS6(a0)		/* save callee saved register */
77*0a6a1f1dSLionel Sambuc	fsd	fs7, JB_FS7(a0)		/* save callee saved register */
78*0a6a1f1dSLionel Sambuc	fsd	fs8, JB_FS8(a0)		/* save callee saved register */
79*0a6a1f1dSLionel Sambuc	fsd	fs9, JB_FS9(a0)		/* save callee saved register */
80*0a6a1f1dSLionel Sambuc	fsd	fs10, JB_FS10(a0)	/* save callee saved register */
81*0a6a1f1dSLionel Sambuc	fsd	fs11, JB_FS11(a0)	/* save callee saved register */
82*0a6a1f1dSLionel Sambuc#endif
83*0a6a1f1dSLionel Sambuc	li	a0, 0			/* indicate success */
84*0a6a1f1dSLionel Sambuc	ret				/* return */
85*0a6a1f1dSLionel SambucEND(_setjmp)
86*0a6a1f1dSLionel Sambuc
87*0a6a1f1dSLionel SambucENTRY(_longjmp)
88*0a6a1f1dSLionel Sambuc	REG_L	ra, JB_RA(a0)		/* save return address */
89*0a6a1f1dSLionel Sambuc	REG_L	sp, JB_SP(a0)		/* save stack pointer */
90*0a6a1f1dSLionel Sambuc	REG_L	gp, JB_GP(a0)		/* save global pointer */
91*0a6a1f1dSLionel Sambuc	#REG_L	tp, JB_TP(a0)		/* save thread pointer */
92*0a6a1f1dSLionel Sambuc	REG_L	s0, JB_S0(a0)		/* save callee saved register */
93*0a6a1f1dSLionel Sambuc	REG_L	s1, JB_S1(a0)		/* save callee saved register */
94*0a6a1f1dSLionel Sambuc	REG_L	s2, JB_S2(a0)		/* save callee saved register */
95*0a6a1f1dSLionel Sambuc	REG_L	s3, JB_S3(a0)		/* save callee saved register */
96*0a6a1f1dSLionel Sambuc	REG_L	s4, JB_S4(a0)		/* save callee saved register */
97*0a6a1f1dSLionel Sambuc	REG_L	s5, JB_S5(a0)		/* save callee saved register */
98*0a6a1f1dSLionel Sambuc	REG_L	s6, JB_S6(a0)		/* save callee saved register */
99*0a6a1f1dSLionel Sambuc	REG_L	s7, JB_S7(a0)		/* save callee saved register */
100*0a6a1f1dSLionel Sambuc	REG_L	s8, JB_S8(a0)		/* save callee saved register */
101*0a6a1f1dSLionel Sambuc	REG_L	s9, JB_S9(a0)		/* save callee saved register */
102*0a6a1f1dSLionel Sambuc	REG_L	s10, JB_S10(a0)		/* save callee saved register */
103*0a6a1f1dSLionel Sambuc	REG_L	s11, JB_S11(a0)		/* save callee saved register */
104*0a6a1f1dSLionel Sambuc#ifndef _SOFT_FLOAT
105*0a6a1f1dSLionel Sambuc	REG_L	t2, JB_FCSR(a0)		/* get it */
106*0a6a1f1dSLionel Sambuc	fscsr	t2			/* restore FSCR */
107*0a6a1f1dSLionel Sambuc	fld	fs0, JB_FS0(a0)		/* restore callee saved register */
108*0a6a1f1dSLionel Sambuc	fld	fs1, JB_FS1(a0)		/* restore callee saved register */
109*0a6a1f1dSLionel Sambuc	fld	fs2, JB_FS2(a0)		/* restore callee saved register */
110*0a6a1f1dSLionel Sambuc	fld	fs3, JB_FS3(a0)		/* restore callee saved register */
111*0a6a1f1dSLionel Sambuc	fld	fs4, JB_FS4(a0)		/* restore callee saved register */
112*0a6a1f1dSLionel Sambuc	fld	fs5, JB_FS5(a0)		/* restore callee saved register */
113*0a6a1f1dSLionel Sambuc	fld	fs6, JB_FS6(a0)		/* restore callee saved register */
114*0a6a1f1dSLionel Sambuc	fld	fs7, JB_FS7(a0)		/* restore callee saved register */
115*0a6a1f1dSLionel Sambuc	fld	fs8, JB_FS8(a0)		/* restore callee saved register */
116*0a6a1f1dSLionel Sambuc	fld	fs9, JB_FS9(a0)		/* restore callee saved register */
117*0a6a1f1dSLionel Sambuc	fld	fs10, JB_FS10(a0)	/* restore callee saved register */
118*0a6a1f1dSLionel Sambuc	fld	fs11, JB_FS11(a0)	/* restore callee saved register */
119*0a6a1f1dSLionel Sambuc#endif
120*0a6a1f1dSLionel Sambuc	li	a0, 1			/* default return value */
121*0a6a1f1dSLionel Sambuc	beqz	a1, 1f			/* test return value */
122*0a6a1f1dSLionel Sambuc	move	a0, a1			/* use it if not 0 */
123*0a6a1f1dSLionel Sambuc1:	ret
124*0a6a1f1dSLionel SambucEND(_longjmp)
125