Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / arc / lib / arch / alpha / setjmp.S
1 /* $FreeBSD: src/sys/boot/arc/lib/arch/alpha/setjmp.S,v 1.2 1999/08/28 00:39:40 peter Exp $ */
2 /*
3  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Chris G. Demetriou
7  *
8  * Permission to use, copy, modify and distribute this software and
9  * its documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28
29 #include <machine/asm.h>
30
31         .text
32 /*
33  * Kernel setjmp and longjmp.  Rather minimalist.
34  *
35  *      longjmp(label_t *a)
36  * will generate a "return (1)" from the last call to
37  *      setjmp(label_t *a)
38  * by restoring registers from the stack,
39  */
40
41         .set    noreorder
42
43 LEAF(setjmp, 1)
44         LDGP(pv)
45
46         stq     ra, (0 * 8)(a0)                 /* return address */
47         stq     s0, (1 * 8)(a0)                 /* callee-saved registers */
48         stq     s1, (2 * 8)(a0)
49         stq     s2, (3 * 8)(a0)
50         stq     s3, (4 * 8)(a0)
51         stq     s4, (5 * 8)(a0)
52         stq     s5, (6 * 8)(a0)
53         stq     s6, (7 * 8)(a0)
54         stq     sp, (8 * 8)(a0)
55
56         ldiq    t0, 0xbeeffedadeadbabe          /* set magic number */
57         stq     t0, (9 * 8)(a0)
58
59         mov     zero, v0                        /* return zero */
60         RET
61 END(setjmp)
62
63 LEAF(longjmp, 1)
64         LDGP(pv)
65
66         ldiq    t0, 0xbeeffedadeadbabe          /* check magic number */
67         ldq     t1, (9 * 8)(a0)
68         cmpeq   t0, t1, t0
69         beq     t0, longjmp_botch               /* if bad, punt */
70
71         ldq     ra, (0 * 8)(a0)                 /* return address */
72         ldq     s0, (1 * 8)(a0)                 /* callee-saved registers */
73         ldq     s1, (2 * 8)(a0)
74         ldq     s2, (3 * 8)(a0)
75         ldq     s3, (4 * 8)(a0)
76         ldq     s4, (5 * 8)(a0)
77         ldq     s5, (6 * 8)(a0)
78         ldq     s6, (7 * 8)(a0)
79         ldq     sp, (8 * 8)(a0)
80
81         ldiq    v0, 1
82         RET
83
84 longjmp_botch:
85         lda     a0, longjmp_botchmsg
86         mov     ra, a1
87         CALL(panic)
88         call_pal PAL_bugchk
89
90         .data
91 longjmp_botchmsg:
92         .asciz  "longjmp botch from %p"
93         .text
94
95 END(longjmp)