_setjmp.S revision 1.2
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	.text
33	.string "$OpenBSD: _setjmp.S,v 1.2 2002/09/18 05:03:54 smurph Exp $\0"
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/*
64int _setjmp(jmp_buf env);
65 */
66ENTRY(_setjmp)
67	st	r1, r2,0	/* save registers to the environment buffer */
68	st	r0, r2,4	/* no signal set */
69	st	r14,r2,8
70	st	r15,r2,12
71	st	r16,r2,16
72	st	r17,r2,20
73	st	r18,r2,24
74	st	r19,r2,28
75	st	r20,r2,32
76	st	r21,r2,36
77	st	r22,r2,40
78	st	r23,r2,44
79	st	r24,r2,48
80	st	r25,r2,52
81	st	r26,r2,56
82	st	r27,r2,60
83	st	r28,r2,64
84	st	r29,r2,68
85	st	r30,r2,72
86	st	r31,r2,76
87	st	r0,r2,80	/* mark environment as NOT returned (0x0) */
88	or	r4,r0,0		/* clear r4 */
89	or	r4,r0,SETJMP_TYPE2	/* r4 now contains setjmp type */
90	st	r4,r2,84	/* setjmp type to _setjmp */
91	jmp.n	r1		/* retrun 0 */
92	or	r2,r0,0
93
94/*
95void _longjmp(jmp_buf env, int val);
96 */
97ENTRY(_longjmp)
98	cpm	r4,r2,0x0	/* check for bad envnvironment buffer address. */
99	bb1	eq,r4,2f	/* if == 0, abort. */
100	ld	r4,r2,80	/* check if environment buffer has */
101	cpm	r4,r4,0x0	/* already returned. */
102	bb1	ne,r4,2f	/* if != 0, abort. */
103	ld	r4,r2,84	/* check setjmp type. */
104	cpm	r4,r4,SETJMP_TYPE2	/* should be SETJMP_TYPE2 */
105	bb1	ne,r4,2f	/* if != SETJMP_TYPE2, abort. */
106
107	ld	r14,r2,8	/* restore registers from the environment buffer */
108	ld	r15,r2,12
109	ld	r16,r2,16
110	ld	r17,r2,20
111	ld	r18,r2,24
112	ld	r19,r2,28
113	ld	r20,r2,32
114	ld	r21,r2,36
115	ld	r22,r2,40
116	ld	r23,r2,44
117	ld	r24,r2,48
118	ld	r25,r2,52
119	ld	r26,r2,56
120	ld	r27,r2,60
121	ld	r28,r2,64
122	ld	r29,r2,68
123	ld	r30,r2,72
124	ld	r31,r2,76
125	or	r4,r0,1
126	st	r4,r2,80	/* mark environment buffer as returned */
127	ld	r1,r2,0		/* restore r1 */
128	cmp	r2,r3,0		/* test retval for 0 */
129	bb0	eq,r2,1f	/* if != 0, it's ok. */
130	jmp.n	r1		/* and jump to it */
131	or	r2,r0,r3	/* but first return r3 value */
1321:	jmp.n	r1
133	or	r2,r0,1		/* return non-zero value. */
1342:
135	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