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#include <picolibc.h>
45
46#if defined(LIBC_SCCS) && !defined(lint)
47        .asciz "@(#)_setjmp.s   8.1 (Berkeley) 6/4/93"
48#endif /* LIBC_SCCS and not lint */
49
50/*
51 *  Recent versions of GNU cpp define variables which indicate the
52 *  need for underscores and percents.  If not using GNU cpp or
53 *  the version does not support this, then you will obviously
54 *  have to define these as appropriate.
55 */
56
57#ifndef __USER_LABEL_PREFIX__
58#define __USER_LABEL_PREFIX__ _
59#endif
60
61#ifndef __REGISTER_PREFIX__
62#define __REGISTER_PREFIX__
63#endif
64
65/* ANSI concatenation macros.  */
66
67#define CONCAT1(a, b) CONCAT2(a, b)
68#define CONCAT2(a, b) a ## b
69
70/* Use the right prefix for global labels.  */
71
72#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
73
74/*********************************************************************
75 *********************************************************************
76 *                       Contents of DEFS.h                          *
77 *********************************************************************
78 *********************************************************************/
79
80#ifdef PROF
81#define ENTRY(x) \
82        .align 4; .globl SYM(x); .proc 1; SYM(x):; .data; .align 4; 1: .long 0; \
83        .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call mcount; \
84        or %lo(1b),%o0,%o0; restore
85#else
86#define ENTRY(x) \
87        .align 4; .globl SYM(x); .proc 1; SYM(x):
88#endif
89
90
91
92/*********************************************************************
93 *********************************************************************
94 *                           END of DEFS.h                           *
95 *********************************************************************
96 *********************************************************************/
97
98
99/*
100 * C library -- _setjmp, _longjmp
101 *
102 *      _longjmp(a,v)
103 * will generate a "return(v?v:1)" from
104 * the last call to
105 *      _setjmp(a)
106 * by unwinding the call stack.
107 * The previous signal state is NOT restored.
108 */
109
110
111/* #include "DEFS.h" */
112
113ENTRY(setjmp)
114ENTRY(_setjmp)
115#ifndef _FLAT
116        ta      0x03            /* Flush registers, just in case another stack
117                                   is used after the setjmp().  */
118#endif
119        st      %sp, [%o0]      /* caller's stack pointer */
120        st      %i7, [%o0+4]    /* caller's return pc */
121        st      %fp, [%o0+8]    /* store caller's frame pointer */
122        st      %o7, [%o0+12]
123        retl
124        clr    %o0              ! return 0
125
126ENTRY(longjmp)
127ENTRY(_longjmp)
128#ifndef _FLAT
129        ta      0x03            /* flush registers */
130#endif
131        addcc   %o1, %g0, %g1   ! compute v ? v : 1 in a global register
132        be,a    0f
133        mov     1, %g1
1340:
135        ld      [%o0], %sp      /* caller's stack pointer */
136
137        ldd     [%sp], %l0
138        ldd     [%sp+8], %l2
139        ldd     [%sp+16], %l4
140        ldd     [%sp+24], %l6
141
142        ldd     [%sp+32], %i0
143        ldd     [%sp+40], %i2
144        ldd     [%sp+48], %i4
145
146        ld      [%o0+4], %i7    /* caller's return pc */
147        ld      [%o0+8], %fp    /* caller's frame pointer */
148        ld      [%o0+12], %o7
149
150        jmp     %o7 + 8         ! success, return %g1
151        mov     %g1, %o0
152
153