]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/mips/gen/_setjmp.S
MFV 354917, 354918, 354919
[FreeBSD/FreeBSD.git] / lib / libc / mips / gen / _setjmp.S
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 __FBSDID("$FreeBSD$");
37
38 #include "SYS.h"
39
40 #if defined(LIBC_SCCS) && !defined(lint)
41 #if 0
42         RCSID("from: @(#)_setjmp.s      8.1 (Berkeley) 6/4/93")
43 #else
44         RCSID("$NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $")
45 #endif
46 #endif /* LIBC_SCCS and not lint */
47
48 /*
49  * C library -- _setjmp, _longjmp
50  *
51  *      _longjmp(a,v)
52  * will generate a "return(v)" from
53  * the last call to
54  *      _setjmp(a)
55  * by restoring registers from the stack,
56  * The previous signal state is NOT restored.
57  */
58
59         .set    noreorder
60
61 LEAF(_setjmp)
62         REG_PROLOGUE
63         REG_LI  v0, _JB_MAGIC__SETJMP           # sigcontext magic number
64         REG_S   v0, (_JB_MAGIC  * SZREG)(a0)
65         REG_S   ra, (_JB_REG_RA * SZREG)(a0)
66         /*
67          * From "MIPSpro N32 ABI Handbook", Table 2-1:
68          * Registers s0..s7 are callee-saved.
69          * The sp register is callee-saved.
70          * The fp (or s8) register is callee-saved.
71          * The gp register is callee-saved (for n32/n64).
72          */
73         REG_S   s0, (_JB_REG_S0 * SZREG)(a0)
74         REG_S   s1, (_JB_REG_S1 * SZREG)(a0)
75         REG_S   s2, (_JB_REG_S2 * SZREG)(a0)
76         REG_S   s3, (_JB_REG_S3 * SZREG)(a0)
77         REG_S   s4, (_JB_REG_S4 * SZREG)(a0)
78         REG_S   s5, (_JB_REG_S5 * SZREG)(a0)
79         REG_S   s6, (_JB_REG_S6 * SZREG)(a0)
80         REG_S   s7, (_JB_REG_S7 * SZREG)(a0)
81         REG_S   sp, (_JB_REG_SP * SZREG)(a0)
82         REG_S   s8, (_JB_REG_S8 * SZREG)(a0)
83 #if defined(__mips_n32) || defined(__mips_n64)
84         REG_S   gp, (_JB_REG_GP * SZREG)(a0)    # newabi gp is callee-saved
85 #endif
86         /*
87          * From "MIPSpro N32 ABI Handbook", Table 2-1:
88          * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
89          * In N64, FP registers F24 .. F31 are callee-saved.
90          * In O32, FP registers F20 .. F23 are callee-saved.
91          */
92 #ifndef __mips_soft_float
93         cfc1    v0, $31                         # too bad can't check if FP used
94 #if defined(__mips_n64) || defined(__mips_n32)
95         FP_S    $f30, (_JB_FPREG_F30 * SZREG)(a0)
96         FP_S    $f28, (_JB_FPREG_F28 * SZREG)(a0)
97         FP_S    $f26, (_JB_FPREG_F26 * SZREG)(a0)
98         FP_S    $f24, (_JB_FPREG_F24 * SZREG)(a0)
99 #endif
100 #if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
101         FP_S    $f22, (_JB_FPREG_F22 * SZREG)(a0)
102         FP_S    $f20, (_JB_FPREG_F20 * SZREG)(a0)
103 #endif
104 #if defined(__mips_o32) || defined(__mips_o64)
105         FP_S    $f21, (_JB_FPREG_F21 * SZREG)(a0)
106         FP_S    $f23, (_JB_FPREG_F23 * SZREG)(a0)
107 #endif
108 #if defined(__mips_n64)
109         FP_S    $f25, (_JB_FPREG_F25 * SZREG)(a0)
110         FP_S    $f27, (_JB_FPREG_F27 * SZREG)(a0)
111         FP_S    $f29, (_JB_FPREG_F29 * SZREG)(a0)
112         FP_S    $f31, (_JB_FPREG_F31 * SZREG)(a0)
113 #endif
114         INT_S   v0, (_JB_FPREG_FCSR * SZREG)(a0)
115 #endif /* ! __mips_soft_float */
116         REG_EPILOGUE
117
118         j       ra
119         move    v0, zero
120 END(_setjmp)
121
122 LEAF(_longjmp)
123         PIC_PROLOGUE(_longjmp)
124         PTR_SUBU        sp, sp, CALLFRAME_SIZ
125         SAVE_GP(CALLFRAME_GP)
126
127         REG_PROLOGUE
128         REG_L           v0, (_JB_MAGIC  * SZREG)(a0)    # get magic number
129         REG_L           ra, (_JB_REG_RA * SZREG)(a0)
130         REG_LI          t0, _JB_MAGIC__SETJMP
131         bne             v0, t0, botch           # jump if error
132         PTR_ADDU        sp, sp, CALLFRAME_SIZ   # does not matter, sanity
133         /*
134          * From "MIPSpro N32 ABI Handbook", Table 2-1:
135          * Registers s0..s7 are callee-saved.
136          * The sp register is callee-saved.
137          * The fp (or s8) register is callee-saved.
138          * The gp register is callee-saved (for n32/n64).
139          */
140         REG_L           s0, (_JB_REG_S0 * SZREG)(a0)
141         REG_L           s1, (_JB_REG_S1 * SZREG)(a0)
142         REG_L           s2, (_JB_REG_S2 * SZREG)(a0)
143         REG_L           s3, (_JB_REG_S3 * SZREG)(a0)
144         REG_L           s4, (_JB_REG_S4 * SZREG)(a0)
145         REG_L           s5, (_JB_REG_S5 * SZREG)(a0)
146         REG_L           s6, (_JB_REG_S6 * SZREG)(a0)
147         REG_L           s7, (_JB_REG_S7 * SZREG)(a0)
148         REG_L           sp, (_JB_REG_SP * SZREG)(a0)
149         REG_L           s8, (_JB_REG_S8 * SZREG)(a0)
150 #if defined(__mips_n32) || defined(__mips_n64)
151         REG_L           gp, (_JB_REG_GP * SZREG)(a0)
152 #endif
153 #ifndef __mips_soft_float
154         # get fpu status
155         INT_L           v0, (_JB_FPREG_FCSR * SZREG)(a0)
156         ctc1            v0, $31
157         /*
158          * From "MIPSpro N32 ABI Handbook", Table 2-1:
159          * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved.
160          * In N64, FP registers F24 .. F31 are callee-saved.
161          * In O32, FP registers F20 .. F23 are callee-saved.
162          */
163 #if defined(__mips_n64) || defined(__mips_n32)
164         FP_L    $f30, (_JB_FPREG_F30 * SZREG)(a0)
165         FP_L    $f28, (_JB_FPREG_F28 * SZREG)(a0)
166         FP_L    $f26, (_JB_FPREG_F26 * SZREG)(a0)
167         FP_L    $f24, (_JB_FPREG_F24 * SZREG)(a0)
168 #endif
169 #if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64)
170         FP_L    $f22, (_JB_FPREG_F22 * SZREG)(a0)
171         FP_L    $f20, (_JB_FPREG_F20 * SZREG)(a0)
172 #endif
173 #if defined(__mips_o32) || defined(__mips_o64)
174         FP_L    $f21, (_JB_FPREG_F21 * SZREG)(a0)
175         FP_L    $f23, (_JB_FPREG_F23 * SZREG)(a0)
176 #endif
177 #if defined(__mips_n64)
178         FP_L    $f25, (_JB_FPREG_F25 * SZREG)(a0)
179         FP_L    $f27, (_JB_FPREG_F27 * SZREG)(a0)
180         FP_L    $f29, (_JB_FPREG_F29 * SZREG)(a0)
181         FP_L    $f31, (_JB_FPREG_F31 * SZREG)(a0)
182 #endif
183 #endif  /* ! __mips_soft_float */
184
185         REG_EPILOGUE
186         move    v0, a1                  # get return value in 1st arg
187         j       ra
188         nop
189
190 botch:
191         /*
192          * We know we aren't returning so we don't care about restoring
193          * our caller's GP.
194          */
195         PTR_LA  t9, _C_LABEL(longjmperror)
196         jalr    t9
197         nop
198
199         PIC_TAILCALL(abort)
200 END(_longjmp)