_setjmp.S revision 1.1 1 1.1 matt /* $NetBSD: _setjmp.S,v 1.1 2014/09/19 17:36:25 matt Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #include <machine/asm.h>
33 1.1 matt #include "assym.h"
34 1.1 matt
35 1.1 matt #if defined(LIBC_SCCS)
36 1.1 matt __RCSID("$NetBSD: _setjmp.S,v 1.1 2014/09/19 17:36:25 matt Exp $")
37 1.1 matt #endif
38 1.1 matt
39 1.1 matt /*
40 1.1 matt * C library -- _setjmp, _longjmp
41 1.1 matt *
42 1.1 matt * _longjmp(a,v)
43 1.1 matt * will generate a "return(v?v:1)" from the last call to
44 1.1 matt * _setjmp(a)
45 1.1 matt * by restoring registers from the stack.
46 1.1 matt * The previous signal state is NOT restored.
47 1.1 matt */
48 1.1 matt
49 1.1 matt ENTRY(_setjmp)
50 1.1 matt REG_S zero, JB_MAGIC(a0) /* indicate no sigmask */
51 1.1 matt REG_S ra, JB_RA(a0) /* save return address */
52 1.1 matt REG_S s0, JB_S0(a0) /* save callee saved register */
53 1.1 matt REG_S s1, JB_S1(a0) /* save callee saved register */
54 1.1 matt REG_S s2, JB_S2(a0) /* save callee saved register */
55 1.1 matt REG_S s3, JB_S3(a0) /* save callee saved register */
56 1.1 matt REG_S s4, JB_S4(a0) /* save callee saved register */
57 1.1 matt REG_S s5, JB_S5(a0) /* save callee saved register */
58 1.1 matt REG_S s6, JB_S6(a0) /* save callee saved register */
59 1.1 matt REG_S s7, JB_S7(a0) /* save callee saved register */
60 1.1 matt REG_S s8, JB_S8(a0) /* save callee saved register */
61 1.1 matt REG_S s9, JB_S9(a0) /* save callee saved register */
62 1.1 matt REG_S s10, JB_S10(a0) /* save callee saved register */
63 1.1 matt REG_S s11, JB_S11(a0) /* save callee saved register */
64 1.1 matt REG_S sp, JB_SP(a0) /* save stack pointer */
65 1.1 matt REG_S tp, JB_TP(a0) /* save thread pointer */
66 1.1 matt REG_S gp, JB_GP(a0) /* save global pointer */
67 1.1 matt #ifndef _SOFT_FLOAT
68 1.1 matt frcsr t2 /* get FSCR */
69 1.1 matt REG_S t2, JB_FCSR(a0) /* save it */
70 1.1 matt fsd fs0, JB_F0(a0) /* save callee saved register */
71 1.1 matt fsd fs1, JB_F1(a0) /* save callee saved register */
72 1.1 matt fsd fs2, JB_F2(a0) /* save callee saved register */
73 1.1 matt fsd fs3, JB_F3(a0) /* save callee saved register */
74 1.1 matt fsd fs4, JB_F4(a0) /* save callee saved register */
75 1.1 matt fsd fs5, JB_F5(a0) /* save callee saved register */
76 1.1 matt fsd fs6, JB_F6(a0) /* save callee saved register */
77 1.1 matt fsd fs7, JB_F7(a0) /* save callee saved register */
78 1.1 matt fsd fs8, JB_F8(a0) /* save callee saved register */
79 1.1 matt fsd fs9, JB_F9(a0) /* save callee saved register */
80 1.1 matt fsd fs10, JB_F10(a0) /* save callee saved register */
81 1.1 matt fsd fs11, JB_F11(a0) /* save callee saved register */
82 1.1 matt fsd fs12, JB_F12(a0) /* save callee saved register */
83 1.1 matt fsd fs13, JB_F13(a0) /* save callee saved register */
84 1.1 matt fsd fs14, JB_F14(a0) /* save callee saved register */
85 1.1 matt fsd fs15, JB_F15(a0) /* save callee saved register */
86 1.1 matt #endif
87 1.1 matt li x1, 0 /* indicate success */
88 1.1 matt ret /* return */
89 1.1 matt END(_setjmp)
90 1.1 matt
91 1.1 matt ENTRY(_longjmp)
92 1.1 matt REG_L ra, JB_RA(a0) /* save return address */
93 1.1 matt REG_L s0, JB_S0(a0) /* save callee saved register */
94 1.1 matt REG_L s1, JB_S1(a0) /* save callee saved register */
95 1.1 matt REG_L s2, JB_S2(a0) /* save callee saved register */
96 1.1 matt REG_L s3, JB_S3(a0) /* save callee saved register */
97 1.1 matt REG_L s4, JB_S4(a0) /* save callee saved register */
98 1.1 matt REG_L s5, JB_S5(a0) /* save callee saved register */
99 1.1 matt REG_L s6, JB_S6(a0) /* save callee saved register */
100 1.1 matt REG_L s7, JB_S7(a0) /* save callee saved register */
101 1.1 matt REG_L s8, JB_S8(a0) /* save callee saved register */
102 1.1 matt REG_L s9, JB_S9(a0) /* save callee saved register */
103 1.1 matt REG_L s10, JB_S10(a0) /* save callee saved register */
104 1.1 matt REG_L s11, JB_S11(a0) /* save callee saved register */
105 1.1 matt REG_L sp, JB_SP(a0) /* save stack pointer */
106 1.1 matt #REG_L tp, JB_TP(a0) /* save thread pointer */
107 1.1 matt REG_L gp, JB_GP(a0) /* save global pointer */
108 1.1 matt #ifndef _SOFT_FLOAT
109 1.1 matt REG_L t2, JB_FCSR(a0) /* get it */
110 1.1 matt fscsr t2 /* restore FSCR */
111 1.1 matt fld fs0, JB_F0(a0) /* restore callee saved register */
112 1.1 matt fld fs1, JB_F1(a0) /* restore callee saved register */
113 1.1 matt fld fs2, JB_F2(a0) /* restore callee saved register */
114 1.1 matt fld fs3, JB_F3(a0) /* restore callee saved register */
115 1.1 matt fld fs4, JB_F4(a0) /* restore callee saved register */
116 1.1 matt fld fs5, JB_F5(a0) /* restore callee saved register */
117 1.1 matt fld fs6, JB_F6(a0) /* restore callee saved register */
118 1.1 matt fld fs7, JB_F7(a0) /* restore callee saved register */
119 1.1 matt fld fs8, JB_F8(a0) /* restore callee saved register */
120 1.1 matt fld fs9, JB_F9(a0) /* restore callee saved register */
121 1.1 matt fld fs10, JB_F10(a0) /* restore callee saved register */
122 1.1 matt fld fs11, JB_F11(a0) /* restore callee saved register */
123 1.1 matt fld fs12, JB_F12(a0) /* restore callee saved register */
124 1.1 matt fld fs13, JB_F13(a0) /* restore callee saved register */
125 1.1 matt fld fs14, JB_F14(a0) /* restore callee saved register */
126 1.1 matt fld fs15, JB_F15(a0) /* restore callee saved register */
127 1.1 matt #endif
128 1.1 matt li v0, 1 /* default return value */
129 1.1 matt beqz a1, 1f /* test return value */
130 1.1 matt move v0, a1 /* use it if not 0 */
131 1.1 matt 1: ret
132 1.1 matt END(_longjmp)
133