Update.
[platform/upstream/glibc.git] / sysdeps / alpha / __longjmp.c
1 /* Copyright (C) 1992, 1994, 1997 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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 not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 /* Global register vars must come before any function defn.  */
20
21 register long int
22   r9 asm ("$9"), r10 asm ("$10"), r11 asm ("$11"), r12 asm ("$12"),
23   r13 asm ("$13"), r14 asm ("$14");
24
25 register long int *fp asm ("$15"), *sp asm ("$30"), *retpc asm ("$26");
26
27 #if 1                           /* XXX */
28 register double
29   f2 asm ("$f2"), f3 asm ("$f3"), f4 asm ("$f4"), f5 asm ("$f5"),
30   f6 asm ("$f6"), f7 asm ("$f7"), f8 asm ("$f8"), f9 asm ("$f9");
31 #endif
32
33 #include <setjmp.h>
34
35
36 /* Jump to the position specified by ENV, causing the
37    setjmp call there to return VAL, or 1 if VAL is 0.  */
38 void
39 __longjmp (__jmp_buf env, int val)
40 {
41   register long int retval asm ("$0");
42
43   /* Restore the integer registers.  */
44   r9 = env[0].__9;
45   r10 = env[0].__10;
46   r11 = env[0].__11;
47   r12 = env[0].__12;
48   r13 = env[0].__13;
49   r14 = env[0].__14;
50
51 #if 1                           /* XXX */
52   /* Restore the floating point registers.  */
53   f2 = env[0].__f2;
54   f3 = env[0].__f3;
55   f4 = env[0].__f4;
56   f5 = env[0].__f5;
57   f6 = env[0].__f6;
58   f7 = env[0].__f7;
59   f8 = env[0].__f8;
60   f9 = env[0].__f9;
61 #endif
62
63   /* Set the return PC to that of setjmp's caller.  */
64   retpc = env[0].__pc;
65
66   /* Restore the FP and SP of setjmp's caller.  */
67   fp = env[0].__fp;
68   sp = env[0].__sp;
69
70   /* Return VAL (or 1 if VAL is zero) to setjmp's caller.
71
72      We use an asm here rather than a normal C return statement
73      just in case the compiler wanted to do some stack frobnication
74      in the function epilogue.  Since we have already restored
75      precisely the FP and SP the desired environment needs,
76      we must avoid the compiler doing anything with the stack.  */
77
78
79   asm volatile
80     ("cmoveq %1, 1, %0\n\t"     /* $0 = val ?: 1; */
81      "ret $31, (%2), 1" /* return $0 */
82      : "=r" (retval)
83      /* The "0" constraint should force VAL into $0.  */
84      : "0" (val), "r" (retpc));
85
86   while (1)
87     {
88       /* The loop is just to avoid `volatile function does return' warnings.
89          The instruction will only be executed once.  */
90       asm volatile ("");
91     }
92 }