| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: _setjmp.S,v 1.6 2020/05/05 06:20:55 skrll Exp $ */ | | 1 | /* $NetBSD: _setjmp.S,v 1.7 2024/05/04 14:48:28 skrll Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matthew Fredette. | | 8 | * by Matthew Fredette. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -19,107 +19,109 @@ | | | @@ -19,107 +19,109 @@ |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
| | | 32 | #include "assym.h" |
| | | 33 | |
32 | #include <machine/asm.h> | | 34 | #include <machine/asm.h> |
33 | #include <machine/frame.h> | | 35 | #include <machine/frame.h> |
34 | | | 36 | |
35 | #if defined(LIBC_SCCS) && !defined(lint) | | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
36 | RCSID("$NetBSD: _setjmp.S,v 1.6 2020/05/05 06:20:55 skrll Exp $") | | 38 | RCSID("$NetBSD: _setjmp.S,v 1.7 2024/05/04 14:48:28 skrll Exp $") |
37 | #endif /* LIBC_SCCS and not lint */ | | 39 | #endif /* LIBC_SCCS and not lint */ |
38 | | | 40 | |
39 | /* | | 41 | /* |
40 | * C library -- setjmp, longjmp | | 42 | * C library -- setjmp, longjmp |
41 | * | | 43 | * |
42 | * longjmp(a,v) | | 44 | * longjmp(a,v) |
43 | * will generate a "return(v)" from | | 45 | * will generate a "return(v)" from |
44 | * the last call to | | 46 | * the last call to |
45 | * setjmp(a) | | 47 | * setjmp(a) |
46 | * by restoring registers from the stack, | | 48 | * by restoring registers from the stack, |
47 | * and a struct sigcontext, see <signal.h> | | 49 | * and a struct sigcontext, see <signal.h> |
48 | */ | | 50 | */ |
49 | | | 51 | |
50 | ENTRY(_setjmp,0) | | 52 | ENTRY(_setjmp,0) |
51 | /* A sigcontext is at the beginning of our jmp_buf. */ | | 53 | /* A sigcontext is at the beginning of our jmp_buf. */ |
52 | stw %r0, 0(%arg0) ; no onstack | | 54 | stw %r0, _SC_ONSTACK(%arg0) ; no onstack |
53 | stw %r0, 4(%arg0) ; unused word (old style signal mask) | | 55 | stw %r0, _SC_MASK13(%arg0) ; unused word (old style signal mask) |
54 | stw %sp, 8(%arg0) ; sc.sc_sp = %sp | | 56 | stw %sp, _SC_REGS_SP(%arg0) ; sc.sc_sp = %sp |
55 | stw %r0, 16(%arg0) ; sc.sc_ap = NULL | | 57 | stw %r0, _SC_REGS_AP(%arg0) ; sc.sc_ap = NULL |
56 | mfsp %sr0, %r1 | | 58 | mfsp %sr0, %r1 |
57 | stw %r1, 20(%arg0) ; sc.sc_pcsqh = %sr0 | | 59 | stw %r1, _SC_REGS_PCSQH(%arg0) ; sc.sc_pcsqh = %sr0 |
58 | stw %rp, 24(%arg0) ; sc.sc_pcoqh = %rp | | 60 | stw %rp, _SC_REGS_PCOQH(%arg0) ; sc.sc_pcoqh = %rp |
59 | stw %r1, 28(%arg0) ; sc.sc_pcsqh = %sr0 | | 61 | stw %r1, _SC_REGS_PCSQT(%arg0) ; sc.sc_pcsqh = %sr0 |
60 | ldo 4(%rp), %r1 | | 62 | ldo 4(%rp), %r1 |
61 | stw %r1, 32(%arg0) ; sc.sc_pcoqt = %rp + 4 | | 63 | stw %r1, _SC_REGS_PCOQT(%arg0) ; sc.sc_pcoqt = %rp + 4 |
62 | stw %r0, 36(%arg0) ; set sc.sc_ps | | 64 | stw %r0, _SC_REGS_PS(%arg0) ; set sc.sc_ps |
63 | | | 65 | |
64 | /* We store all callee-saved registers after the sigcontext. */ | | 66 | /* We store all callee-saved registers after the sigcontext. */ |
65 | ldo 56(%arg0), %r1 | | 67 | ldo SIZEOF_SIGCONTEXT(%arg0), %r1 |
66 | stwm %r3, 4(%r1) | | 68 | stwm %r3, 4(%r1) |
67 | stwm %r4, 4(%r1) | | 69 | stwm %r4, 4(%r1) |
68 | stwm %r5, 4(%r1) | | 70 | stwm %r5, 4(%r1) |
69 | stwm %r6, 4(%r1) | | 71 | stwm %r6, 4(%r1) |
70 | stwm %r7, 4(%r1) | | 72 | stwm %r7, 4(%r1) |
71 | stwm %r8, 4(%r1) | | 73 | stwm %r8, 4(%r1) |
72 | stwm %r9, 4(%r1) | | 74 | stwm %r9, 4(%r1) |
73 | stwm %r10, 4(%r1) | | 75 | stwm %r10, 4(%r1) |
74 | stwm %r11, 4(%r1) | | 76 | stwm %r11, 4(%r1) |
75 | stwm %r12, 4(%r1) | | 77 | stwm %r12, 4(%r1) |
76 | stwm %r13, 4(%r1) | | 78 | stwm %r13, 4(%r1) |
77 | stwm %r14, 4(%r1) | | 79 | stwm %r14, 4(%r1) |
78 | stwm %r15, 4(%r1) | | 80 | stwm %r15, 4(%r1) |
79 | stwm %r16, 4(%r1) | | 81 | stwm %r16, 4(%r1) |
80 | stwm %r17, 4(%r1) | | 82 | stwm %r17, 4(%r1) |
81 | stwm %r18, 4(%r1) | | 83 | stwm %r18, 4(%r1) |
82 | | | 84 | |
83 | /* Return 0. */ | | 85 | /* Return 0. */ |
84 | bv %r0(%rp) | | 86 | bv %r0(%rp) |
85 | copy %r0, %ret0 | | 87 | copy %r0, %ret0 |
86 | EXIT(_setjmp) | | 88 | EXIT(_setjmp) |
87 | | | 89 | |
88 | ENTRY(_longjmp,0) | | 90 | ENTRY(_longjmp,0) |
89 | ldw 8(%arg0), %r1 ; ensure non-zero SP | | 91 | ldw _SC_REGS_SP(%arg0), %r1 ; ensure non-zero SP |
90 | combt,=,n %r0, %r1, botch ; oops! | | 92 | combt,=,n %r0, %r1, botch ; oops! |
91 | add,<> %r0, %arg1, %ret0 ; ensure return value non-zero | | 93 | add,<> %r0, %arg1, %ret0 ; ensure return value non-zero |
92 | ldi 1, %ret0 | | 94 | ldi 1, %ret0 |
93 | | | 95 | |
94 | /* restore callee-saved registers */ | | 96 | /* restore callee-saved registers */ |
95 | ldo 56(%arg0), %r1 | | 97 | ldo SIZEOF_SIGCONTEXT(%arg0), %r1 |
96 | ldwm 4(%r1), %r3 | | 98 | ldwm 4(%r1), %r3 |
97 | ldwm 4(%r1), %r4 | | 99 | ldwm 4(%r1), %r4 |
98 | ldwm 4(%r1), %r5 | | 100 | ldwm 4(%r1), %r5 |
99 | ldwm 4(%r1), %r6 | | 101 | ldwm 4(%r1), %r6 |
100 | ldwm 4(%r1), %r7 | | 102 | ldwm 4(%r1), %r7 |
101 | ldwm 4(%r1), %r8 | | 103 | ldwm 4(%r1), %r8 |
102 | ldwm 4(%r1), %r9 | | 104 | ldwm 4(%r1), %r9 |
103 | ldwm 4(%r1), %r10 | | 105 | ldwm 4(%r1), %r10 |
104 | ldwm 4(%r1), %r11 | | 106 | ldwm 4(%r1), %r11 |
105 | ldwm 4(%r1), %r12 | | 107 | ldwm 4(%r1), %r12 |
106 | ldwm 4(%r1), %r13 | | 108 | ldwm 4(%r1), %r13 |
107 | ldwm 4(%r1), %r14 | | 109 | ldwm 4(%r1), %r14 |
108 | ldwm 4(%r1), %r15 | | 110 | ldwm 4(%r1), %r15 |
109 | ldwm 4(%r1), %r16 | | 111 | ldwm 4(%r1), %r16 |
110 | ldwm 4(%r1), %r17 | | 112 | ldwm 4(%r1), %r17 |
111 | ldwm 4(%r1), %r18 | | 113 | ldwm 4(%r1), %r18 |
112 | | | 114 | |
113 | /* restore the rest */ | | 115 | /* restore the rest */ |
114 | ldw 8(%arg0), %sp | | 116 | ldw _SC_REGS_SP(%arg0), %sp |
115 | ldw 24(%arg0), %rp | | 117 | ldw _SC_REGS_PCOQH(%arg0), %rp |
116 | bv %r0(%rp) | | 118 | bv %r0(%rp) |
117 | nop | | 119 | nop |
118 | botch: | | 120 | botch: |
119 | bl longjmperror, %rp | | 121 | bl longjmperror, %rp |
120 | nop | | 122 | nop |
121 | bl abort, %rp | | 123 | bl abort, %rp |
122 | nop | | 124 | nop |
123 | EXIT(_longjmp) | | 125 | EXIT(_longjmp) |
124 | | | 126 | |
125 | .end | | 127 | .end |