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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 #include "namespace.h"
35 #include <sys/types.h>
41 #include <machine/regnum.h>
44 __longjmp14(jmp_buf env, int val)
46 struct sigcontext *sc = (void *)env;
49 /* Ensure non-zero SP and sigcontext magic number is present */
50 if (sc->sc_regs[_R_SP] == 0 || sc->sc_regs[_R_ZERO] != 0xACEDBADE)
53 /* Ensure non-zero return value */
58 * Set _UC_{SET,CLR}STACK according to SS_ONSTACK.
60 * Restore the signal mask with sigprocmask() instead of _UC_SIGMASK,
61 * since libpthread may want to interpose on signal handling.
63 uc.uc_flags = _UC_CPU | (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
65 sigprocmask(SIG_SETMASK, &sc->sc_mask, NULL);
70 /* Save return value in context */
71 uc.uc_mcontext.__gregs[_R_V0] = val;
73 /* Copy saved registers */
74 uc.uc_mcontext.__gregs[_REG_S0] = sc->sc_regs[_R_S0];
75 uc.uc_mcontext.__gregs[_REG_S1] = sc->sc_regs[_R_S1];
76 uc.uc_mcontext.__gregs[_REG_S2] = sc->sc_regs[_R_S2];
77 uc.uc_mcontext.__gregs[_REG_S3] = sc->sc_regs[_R_S3];
78 uc.uc_mcontext.__gregs[_REG_S4] = sc->sc_regs[_R_S4];
79 uc.uc_mcontext.__gregs[_REG_S5] = sc->sc_regs[_R_S5];
80 uc.uc_mcontext.__gregs[_REG_S6] = sc->sc_regs[_R_S6];
81 uc.uc_mcontext.__gregs[_REG_S7] = sc->sc_regs[_R_S7];
82 uc.uc_mcontext.__gregs[_REG_S8] = sc->sc_regs[_R_S8];
83 uc.uc_mcontext.__gregs[_REG_SP] = sc->sc_regs[_R_SP];
84 uc.uc_mcontext.__gregs[_REG_RA] = sc->sc_regs[_R_RA];
85 uc.uc_mcontext.__gregs[_REG_EPC] = sc->sc_pc;
89 /* FP saved regs are $f20 .. $f31 */
90 memcpy(&uc.uc_mcontext.__fpregs.__fp_r.__fp_regs[20],
91 &sc->sc_fpregs[20], 32 - 20);
92 uc.uc_mcontext.__fpregs.__fp_csr =
93 sc->sc_fpregs[_R_FSR - _FPBASE];
94 /* XXX sc_fp_control */
95 uc.uc_flags |= _UC_FPU;