1 /* $NetBSD: __longjmp14.c,v 1.3 2005/12/24 21:41:01 perry 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.
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 "namespace.h"
33 #include <sys/types.h>
39 #define __LIBC12_SOURCE__
41 #include <compat/include/setjmp.h>
46 ssize_t
_sys_write(int, void *, size_t);
49 __longjmp14(jmp_buf env
, int val
)
52 struct sigcontext
*sc
= (void *)env
;
53 register_t
*regs
= (void *)(sc
+ 1);
54 register register_t dp
__asm("r27");
56 /* Ensure non-zero SP */
60 /* Make return value non-zero */
64 /* Copy callee-saved regs */
66 uc
.uc_mcontext
.__gregs
[3] = regs
[3];
67 uc
.uc_mcontext
.__gregs
[4] = regs
[4];
68 uc
.uc_mcontext
.__gregs
[5] = regs
[5];
69 uc
.uc_mcontext
.__gregs
[6] = regs
[6];
70 uc
.uc_mcontext
.__gregs
[7] = regs
[7];
71 uc
.uc_mcontext
.__gregs
[8] = regs
[8];
72 uc
.uc_mcontext
.__gregs
[9] = regs
[9];
73 uc
.uc_mcontext
.__gregs
[10] = regs
[10];
74 uc
.uc_mcontext
.__gregs
[11] = regs
[11];
75 uc
.uc_mcontext
.__gregs
[12] = regs
[12];
76 uc
.uc_mcontext
.__gregs
[13] = regs
[13];
77 uc
.uc_mcontext
.__gregs
[14] = regs
[14];
78 uc
.uc_mcontext
.__gregs
[15] = regs
[15];
79 uc
.uc_mcontext
.__gregs
[16] = regs
[16];
80 uc
.uc_mcontext
.__gregs
[17] = regs
[17];
81 uc
.uc_mcontext
.__gregs
[18] = regs
[18];
83 /* Preserve the current value of DP */
84 uc
.uc_mcontext
.__gregs
[27] = dp
;
86 /* Set the desired return value. */
87 uc
.uc_mcontext
.__gregs
[_REG_RET0
] = val
;
90 * Set _UC_{SET,CLR}STACK according to SS_ONSTACK.
92 * Restore the signal mask with sigprocmask() instead of _UC_SIGMASK,
93 * since libpthread may want to interpose on signal handling.
95 uc
.uc_flags
= _UC_CPU
| (sc
->sc_onstack
? _UC_SETSTACK
: _UC_CLRSTACK
);
97 sigprocmask(SIG_SETMASK
, &sc
->sc_mask
, NULL
);
102 /* Copy signal mask */
103 uc
.uc_sigmask
= sc
->sc_mask
;
105 /* Copy special regs */
106 uc
.uc_mcontext
.__gregs
[_REG_PSW
] = sc
->sc_ps
;
107 uc
.uc_mcontext
.__gregs
[_REG_SP
] = sc
->sc_sp
;
108 uc
.uc_mcontext
.__gregs
[_REG_PCSQH
] = sc
->sc_pcsqh
;
109 uc
.uc_mcontext
.__gregs
[_REG_PCOQH
] = sc
->sc_pcoqh
;
110 uc
.uc_mcontext
.__gregs
[_REG_PCSQT
] = sc
->sc_pcsqt
;
111 uc
.uc_mcontext
.__gregs
[_REG_PCOQT
] = sc
->sc_pcoqt
;