Mon Dec 2 15:32:15 1996 Ulrich Drepper <drepper@cygnus.com>
[glibc.git] / sysdeps / sparc / __longjmp.S
blob5424300fe597486f4dc9e3a14fdd9991a2b2b089
1 /* Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB.  If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA.  */
19 #include <sysdep.h>
21 #define _ASM 1
22 #include <jmp_buf.h>
23 #define ENV(reg) [%g1 + (reg * 4)]
25 ENTRY (__longjmp)
26         /* Store our arguments in global registers so we can still
27            use them while unwinding frames and their register windows.  */
28         mov %o0, %g1            /* ENV in %g1 */
29         orcc %o1, %g0, %g6      /* VAL in %g6 */
30         be,a 0f                 /* Branch if zero; else skip delay slot.  */
31          mov 1, %g6             /* Delay slot only hit if zero: VAL = 1.  */
34         /* Cache target FP in register %g7.  */
35         ld ENV (JB_FP), %g7
37         /* Now we will loop, unwinding the register windows up the stack
38            until the restored %fp value matches the target value in %g7.  */
40 loop:   cmp %fp, %g7            /* Have we reached the target frame? */
41         bl,a loop               /* Loop while current fp is below target.  */
42          restore                /* Unwind register window in delay slot.  */
43         be,a found              /* Better have hit it exactly.  */
44          ld ENV (JB_SP), %o0    /* Delay slot: extract target SP.  */
46 bogus:  /* Get here only if the jmp_buf or stack is clobbered.  */
47         call C_SYMBOL_NAME (abort)
48         nop
49         unimp 0
51 found:  /* We have unwound register windows so %fp matches the target.  */
52         cmp %o0, %sp            /* Check jmp_buf SP vs register window.  */
53         bge,a sp_ok             /* Saved must not be deeper than register.  */
54          mov %o0, %sp           /* OK, install new SP.  */
55         b,a bogus               /* Bogus, we lose.  */
57 sp_ok:  ld ENV (JB_PC), %o0     /* Extract target return PC.  */
58         jmp %o0 + 8             /* Return there.  */
59          mov %g6, %o0           /* Delay slot: set return value.  */