xref: /openbsd/lib/libc/arch/powerpc/gen/sigsetjmp.S (revision 09467b48)
1/*	$OpenBSD: sigsetjmp.S,v 1.7 2016/05/22 23:56:30 guenther Exp $ */
2/*
3 * Copyright (c) 1996 Dale Rahn. All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "SYS.h"
28#include <machine/asm.h>
29
30#define JMP_sigflag	0x00
31#define JMP_r1		0x04
32#define JMP_r14		0x08
33#define JMP_r15		0x0c
34#define JMP_r16		0x10
35#define JMP_r17		0x14
36#define JMP_r18		0x18
37#define JMP_r19		0x1c
38#define JMP_r20		0x20
39#define JMP_r21		0x24
40#define JMP_r22		0x28
41#define JMP_r23		0x2c
42#define JMP_r24		0x30
43#define JMP_r25		0x34
44#define JMP_r26		0x38
45#define JMP_r27		0x3c
46#define JMP_r28		0x40
47#define JMP_r29		0x44
48#define JMP_r30		0x48
49#define JMP_r31		0x4c
50#define JMP_lr		0x50
51#define JMP_cr		0x54
52#define JMP_ctr		0x58
53#define JMP_xer		0x5c
54#define JMP_sigmask	0x60
55
56	.extern	__jmpxor
57
58/* int sigsetjmp(sigjmp_buf env, int savemask) */
59ENTRY(sigsetjmp)
60	mr	5, 3			/* save jmpbuf addr in r5 */
61	stw	4, JMP_sigflag(5)
62	or.	4, 4, 4
63	beq	1f
64	li	3, 1			/* how = SIG_BLOCK */
65	li	4, 0			/* oset = empty */
66	li	0, SYS_sigprocmask
67	sc
68	stw	3, JMP_sigmask(5)
691:	mflr	6
70	bcl	20, 31, 2f
712:	mflr	7
72	addis	7, 7, __jmpxor-2b@ha
73	addi	7, 7, __jmpxor-2b@l
74	mtlr	6
75	lwz	0, 0(7)			/* xor for r1 */
76	lwz	7, 4(7)			/* xor for lr, overwrite addr */
77
78	/* r1, r14-r31 */
79	xor  0, 0, 1			/* use and overwrite the r1 xor */
80	/* "mflr 6" done at 1: above */
81	xor  7, 6, 7			/* use and overwrite the lr xor */
82	stw 7, JMP_lr(5)
83	stw  0, JMP_r1 (5)
84	stw 14, JMP_r14(5)
85	stw 15, JMP_r15(5)
86	stw 16, JMP_r16(5)
87	stw 17, JMP_r17(5)
88	stw 18, JMP_r18(5)
89	stw 19, JMP_r19(5)
90	stw 20, JMP_r20(5)
91	stw 21, JMP_r21(5)
92	stw 22, JMP_r22(5)
93	stw 23, JMP_r23(5)
94	stw 24, JMP_r24(5)
95	stw 25, JMP_r25(5)
96	stw 26, JMP_r26(5)
97	stw 27, JMP_r27(5)
98	stw 28, JMP_r28(5)
99	stw 29, JMP_r29(5)
100	stw 30, JMP_r30(5)
101	stw 31, JMP_r31(5)
102	/* cr, lr, ctr, xer */
103	mfcr 0
104	stw 0, JMP_cr(5)
105	mfctr 0
106	stw 0, JMP_ctr(5)
107	mfxer 0
108	stw 0, JMP_xer(5)
109	/* f14-f31, fpscr */
110	li 3, 0
111	blr
112END(sigsetjmp)
113
114
115/* int siglongjmp(sigjmp_buf env, int val) */
116ENTRY(siglongjmp)
117	mr	5, 3			/* save jmpbuf addr in r5 */
118	mr	6, 4			/* save val in r6 */
119	lwz	4, JMP_sigflag(5)	/* do we need to restore sigmask? */
120	or.	4, 4, 4
121	beq	1f
122
123	li	3, 3			/* how = SIG_SETMASK */
124	lwz	4, JMP_sigmask(5)	/* oset from the jmpbuf */
125	li	0, SYS_sigprocmask
126	sc
127
1281:	bcl	20, 31, 2f
1292:	mflr	9
130	addis	9, 9, __jmpxor-2b@ha
131	addi	9, 9, __jmpxor-2b@l
132	lwz	8, 0(9)			/* xor for r1 */
133	lwz	9, 4(9)			/* xor for lr, overwrite addr */
134
135	/* r1, r14-r31 */
136	lwz  0, JMP_r1(5)
137	xor  1, 0, 8			/* use the r1 xor */
138	lwz 14, JMP_r14(5)
139	lwz 15, JMP_r15(5)
140	lwz 16, JMP_r16(5)
141	lwz 17, JMP_r17(5)
142	lwz 18, JMP_r18(5)
143	lwz 19, JMP_r19(5)
144	lwz 20, JMP_r20(5)
145	lwz 21, JMP_r21(5)
146	lwz 22, JMP_r22(5)
147	lwz 23, JMP_r23(5)
148	lwz 24, JMP_r24(5)
149	lwz 25, JMP_r25(5)
150	lwz 26, JMP_r26(5)
151	lwz 27, JMP_r27(5)
152	lwz 28, JMP_r28(5)
153	lwz 29, JMP_r29(5)
154	lwz 30, JMP_r30(5)
155	lwz 31, JMP_r31(5)
156	/* cr, lr, ctr, xer */
157	lwz 8, JMP_cr(5)		/* overwrite the r1 xor */
158	mtcr 8
159	lwz 0, JMP_lr(5)
160	xor  0, 0, 9			/* use the lr xor */
161	mtlr 0
162	lwz 9, JMP_ctr(5)		/* overwrite the lr xor */
163	mtctr 9
164	lwz 0, JMP_xer(5)
165	mtxer 0
166	/* f14-f31, fpscr */
167
168	/* if r6 == 0, return 1, not 0 */
169	mr	3, 6
170	cmpwi	6, 0
171	bnelr
172	li	3, 1
173	blr
174END(siglongjmp)
175