xref: /netbsd-src/lib/libc/arch/mips/gen/_setjmp.S (revision fdecd6a253f999ae92b139670d9e15cc9df4497c)
1/*	$NetBSD: _setjmp.S,v 1.8 1997/07/07 00:13:56 jonathan 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. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the University of
21 *	California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39#include <mips/regnum.h>
40#include <mips/asm.h>
41
42#if defined(LIBC_SCCS) && !defined(lint)
43	ASMSTR("from: @(#)_setjmp.s	8.1 (Berkeley) 6/4/93")
44	ASMSTR("$NetBSD: _setjmp.S,v 1.8 1997/07/07 00:13:56 jonathan Exp $")
45#endif /* LIBC_SCCS and not lint */
46
47#ifdef ABICALLS
48	.abicalls
49#endif
50
51/*
52 * C library -- _setjmp, _longjmp
53 *
54 *	_longjmp(a,v)
55 * will generate a "return(v)" from
56 * the last call to
57 *	_setjmp(a)
58 * by restoring registers from the stack,
59 * The previous signal state is NOT restored.
60 */
61
62	.set	noreorder
63
64LEAF(_setjmp)
65#ifdef ABICALLS
66	#.set noreorder
67	.cpload t9
68	#.set reorder
69#endif
70
71	li	v0, 0xACEDBADE			# sigcontext magic number
72	sw	ra, (2 * 4)(a0)			# sc_pc = return address
73	sw	v0, (3 * 4)(a0)			#   saved in sc_regs[0]
74	sw	s0, ((S0 + 3) * 4)(a0)
75	sw	s1, ((S1 + 3) * 4)(a0)
76	sw	s2, ((S2 + 3) * 4)(a0)
77	sw	s3, ((S3 + 3) * 4)(a0)
78	sw	s4, ((S4 + 3) * 4)(a0)
79	sw	s5, ((S5 + 3) * 4)(a0)
80	sw	s6, ((S6 + 3) * 4)(a0)
81	sw	s7, ((S7 + 3) * 4)(a0)
82	sw	sp, ((SP + 3) * 4)(a0)
83	sw	s8, ((S8 + 3) * 4)(a0)
84	cfc1	v0, $31				# too bad cant check if FP used
85	swc1	$f20, ((20 + 38) * 4)(a0)
86	swc1	$f21, ((21 + 38) * 4)(a0)
87	swc1	$f22, ((22 + 38) * 4)(a0)
88	swc1	$f23, ((23 + 38) * 4)(a0)
89	swc1	$f24, ((24 + 38) * 4)(a0)
90	swc1	$f25, ((25 + 38) * 4)(a0)
91	swc1	$f26, ((26 + 38) * 4)(a0)
92	swc1	$f27, ((27 + 38) * 4)(a0)
93	swc1	$f28, ((28 + 38) * 4)(a0)
94	swc1	$f29, ((29 + 38) * 4)(a0)
95	swc1	$f30, ((30 + 38) * 4)(a0)
96	swc1	$f31, ((31 + 38) * 4)(a0)
97	sw	v0, ((32 + 38) * 4)(a0)
98	j	ra
99	move	v0, zero
100END(_setjmp)
101
102LEAF(_longjmp)
103#ifdef ABICALLS
104	.set    noreorder
105	.cpload t9
106	.set    reorder
107	subu	sp, sp, 32
108	.cprestore 16
109	.set    noreorder
110#endif
111	lw	v0, (3 * 4)(a0)			# get magic number
112	lw	ra, (2 * 4)(a0)
113	bne	v0, 0xACEDBADE, botch		# jump if error
114
115	addu	sp, sp, 32			# don't matter, sanity
116	lw	s0, ((S0 + 3) * 4)(a0)
117	lw	s1, ((S1 + 3) * 4)(a0)
118	lw	s2, ((S2 + 3) * 4)(a0)
119	lw	s3, ((S3 + 3) * 4)(a0)
120	lw	s4, ((S4 + 3) * 4)(a0)
121	lw	s5, ((S5 + 3) * 4)(a0)
122	lw	s6, ((S6 + 3) * 4)(a0)
123	lw	s7, ((S7 + 3) * 4)(a0)
124	lw	v0, ((32 + 38) * 4)(a0)		# get fpu status
125	lw	sp, ((SP + 3) * 4)(a0)
126	lw	s8, ((S8 + 3) * 4)(a0)
127	ctc1	v0, $31
128	lwc1	$f20, ((20 + 38) * 4)(a0)
129	lwc1	$f21, ((21 + 38) * 4)(a0)
130	lwc1	$f22, ((22 + 38) * 4)(a0)
131	lwc1	$f23, ((23 + 38) * 4)(a0)
132	lwc1	$f24, ((24 + 38) * 4)(a0)
133	lwc1	$f25, ((25 + 38) * 4)(a0)
134	lwc1	$f26, ((26 + 38) * 4)(a0)
135	lwc1	$f27, ((27 + 38) * 4)(a0)
136	lwc1	$f28, ((28 + 38) * 4)(a0)
137	lwc1	$f29, ((29 + 38) * 4)(a0)
138	lwc1	$f30, ((30 + 38) * 4)(a0)
139	lwc1	$f31, ((31 + 38) * 4)(a0)
140
141	j	ra
142	move	v0, a1
143botch:
144	jal	_C_LABEL(longjmperror)
145	nop
146	jal	_C_LABEL(abort)
147	nop
148END(_longjmp)
149