Tue Nov 28 13:09:05 2017 UTC ()
fix to work
* no need to check x29 != NULL. fp may be NULL.
* don't break in-use register x5.


(ryo)
diff -r1.2 -r1.3 src/lib/libc/arch/aarch64/gen/_setjmp.S
diff -r1.1 -r1.2 src/lib/libc/arch/aarch64/gen/setjmp.S

cvs diff -r1.2 -r1.3 src/lib/libc/arch/aarch64/gen/_setjmp.S (switch to unified diff)

--- src/lib/libc/arch/aarch64/gen/_setjmp.S 2017/11/28 09:06:25 1.2
+++ src/lib/libc/arch/aarch64/gen/_setjmp.S 2017/11/28 13:09:05 1.3
@@ -1,117 +1,116 @@ @@ -1,117 +1,116 @@
1/* $NetBSD: _setjmp.S,v 1.2 2017/11/28 09:06:25 ryo Exp $ */ 1/* $NetBSD: _setjmp.S,v 1.3 2017/11/28 13:09:05 ryo Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 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 Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
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 <machine/asm.h> 32#include <machine/asm.h>
33#include "assym.h" 33#include "assym.h"
34 34
35/* 35/*
36 * C library -- _setjmp, _longjmp 36 * C library -- _setjmp, _longjmp
37 * 37 *
38 * _longjmp(a, v) 38 * _longjmp(a, v)
39 * will generate a "return v;" from the last call to 39 * will generate a "return v;" from the last call to
40 * _setjmp(a) 40 * _setjmp(a)
41 * by restoring registers from the stack. 41 * by restoring registers from the stack.
42 * The previous signal state is NOT restored. 42 * The previous signal state is NOT restored.
43 * 43 *
44 * Note: x0 is the return value 44 * Note: x0 is the return value
45 */ 45 */
46 .section .rodata.cst8,"aM",@progbits,8 46 .section .rodata.cst8,"aM",@progbits,8
47 .align 3 47 .align 3
48.L_MAGIC: 48.L_MAGIC:
49 .xword _JB_MAGIC_AARCH64__SETJMP 49 .xword _JB_MAGIC_AARCH64__SETJMP
50 50
51ENTRY(_setjmp) 51ENTRY(_setjmp)
52 adrp x7, .L_MAGIC 52 adrp x7, .L_MAGIC
53 ldr x7, [x7, #:lo12:.L_MAGIC] 53 ldr x7, [x7, #:lo12:.L_MAGIC]
54 54
55 mov x3, sp 55 mov x3, sp
56 56
57 stp x7, x3, [x0, #_JB_MAGIC] 57 stp x7, x3, [x0, #_JB_MAGIC]
58 58
59 stp x19, x20, [x0, #_JB_X19] 59 stp x19, x20, [x0, #_JB_X19]
60 stp x21, x22, [x0, #_JB_X21] 60 stp x21, x22, [x0, #_JB_X21]
61 stp x23, x24, [x0, #_JB_X23] 61 stp x23, x24, [x0, #_JB_X23]
62 stp x25, x26, [x0, #_JB_X25] 62 stp x25, x26, [x0, #_JB_X25]
63 stp x27, x28, [x0, #_JB_X27] 63 stp x27, x28, [x0, #_JB_X27]
64 stp x29, x30, [x0, #_JB_X29] 64 stp x29, x30, [x0, #_JB_X29]
65 65
66 mrs x5, tpidr_el0 66 mrs x5, tpidr_el0
67 str x5, [x0, #_JB_TPIDR] 67 str x5, [x0, #_JB_TPIDR]
68 68
69 stp d8, d9, [x0, #_JB_D8] 69 stp d8, d9, [x0, #_JB_D8]
70 stp d10, d11, [x0, #_JB_D10] 70 stp d10, d11, [x0, #_JB_D10]
71 stp d12, d13, [x0, #_JB_D12] 71 stp d12, d13, [x0, #_JB_D12]
72 stp d14, d15, [x0, #_JB_D14] 72 stp d14, d15, [x0, #_JB_D14]
73 73
74 mov x0, xzr 74 mov x0, xzr
75 ret 75 ret
76END(_setjmp) 76END(_setjmp)
77 77
78ENTRY(_longjmp) 78ENTRY(_longjmp)
79 adrp x7, .L_MAGIC 79 adrp x7, .L_MAGIC
80 ldr x7, [x7, #:lo12:.L_MAGIC] 80 ldr x7, [x7, #:lo12:.L_MAGIC]
81 81
82 ldp x2, x3, [x0, #_JB_MAGIC] 82 ldp x2, x3, [x0, #_JB_MAGIC]
83 ldp x4, x5, [x0, #_JB_X29] 83 ldp x4, x5, [x0, #_JB_X29]
84 84
85 cbz x3, .Lbotch 85 cbz x3, .Lbotch
86 cbz x4, .Lbotch 
87 cbz x5, .Lbotch 86 cbz x5, .Lbotch
88 cmp x2, x7 87 cmp x2, x7
89 b.ne .Lbotch 88 b.ne .Lbotch
90 89
91 ldp x19, x20, [x0, #_JB_X19] 90 ldp x19, x20, [x0, #_JB_X19]
92 ldp x21, x22, [x0, #_JB_X21] 91 ldp x21, x22, [x0, #_JB_X21]
93 ldp x23, x24, [x0, #_JB_X23] 92 ldp x23, x24, [x0, #_JB_X23]
94 ldp x25, x26, [x0, #_JB_X25] 93 ldp x25, x26, [x0, #_JB_X25]
95 ldp x27, x28, [x0, #_JB_X27] 94 ldp x27, x28, [x0, #_JB_X27]
96 95
97 ldr x5, [x0, #_JB_TPIDR] 96 ldr x2, [x0, #_JB_TPIDR]
98 msr tpidr_el0, x5 97 msr tpidr_el0, x2
99 98
100 ldp d8, d9, [x0, #_JB_D8] 99 ldp d8, d9, [x0, #_JB_D8]
101 ldp d10, d11, [x0, #_JB_D10] 100 ldp d10, d11, [x0, #_JB_D10]
102 ldp d12, d13, [x0, #_JB_D12] 101 ldp d12, d13, [x0, #_JB_D12]
103 ldp d14, d15, [x0, #_JB_D14] 102 ldp d14, d15, [x0, #_JB_D14]
104 103
105 mov sp, x3 104 mov sp, x3
106 mov x29, x4 105 mov x29, x4
107 mov x30, x5 106 mov x30, x5
108 107
109 mov x0, x1 108 mov x0, x1
110 ret 109 ret
111 110
112 /* validation failed, die die die. */ 111 /* validation failed, die die die. */
113.Lbotch: 112.Lbotch:
114 bl _C_LABEL(longjmperror) 113 bl _C_LABEL(longjmperror)
115 bl _C_LABEL(abort) 114 bl _C_LABEL(abort)
1161: b 1b /* Cannot get here */ 1151: b 1b /* Cannot get here */
117END(_longjmp) 116END(_longjmp)

cvs diff -r1.1 -r1.2 src/lib/libc/arch/aarch64/gen/setjmp.S (switch to unified diff)

--- src/lib/libc/arch/aarch64/gen/setjmp.S 2014/08/10 05:47:36 1.1
+++ src/lib/libc/arch/aarch64/gen/setjmp.S 2017/11/28 13:09:05 1.2
@@ -1,133 +1,132 @@ @@ -1,133 +1,132 @@
1/*.$NetBSD: setjmp.S,v 1.1 2014/08/10 05:47:36 matt Exp $.*/ 1/*.$NetBSD: setjmp.S,v 1.2 2017/11/28 13:09:05 ryo Exp $.*/
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 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 Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
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 <machine/asm.h> 32#include <machine/asm.h>
33#include "assym.h" 33#include "assym.h"
34 34
35/* 35/*
36 * C library -- setjmp, longjmp 36 * C library -- setjmp, longjmp
37 * 37 *
38 * longjmp(a,v) 38 * longjmp(a,v)
39 * will generate a "return(v)" from the last call to 39 * will generate a "return(v)" from the last call to
40 * setjmp(a) 40 * setjmp(a)
41 * by restoring registers from the stack. 41 * by restoring registers from the stack.
42 * The previous signal state is restored. 42 * The previous signal state is restored.
43 */ 43 */
44 44
45 .section .rodata.cst8,"aM",@progbits,8 45 .section .rodata.cst8,"aM",@progbits,8
46 .align 3 46 .align 3
47.L_MAGIC: 47.L_MAGIC:
48 .xword _JB_MAGIC_AARCH64_SETJMP 48 .xword _JB_MAGIC_AARCH64_SETJMP
49 49
50ENTRY(__setjmp14) 50ENTRY(__setjmp14)
51 adrp x7, .L_MAGIC 51 adrp x7, .L_MAGIC
52 ldr x7, [x7, #:lo12:.L_MAGIC] 52 ldr x7, [x7, #:lo12:.L_MAGIC]
53 53
54 mov x3, sp 54 mov x3, sp
55 stp x7, x3, [x0, #_JB_MAGIC] 55 stp x7, x3, [x0, #_JB_MAGIC]
56 56
57 stp x19, x20, [x0, #_JB_X19] 57 stp x19, x20, [x0, #_JB_X19]
58 stp x21, x22, [x0, #_JB_X21] 58 stp x21, x22, [x0, #_JB_X21]
59 stp x23, x24, [x0, #_JB_X23] 59 stp x23, x24, [x0, #_JB_X23]
60 stp x25, x26, [x0, #_JB_X25] 60 stp x25, x26, [x0, #_JB_X25]
61 stp x27, x28, [x0, #_JB_X27] 61 stp x27, x28, [x0, #_JB_X27]
62 stp x29, x30, [x0, #_JB_X29] 62 stp x29, x30, [x0, #_JB_X29]
63 63
64 mrs x5, tpidr_el0 64 mrs x5, tpidr_el0
65 str x5, [x0, #_JB_TPIDR] 65 str x5, [x0, #_JB_TPIDR]
66 66
67 stp d8, d9, [x0, #_JB_D8] 67 stp d8, d9, [x0, #_JB_D8]
68 stp d10, d11, [x0, #_JB_D10] 68 stp d10, d11, [x0, #_JB_D10]
69 stp d12, d13, [x0, #_JB_D12] 69 stp d12, d13, [x0, #_JB_D12]
70 stp d14, d15, [x0, #_JB_D14] 70 stp d14, d15, [x0, #_JB_D14]
71 71
72 /* Get the signal mask. */ 72 /* Get the signal mask. */
73 add x2, x0, #_JB_SIGMASK 73 add x2, x0, #_JB_SIGMASK
74 mov x1, #0 74 mov x1, #0
75 mov x0, #0 75 mov x0, #0
76 76
77 stp x29, x30, [sp, #-16]! 77 stp x29, x30, [sp, #-16]!
78 mov x29, sp 78 mov x29, sp
79 bl _C_LABEL(__sigprocmask14) 79 bl _C_LABEL(__sigprocmask14)
80 ldp x29, x30, [sp], #16 80 ldp x29, x30, [sp], #16
81 81
82 mov x0, xzr 82 mov x0, xzr
83 ret 83 ret
84END(__setjmp14) 84END(__setjmp14)
85 85
86ENTRY(__longjmp14) 86ENTRY(__longjmp14)
87 adrp x7, .L_MAGIC 87 adrp x7, .L_MAGIC
88 ldr x7, [x7, #:lo12:.L_MAGIC] 88 ldr x7, [x7, #:lo12:.L_MAGIC]
89 ldp x2, x3, [x0, #_JB_MAGIC] 89 ldp x2, x3, [x0, #_JB_MAGIC]
90 cmp x2, x7 90 cmp x2, x7
91 b.ne .Lbotch 91 b.ne .Lbotch
92 92
93 ldp x4, x5, [x0, #_JB_X29] 93 ldp x4, x5, [x0, #_JB_X29]
94 cbz x3, .Lbotch 94 cbz x3, .Lbotch
95 cbz x4, .Lbotch 
96 cbz x5, .Lbotch 95 cbz x5, .Lbotch
97 96
98 ldp x19, x20, [x0, #_JB_X19] 97 ldp x19, x20, [x0, #_JB_X19]
99 ldp x21, x22, [x0, #_JB_X21] 98 ldp x21, x22, [x0, #_JB_X21]
100 ldp x23, x24, [x0, #_JB_X23] 99 ldp x23, x24, [x0, #_JB_X23]
101 ldp x25, x26, [x0, #_JB_X25] 100 ldp x25, x26, [x0, #_JB_X25]
102 ldp x27, x28, [x0, #_JB_X27] 101 ldp x27, x28, [x0, #_JB_X27]
103 102
104 ldr x5, [x0, #_JB_TPIDR] 103 ldr x2, [x0, #_JB_TPIDR]
105 msr tpidr_el0, x5  104 msr tpidr_el0, x2
106 105
107 ldp d8, d9, [x0, #_JB_D8] 106 ldp d8, d9, [x0, #_JB_D8]
108 ldp d10, d11, [x0, #_JB_D10] 107 ldp d10, d11, [x0, #_JB_D10]
109 ldp d12, d13, [x0, #_JB_D12] 108 ldp d12, d13, [x0, #_JB_D12]
110 ldp d14, d15, [x0, #_JB_D14] 109 ldp d14, d15, [x0, #_JB_D14]
111 110
112 sub sp, x3, #32 111 sub sp, x3, #32
113 112
114 stp x4, x5, [sp, #16] 113 stp x4, x5, [sp, #16]
115 str x1, [sp, #8] 114 str x1, [sp, #8]
116 add x29, sp, #16 115 add x29, sp, #16
117 116
118 mov x2, #0 117 mov x2, #0
119 add x1, x0, #_JB_SIGMASK 118 add x1, x0, #_JB_SIGMASK
120 mov x0, #3 /* SIG_SETMASK */ 119 mov x0, #3 /* SIG_SETMASK */
121 bl _C_LABEL(__sigprocmask14) 120 bl _C_LABEL(__sigprocmask14)
122 121
123 ldp x29, x30, [sp, #16] 122 ldp x29, x30, [sp, #16]
124 ldr x0, [sp, #8] 123 ldr x0, [sp, #8]
125 add sp, sp, #32 124 add sp, sp, #32
126 ret 125 ret
127 126
128 /* validation failed, die die die. */ 127 /* validation failed, die die die. */
129.Lbotch: 128.Lbotch:
130 bl _C_LABEL(longjmperror) 129 bl _C_LABEL(longjmperror)
131 bl _C_LABEL(abort) 130 bl _C_LABEL(abort)
1321: b 1b /* Cannot get here */ 1311: b 1b /* Cannot get here */
133END(__longjmp14) 132END(__longjmp14)