xref: /openbsd-src/lib/libc/arch/powerpc/gen/setjmp.S (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1/*	$OpenBSD: setjmp.S,v 1.5 2004/03/01 18:05:50 drahn 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/* int setjmp(jmp_buf env) */
31
32#define JMP_r1	0x04
33#define JMP_r14	0x08
34#define JMP_r15	0x0c
35#define JMP_r16	0x10
36#define JMP_r17	0x14
37#define JMP_r18	0x18
38#define JMP_r19	0x1c
39#define JMP_r20	0x20
40#define JMP_r21	0x24
41#define JMP_r22	0x28
42#define JMP_r23	0x2c
43#define JMP_r24	0x30
44#define JMP_r25	0x34
45#define JMP_r26	0x38
46#define JMP_r27	0x3c
47#define JMP_r28	0x40
48#define JMP_r29	0x44
49#define JMP_r30	0x48
50#define JMP_r31	0x4c
51#define JMP_lr  0x50
52#define JMP_cr  0x54
53#define JMP_ctr	0x58
54#define JMP_xer	0x5c
55#define JMP_sig	0x60
56
57
58.extern sigblock
59
60ENTRY(setjmp)
61	/* r31, mask */
62	stw 31, JMP_r31(3)
63	mflr 0
64	stw 0, JMP_lr(3)
65	mr 31, 3
66	li 3, 0
67	bl PIC_PLT(sigblock)
68	stw 3, JMP_sig(31)
69	/* should sigstack be checked and saved */
70	mr 3, 31
71	lwz 0, JMP_lr(3)
72	mtlr 0
73	lwz 31, JMP_r31(3)
74ENTRY(_setjmp)
75	stw 31, JMP_r31(3)
76	/* r1, r14-r30 */
77	stw 1,  JMP_r1 (3)
78	stw 14, JMP_r14(3)
79	stw 15, JMP_r15(3)
80	stw 16, JMP_r16(3)
81	stw 17, JMP_r17(3)
82	stw 18, JMP_r18(3)
83	stw 19, JMP_r19(3)
84	stw 20, JMP_r20(3)
85	stw 21, JMP_r21(3)
86	stw 22, JMP_r22(3)
87	stw 23, JMP_r23(3)
88	stw 24, JMP_r24(3)
89	stw 25, JMP_r25(3)
90	stw 26, JMP_r26(3)
91	stw 27, JMP_r27(3)
92	stw 28, JMP_r28(3)
93	stw 29, JMP_r29(3)
94	stw 30, JMP_r30(3)
95	/* cr, lr, ctr, xer */
96	mfcr 0
97	stw 0, JMP_cr(3)
98	mflr 0
99	stw 0, JMP_lr(3)
100	mfctr 0
101	stw 0, JMP_ctr(3)
102	mfxer 0
103	stw 0, JMP_xer(3)
104	/* f14-f31, fpscr */
105	li 3, 0
106	blr
107
108
109.extern sigsetmask
110ENTRY(longjmp)
111	/* r31, mask */
112	mr 30, 3
113	mr 31, 4
114	lwz 3, JMP_sig(3)
115	bl PIC_PLT(sigsetmask)
116	/* should we deal with sigonstack here ?? */
117	mr 4, 31
118	mr 3, 30
119ENTRY(_longjmp)
120	lwz 31, JMP_r31(3)
121	/* r1, r14-r30 */
122	lwz 1,  JMP_r1 (3)
123	lwz 14, JMP_r14(3)
124	lwz 15, JMP_r15(3)
125	lwz 16, JMP_r16(3)
126	lwz 17, JMP_r17(3)
127	lwz 18, JMP_r18(3)
128	lwz 19, JMP_r19(3)
129	lwz 20, JMP_r20(3)
130	lwz 21, JMP_r21(3)
131	lwz 22, JMP_r22(3)
132	lwz 23, JMP_r23(3)
133	lwz 24, JMP_r24(3)
134	lwz 25, JMP_r25(3)
135	lwz 26, JMP_r26(3)
136	lwz 27, JMP_r27(3)
137	lwz 28, JMP_r28(3)
138	lwz 29, JMP_r29(3)
139	lwz 30, JMP_r30(3)
140	/* cr, lr, ctr, xer */
141	lwz 0, JMP_cr(3)
142	mtcr 0
143	lwz 0, JMP_lr(3)
144	mtlr 0
145	lwz 0, JMP_ctr(3)
146	mtctr 0
147	lwz 0, JMP_xer(3)
148	mtxer 0
149	/* f14-f31, fpscr */
150
151	/* if r4 == 0, return 1, not 0 */
152	mr	3, 4
153	cmpwi	4,0
154	bne	1f
155	li	3, 1
1561:
157	blr
158