]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/mips/gen/_setjmp.S
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 #include <machine/regnum.h>
38
39 #include "SYS.h"
40
41 #if defined(LIBC_SCCS) && !defined(lint)
42 #if 0
43         RCSID("from: @(#)_setjmp.s      8.1 (Berkeley) 6/4/93")
44 #else
45         RCSID("$NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $")
46 #endif
47 #endif /* LIBC_SCCS and not lint */
48
49 /*
50  * C library -- _setjmp, _longjmp
51  *
52  *      _longjmp(a,v)
53  * will generate a "return(v)" from
54  * the last call to
55  *      _setjmp(a)
56  * by restoring registers from the stack,
57  * The previous signal state is NOT restored.
58  */
59
60         .set    noreorder
61
62 LEAF(_setjmp)
63         REG_PROLOGUE
64         REG_LI  v0, _JB_MAGIC__SETJMP
65         REG_S   v0, (_JB_MAGIC  * SZREG)(a0)
66         REG_S   ra, (_JB_REG_RA * SZREG)(a0)
67         REG_S   s0, (_JB_REG_S0 * SZREG)(a0)
68         REG_S   s1, (_JB_REG_S1 * SZREG)(a0)
69         REG_S   s2, (_JB_REG_S2 * SZREG)(a0)
70         REG_S   s3, (_JB_REG_S3 * SZREG)(a0)
71         REG_S   s4, (_JB_REG_S4 * SZREG)(a0)
72         REG_S   s5, (_JB_REG_S5 * SZREG)(a0)
73         REG_S   s6, (_JB_REG_S6 * SZREG)(a0)
74         REG_S   s7, (_JB_REG_S7 * SZREG)(a0)
75         REG_S   s8, (_JB_REG_S8 * SZREG)(a0)
76 #if defined(__mips_n32) || defined(__mips_n64)
77         REG_S   gp, (_JB_REG_GP * SZREG)(a0)    # newabi gp is callee-saved
78 #endif
79         REG_S   sp, (_JB_REG_SP * SZREG)(a0)
80         REG_EPILOGUE
81
82         j       ra
83         move    v0, zero
84 END(_setjmp)
85
86 LEAF(_longjmp)
87         PIC_PROLOGUE(_longjmp)
88         PTR_SUBU        sp, sp, CALLFRAME_SIZ
89         SAVE_GP(CALLFRAME_GP)
90
91         REG_PROLOGUE
92         REG_L           v0, (_JB_MAGIC  * SZREG)(a0)    # get magic number
93         REG_L           ra, (_JB_REG_RA * SZREG)(a0)
94         REG_LI          t0, _JB_MAGIC__SETJMP
95         bne             v0, t0, botch           # jump if error
96         PTR_ADDU        sp, sp, CALLFRAME_SIZ   # does not matter, sanity
97         REG_L           s0, (_JB_REG_S0 * SZREG)(a0)
98         REG_L           s1, (_JB_REG_S1 * SZREG)(a0)
99         REG_L           s2, (_JB_REG_S2 * SZREG)(a0)
100         REG_L           s3, (_JB_REG_S3 * SZREG)(a0)
101         REG_L           s4, (_JB_REG_S4 * SZREG)(a0)
102         REG_L           s5, (_JB_REG_S5 * SZREG)(a0)
103         REG_L           s6, (_JB_REG_S6 * SZREG)(a0)
104         REG_L           s7, (_JB_REG_S7 * SZREG)(a0)
105 #if defined(__mips_n32) || defined(__mips_n64)
106         REG_L           gp, (_JB_REG_GP * SZREG)(a0)
107 #endif
108         REG_L           sp, (_JB_REG_SP * SZREG)(a0)
109         REG_L           s8, (_JB_REG_S8 * SZREG)(a0)
110
111         REG_EPILOGUE
112         move    v0, a1                  # get return value in 1st arg
113         j       ra
114         nop
115
116 botch:
117         /*
118          * We know we aren't returning so we don't care about restoring
119          * our caller's GP.
120          */
121         PTR_LA  t9, _C_LABEL(longjmperror)
122         jalr    t9
123         nop
124
125         PIC_TAILCALL(abort)
126 END(_longjmp)