_setjmp.S revision 1.7
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.7 2004/07/28 08:49:03 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 21 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] setjmp type 57 * 58 */ 59 60#include <machine/setjmp.h> 61 62#define U_SETJMP_SIG 0x1764 63 64/* 65int _setjmp(jmp_buf env); 66 */ 67ENTRY(_setjmp) 68 st r1, r2,0 /* save registers to the environment buffer */ 69 st r0, r2,4 /* no signal set */ 70 st r14,r2,8 71 st r15,r2,12 72 st r16,r2,16 73 st r17,r2,20 74 st r18,r2,24 75 st r19,r2,28 76 st r20,r2,32 77 st r21,r2,36 78 st r22,r2,40 79 st r23,r2,44 80 st r24,r2,48 81 st r25,r2,52 82 st r26,r2,56 83 st r27,r2,60 84 st r28,r2,64 85 st r29,r2,68 86 st r30,r2,72 87 st r31,r2,76 88 or r4,r0,0 /* clear r4 */ 89 or r4,r0,U_SETJMP_SIG /* r4 now contains setjmp type */ 90 st r4,r2,80 /* setjmp type to _setjmp */ 91 jmp.n r1 /* return 0 */ 92 or r2,r0,0 93 94/* 95void _longjmp(jmp_buf env, int val); 96 */ 97ENTRY(_longjmp) 98 cmp r4,r2,r0 /* check for bad environment buffer address. */ 99 bb1 eq,r4,2f /* if == 0, abort. */ 100 ld r4,r2,80 /* check setjmp type. */ 101 cmp r4,r4,U_SETJMP_SIG /* should be U_SETJMP_SIG */ 102 bb1 ne,r4,2f /* if != U_SETJMP_SIG, abort. */ 103 104 ld r14,r2,8 /* restore registers from the environment buffer */ 105 ld r15,r2,12 106 ld r16,r2,16 107 ld r17,r2,20 108 ld r18,r2,24 109 ld r19,r2,28 110 ld r20,r2,32 111 ld r21,r2,36 112 ld r22,r2,40 113 ld r23,r2,44 114 ld r24,r2,48 115 ld r25,r2,52 116 ld r26,r2,56 117 ld r27,r2,60 118 ld r28,r2,64 119 ld r29,r2,68 120 ld r30,r2,72 121 ld r31,r2,76 122 ld r1,r2,0 /* restore r1 */ 123 bcnd.n ne0,r3,1f 124 or r2,r3,r0 125 or r2,r0,1 /* never return zero! */ 1261: jmp r1 127 1282: subu r31,r31,16 /* get a temporary stack */ 129 st r1,r31,0 /* save r1 on stack (return address) */ 130 bsr _C_LABEL(longjmperror) 131 bsr _C_LABEL(abort) /* NO RETURN */ 132 ld r1,r31,0 /* restore r1 from stack */ 133 jmp.n r1 /* this should not happen but we are prepared */ 134 addu r31,r31,16 /* restore the stack */ 135 136