1/* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Modified for incorporation into newlib by Joel Sherrill 6 * (joel@OARcorp.com), On-Line Applications Research, 1995. 7 * Did the following: 8 * + merged in DEFS.h 9 * + removed error check since it prevented using this setjmp 10 * to "context switch" 11 * + added the support for the "user label" and "register" prefix 12 * 13 * This software was developed by the Computer Systems Engineering group 14 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 15 * contributed to Berkeley. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * from: $Header$ 42 */ 43 44#if defined(LIBC_SCCS) && !defined(lint) 45 .asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93" 46#endif /* LIBC_SCCS and not lint */ 47 48/* 49 * Recent versions of GNU cpp define variables which indicate the 50 * need for underscores and percents. If not using GNU cpp or 51 * the version does not support this, then you will obviously 52 * have to define these as appropriate. 53 */ 54 55#ifndef __USER_LABEL_PREFIX__ 56#define __USER_LABEL_PREFIX__ _ 57#endif 58 59#ifndef __REGISTER_PREFIX__ 60#define __REGISTER_PREFIX__ 61#endif 62 63/* ANSI concatenation macros. */ 64 65#define CONCAT1(a, b) CONCAT2(a, b) 66#define CONCAT2(a, b) a ## b 67 68/* Use the right prefix for global labels. */ 69 70#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) 71 72/********************************************************************* 73 ********************************************************************* 74 * Contents of DEFS.h * 75 ********************************************************************* 76 *********************************************************************/ 77 78#ifdef PROF 79#define ENTRY(x) \ 80 .align 4; .globl SYM(x); .proc 1; SYM(x):; .data; .align 4; 1: .long 0; \ 81 .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call mcount; \ 82 or %lo(1b),%o0,%o0; restore 83#else 84#define ENTRY(x) \ 85 .align 4; .globl SYM(x); .proc 1; SYM(x): 86#endif 87 88 89 90/********************************************************************* 91 ********************************************************************* 92 * END of DEFS.h * 93 ********************************************************************* 94 *********************************************************************/ 95 96 97/* 98 * C library -- _setjmp, _longjmp 99 * 100 * _longjmp(a,v) 101 * will generate a "return(v?v:1)" from 102 * the last call to 103 * _setjmp(a) 104 * by unwinding the call stack. 105 * The previous signal state is NOT restored. 106 */ 107 108 109/* #include "DEFS.h" */ 110 111ENTRY(setjmp) 112ENTRY(_setjmp) 113 st %sp, [%o0] /* caller's stack pointer */ 114 st %i7, [%o0+4] /* caller's return pc */ 115 st %fp, [%o0+8] /* store caller's frame pointer */ 116 st %o7, [%o0+12] 117 retl 118 clr %o0 ! return 0 119 120ENTRY(longjmp) 121ENTRY(_longjmp) 122 ta 0x03 /* flush registers */ 123 addcc %o1, %g0, %g1 ! compute v ? v : 1 in a global register 124 be,a 0f 125 mov 1, %g1 1260: 127 ld [%o0], %sp /* caller's stack pointer */ 128 129 ldd [%sp], %l0 130 ldd [%sp+8], %l2 131 ldd [%sp+16], %l4 132 ldd [%sp+24], %l6 133 134 ldd [%sp+32], %i0 135 ldd [%sp+40], %i2 136 ldd [%sp+48], %i4 137 138 ld [%o0+4], %i7 /* caller's return pc */ 139 ld [%o0+8], %fp /* caller's frame pointer */ 140 ld [%o0+12], %o7 141 142 jmp %o7 + 8 ! success, return %g1 143 mov %g1, %o0 144 145