xref: /netbsd-src/lib/libc/arch/mips/gen/_setjmp.S (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1/*	$NetBSD: _setjmp.S,v 1.20 2005/10/07 17:16:40 tsutsui 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/cdefs.h>
36#include <mips/regnum.h>
37#include <mips/asm.h>
38#include <machine/setjmp.h>
39#include <machine/signal.h>		/* XXX */
40
41#if defined(LIBC_SCCS) && !defined(lint)
42	ASMSTR("from: @(#)_setjmp.s	8.1 (Berkeley) 6/4/93")
43	ASMSTR("$NetBSD: _setjmp.S,v 1.20 2005/10/07 17:16:40 tsutsui Exp $")
44#endif /* LIBC_SCCS and not lint */
45
46#ifdef __ABICALLS__
47	.abicalls
48#endif
49
50/*
51 * C library -- _setjmp, _longjmp
52 *
53 *	_longjmp(a,v)
54 * will generate a "return(v)" from
55 * the last call to
56 *	_setjmp(a)
57 * by restoring registers from the stack,
58 * The previous signal state is NOT restored.
59 */
60
61	.set	noreorder
62
63LEAF(_setjmp)
64#ifdef __ABICALLS__
65	#.set noreorder
66	.cpload t9
67	#.set reorder
68#endif
69
70	REG_PROLOGUE
71	REG_LI	v0, 0xACEDBADE			# sigcontext magic number
72	REG_S	ra, (2 * 4)(a0)			# sc_pc = return address
73	REG_S	v0, (_OFFSETOF_SC_REGS)(a0)	#   saved in sc_regs[0]
74	REG_S	s0, (_R_S0 * SZREG + _OFFSETOF_SC_REGS)(a0)
75	REG_S	s1, (_R_S1 * SZREG + _OFFSETOF_SC_REGS)(a0)
76	REG_S	s2, (_R_S2 * SZREG + _OFFSETOF_SC_REGS)(a0)
77	REG_S	s3, (_R_S3 * SZREG + _OFFSETOF_SC_REGS)(a0)
78	REG_S	s4, (_R_S4 * SZREG + _OFFSETOF_SC_REGS)(a0)
79	REG_S	s5, (_R_S5 * SZREG + _OFFSETOF_SC_REGS)(a0)
80	REG_S	s6, (_R_S6 * SZREG + _OFFSETOF_SC_REGS)(a0)
81	REG_S	s7, (_R_S7 * SZREG + _OFFSETOF_SC_REGS)(a0)
82	REG_S	sp, (_R_SP * SZREG + _OFFSETOF_SC_REGS)(a0)
83	REG_S	s8, (_R_S8 * SZREG + _OFFSETOF_SC_REGS)(a0)
84	cfc1	v0, $31				# too bad cant check if FP used
85	swc1	$f20, (20 * 4 + _OFFSETOF_SC_FPREGS)(a0)
86	swc1	$f21, (21 * 4 + _OFFSETOF_SC_FPREGS)(a0)
87	swc1	$f22, (22 * 4 + _OFFSETOF_SC_FPREGS)(a0)
88	swc1	$f23, (23 * 4 + _OFFSETOF_SC_FPREGS)(a0)
89	swc1	$f24, (24 * 4 + _OFFSETOF_SC_FPREGS)(a0)
90	swc1	$f25, (25 * 4 + _OFFSETOF_SC_FPREGS)(a0)
91	swc1	$f26, (26 * 4 + _OFFSETOF_SC_FPREGS)(a0)
92	swc1	$f27, (27 * 4 + _OFFSETOF_SC_FPREGS)(a0)
93	swc1	$f28, (28 * 4 + _OFFSETOF_SC_FPREGS)(a0)
94	swc1	$f29, (29 * 4 + _OFFSETOF_SC_FPREGS)(a0)
95	swc1	$f30, (30 * 4 + _OFFSETOF_SC_FPREGS)(a0)
96	swc1	$f31, (31 * 4 + _OFFSETOF_SC_FPREGS)(a0)
97	sw	v0, (32 * 4 + _OFFSETOF_SC_FPREGS)(a0)
98	REG_EPILOGUE
99	j	ra
100	move	v0, zero
101END(_setjmp)
102
103LEAF(_longjmp)
104#ifdef __ABICALLS__
105	.set    noreorder
106	.cpload t9
107	.set    reorder
108	subu	sp, sp, 32
109	.cprestore 16
110	.set    noreorder
111#endif
112	REG_PROLOGUE
113	REG_L	v0, (_OFFSETOF_SC_REGS)(a0)	# get magic number
114	REG_L	ra, (2 * 4)(a0)
115	REG_LI	t0, 0xACEDBADE
116	bne	v0, t0, botch		# jump if error
117	addu	sp, sp, 32			# does not matter, sanity
118	REG_L	s0, (_R_S0 * SZREG + _OFFSETOF_SC_REGS)(a0)
119	REG_L	s1, (_R_S1 * SZREG + _OFFSETOF_SC_REGS)(a0)
120	REG_L	s2, (_R_S2 * SZREG + _OFFSETOF_SC_REGS)(a0)
121	REG_L	s3, (_R_S3 * SZREG + _OFFSETOF_SC_REGS)(a0)
122	REG_L	s4, (_R_S4 * SZREG + _OFFSETOF_SC_REGS)(a0)
123	REG_L	s5, (_R_S5 * SZREG + _OFFSETOF_SC_REGS)(a0)
124	REG_L	s6, (_R_S6 * SZREG + _OFFSETOF_SC_REGS)(a0)
125	REG_L	s7, (_R_S7 * SZREG + _OFFSETOF_SC_REGS)(a0)
126	lw	v0, (32 * 4 + _OFFSETOF_SC_FPREGS)(a0)	# get fpu status
127	REG_L	sp, (_R_SP * SZREG + _OFFSETOF_SC_REGS)(a0)
128	REG_L	s8, (_R_S8 * SZREG + _OFFSETOF_SC_REGS)(a0)
129	ctc1	v0, $31
130	lwc1	$f20, (20 * 4 + _OFFSETOF_SC_FPREGS)(a0)
131	lwc1	$f21, (21 * 4 + _OFFSETOF_SC_FPREGS)(a0)
132	lwc1	$f22, (22 * 4 + _OFFSETOF_SC_FPREGS)(a0)
133	lwc1	$f23, (23 * 4 + _OFFSETOF_SC_FPREGS)(a0)
134	lwc1	$f24, (24 * 4 + _OFFSETOF_SC_FPREGS)(a0)
135	lwc1	$f25, (25 * 4 + _OFFSETOF_SC_FPREGS)(a0)
136	lwc1	$f26, (26 * 4 + _OFFSETOF_SC_FPREGS)(a0)
137	lwc1	$f27, (27 * 4 + _OFFSETOF_SC_FPREGS)(a0)
138	lwc1	$f28, (28 * 4 + _OFFSETOF_SC_FPREGS)(a0)
139	lwc1	$f29, (29 * 4 + _OFFSETOF_SC_FPREGS)(a0)
140	lwc1	$f30, (30 * 4 + _OFFSETOF_SC_FPREGS)(a0)
141	lwc1	$f31, (31 * 4 + _OFFSETOF_SC_FPREGS)(a0)
142
143	j	ra
144	move	v0, a1
145	REG_EPILOGUE
146botch:
147	jal	_C_LABEL(longjmperror)
148	nop
149	jal	_C_LABEL(abort)
150	nop
151END(_longjmp)
152