Remove building with NOCRYPTO option
[minix3.git] / lib / libc / arch / alpha / gen / __longjmp14.c
blobb641a0769e23b257f6cf4c00f8153edbab4bbe3b
1 /* $NetBSD: __longjmp14.c,v 1.7 2013/03/13 08:05:46 martin Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
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.
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 "namespace.h"
33 #include <sys/types.h>
34 #include <ucontext.h>
35 #include <signal.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <machine/reg.h>
39 #include <machine/alpha_cpu.h>
41 #define __LIBC12_SOURCE__
42 #include <setjmp.h>
43 #include <compat/include/setjmp.h>
45 void
46 __longjmp14(jmp_buf env, int val)
48 struct sigcontext *sc = (void *)env;
49 ucontext_t uc;
51 /* Ensure non-zero SP */
52 if (sc->sc_sp == 0 || sc->sc_regs[R_ZERO] != 0xacedbade)
53 goto err;
55 /* Ensure non-zero return value */
56 if (val == 0)
57 val = -1;
59 /* Set _UC_SIGMASK and _UC_CPU */
60 uc.uc_flags = _UC_SIGMASK | _UC_CPU;
62 /* Clear uc_link */
63 uc.uc_link = 0;
65 /* Save return value in context */
66 uc.uc_mcontext.__gregs[_REG_V0] = val;
68 /* Copy saved registers */
69 uc.uc_mcontext.__gregs[_REG_S0] = sc->sc_regs[R_S0];
70 uc.uc_mcontext.__gregs[_REG_S1] = sc->sc_regs[R_S1];
71 uc.uc_mcontext.__gregs[_REG_S2] = sc->sc_regs[R_S2];
72 uc.uc_mcontext.__gregs[_REG_S3] = sc->sc_regs[R_S3];
73 uc.uc_mcontext.__gregs[_REG_S4] = sc->sc_regs[R_S4];
74 uc.uc_mcontext.__gregs[_REG_S5] = sc->sc_regs[R_S5];
75 uc.uc_mcontext.__gregs[_REG_S6] = sc->sc_regs[R_S6];
76 uc.uc_mcontext.__gregs[_REG_RA] = sc->sc_regs[R_RA];
77 uc.uc_mcontext.__gregs[_REG_GP] = sc->sc_regs[R_GP];
78 uc.uc_mcontext.__gregs[_REG_SP] = sc->sc_sp;
79 uc.uc_mcontext.__gregs[_REG_PC] = sc->sc_pc;
80 uc.uc_mcontext.__gregs[_REG_PS] =
81 (sc->sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
83 /* Copy FP state */
84 if (sc->sc_ownedfp) {
85 memcpy(&uc.uc_mcontext.__fpregs.__fp_fr,
86 &sc->sc_fpregs, 31 * sizeof(unsigned long));
87 uc.uc_mcontext.__fpregs.__fp_fpcr = sc->sc_fpcr;
88 /* XXX sc_fp_control */
89 uc.uc_flags |= _UC_FPU;
92 /* Copy signal mask */
93 uc.uc_sigmask = sc->sc_mask;
95 setcontext(&uc);
96 err:
97 longjmperror();
98 abort();
99 /* NOTREACHED */