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