1 /* $NetBSD: longjmp.c,v 1.1 2005/09/17 11:49:39 tsutsui Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christian Limpach and Matt Thomas.
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
41 #include "namespace.h"
42 #include <sys/types.h>
48 #include <machine/regnum.h>
51 __longjmp14(jmp_buf env, int val)
53 struct sigcontext *sc = (void *)env;
56 /* Ensure non-zero SP and sigcontext magic number is present */
57 if (sc->sc_regs[_R_SP] == 0 || sc->sc_regs[_R_ZERO] != 0xACEDBADE)
60 /* Ensure non-zero return value */
65 * Set _UC_{SET,CLR}STACK according to SS_ONSTACK.
67 * Restore the signal mask with sigprocmask() instead of _UC_SIGMASK,
68 * since libpthread may want to interpose on signal handling.
70 uc.uc_flags = _UC_CPU | (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
72 sigprocmask(SIG_SETMASK, &sc->sc_mask, NULL);
77 /* Save return value in context */
78 uc.uc_mcontext.__gregs[_R_V0] = val;
80 /* Copy saved registers */
81 uc.uc_mcontext.__gregs[_REG_S0] = sc->sc_regs[_R_S0];
82 uc.uc_mcontext.__gregs[_REG_S1] = sc->sc_regs[_R_S1];
83 uc.uc_mcontext.__gregs[_REG_S2] = sc->sc_regs[_R_S2];
84 uc.uc_mcontext.__gregs[_REG_S3] = sc->sc_regs[_R_S3];
85 uc.uc_mcontext.__gregs[_REG_S4] = sc->sc_regs[_R_S4];
86 uc.uc_mcontext.__gregs[_REG_S5] = sc->sc_regs[_R_S5];
87 uc.uc_mcontext.__gregs[_REG_S6] = sc->sc_regs[_R_S6];
88 uc.uc_mcontext.__gregs[_REG_S7] = sc->sc_regs[_R_S7];
89 uc.uc_mcontext.__gregs[_REG_S8] = sc->sc_regs[_R_S8];
90 uc.uc_mcontext.__gregs[_REG_SP] = sc->sc_regs[_R_SP];
91 uc.uc_mcontext.__gregs[_REG_RA] = sc->sc_regs[_R_RA];
92 uc.uc_mcontext.__gregs[_REG_EPC] = sc->sc_pc;
96 /* FP saved regs are $f20 .. $f31 */
97 memcpy(&uc.uc_mcontext.__fpregs.__fp_r.__fp_regs[20],
98 &sc->sc_fpregs[20], 32 - 20);
99 uc.uc_mcontext.__fpregs.__fp_csr =
100 sc->sc_fpregs[_R_FSR - _FPBASE];
101 /* XXX sc_fp_control */
102 uc.uc_flags |= _UC_FPU;