1 /* $NetBSD: _setjmp.S,v 1.3 2004/07/18 20:51:24 chs Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
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 <machine/asm.h>
33 /* XXX fredette - this is awful */
35 #include <machine/frame.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
39 RCSID("$NetBSD: _setjmp.S,v 1.3 2004/07/18 20:51:24 chs Exp $")
40 #endif /* LIBC_SCCS and not lint */
43 * C library -- setjmp, longjmp
46 * will generate a "return(v)" from
49 * by restoring registers from the stack,
50 * and a struct sigcontext, see <signal.h>
54 /* A sigcontext is at the beginning of our jmp_buf. */
55 stw %r0, 0(%arg0) ; no onstack
56 stw %r0, 4(%arg0) ; unused word (old style signal mask)
57 stw %sp, 8(%arg0) ; sc.sc_sp = %sp
58 stw %r0, 16(%arg0) ; sc.sc_ap = NULL
60 stw %r1, 20(%arg0) ; sc.sc_pcsqh = %sr0
61 stw %rp, 24(%arg0) ; sc.sc_pcoqh = %rp
62 stw %r1, 28(%arg0) ; sc.sc_pcsqh = %sr0
64 stw %r1, 32(%arg0) ; sc.sc_pcoqt = %rp + 4
65 stw %r0, 36(%arg0) ; set sc.sc_ps
67 /* We store all callee-saved registers after the sigcontext. */
92 ldw 8(%arg0), %r1 ; ensure non-zero SP
93 combt,=,n %r0, %r1, botch ; oops!
94 add,<> %r0, %arg1, %ret0 ; ensure return value non-zero
97 /* restore callee-saved registers */
116 /* restore the rest */