setjmp.S revision 1.9
1/*	$OpenBSD: setjmp.S,v 1.9 2015/09/13 07:36:58 guenther 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/*
42 * C library -- setjmp, longjmp
43 *
44 *	longjmp(a,v)
45 * will generate a "return(v)" from
46 * the last call to
47 *	setjmp(a)
48 * by restoring registers from the stack,
49 * and a struct sigcontext, see <signal.h>
50 */
51
52ENTRY(sigsetjmp, 64)
53	sub,<>	%r0, %arg1, %r0
54	b,n	_setjmp
55	nop
56
57	stw	%arg1, 44(%arg0)	; last of reserved words
58
59ALTENTRY(setjmp)
60	stw	%rp, HPPA_FRAME_CRP(%sp)
61	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
62
63	copy	%r3, %r1
64	copy	%sp, %r3
65	stw,ma	%r1, HPPA_FRAME_SIZE(%sp)
66
67	bl	_libc_sigblock, %rp
68	copy	%r0, %arg0
69
70	ldo	HPPA_FRAME_SIZE(%r3), %sp
71	ldw,mb	-HPPA_FRAME_SIZE(%sp),%r3
72	ldw	HPPA_FRAME_CRP(%sp), %rp
73	ldw	HPPA_FRAME_ARG(0)(%sp), %arg0
74
75	stw	%r0, 0(%arg0)		; no onstack
76	b	_setjmp$dosaves
77	stw	%ret0, 4(%arg0)		; mask
78
79ALTENTRY(_setjmp)
80	/* A sigcontext is at the beginning of our jmp_buf. */
81	stw	%r0, 0(%arg0)		; no onstack
82	stw	%r0, 4(%arg0)		; mask
83_setjmp$dosaves
84	stw	%r0, 8(%arg0)		; set sc.sc_ps
85	stw	%sp, 12(%arg0)		; sc.sc_sp = %sp
86	stw	%r0, 16(%arg0)		; sc.sc_fp
87	ldo	4(%rp), %r1
88	stw	%rp, 20(%arg0)		; sc.sc_pcoqh = %rp
89	stw	%r1, 24(%arg0)		; sc.sc_pcoqt = %rp + 4
90
91	/* We store all callee-saved registers after the sigcontext. */
92	ldo	48(%arg0), %r1		; offset to after sc
93	stwm	%r3, 4(%r1)
94	stwm	%r4, 4(%r1)
95	stwm	%r5, 4(%r1)
96	stwm	%r6, 4(%r1)
97	stwm	%r7, 4(%r1)
98	stwm	%r8, 4(%r1)
99	stwm	%r9, 4(%r1)
100	stwm	%r10, 4(%r1)
101	stwm	%r11, 4(%r1)
102	stwm	%r12, 4(%r1)
103	stwm	%r13, 4(%r1)
104	stwm	%r14, 4(%r1)
105	stwm	%r15, 4(%r1)
106	stwm	%r16, 4(%r1)
107	stwm	%r17, 4(%r1)
108	stwm	%r18, 4(%r1)
109
110	/* Return 0. */
111	bv	%r0(%rp)
112	copy	%r0, %ret0
113EXIT(_setjmp)
114
115ENTRY(siglongjmp,64)
116	/* XXX have to dup this from below */
117	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
118	add,=	%r0, %r1, %r0
119	bl,n	longjmperror, %rp
120	nop
121
122	ldw	44(%arg0), %arg2
123	sub,<>	%r0, %arg2, %r0
124	b	_longjmp
125	nop
126
127ALTENTRY(longjmp)
128	/* XXX have to dup this from below */
129	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
130	add,=	%r0, %r1, %r0
131	bl,n	longjmperror, %rp
132	nop
133
134	stw	%rp, HPPA_FRAME_CRP(%sp)
135	stw	%arg0, HPPA_FRAME_ARG(0)(%sp)
136	stw	%arg1, HPPA_FRAME_ARG(1)(%sp)
137
138	copy	%r3, %r1
139	copy	%sp, %r3
140	stw,ma	%r1, HPPA_FRAME_SIZE(%sp)
141
142	bl	_libc_sigsetmask, %rp
143	ldw	4(%arg0), %arg0
144
145	ldo	HPPA_FRAME_SIZE(%r3), %sp
146	ldw,mb	-HPPA_FRAME_SIZE(%sp),%r3
147	ldw	HPPA_FRAME_CRP(%sp), %rp
148	ldw	HPPA_FRAME_ARG(0)(%sp), %arg0
149	b	_longjmp$restores
150	ldw	HPPA_FRAME_ARG(1)(%sp), %arg1
151
152ALTENTRY(_longjmp)
153	ldw	16(%arg0), %r1		/* botch if it's a real signal frame */
154	add,=	%r0, %r1, %r0
155	bl,n	longjmperror, %rp
156	nop
157
158_longjmp$restores
159	/* restore callee-saved registers */
160	ldo	48(%arg0), %r1
161	ldwm	4(%r1), %r3
162	ldwm	4(%r1), %r4
163	ldwm	4(%r1), %r5
164	ldwm	4(%r1), %r6
165	ldwm	4(%r1), %r7
166	ldwm	4(%r1), %r8
167	ldwm	4(%r1), %r9
168	ldwm	4(%r1), %r10
169	ldwm	4(%r1), %r11
170	ldwm	4(%r1), %r12
171	ldwm	4(%r1), %r13
172	ldwm	4(%r1), %r14
173	ldwm	4(%r1), %r15
174	ldwm	4(%r1), %r16
175	ldwm	4(%r1), %r17
176	ldwm	4(%r1), %r18
177
178	/* restore the rest */
179	ldw	12(%arg0), %sp
180	ldw	20(%arg0), %rp		/* check the priv level */
181	sub,<>	%arg1, %r0, %r0
182	ldo	1(%arg1), %arg1
183	bv	%r0(%rp)
184	copy	%arg1, %ret0
185EXIT(_longjmp)
186
187	.end
188