1 /* $NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
35 #include <machine/asm.h>
36 __FBSDID("$FreeBSD$");
37 #include <machine/regnum.h>
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 */
49 * C library -- setjmp, longjmp
52 * will generate a "return(v)" from
55 * by restoring registers from the stack,
56 * and a struct sigcontext, see <signal.h>
59 #define SETJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2))
62 NESTED(setjmp, SETJMP_FRAME_SIZE, ra)
63 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
68 subu sp, sp, SETJMP_FRAME_SIZE # allocate stack frame
72 sw ra, CALLFRAME_RA(sp) # save RA
73 sw a0, CALLFRAME_SIZ(sp) # store env
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
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
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)
105 #define LONGJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2))
107 NESTED(longjmp, LONGJMP_FRAME_SIZE, ra)
108 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
113 subu sp, sp, LONGJMP_FRAME_SIZE # allocate stack frame
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
123 sw a0, CALLFRAME_SIZ(sp) # save env
124 sw a1, (CALLFRAME_SIZ + SZREG)(sp) # save return value
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
134 lw a0, CALLFRAME_SIZ(sp) # restore env
135 lw a1, (CALLFRAME_SIZ + SZREG)(sp) # restore return value
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)
153 la t9, _C_LABEL(longjmperror)
157 la t9, _C_LABEL(abort)