1/*	$OpenBSD: setjmp.S,v 1.11 2022/12/08 01:25:45 guenther Exp $	*/
2/* kernel version of this file, does not have signal goop */
3/* int setjmp(jmp_buf env) */
4
5/*
6 * Copyright (c) 1996 Dale Rahn.
7 * All rights reserved.
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <machine/asm.h>
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
58ENTRY(setjmp)
59	mflr %r12
60	RETGUARD_SETUP_LATE(setjmp, %r11, %r12)
61	stw %r31, JMP_r31(%r3)
62	/* r1, r14-r30 */
63	stw %r1,  JMP_r1 (%r3)
64	stw %r14, JMP_r14(%r3)
65	stw %r15, JMP_r15(%r3)
66	stw %r16, JMP_r16(%r3)
67	stw %r17, JMP_r17(%r3)
68	stw %r18, JMP_r18(%r3)
69	stw %r19, JMP_r19(%r3)
70	stw %r20, JMP_r20(%r3)
71	stw %r21, JMP_r21(%r3)
72	stw %r22, JMP_r22(%r3)
73	stw %r23, JMP_r23(%r3)
74	stw %r24, JMP_r24(%r3)
75	stw %r25, JMP_r25(%r3)
76	stw %r26, JMP_r26(%r3)
77	stw %r27, JMP_r27(%r3)
78	stw %r28, JMP_r28(%r3)
79	stw %r29, JMP_r29(%r3)
80	stw %r30, JMP_r30(%r3)
81	/* cr, lr, ctr, xer */
82	mfcr %r0
83	stw %r0, JMP_cr(%r3)
84	stw %r12, JMP_lr(%r3)
85	mfctr %r0
86	stw %r0, JMP_ctr(%r3)
87	mfxer %r0
88	stw %r0, JMP_xer(%r3)
89	/* f14-f31, fpscr */
90	li %r3, 0
91	RETGUARD_CHECK(setjmp, %r11, %r12)
92	blr
93
94
95ENTRY(longjmp)
96	/* lr, r31 */
97	lwz %r12, JMP_lr(%r3)
98	RETGUARD_SETUP_LATE(longjmp, %r11, %r12)
99	mtlr %r12
100	lwz %r31, JMP_r31(%r3)
101	/* r1, r14-r30 */
102	lwz %r1,  JMP_r1 (%r3)
103	lwz %r14, JMP_r14(%r3)
104	lwz %r15, JMP_r15(%r3)
105	lwz %r16, JMP_r16(%r3)
106	lwz %r17, JMP_r17(%r3)
107	lwz %r18, JMP_r18(%r3)
108	lwz %r19, JMP_r19(%r3)
109	lwz %r20, JMP_r20(%r3)
110	lwz %r21, JMP_r21(%r3)
111	lwz %r22, JMP_r22(%r3)
112	lwz %r23, JMP_r23(%r3)
113	lwz %r24, JMP_r24(%r3)
114	lwz %r25, JMP_r25(%r3)
115	lwz %r26, JMP_r26(%r3)
116	lwz %r27, JMP_r27(%r3)
117	lwz %r28, JMP_r28(%r3)
118	lwz %r29, JMP_r29(%r3)
119	lwz %r30, JMP_r30(%r3)
120	/* cr, ctr, xer */
121	lwz %r0, JMP_cr(%r3)
122	mtcr %r0
123	lwz %r0, JMP_ctr(%r3)
124	mtctr %r0
125	lwz %r0, JMP_xer(%r3)
126	mtxer %r0
127	/* f14-f31, fpscr */
128	li %r3, 1
129	RETGUARD_CHECK(longjmp, %r11, %r12)
130	blr
131