* posix/execl.c: Fix last argument of memcpy. Reported by Brian
[glibc/pb-stable.git] / sysdeps / vax / __longjmp.c
blob0ab593f56a52fa7b64d4c926dd30ed1aab22df38
1 /* Copyright (C) 1991, 1992, 1994, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Derived from @(#)_setjmp.s 5.7 (Berkeley) 6/27/88,
4 Copyright (c) 1980 Regents of the University of California.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <setjmp.h>
24 #ifndef __GNUC__
25 #error This file uses GNU C extensions; you must compile with GCC.
26 #endif
29 #define REI 02 /* Vax `rei' opcode. */
31 /* Jump to the position specified by ENV, causing the
32 setjmp call there to return VAL, or 1 if VAL is 0. */
33 __NORETURN
34 void
35 __longjmp (env, val)
36 const __jmp_buf env;
37 int val;
39 register long int *fp asm("fp");
40 long int *regsave;
41 unsigned long int flags;
43 if (env.__fp == NULL)
44 __libc_fatal("longjmp: Invalid ENV argument.\n");
46 if (val == 0)
47 val = 1;
49 asm volatile("loop:");
51 flags = *(long int *) (6 + (char *) fp);
52 regsave = (long int *) (20 + (char *) fp);
53 if (flags & 1)
54 /* R0 was saved by the caller.
55 Store VAL where it will be restored from. */
56 *regsave++ = val;
57 if (flags & 2)
58 /* R1 was saved by the caller.
59 Store ENV where it will be restored from. */
60 *regsave = env;
62 /* Was the FP saved in the last call the same one in ENV? */
63 asm volatile("cmpl %0, 12(fp);"
64 /* Yes, return to it. */
65 "beql done;"
66 /* The FP in ENV is less than the one saved in the last call.
67 This means we have already returned from the function that
68 called `setjmp' with ENV! */
69 "blssu latejump;" : /* No outputs. */ : "g" (env.__fp));
71 /* We are more than one level below the state in ENV.
72 Return to where we will pop another stack frame. */
73 asm volatile("movl $loop, 16(fp);"
74 "ret");
76 asm volatile("done:");
78 char return_insn asm("*16(fp)");
79 if (return_insn == REI)
80 /* We're returning with an `rei' instruction.
81 Do a return with PSL-PC pop. */
82 asm volatile("movab 0f, 16(fp)");
83 else
84 /* Do a standard return. */
85 asm volatile("movab 1f, 16(fp)");
87 /* Return. */
88 asm volatile("ret");
91 asm volatile("0:" /* `rei' return. */
92 /* Compensate for PSL-PC push. */
93 "addl2 %0, sp;"
94 "1:" /* Standard return. */
95 /* Return to saved PC. */
96 "jmp %1" : /* No outputs. */ :
97 "g" (8), "g" (env.__pc));
99 /* Jump here when the FP saved in ENV points
100 to a function that has already returned. */
101 asm volatile("latejump:");
102 __libc_fatal("longjmp: Attempt to jump to a function that has returned.\n");