_setjmp.S revision 1.8
1/* $OpenBSD: _setjmp.S,v 1.8 2005/08/07 16:40:14 espie Exp $ */ 2/*- 3 * Copyright (c) 2002 Steve Murphree, Jr. 4 * All rights reserved. 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 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Steve Murphree, Jr. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include "SYS.h" 33 34/* 35 * C library -- _setjmp, _longjmp 36 * 37 * _longjmp(a,v) 38 * will generate a "return(v)" from 39 * the last call to 40 * _setjmp(a) 41 * by restoring registers from the stack, 42 * The previous signal state is NOT saved 43 * or restored. 44 * 45 * For m88k, we define our jmp_buf length 46 * to be the size of 21 longs. <machine/setjmp.h> 47 * The buffer's usage is as follows: 48 * 49 * jmp_buf[0] return address 50 * jmp_buf[1] signal set (if used) 51 * jmp_buf[2 to 19] r14 to r31 52 * jmp_buf[20] setjmp type 53 * 54 */ 55 56#include <machine/setjmp.h> 57 58#define U_SETJMP_SIG 0x1764 59 60/* 61int _setjmp(jmp_buf env); 62 */ 63ENTRY(_setjmp) 64 st r1, r2,0 /* save registers to the environment buffer */ 65 st r0, r2,4 /* no signal set */ 66 st r14,r2,8 67 st r15,r2,12 68 st r16,r2,16 69 st r17,r2,20 70 st r18,r2,24 71 st r19,r2,28 72 st r20,r2,32 73 st r21,r2,36 74 st r22,r2,40 75 st r23,r2,44 76 st r24,r2,48 77 st r25,r2,52 78 st r26,r2,56 79 st r27,r2,60 80 st r28,r2,64 81 st r29,r2,68 82 st r30,r2,72 83 st r31,r2,76 84 or r4,r0,0 /* clear r4 */ 85 or r4,r0,U_SETJMP_SIG /* r4 now contains setjmp type */ 86 st r4,r2,80 /* setjmp type to _setjmp */ 87 jmp.n r1 /* return 0 */ 88 or r2,r0,0 89 90/* 91void _longjmp(jmp_buf env, int val); 92 */ 93ENTRY(_longjmp) 94 cmp r4,r2,r0 /* check for bad environment buffer address. */ 95 bb1 eq,r4,2f /* if == 0, abort. */ 96 ld r4,r2,80 /* check setjmp type. */ 97 cmp r4,r4,U_SETJMP_SIG /* should be U_SETJMP_SIG */ 98 bb1 ne,r4,2f /* if != U_SETJMP_SIG, abort. */ 99 100 ld r14,r2,8 /* restore registers from the environment buffer */ 101 ld r15,r2,12 102 ld r16,r2,16 103 ld r17,r2,20 104 ld r18,r2,24 105 ld r19,r2,28 106 ld r20,r2,32 107 ld r21,r2,36 108 ld r22,r2,40 109 ld r23,r2,44 110 ld r24,r2,48 111 ld r25,r2,52 112 ld r26,r2,56 113 ld r27,r2,60 114 ld r28,r2,64 115 ld r29,r2,68 116 ld r30,r2,72 117 ld r31,r2,76 118 ld r1,r2,0 /* restore r1 */ 119 bcnd.n ne0,r3,1f 120 or r2,r3,r0 121 or r2,r0,1 /* never return zero! */ 1221: jmp r1 123 1242: subu r31,r31,16 /* get a temporary stack */ 125 st r1,r31,0 /* save r1 on stack (return address) */ 126 bsr _C_LABEL(longjmperror) 127 bsr _C_LABEL(abort) /* NO RETURN */ 128 ld r1,r31,0 /* restore r1 from stack */ 129 jmp.n r1 /* this should not happen but we are prepared */ 130 addu r31,r31,16 /* restore the stack */ 131 132