xref: /freebsd-13-stable/lib/libc/mips/gen/_setjmp.S (revision 3d497e17ebd33fe0f58d773e35ab994d750258d6)
1/*	$NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $	*/
2
3/*-
4 * Copyright (c) 1991, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <machine/asm.h>
36#include "SYS.h"
37
38#if defined(LIBC_SCCS) && !defined(lint)
39#if 0
40	RCSID("from: @(#)_setjmp.s	8.1 (Berkeley) 6/4/93")
41#else
42	RCSID("$NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $")
43#endif
44#endif /* LIBC_SCCS and not lint */
45
46/*
47 * C library -- _setjmp, _longjmp
48 *
49 *	_longjmp(a,v)
50 * will generate a "return(v)" from
51 * the last call to
52 *	_setjmp(a)
53 * by restoring registers from the stack,
54 * The previous signal state is NOT restored.
55 */
56
57	.set	noreorder
58
59LEAF(_setjmp)
60	REG_PROLOGUE
61	REG_LI	v0, _JB_MAGIC__SETJMP		# sigcontext magic number
62	REG_S	v0, (_JB_MAGIC  * SZREG)(a0)
63	REG_S	ra, (_JB_REG_RA * SZREG)(a0)
64	/*
65	 * From "MIPSpro N32 ABI Handbook", Table 2-1:
66	 * Registers s0..s7 are callee-saved.
67	 * The sp register is callee-saved.
68	 * The fp (or s8) register is callee-saved.
69	 * The gp register is callee-saved (for n32/n64).
70	 */
71	REG_S	s0, (_JB_REG_S0 * SZREG)(a0)
72	REG_S	s1, (_JB_REG_S1 * SZREG)(a0)
73	REG_S	s2, (_JB_REG_S2 * SZREG)(a0)
74	REG_S	s3, (_JB_REG_S3 * SZREG)(a0)
75	REG_S	s4, (_JB_REG_S4 * SZREG)(a0)
76	REG_S	s5, (_JB_REG_S5 * SZREG)(a0)
77	REG_S	s6, (_JB_REG_S6 * SZREG)(a0)
78	REG_S	s7, (_JB_REG_S7 * SZREG)(a0)
79	REG_S	sp, (_JB_REG_SP * SZREG)(a0)
80	REG_S	s8, (_JB_REG_S8 * SZREG)(a0)
81#if defined(__mips_n32) || defined(__mips_n64)
82	REG_S	gp, (_JB_REG_GP * SZREG)(a0)	# newabi gp is callee-saved
83#endif
84	/*
85	 * From "MIPSpro N32 ABI Handbook", Table 2-1:
86	 * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
87	 * In N64, FP registers F24 .. F31 are callee-saved.
88	 * In O32, FP registers F20 .. F23 are callee-saved.
89	 */
90#ifndef __mips_soft_float
91	cfc1	v0, $31				# too bad can't check if FP used
92#if defined(__mips_n64) || defined(__mips_n32)
93	FP_S	$f30, (_JB_FPREG_F30 * SZREG)(a0)
94	FP_S	$f28, (_JB_FPREG_F28 * SZREG)(a0)
95	FP_S	$f26, (_JB_FPREG_F26 * SZREG)(a0)
96	FP_S	$f24, (_JB_FPREG_F24 * SZREG)(a0)
97#endif
98#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
99	FP_S	$f22, (_JB_FPREG_F22 * SZREG)(a0)
100	FP_S	$f20, (_JB_FPREG_F20 * SZREG)(a0)
101#endif
102#if defined(__mips_o32) || defined(__mips_o64)
103	FP_S	$f21, (_JB_FPREG_F21 * SZREG)(a0)
104	FP_S	$f23, (_JB_FPREG_F23 * SZREG)(a0)
105#endif
106#if defined(__mips_n64)
107	FP_S	$f25, (_JB_FPREG_F25 * SZREG)(a0)
108	FP_S	$f27, (_JB_FPREG_F27 * SZREG)(a0)
109	FP_S	$f29, (_JB_FPREG_F29 * SZREG)(a0)
110	FP_S	$f31, (_JB_FPREG_F31 * SZREG)(a0)
111#endif
112	INT_S	v0, (_JB_FPREG_FCSR * SZREG)(a0)
113#endif /* ! __mips_soft_float */
114	REG_EPILOGUE
115
116	j	ra
117	move	v0, zero
118END(_setjmp)
119
120LEAF(_longjmp)
121	PIC_PROLOGUE(_longjmp)
122	PTR_SUBU	sp, sp, CALLFRAME_SIZ
123	SAVE_GP(CALLFRAME_GP)
124
125	REG_PROLOGUE
126	REG_L		v0, (_JB_MAGIC  * SZREG)(a0)	# get magic number
127	REG_L		ra, (_JB_REG_RA * SZREG)(a0)
128	REG_LI		t0, _JB_MAGIC__SETJMP
129	bne		v0, t0, botch		# jump if error
130	PTR_ADDU	sp, sp, CALLFRAME_SIZ	# does not matter, sanity
131	/*
132	 * From "MIPSpro N32 ABI Handbook", Table 2-1:
133	 * Registers s0..s7 are callee-saved.
134	 * The sp register is callee-saved.
135	 * The fp (or s8) register is callee-saved.
136	 * The gp register is callee-saved (for n32/n64).
137	 */
138	REG_L		s0, (_JB_REG_S0 * SZREG)(a0)
139	REG_L		s1, (_JB_REG_S1 * SZREG)(a0)
140	REG_L		s2, (_JB_REG_S2 * SZREG)(a0)
141	REG_L		s3, (_JB_REG_S3 * SZREG)(a0)
142	REG_L		s4, (_JB_REG_S4 * SZREG)(a0)
143	REG_L		s5, (_JB_REG_S5 * SZREG)(a0)
144	REG_L		s6, (_JB_REG_S6 * SZREG)(a0)
145	REG_L		s7, (_JB_REG_S7 * SZREG)(a0)
146	REG_L		sp, (_JB_REG_SP * SZREG)(a0)
147	REG_L		s8, (_JB_REG_S8 * SZREG)(a0)
148#if defined(__mips_n32) || defined(__mips_n64)
149	REG_L		gp, (_JB_REG_GP * SZREG)(a0)
150#endif
151#ifndef __mips_soft_float
152	# get fpu status
153	INT_L		v0, (_JB_FPREG_FCSR * SZREG)(a0)
154	ctc1		v0, $31
155	/*
156	 * From "MIPSpro N32 ABI Handbook", Table 2-1:
157	 * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
158	 * In N64, FP registers F24 .. F31 are callee-saved.
159	 * In O32, FP registers F20 .. F23 are callee-saved.
160	 */
161#if defined(__mips_n64) || defined(__mips_n32)
162	FP_L	$f30, (_JB_FPREG_F30 * SZREG)(a0)
163	FP_L	$f28, (_JB_FPREG_F28 * SZREG)(a0)
164	FP_L	$f26, (_JB_FPREG_F26 * SZREG)(a0)
165	FP_L	$f24, (_JB_FPREG_F24 * SZREG)(a0)
166#endif
167#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
168	FP_L	$f22, (_JB_FPREG_F22 * SZREG)(a0)
169	FP_L	$f20, (_JB_FPREG_F20 * SZREG)(a0)
170#endif
171#if defined(__mips_o32) || defined(__mips_o64)
172	FP_L	$f21, (_JB_FPREG_F21 * SZREG)(a0)
173	FP_L	$f23, (_JB_FPREG_F23 * SZREG)(a0)
174#endif
175#if defined(__mips_n64)
176	FP_L	$f25, (_JB_FPREG_F25 * SZREG)(a0)
177	FP_L	$f27, (_JB_FPREG_F27 * SZREG)(a0)
178	FP_L	$f29, (_JB_FPREG_F29 * SZREG)(a0)
179	FP_L	$f31, (_JB_FPREG_F31 * SZREG)(a0)
180#endif
181#endif	/* ! __mips_soft_float */
182
183	REG_EPILOGUE
184	bne	a1, zero, 1f
185	move	v0, a1			# get return value in 1st arg
186	REG_LI	v0, 1			# return 1 if arg is 0
1871:
188	j	ra
189	nop
190
191botch:
192	/*
193	 * We know we aren't returning so we don't care about restoring
194	 * our caller's GP.
195	 */
196	PTR_LA	t9, _C_LABEL(longjmperror)
197	jalr	t9
198	nop
199
200	PIC_TAILCALL(abort)
201END(_longjmp)
202