_setjmp.S revision 1.5
1/*-
2 * Copyright (c) 2002 Steve Murphree, Jr.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by Steve Murphree, Jr.
16 * 4. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
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#if defined(LIBC_SCCS)
32	.data
33	.string "$OpenBSD: _setjmp.S,v 1.5 2003/01/07 22:01:29 miod Exp $"
34#endif /* LIBC_SCCS */
35
36#include "SYS.h"
37
38/*
39 * C library -- _setjmp, _longjmp
40 *
41 *	_longjmp(a,v)
42 * will generate a "return(v)" from
43 * the last call to
44 *	_setjmp(a)
45 * by restoring registers from the stack,
46 * The previous signal state is NOT saved
47 * or restored.
48 *
49 * For m88k, we define our jmp_buf length
50 * to be the size of 22 longs.  <machine/setjmp.h>
51 * The buffer's usage is as follows:
52 *
53 * jmp_buf[0]		return address
54 * jmp_buf[1]		signal set (if used)
55 * jmp_buf[2 to 19]	r14 to r31
56 * jmp_buf[20]		'used' flag
57 * jmp_buf[21]		setjmp type
58 *
59 */
60
61#include <machine/setjmp.h>
62
63#define	U_SETJMP_SIG	0x1764
64
65/*
66int _setjmp(jmp_buf env);
67 */
68ENTRY(_setjmp)
69	st	r1, r2,0	/* save registers to the environment buffer */
70	st	r0, r2,4	/* no signal set */
71	st	r14,r2,8
72	st	r15,r2,12
73	st	r16,r2,16
74	st	r17,r2,20
75	st	r18,r2,24
76	st	r19,r2,28
77	st	r20,r2,32
78	st	r21,r2,36
79	st	r22,r2,40
80	st	r23,r2,44
81	st	r24,r2,48
82	st	r25,r2,52
83	st	r26,r2,56
84	st	r27,r2,60
85	st	r28,r2,64
86	st	r29,r2,68
87	st	r30,r2,72
88	st	r31,r2,76
89	st	r0,r2,80	/* mark environment as NOT returned (0x0) */
90	or	r4,r0,0		/* clear r4 */
91	or	r4,r0,U_SETJMP_SIG	/* r4 now contains setjmp type */
92	st	r4,r2,84	/* setjmp type to _setjmp */
93	jmp.n	r1		/* return 0 */
94	 or	r2,r0,0
95
96/*
97void _longjmp(jmp_buf env, int val);
98 */
99ENTRY(_longjmp)
100	cmp	r4,r2,r0	/* check for bad environment buffer address. */
101	bb1	eq,r4,2f	/* if == 0, abort. */
102	ld	r4,r2,80	/* check if environment buffer has */
103	cmp	r4,r4,r0	/* already returned. */
104	bb1	ne,r4,2f	/* if != 0, abort. */
105	ld	r4,r2,84	/* check setjmp type. */
106	cmp	r4,r4,U_SETJMP_SIG	/* should be U_SETJMP_SIG */
107	bb1	ne,r4,2f	/* if != U_SETJMP_SIG, abort. */
108
109	ld	r14,r2,8	/* restore registers from the environment buffer */
110	ld	r15,r2,12
111	ld	r16,r2,16
112	ld	r17,r2,20
113	ld	r18,r2,24
114	ld	r19,r2,28
115	ld	r20,r2,32
116	ld	r21,r2,36
117	ld	r22,r2,40
118	ld	r23,r2,44
119	ld	r24,r2,48
120	ld	r25,r2,52
121	ld	r26,r2,56
122	ld	r27,r2,60
123	ld	r28,r2,64
124	ld	r29,r2,68
125	ld	r30,r2,72
126	ld	r31,r2,76
127	or	r4,r0,1
128	st	r4,r2,80	/* mark environment buffer as returned */
129	ld	r1,r2,0		/* restore r1 */
130	bcnd.n	ne0,r3,1f
131	 or	r2,r3,r0
132	or	r2,r0,1		/* never return zero! */
1331:	jmp	r1
134
1352:	subu	r31,r31,32	/* get a temporary stack */
136	st	r1,r31,20	/* save r1 on stack (return address) */
137	bsr	_C_LABEL(longjmperror)
138	bsr	_C_LABEL(abort)	/* NO RETURN */
139	ld	r1,r31,20	/* restore r1 from stack */
140	addu	r31,r31,32	/* restore the stack */
141	jmp	r1	/* this should not happen but we are prepared */
142
143