]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libc/mips/gen/setjmp.S
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libc / mips / gen / setjmp.S
1 /*      $NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui 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 #if defined(LIBC_SCCS) && !defined(lint)
40         ASMSTR("from: @(#)setjmp.s      8.1 (Berkeley) 6/4/93")
41         ASMSTR("$NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $")
42 #endif /* LIBC_SCCS and not lint */
43
44 #ifdef __ABICALLS__
45         .abicalls
46 #endif
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  * and a struct sigcontext, see <signal.h>
57  */
58
59 #define SETJMP_FRAME_SIZE       (CALLFRAME_SIZ + (SZREG * 2))
60
61
62 NESTED(setjmp, SETJMP_FRAME_SIZE, ra)
63         .mask   0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
64         .set    noreorder
65 #ifdef __ABICALLS__
66         .cpload t9
67 #endif
68         subu    sp, sp, SETJMP_FRAME_SIZE       # allocate stack frame
69 #ifdef __ABICALLS__
70         .cprestore 16
71 #endif
72         sw      ra, CALLFRAME_RA(sp)            # save RA
73         sw      a0, CALLFRAME_SIZ(sp)           # store env
74
75         /* Get the signal mask. */
76         addu    a2, a0, _JB_SIGMASK * SZREG     # &oenv
77         li      a0, 1                           # SIG_SETBLOCK
78         move    a1, zero                        # &env == 0
79         la      t9, _C_LABEL(sigprocmask)       # get current signal mask
80         jal     t9
81         nop
82
83         lw      a0, CALLFRAME_SIZ(sp)           # restore env pointer
84         lw      ra, CALLFRAME_RA(sp)            # restore RA
85         addu    sp, sp, SETJMP_FRAME_SIZE       # pop stack frame
86
87         li      v0, _JB_MAGIC_SETJMP
88         sw      v0, (_JB_MAGIC  * SZREG)(a0)
89         sw      ra, (_JB_REG_RA * SZREG)(a0)
90         sw      s0, (_JB_REG_S0 * SZREG)(a0)
91         sw      s1, (_JB_REG_S1 * SZREG)(a0)
92         sw      s2, (_JB_REG_S2 * SZREG)(a0)
93         sw      s3, (_JB_REG_S3 * SZREG)(a0)
94         sw      s4, (_JB_REG_S4 * SZREG)(a0)
95         sw      s5, (_JB_REG_S5 * SZREG)(a0)
96         sw      s6, (_JB_REG_S6 * SZREG)(a0)
97         sw      s7, (_JB_REG_S7 * SZREG)(a0)
98         sw      sp, (_JB_REG_SP * SZREG)(a0)
99         sw      s8, (_JB_REG_S8 * SZREG)(a0)
100
101         move    v0, zero
102         j       ra
103 END(setjmp)
104
105 #define LONGJMP_FRAME_SIZE      (CALLFRAME_SIZ + (SZREG * 2))
106
107 NESTED(longjmp, LONGJMP_FRAME_SIZE, ra)
108         .mask   0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
109         .set    noreorder
110 #ifdef __ABICALLS__
111         .cpload t9
112 #endif
113         subu    sp, sp, LONGJMP_FRAME_SIZE      # allocate stack frame
114 #ifdef __ABICALLS__
115         .cprestore 16
116 #endif
117         sw      ra, CALLFRAME_RA(sp)            # save RA
118         lw      v0, (_JB_MAGIC  * SZREG)(a0)
119         li      t0, _JB_MAGIC_SETJMP
120         bne     v0, t0, botch           # jump if error
121         nop
122
123         sw      a0, CALLFRAME_SIZ(sp)           # save env
124         sw      a1, (CALLFRAME_SIZ + SZREG)(sp) # save return value
125
126         # set sigmask
127         addu    a1, a0, _JB_SIGMASK * SZREG     # &set
128         move    a2, zero                        # &oset == NULL
129         li      a0, 3                           # SIG_SETMASK
130         la      t9,_C_LABEL(sigprocmask)        # set current signal mask
131         jal     t9
132         nop
133
134         lw      a0, CALLFRAME_SIZ(sp)           # restore env
135         lw      a1, (CALLFRAME_SIZ + SZREG)(sp) # restore return value
136
137         lw      ra, (_JB_REG_RA * SZREG)(a0)
138         lw      s0, (_JB_REG_S0 * SZREG)(a0)
139         lw      s1, (_JB_REG_S1 * SZREG)(a0)
140         lw      s2, (_JB_REG_S2 * SZREG)(a0)
141         lw      s3, (_JB_REG_S3 * SZREG)(a0)
142         lw      s4, (_JB_REG_S4 * SZREG)(a0)
143         lw      s5, (_JB_REG_S5 * SZREG)(a0)
144         lw      s6, (_JB_REG_S6 * SZREG)(a0)
145         lw      s7, (_JB_REG_S7 * SZREG)(a0)
146         lw      sp, (_JB_REG_SP * SZREG)(a0)
147         lw      s8, (_JB_REG_S8 * SZREG)(a0)
148         move    v0, a1
149         j       ra
150         nop
151
152 botch:
153         la      t9, _C_LABEL(longjmperror)
154         jal     t9
155         nop
156
157         la      t9, _C_LABEL(abort)
158         jal     t9
159         nop
160 END(longjmp)