setjmp.S revision 1.4 1 1.4 skrll /*.$NetBSD: setjmp.S,v 1.4 2021/10/07 06:44:18 skrll 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 /*
36 1.1 matt * C library -- setjmp, longjmp
37 1.1 matt *
38 1.1 matt * longjmp(a,v)
39 1.1 matt * will generate a "return(v)" from the last call to
40 1.1 matt * setjmp(a)
41 1.1 matt * by restoring registers from the stack.
42 1.1 matt * The previous signal state is restored.
43 1.1 matt */
44 1.1 matt
45 1.1 matt .section .rodata.cst8,"aM",@progbits,8
46 1.1 matt .align 3
47 1.1 matt .L_MAGIC:
48 1.1 matt .xword _JB_MAGIC_AARCH64_SETJMP
49 1.1 matt
50 1.1 matt ENTRY(__setjmp14)
51 1.1 matt adrp x7, .L_MAGIC
52 1.1 matt ldr x7, [x7, #:lo12:.L_MAGIC]
53 1.1 matt
54 1.1 matt mov x3, sp
55 1.1 matt stp x7, x3, [x0, #_JB_MAGIC]
56 1.1 matt
57 1.1 matt stp x19, x20, [x0, #_JB_X19]
58 1.1 matt stp x21, x22, [x0, #_JB_X21]
59 1.1 matt stp x23, x24, [x0, #_JB_X23]
60 1.1 matt stp x25, x26, [x0, #_JB_X25]
61 1.1 matt stp x27, x28, [x0, #_JB_X27]
62 1.1 matt stp x29, x30, [x0, #_JB_X29]
63 1.1 matt
64 1.1 matt stp d8, d9, [x0, #_JB_D8]
65 1.1 matt stp d10, d11, [x0, #_JB_D10]
66 1.1 matt stp d12, d13, [x0, #_JB_D12]
67 1.1 matt stp d14, d15, [x0, #_JB_D14]
68 1.1 matt
69 1.1 matt /* Get the signal mask. */
70 1.1 matt add x2, x0, #_JB_SIGMASK
71 1.1 matt mov x1, #0
72 1.1 matt mov x0, #0
73 1.1 matt
74 1.1 matt stp x29, x30, [sp, #-16]!
75 1.1 matt mov x29, sp
76 1.1 matt bl _C_LABEL(__sigprocmask14)
77 1.1 matt ldp x29, x30, [sp], #16
78 1.1 matt
79 1.1 matt mov x0, xzr
80 1.1 matt ret
81 1.1 matt END(__setjmp14)
82 1.1 matt
83 1.1 matt ENTRY(__longjmp14)
84 1.1 matt adrp x7, .L_MAGIC
85 1.1 matt ldr x7, [x7, #:lo12:.L_MAGIC]
86 1.1 matt ldp x2, x3, [x0, #_JB_MAGIC]
87 1.1 matt cmp x2, x7
88 1.1 matt b.ne .Lbotch
89 1.1 matt
90 1.1 matt ldp x4, x5, [x0, #_JB_X29]
91 1.1 matt cbz x3, .Lbotch
92 1.1 matt cbz x5, .Lbotch
93 1.1 matt
94 1.1 matt ldp x19, x20, [x0, #_JB_X19]
95 1.1 matt ldp x21, x22, [x0, #_JB_X21]
96 1.1 matt ldp x23, x24, [x0, #_JB_X23]
97 1.1 matt ldp x25, x26, [x0, #_JB_X25]
98 1.1 matt ldp x27, x28, [x0, #_JB_X27]
99 1.1 matt
100 1.1 matt ldp d8, d9, [x0, #_JB_D8]
101 1.1 matt ldp d10, d11, [x0, #_JB_D10]
102 1.1 matt ldp d12, d13, [x0, #_JB_D12]
103 1.1 matt ldp d14, d15, [x0, #_JB_D14]
104 1.1 matt
105 1.1 matt sub sp, x3, #32
106 1.1 matt
107 1.1 matt stp x4, x5, [sp, #16]
108 1.1 matt str x1, [sp, #8]
109 1.1 matt add x29, sp, #16
110 1.1 matt
111 1.1 matt mov x2, #0
112 1.1 matt add x1, x0, #_JB_SIGMASK
113 1.1 matt mov x0, #3 /* SIG_SETMASK */
114 1.1 matt bl _C_LABEL(__sigprocmask14)
115 1.1 matt
116 1.1 matt ldp x29, x30, [sp, #16]
117 1.4 skrll ldr x1, [sp, #8]
118 1.1 matt add sp, sp, #32
119 1.4 skrll
120 1.4 skrll cmp x1, #0
121 1.4 skrll csinc x0, x1, xzr, ne
122 1.1 matt ret
123 1.1 matt
124 1.1 matt /* validation failed, die die die. */
125 1.1 matt .Lbotch:
126 1.1 matt bl _C_LABEL(longjmperror)
127 1.1 matt bl _C_LABEL(abort)
128 1.1 matt 1: b 1b /* Cannot get here */
129 1.1 matt END(__longjmp14)
130