_setjmp.S revision 85518
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1992, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * This software was developed by the Computer Systems Engineering group 61558Srgrimes * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 71558Srgrimes * contributed to Berkeley. 81558Srgrimes * 91558Srgrimes * Redistribution and use in source and binary forms, with or without 101558Srgrimes * modification, are permitted provided that the following conditions 111558Srgrimes * are met: 121558Srgrimes * 1. Redistributions of source code must retain the above copyright 131558Srgrimes * notice, this list of conditions and the following disclaimer. 141558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151558Srgrimes * notice, this list of conditions and the following disclaimer in the 161558Srgrimes * documentation and/or other materials provided with the distribution. 171558Srgrimes * 3. All advertising materials mentioning features or use of this software 181558Srgrimes * must display the following acknowledgement: 191558Srgrimes * This product includes software developed by the University of 201558Srgrimes * California, Berkeley and its contributors. 211558Srgrimes * 4. Neither the name of the University nor the names of its contributors 221558Srgrimes * may be used to endorse or promote products derived from this software 231558Srgrimes * without specific prior written permission. 241558Srgrimes * 251558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 357585Sbde * SUCH DAMAGE. 361558Srgrimes * 371558Srgrimes * from: Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp 381558Srgrimes */ 391558Srgrimes 401558Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 411558Srgrimes#if 0 421558Srgrimes .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" 431558Srgrimes#else 441558Srgrimes RCSID("$NetBSD: _setjmp.S,v 1.4 1998/10/08 02:27:59 eeh Exp $") 457585Sbde#endif 467585Sbde#endif /* LIBC_SCCS and not lint */ 471558Srgrimes 481558Srgrimes#if defined(SYSLIBC_RCS) && !defined(lint) 491558Srgrimes .text 501558Srgrimes .asciz "$FreeBSD: head/lib/libc/sparc64/gen/_setjmp.S 85518 2001-10-26 05:40:07Z jake $" 511558Srgrimes#endif /* SYSLIBC_RCS and not lint */ 527585Sbde 537585Sbde#include <machine/asm.h> 547585Sbde 551558Srgrimes/* 561558Srgrimes * C library -- _setjmp, _longjmp 571558Srgrimes * 581558Srgrimes * _longjmp(a,v) 591558Srgrimes * will generate a "return(v?v:1)" from 601558Srgrimes * the last call to 611558Srgrimes * _setjmp(a) 621558Srgrimes * by unwinding the call stack. 631558Srgrimes * The previous signal state is NOT restored. 641558Srgrimes */ 651558Srgrimes 661558Srgrimes#define JB_SP 0x0 671558Srgrimes#define JB_PC 0x8 681558Srgrimes#define JB_FP 0x10 691558Srgrimes 701558SrgrimesENTRY(_setjmp) 711558Srgrimes stx %sp, [%o0 + JB_SP] /* store caller's stack pointer */ 721558Srgrimes stx %o7, [%o0 + JB_PC] /* ... return pc */ 731558Srgrimes stx %fp, [%o0 + JB_FP] /* ... and frame pointer */ 741558Srgrimes retl 751558Srgrimes clr %o0 ! return 0 767585Sbde 771558SrgrimesENTRY(_longjmp) 781558Srgrimes mov 1, %g6 791558Srgrimes movrnz %o1, %o1, %g6 ! compute v ? v : 1 in a global register 801558Srgrimes mov %o0, %g1 ! save a in another global register 811558Srgrimes ldx [%g1 + JB_FP], %g7 /* get caller's frame */ 821558Srgrimes1: cmp %fp, %g7 ! compare against desired frame 831558Srgrimes bl,a 1b ! if below, 841558Srgrimes restore ! pop frame and loop 851558Srgrimes be,a 2f ! if there, 861558Srgrimes ldx [%g1 + JB_SP], %o2 ! fetch return %sp 871558Srgrimes 881558Srgrimes.Lbotch: 891558Srgrimes call CNAME(longjmperror) ! otherwise, went too far; bomb out 901558Srgrimes nop 911558Srgrimes illtrap 921558Srgrimes 931558Srgrimes2: cmp %o2, %sp ! %sp must not decrease 941558Srgrimes bge,a 3f 951558Srgrimes mov %o2, %sp ! it is OK, put it in place 961558Srgrimes b,a .Lbotch 971558Srgrimes nop 981558Srgrimes3: ldx [%g1 + JB_PC], %o3 ! fetch pc 991558Srgrimes jmp %o3 + 8 ! success, return %g6 1001558Srgrimes mov %g6, %o0 1011558Srgrimes 1021558Srgrimes