summaryrefslogtreecommitdiff
path: root/cpukit/score/cpu/sparc/setjmp.S
blob: 613df2ba202a93cb39b6942d2d584436fa92d5f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (c) 1992, 1993
 *      The Regents of the University of California.  All rights reserved.
 *
 *  Modified for incorporation into newlib by Joel Sherrill
 *  (joel@OARcorp.com), On-Line Applications Research, 1995.
 *  Did the following:
 *     + merged in DEFS.h
 *     + removed error check since it prevented using this setjmp
 *       to "context switch" 
 *     + added the support for the "user label" and "register" prefix
 *
 * This software was developed by the Computer Systems Engineering group
 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
 * contributed to Berkeley.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * from: $Header$
 */

#if defined(LIBC_SCCS) && !defined(lint)
        .asciz "@(#)_setjmp.s   8.1 (Berkeley) 6/4/93"
#endif /* LIBC_SCCS and not lint */

/*
 *  Recent versions of GNU cpp define variables which indicate the
 *  need for underscores and percents.  If not using GNU cpp or
 *  the version does not support this, then you will obviously
 *  have to define these as appropriate.
 */
 
#ifndef __USER_LABEL_PREFIX__
#define __USER_LABEL_PREFIX__ _
#endif
 
#ifndef __REGISTER_PREFIX__
#define __REGISTER_PREFIX__
#endif

/* ANSI concatenation macros.  */
 
#define CONCAT1(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a ## b
 
/* Use the right prefix for global labels.  */
 
#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)

/*********************************************************************
 *********************************************************************
 *                       Contents of DEFS.h                          *
 *********************************************************************
 *********************************************************************/

#ifdef PROF
#define ENTRY(x) \
        .align 4; .globl SYM(x); .proc 1; SYM(x):; .data; .align 4; 1: .long 0; \
        .text; save %sp,-96,%sp; sethi %hi(1b),%o0; call mcount; \
        or %lo(1b),%o0,%o0; restore
#else
#define ENTRY(x) \
        .align 4; .globl SYM(x); .proc 1; SYM(x):
#endif


 
/*********************************************************************
 *********************************************************************
 *                           END of DEFS.h                           *
 *********************************************************************
 *********************************************************************/


/*
 * C library -- _setjmp, _longjmp
 *
 *      _longjmp(a,v)
 * will generate a "return(v?v:1)" from
 * the last call to
 *      _setjmp(a)
 * by unwinding the call stack.
 * The previous signal state is NOT restored.
 */


/* #include "DEFS.h" */

ENTRY(setjmp)
ENTRY(_setjmp)
        st      %sp, [%o0]      /* caller's stack pointer */
        st      %i7, [%o0+4]    /* caller's return pc */
        st      %fp, [%o0+8]    /* store caller's frame pointer */
        st      %o7, [%o0+12]
        retl
        clr    %o0              ! return 0

ENTRY(longjmp)
ENTRY(_longjmp)
        ta      0x03            /* flush registers */
        addcc   %o1, %g0, %g1   ! compute v ? v : 1 in a global register
        be,a    0f
        mov     1, %g1
0:
        ld      [%o0], %sp      /* caller's stack pointer */

        ldd     [%sp], %l0
        ldd     [%sp+8], %l2
        ldd     [%sp+16], %l4
        ldd     [%sp+24], %l6

        ldd     [%sp+32], %i0
        ldd     [%sp+40], %i2
        ldd     [%sp+48], %i4

        ld      [%o0+4], %i7    /* caller's return pc */
        ld      [%o0+8], %fp    /* caller's frame pointer */
        ld      [%o0+12], %o7 

        jmp     %o7 + 8         ! success, return %g1
        mov     %g1, %o0