setjmp.S revision 1.6
1/*	$OpenBSD: setjmp.S,v 1.6 2003/06/02 20:18:30 millert Exp $	*/
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <machine/asm.h>
37#define _LOCORE
38#include <machine/frame.h>
39#undef _LOCORE
40
41#if defined(LIBC_SCCS) && !defined(lint)
42	.text
43	.asciz	"$OpenBSD: setjmp.S,v 1.6 2003/06/02 20:18:30 millert Exp $"
44	.align	4
45#endif /* LIBC_SCCS and not lint */
46
47/*
48 * C library -- setjmp, longjmp
49 *
50 *	longjmp(a,v)
51 * will generate a "return(v)" from
52 * the last call to
53 *	setjmp(a)
54 * by restoring registers from the stack,
55 * and a struct sigcontext, see <signal.h>
56 */
57
58ENTRY(sigsetjmp, 64)
59	sub,<>	%r0, %arg1, %r0
60	b,n	_setjmp
61	nop
62
63	stw	%arg1, 44(%arg0)	; last of reserved words
64
65ALTENTRY(setjmp)
66	stw	%rp, HPPA_FRAME_CRP(%sp)
67	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
68
69	copy	%r3, %r1
70	copy	%sp, %r3
71	stw,ma	%r1, HPPA_FRAME_SIZE(%sp)
72
73	bl	sigblock, %rp
74	copy	%r0, %arg0
75
76	ldo	HPPA_FRAME_SIZE(%r3), %sp
77	ldw,mb	-HPPA_FRAME_SIZE(%sp),%r3
78	ldw	HPPA_FRAME_CRP(%sp), %rp
79	ldw	HPPA_FRAME_ARG(0)(%sp), %arg0
80
81	stw	%r0, 0(%arg0)		; no onstack
82	b	_setjmp$dosaves
83	stw	%ret0, 4(%arg0)		; mask
84
85ALTENTRY(_setjmp)
86	/* A sigcontext is at the beginning of our jmp_buf. */
87	stw	%r0, 0(%arg0)		; no onstack
88	stw	%r0, 4(%arg0)		; mask
89_setjmp$dosaves
90	stw	%r0, 8(%arg0)		; set sc.sc_ps
91	stw	%sp, 12(%arg0)		; sc.sc_sp = %sp
92	stw	%r0, 16(%arg0)		; sc.sc_fp
93	ldo	4(%rp), %r1
94	stw	%rp, 20(%arg0)		; sc.sc_pcoqh = %rp
95	stw	%r1, 24(%arg0)		; sc.sc_pcoqt = %rp + 4
96
97	/* We store all callee-saved registers after the sigcontext. */
98	ldo	48(%arg0), %r1		; offset to after sc
99	stwm	%r3, 4(%r1)
100	stwm	%r4, 4(%r1)
101	stwm	%r5, 4(%r1)
102	stwm	%r6, 4(%r1)
103	stwm	%r7, 4(%r1)
104	stwm	%r8, 4(%r1)
105	stwm	%r9, 4(%r1)
106	stwm	%r10, 4(%r1)
107	stwm	%r11, 4(%r1)
108	stwm	%r12, 4(%r1)
109	stwm	%r13, 4(%r1)
110	stwm	%r14, 4(%r1)
111	stwm	%r15, 4(%r1)
112	stwm	%r16, 4(%r1)
113	stwm	%r17, 4(%r1)
114	stwm	%r18, 4(%r1)
115
116	/* Return 0. */
117	bv	%r0(%rp)
118	copy	%r0, %ret0
119EXIT(_setjmp)
120
121ENTRY(siglongjmp,64)
122	/* XXX have to dup this from below */
123	sub,>>	%sp, %arg0, %r0		/* botch if jbuf was on stack */
124	bl,n	longjmperror, %rp
125	nop
126	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
127	add,=	%r0, %r1, %r0
128	bl,n	longjmperror, %rp
129	nop
130
131	ldw	44(%arg0), %arg2
132	sub,<>	%r0, %arg2, %r0
133	b	_longjmp
134	nop
135
136ALTENTRY(longjmp)
137	/* XXX have to dup this from below */
138	sub,>>	%sp, %arg0, %r0		/* botch if jbuf was on stack */
139	bl,n	longjmperror, %rp
140	nop
141	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
142	add,=	%r0, %r1, %r0
143	bl,n	longjmperror, %rp
144	nop
145
146	stw	%rp, HPPA_FRAME_CRP(%sp)
147	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
148	stw	%arg1, HPPA_FRAME_ARG(1)(%sp)
149
150	copy	%r3, %r1
151	copy	%sp, %r3
152	stw,ma	%r1, HPPA_FRAME_SIZE(%sp)
153
154	bl	sigsetmask, %rp
155	ldw	4(%arg0), %arg0
156
157	ldo	HPPA_FRAME_SIZE(%r3), %sp
158	ldw,mb	-HPPA_FRAME_SIZE(%sp),%r3
159	ldw	HPPA_FRAME_CRP(%sp), %rp
160	ldw	HPPA_FRAME_ARG(0)(%sp), %arg0
161	b	_longjmp$restores
162	ldw	HPPA_FRAME_ARG(1)(%sp), %arg1
163
164ALTENTRY(_longjmp)
165	sub,>>	%sp, %arg0, %r0		/* botch if jbuf was on stack */
166	bl,n	longjmperror, %rp
167	nop
168	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
169	add,=	%r0, %r1, %r0
170	bl,n	longjmperror, %rp
171	nop
172
173_longjmp$restores
174	/* restore callee-saved registers */
175	ldo	48(%arg0), %r1
176	ldwm	4(%r1), %r3
177	ldwm	4(%r1), %r4
178	ldwm	4(%r1), %r5
179	ldwm	4(%r1), %r6
180	ldwm	4(%r1), %r7
181	ldwm	4(%r1), %r8
182	ldwm	4(%r1), %r9
183	ldwm	4(%r1), %r10
184	ldwm	4(%r1), %r11
185	ldwm	4(%r1), %r12
186	ldwm	4(%r1), %r13
187	ldwm	4(%r1), %r14
188	ldwm	4(%r1), %r15
189	ldwm	4(%r1), %r16
190	ldwm	4(%r1), %r17
191	ldwm	4(%r1), %r18
192
193	/* restore the rest */
194	ldw	12(%arg0), %sp
195	ldw	20(%arg0), %rp		/* check the priv level */
196	sub,<>	%arg1, %r0, %r0
197	ldo	1(%arg1), %arg1
198	bv	%r0(%rp)
199	copy	%arg1, %ret0
200EXIT(_longjmp)
201
202	.end
203