xref: /netbsd/lib/libc/arch/hppa/gen/__setjmp14.S (revision c4a72b64)
1/*	$NetBSD: __setjmp14.S,v 1.2 2002/07/01 16:00:51 fredette Exp $	*/
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matthew Fredette.
9 *
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.
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.
25 *
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.
37 */
38
39#include <machine/asm.h>
40/* XXX fredette - this is awful */
41#define _LOCORE
42#include <machine/frame.h>
43#undef _LOCORE
44#include <machine/psl.h>
45
46#if defined(LIBC_SCCS) && !defined(lint)
47	RCSID("$NetBSD: __setjmp14.S,v 1.2 2002/07/01 16:00:51 fredette Exp $")
48#endif /* LIBC_SCCS and not lint */
49
50/*
51 * C library -- setjmp, longjmp
52 *
53 *	longjmp(a,v)
54 * will generate a "return(v)" from
55 * the last call to
56 *	setjmp(a)
57 * by restoring registers from the stack,
58 * and a struct sigcontext, see <signal.h>
59 */
60
61ENTRY(__setjmp14,0)
62	/* Finish our stack frame. */
63	stw	%rp, HPPA_FRAME_CRP(%sp)
64	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
65
66	/* A sigcontext is at the beginning of our jmp_buf. */
67	stw	%r0, 4(%arg0)		; unused word (old style signal mask)
68	stw	%sp, 8(%arg0)		; sc.sc_sp = %sp
69	stw	%r0, 16(%arg0)		; sc.sc_ap = NULL
70	mfsp	%sr0, %r1
71	stw	%r1, 20(%arg0)		; sc.sc_pcsqh = %sr0
72	stw	%rp, 24(%arg0)		; sc.sc_pcoqh = %rp
73	stw	%r1, 28(%arg0)		; sc.sc_pcsqh = %sr0
74	ldo	4(%rp), %r1
75	stw	%r1, 32(%arg0)		; sc.sc_pcoqt = %rp + 4
76#define PSW_MBS (PSW_C|PSW_Q|PSW_P|PSW_D|PSW_I)
77	ldil	L%PSW_MBS, %r1
78	ldo	R%PSW_MBS(%r1), %r1
79	stw	%r1, 36(%arg0)		; set sc.sc_ps
80
81	/* We store all callee-saved registers after the sigcontext. */
82	ldo	56(%arg0), %r1
83	stwm	%r3, 4(%r1)
84	stwm	%r4, 4(%r1)
85	stwm	%r5, 4(%r1)
86	stwm	%r6, 4(%r1)
87	stwm	%r7, 4(%r1)
88	stwm	%r8, 4(%r1)
89	stwm	%r9, 4(%r1)
90	stwm	%r10, 4(%r1)
91	stwm	%r11, 4(%r1)
92	stwm	%r12, 4(%r1)
93	stwm	%r13, 4(%r1)
94	stwm	%r14, 4(%r1)
95	stwm	%r15, 4(%r1)
96	stwm	%r16, 4(%r1)
97	stwm	%r17, 4(%r1)
98	stwm	%r18, 4(%r1)
99
100	/*
101	 * Start the stack frame for the calls we will make.
102	 * The minimum frame is 48 bytes, but the stack must
103	 * always be 64-byte aligned; we use the top 4 bytes
104	 * to save our caller's %r3, and the following 12 bytes
105	 * as the stack_t for our sigaltstack call.
106	 * XXX - this assumes that sizeof(stack_t) <= 12
107	 */
108	copy	%r3, %r1
109	copy	%sp, %r3
110	stwm	%r1, HPPA_FRAME_SIZE(%sp)
111
112	/* Get signal stack info. */
113	ldo	4(%r3), %arg1		; set up oss
114	bl	__sigaltstack14, %rp
115	copy	%r0, %arg0		; set up ss
116
117	/* Recover our jmp_buf and extract SS_ONSTACK */
118	ldw	HPPA_FRAME_ARG(0)(%r3), %arg0
119	ldw	12(%r3), %r1		; get ss_flags
120	ldi	1, %r20			; SS_ONSTACK
121	and	%r1, %r20, %r1
122	stw	%r1, 0(%arg0)		; sc.sc_onstack
123
124	/* Get the signal mask. */
125	ldo	40(%arg0), %arg2	; oset = &sc.sc_mask
126	copy	%r0, %arg1		; set = NULL
127	bl	__sigprocmask14, %rp
128	copy	%r0, %arg0		; action = 0 <ignored>
129
130	/* Return 0. */
131	ldo	HPPA_FRAME_SIZE(%r3),%sp
132	ldwm	-HPPA_FRAME_SIZE(%sp),%r3
133	ldw	HPPA_FRAME_CRP(%sp), %rp
134	bv	%r0(%rp)
135	copy	%r0, %ret0
136EXIT(__setjmp14)
137
138ENTRY(__longjmp14,0)
139	/* Finish our stack frame. */
140	stw	%rp, HPPA_FRAME_CRP(%sp)
141	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
142
143	ldw	8(%arg0), %r1		; ensure non-zero SP
144	combt,=,n	%r0, %r1, botch	; oops!
145	add,<>	%r0, %arg1, %ret0	; ensure return value non-zero
146	ldi	1, %ret0
147
148	/* restore callee-saved registers */
149	ldo	56(%arg0), %r1
150	ldwm	4(%r1), %r3
151	ldwm	4(%r1), %r4
152	ldwm	4(%r1), %r5
153	ldwm	4(%r1), %r6
154	ldwm	4(%r1), %r7
155	ldwm	4(%r1), %r8
156	ldwm	4(%r1), %r9
157	ldwm	4(%r1), %r10
158	ldwm	4(%r1), %r11
159	ldwm	4(%r1), %r12
160	ldwm	4(%r1), %r13
161	ldwm	4(%r1), %r14
162	ldwm	4(%r1), %r15
163	ldwm	4(%r1), %r16
164	ldwm	4(%r1), %r17
165	ldwm	4(%r1), %r18
166
167	/* let sigreturn finish for us */
168	bl	__sigreturn14, %rp
169	nop
170botch
171	bl	longjmperror, %rp
172	nop
173EXIT(__longjmp14)
174
175	.end
176