setjmp.S revision 1.1 1 1.1 matt /*.$NetBSD: setjmp.S,v 1.1 2014/08/10 05:47:36 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 /*
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 mrs x5, tpidr_el0
65 1.1 matt str x5, [x0, #_JB_TPIDR]
66 1.1 matt
67 1.1 matt stp d8, d9, [x0, #_JB_D8]
68 1.1 matt stp d10, d11, [x0, #_JB_D10]
69 1.1 matt stp d12, d13, [x0, #_JB_D12]
70 1.1 matt stp d14, d15, [x0, #_JB_D14]
71 1.1 matt
72 1.1 matt /* Get the signal mask. */
73 1.1 matt add x2, x0, #_JB_SIGMASK
74 1.1 matt mov x1, #0
75 1.1 matt mov x0, #0
76 1.1 matt
77 1.1 matt stp x29, x30, [sp, #-16]!
78 1.1 matt mov x29, sp
79 1.1 matt bl _C_LABEL(__sigprocmask14)
80 1.1 matt ldp x29, x30, [sp], #16
81 1.1 matt
82 1.1 matt mov x0, xzr
83 1.1 matt ret
84 1.1 matt END(__setjmp14)
85 1.1 matt
86 1.1 matt ENTRY(__longjmp14)
87 1.1 matt adrp x7, .L_MAGIC
88 1.1 matt ldr x7, [x7, #:lo12:.L_MAGIC]
89 1.1 matt ldp x2, x3, [x0, #_JB_MAGIC]
90 1.1 matt cmp x2, x7
91 1.1 matt b.ne .Lbotch
92 1.1 matt
93 1.1 matt ldp x4, x5, [x0, #_JB_X29]
94 1.1 matt cbz x3, .Lbotch
95 1.1 matt cbz x4, .Lbotch
96 1.1 matt cbz x5, .Lbotch
97 1.1 matt
98 1.1 matt ldp x19, x20, [x0, #_JB_X19]
99 1.1 matt ldp x21, x22, [x0, #_JB_X21]
100 1.1 matt ldp x23, x24, [x0, #_JB_X23]
101 1.1 matt ldp x25, x26, [x0, #_JB_X25]
102 1.1 matt ldp x27, x28, [x0, #_JB_X27]
103 1.1 matt
104 1.1 matt ldr x5, [x0, #_JB_TPIDR]
105 1.1 matt msr tpidr_el0, x5
106 1.1 matt
107 1.1 matt ldp d8, d9, [x0, #_JB_D8]
108 1.1 matt ldp d10, d11, [x0, #_JB_D10]
109 1.1 matt ldp d12, d13, [x0, #_JB_D12]
110 1.1 matt ldp d14, d15, [x0, #_JB_D14]
111 1.1 matt
112 1.1 matt sub sp, x3, #32
113 1.1 matt
114 1.1 matt stp x4, x5, [sp, #16]
115 1.1 matt str x1, [sp, #8]
116 1.1 matt add x29, sp, #16
117 1.1 matt
118 1.1 matt mov x2, #0
119 1.1 matt add x1, x0, #_JB_SIGMASK
120 1.1 matt mov x0, #3 /* SIG_SETMASK */
121 1.1 matt bl _C_LABEL(__sigprocmask14)
122 1.1 matt
123 1.1 matt ldp x29, x30, [sp, #16]
124 1.1 matt ldr x0, [sp, #8]
125 1.1 matt add sp, sp, #32
126 1.1 matt ret
127 1.1 matt
128 1.1 matt /* validation failed, die die die. */
129 1.1 matt .Lbotch:
130 1.1 matt bl _C_LABEL(longjmperror)
131 1.1 matt bl _C_LABEL(abort)
132 1.1 matt 1: b 1b /* Cannot get here */
133 1.1 matt END(__longjmp14)
134