1/* $OpenBSD: _setjmp.S,v 1.2 2001/08/20 20:15:29 jason Exp $ */ 2/* $NetBSD: _setjmp.S,v 1.1.1.1 1998/06/20 05:18:14 eeh Exp $ */ 3 4/* 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This software was developed by the Computer Systems Engineering group 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 10 * contributed to Berkeley. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp 41 */ 42 43#if defined(LIBC_SCCS) && !defined(lint) 44#ifdef notdef 45 .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" 46#endif 47 .asciz "$NetBSD: _setjmp.S,v 1.1.1.1 1998/06/20 05:18:14 eeh Exp $" 48#endif /* LIBC_SCCS and not lint */ 49 50/* 51 * C library -- _setjmp, _longjmp 52 * 53 * _longjmp(a,v) 54 * will generate a "return(v?v:1)" from 55 * the last call to 56 * _setjmp(a) 57 * by unwinding the call stack. 58 * The previous signal state is NOT restored. 59 */ 60 61#include "DEFS.h" 62 63ENTRY(_setjmp) 64 btst 1, %sp 65 bne,a,pt %xcc, 1f ! 32 or 64-bit stack? 66 std %sp, [%o0+0] ! 32-bit stack pointer & return pc 67 68 stx %sp, [%o0+0] ! 64-bit stack pointer 69 stx %o7, [%o0+8] ! 64-bit return pc 70 stx %fp, [%o0+16] ! 64-bit frame pointer 71 retl 72 clr %o0 731: 74 st %fp, [%o0+8] ! 32-bit frame pointer 75 retl 76 clr %o0 77 78ENTRY(_longjmp) 79 set 1, %g6 80 btst 1, %fp ! 32 or 64-bit stack? 81 movrz %o1, %o1, %g6 ! compute v ? v : 1 in a global register 82 bne,pt %xcc, 2f ! 64-bit 83 mov %o0, %g1 ! save a in another global register 84 ld [%g1+8], %g7 /* get caller's frame */ 85 861: 87 cmp %fp, %g7 ! compare against desired frame 88 bl,a 1b ! if below, 89 restore ! pop frame and loop 90 bne,pn %icc, Llongjmpbotch ! if there, 91 ldd [%g1+0], %o2 ! fetch return %sp and pc, and get out 92 ba,a,pt %icc, 4f 932: 94 ldx [%g1+16], %g7 /* get caller's frame */ 95 963: 97 cmp %fp, %g7 ! compare against desired frame 98 bl,a,pt %xcc, 3b ! if below, 99 restore ! pop frame and loop 100 bne,pn %xcc, Llongjmpbotch ! if there, 101 ldx [%g1+0], %o2 ! fetch return %sp and pc, and get out 102 ldx [%g1+8], %o3 1034: 104 cmp %o2, %sp ! %sp must not decrease 105 blt,pn %icc, Llongjmpbotch 106 movge %icc, %o2, %sp ! it is OK, put it in place 107 jmp %o3 + 8 ! success, return %g6 108 mov %g6, %o0 109 110Lbotch: 111 call _longjmperror ! otherwise, went too far; bomb out 112 nop 113 unimp 0 114 ! otherwise, went too far; bomb out 115 116 117 118 119