xref: /openbsd/lib/libc/arch/hppa/gen/setjmp.S (revision 09467b48)
1/*	$OpenBSD: setjmp.S,v 1.11 2016/05/29 07:59:36 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 "SYS.h"
37
38	.section	.openbsd.randomdata,"aw",@progbits
39	.align	4
40.L__jmpxor
41	.zero	4*2		; (r2/rp, r30/sp)
42
43/*
44 * C library -- setjmp, longjmp
45 *
46 *	longjmp(a,v)
47 * will generate a "return(v)" from
48 * the last call to
49 *	setjmp(a)
50 * by restoring registers from the stack,
51 * and a struct sigcontext, see <signal.h>
52 */
53
54ENTRY(sigsetjmp, 64)
55	sub,<>	%r0, %arg1, %r0
56	b	.L_setjmp$dosaves
57	 stw	%arg1, 44(%arg0)	; last of reserved words
58
59ALTENTRY(setjmp)
60	copy	%arg0, %arg2		; save jmpbuf in %arg2
61
62	ldi	1, %arg0		; how = SIG_BLOCK
63	copy	%r0, %arg1		; set = empty
64	stw	%rp, HPPA_FRAME_ERP(%sr0,%sp)
65	ldil	L%SYSCALLGATE, %r1
66	ble	4(%sr7, %r1)
67	 ldi	SYS_sigprocmask, %t1
68	ldw	HPPA_FRAME_ERP(%sr0,%sp), %rp
69
70	copy	%arg2, %arg0		; restore jmpbuf to %arg0
71	stw	%ret0, 4(%arg0)		; mask
72
73ALTENTRY(_setjmp)
74.L_setjmp$dosaves
75#ifdef __PIC__
76	addil	LT%.L__jmpxor, %r19
77	ldw	RT%.L__jmpxor(%r1), %t2
78#else
79	ldil	L%.L__jmpxor, %t1
80	ldo	R%.L__jmpxor(%t1), %t2
81#endif
82	ldw	0(%t2), %t1		; xor for r2/rp
83	ldw	4(%t2), %t2		; xor for r30/sp, overwrite address
84
85	xor	%sp, %t2, %t2
86	stw	%t2, 12(%arg0)		; sc.sc_sp = %sp
87	xor	%rp, %t1, %t1
88	stw	%t1, 20(%arg0)		; sc.sc_pcoqh = %rp
89	copy	%r0, %t1
90	copy	%r0, %t2
91
92	/* We store all callee-saved registers after the sigcontext. */
93	ldo	48(%arg0), %r1		; offset to after sc
94	stwm	%r3, 4(%r1)
95	stwm	%r4, 4(%r1)
96	stwm	%r5, 4(%r1)
97	stwm	%r6, 4(%r1)
98	stwm	%r7, 4(%r1)
99	stwm	%r8, 4(%r1)
100	stwm	%r9, 4(%r1)
101	stwm	%r10, 4(%r1)
102	stwm	%r11, 4(%r1)
103	stwm	%r12, 4(%r1)
104	stwm	%r13, 4(%r1)
105	stwm	%r14, 4(%r1)
106	stwm	%r15, 4(%r1)
107	stwm	%r16, 4(%r1)
108	stwm	%r17, 4(%r1)
109	stwm	%r18, 4(%r1)
110
111	/* Return 0. */
112	bv	%r0(%rp)
113	 copy	%r0, %ret0
114EXIT(sigsetjmp)
115	.size _setjmp, . - _setjmp
116	.size setjmp, . - setjmp
117
118ENTRY(siglongjmp,64)
119	ldw	44(%arg0), %arg2
120	sub,<>	%r0, %arg2, %r0
121	b	.L_longjmp$restores
122	 nop
123
124ALTENTRY(longjmp)
125	copy	%arg1, %arg3		; save val in %arg3
126	copy	%arg0, %arg2		; save jmpbuf in %arg2
127
128	ldw	4(%arg0), %arg1		; set from jumpbuf
129	ldi	3, %arg0		; how = SIG_SETMASK
130	stw	%rp, HPPA_FRAME_ERP(%sr0,%sp)
131	ldil	L%SYSCALLGATE, %r1
132	ble	4(%sr7, %r1)
133	 ldi	SYS_sigprocmask, %t1
134	ldw	HPPA_FRAME_ERP(%sr0,%sp), %rp
135
136	copy	%arg2, %arg0		; restore jmpbuf to %arg0
137	copy	%arg3, %arg1		; restore val to %arg1
138
139ALTENTRY(_longjmp)
140.L_longjmp$restores
141	/* restore callee-saved registers */
142	ldo	48(%arg0), %r1
143	ldwm	4(%r1), %r3
144	ldwm	4(%r1), %r4
145	ldwm	4(%r1), %r5
146	ldwm	4(%r1), %r6
147	ldwm	4(%r1), %r7
148	ldwm	4(%r1), %r8
149	ldwm	4(%r1), %r9
150	ldwm	4(%r1), %r10
151	ldwm	4(%r1), %r11
152	ldwm	4(%r1), %r12
153	ldwm	4(%r1), %r13
154	ldwm	4(%r1), %r14
155	ldwm	4(%r1), %r15
156	ldwm	4(%r1), %r16
157	ldwm	4(%r1), %r17
158	ldwm	4(%r1), %r18
159
160	/* restore the rest */
161#ifdef __PIC__
162	addil	LT%.L__jmpxor, %r19
163	ldw	RT%.L__jmpxor(%r1), %t2
164#else
165	ldil	L%.L__jmpxor, t1
166	ldo	R%.L__jmpxor(t1), t2
167#endif
168	ldw	0(t2), t1		; xor for r2/rp
169	ldw	4(t2), t2		; xor for r30/sp, overwrite address
170
171	ldw	12(%arg0), %r1
172	xor	%r1, %t2, %sp
173	ldw	20(%arg0), %r1
174	xor	%r1, %t1, %rp
175	copy	%r0, %t1		; overwrite the cookies
176	copy	%r0, %t2
177	sub,<>	%arg1, %r0, %r0
178	ldo	1(%arg1), %arg1
179	bv	%r0(%rp)
180	 copy	%arg1, %ret0
181EXIT(siglongjmp)
182	.size _longjmp, . - _longjmp
183	.size longjmp, . - longjmp
184
185	.end
186