_setjmp.S revision 250020
1263409Smarcel/*-
2263409Smarcel * Copyright (c) 1991, 1993
3263409Smarcel *	The Regents of the University of California.  All rights reserved.
4263409Smarcel *
5263409Smarcel * This code is derived from software contributed to Berkeley by
6263409Smarcel * Ralph Campbell.
7263409Smarcel *
8263409Smarcel * Redistribution and use in source and binary forms, with or without
9263409Smarcel * modification, are permitted provided that the following conditions
10263409Smarcel * are met:
11263409Smarcel * 1. Redistributions of source code must retain the above copyright
12263409Smarcel *    notice, this list of conditions and the following disclaimer.
13263409Smarcel * 2. Redistributions in binary form must reproduce the above copyright
14263409Smarcel *    notice, this list of conditions and the following disclaimer in the
15263409Smarcel *    documentation and/or other materials provided with the distribution.
16263409Smarcel * 3. All advertising materials mentioning features or use of this software
17263409Smarcel *    must display the following acknowledgement:
18263409Smarcel *	This product includes software developed by the University of
19263409Smarcel *	California, Berkeley and its contributors.
20263409Smarcel * 4. Neither the name of the University nor the names of its contributors
21263409Smarcel *    may be used to endorse or promote products derived from this software
22263409Smarcel *    without specific prior written permission.
23263409Smarcel *
24263409Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25263409Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26263409Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27263409Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28263409Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29263409Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30263409Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31263442Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32263674Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33263442Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34263409Smarcel * SUCH DAMAGE.
35263674Smarcel *
36263674Smarcel * $FreeBSD: head/lib/libstand/mips/_setjmp.S 250020 2013-04-28 14:40:29Z rwatson $
37263409Smarcel */
38263409Smarcel
39263409Smarcel#include <machine/regnum.h>
40263409Smarcel#include <machine/asm.h>
41263409Smarcel
42263674Smarcel#if 0
43263674Smarcel#if defined(LIBC_SCCS)
44263487Smarcel	.text
45263409Smarcel	.asciz "$OpenBSD: _setjmp.S,v 1.6 1996/09/23 21:27:53 imp Exp $"
46263409Smarcel#endif /* LIBC_SCCS */
47263440Smarcel#endif
48263653Smarcel
49263409Smarcel/*
50263440Smarcel * C library -- _setjmp, _longjmp
51263409Smarcel *
52263440Smarcel *	_longjmp(a,v)
53263440Smarcel * will generate a "return(v)" from
54263409Smarcel * the last call to
55263409Smarcel *	_setjmp(a)
56263674Smarcel * by restoring registers from the stack,
57263674Smarcel * The previous signal state is NOT restored.
58263674Smarcel */
59263674Smarcel
60263674SmarcelLEAF(_setjmp)
61263674Smarcel	.set	noreorder
62263674Smarcel	REG_LI	v0, 0xACEDBADE			# sigcontext magic number
63263674Smarcel	REG_S	ra, (2 * SZREG)(a0)		# sc_pc = return address
64263674Smarcel	REG_S	v0, (3 * SZREG)(a0)		#   saved in sc_regs[0]
65263442Smarcel	REG_S	s0, ((S0 + 3) * SZREG)(a0)
66263674Smarcel	REG_S	s1, ((S1 + 3) * SZREG)(a0)
67263442Smarcel	REG_S	s2, ((S2 + 3) * SZREG)(a0)
68263674Smarcel	REG_S	s3, ((S3 + 3) * SZREG)(a0)
69263674Smarcel	REG_S	s4, ((S4 + 3) * SZREG)(a0)
70263674Smarcel	REG_S	s5, ((S5 + 3) * SZREG)(a0)
71263843Smarcel	REG_S	s6, ((S6 + 3) * SZREG)(a0)
72263674Smarcel	REG_S	s7, ((S7 + 3) * SZREG)(a0)
73263674Smarcel	REG_S	sp, ((SP + 3) * SZREG)(a0)
74263674Smarcel	REG_S	s8, ((S8 + 3) * SZREG)(a0)
75263674Smarcel	j	ra
76263674Smarcel	move	v0, zero
77263674SmarcelEND(_setjmp)
78263674Smarcel
79263674SmarcelLEAF(_longjmp)
80263674Smarcel#ifdef ABICALLS
81263674Smarcel	subu	sp, sp, 32
82263843Smarcel	.cprestore 16
83263674Smarcel#endif
84263843Smarcel	.set    noreorder
85263674Smarcel	REG_L	v0, (3 * SZREG)(a0)		# get magic number
86263674Smarcel	REG_L	ra, (2 * SZREG)(a0)
87263674Smarcel	bne	v0, 0xACEDBADE, botch		# jump if error
88263843Smarcel
89263674Smarcel	addu	sp, sp, 32			# does not matter, sanity
90263674Smarcel	REG_L	s0, ((S0 + 3) * SZREG)(a0)
91263674Smarcel	REG_L	s1, ((S1 + 3) * SZREG)(a0)
92263674Smarcel	REG_L	s2, ((S2 + 3) * SZREG)(a0)
93263674Smarcel	REG_L	s3, ((S3 + 3) * SZREG)(a0)
94263674Smarcel	REG_L	s4, ((S4 + 3) * SZREG)(a0)
95263843Smarcel	REG_L	s5, ((S5 + 3) * SZREG)(a0)
96263674Smarcel	REG_L	s6, ((S6 + 3) * SZREG)(a0)
97263674Smarcel	REG_L	s7, ((S7 + 3) * SZREG)(a0)
98263674Smarcel	REG_L	sp, ((SP + 3) * SZREG)(a0)
99263843Smarcel	REG_L	s8, ((S8 + 3) * SZREG)(a0)
100263843Smarcel
101263674Smarcel	j	ra
102263674Smarcel	move	v0, a1
103263674Smarcelbotch:
104263674Smarcel	jal	_C_LABEL(longjmperror)
105263674Smarcel	nop
106263674Smarcel	jal	_C_LABEL(abort)
107263674Smarcel	nop
108263674SmarcelEND(_longjmp)
109263674Smarcel