chiark / gitweb /
Merge branch '2.5.x' into HEAD
[catacomb] / base / regdump-arm64.S
1 /// -*- mode: asm; asm-comment-char: ?/ -*-
2 ///
3 /// Register dump and debugging for 64-bit ARM
4 ///
5 /// (c) 2019 Straylight/Edgeware
6 ///
7
8 ///----- Licensing notice ---------------------------------------------------
9 ///
10 /// This file is part of Catacomb.
11 ///
12 /// Catacomb is free software: you can redistribute it and/or modify it
13 /// under the terms of the GNU Library General Public License as published
14 /// by the Free Software Foundation; either version 2 of the License, or
15 /// (at your option) any later version.
16 ///
17 /// Catacomb is distributed in the hope that it will be useful, but
18 /// WITHOUT ANY WARRANTY; without even the implied warranty of
19 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 /// Library General Public License for more details.
21 ///
22 /// You should have received a copy of the GNU Library General Public
23 /// License along with Catacomb.  If not, write to the Free Software
24 /// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 /// USA.
26
27 ///--------------------------------------------------------------------------
28 /// Preliminaries.
29
30 #include "config.h"
31 #include "asm-common.h"
32 #include "regdump.h"
33
34         .arch   armv8-a
35
36         .text
37
38 ///--------------------------------------------------------------------------
39 /// Main code.
40
41 FUNC(regdump_gpsave)
42   endprologue
43         // On entry, sp should point to `REGDUMP_GPSIZE' bytes of
44         // doubleword-aligned storage to be the general-purpose save area,
45         // with x16, x17, and x30 already saved.  On exit, the initial
46         // registers are saved in this space, and modified: x20 points to the
47         // general-purpose save area, x22 holds the focus address (possibly
48         // already saved), x0 contains the number of bytes required in the
49         // extended save area, and other general-purpose registers are
50         // clobbered or used to communicate with `regdump_xtsave' below.
51         // Doing anything other than lowering the stack pointer and calling
52         // `regdump_xtsave' is not recommended.
53
54         // Save the easy registers.
55         stp     x0, x1, [sp, #0]
56         stp     x2, x3, [sp, #16]
57         stp     x4, x5, [sp, #32]
58         stp     x6, x7, [sp, #48]
59         stp     x18, x19, [sp, #144]
60         stp     x20, x21, [sp, #160]
61         stp     x22, x23, [sp, #176]
62         stp     x24, x25, [sp, #192]
63         stp     x26, x27, [sp, #208]
64         stp     x28, x29, [sp, #224]
65
66         mov     x20, sp
67
68         // Determine the previous stack pointer and save it.
69         add     x0, x20, #REGDUMP_GPSIZE
70         str     x0, [x20, #31*8]
71
72         // Set the return address as our PC.
73         str     x30, [x20, #8*REGIX_PC]
74
75         // Load the focus address and save it as x22.
76         ldr     x22, [x20, #8*REGIX_ADDR]
77
78         // Determine the extended save area size.
79         mov     x0, #REGDUMP_FPSIZE
80
81         // Done.
82         ret
83
84 ENDFUNC
85
86 FUNC(regdump_gprstr)
87   endprologue
88         // On entry, x20 points to a general-purpose save area, established
89         // by `regdump_gpsave'.  On exit, the general-purpose registers
90         // (other than x30 and sp) are restored to their original values.
91
92         // Restore the processor flags.
93         ldr     w0, [x20, #8*REGIX_NZCV]
94         msr     nzcv, x0
95
96         // Load the easy registers.
97         ldp     x0, x1, [sp, #0]
98         ldp     x2, x3, [sp, #16]
99         ldp     x4, x5, [sp, #32]
100         ldp     x6, x7, [sp, #48]
101         ldp     x8, x9, [sp, #64]
102         ldp     x10, x11, [sp, #80]
103         ldp     x12, x13, [sp, #96]
104         ldp     x14, x15, [sp, #112]
105         ldp     x16, x17, [sp, #128]
106         ldp     x18, x19, [sp, #144]
107         ldp     x20, x21, [sp, #160]
108         ldp     x22, x23, [sp, #176]
109         ldp     x24, x25, [sp, #192]
110         ldp     x26, x27, [sp, #208]
111         ldp     x28, x29, [sp, #224]
112
113         // Done.
114         ret
115
116 ENDFUNC
117
118 FUNC(regdump_xtsave)
119   endprologue
120         // On entry, sp points to an extended save area, of size determined
121         // by `regdump_gpsave' above.  On exit, the save area is filled in
122         // and a handy map placed at its base.
123
124         // Set up the map/extended save area pointer.
125         mov     x21, sp
126
127         // Start by filling in the easy part of the map.
128         add     x0, x21, #regmap_size
129         stp     x20, x0, [x21]
130
131         // Get the FP status register.
132         mrs     x1, fpsr
133         mrs     x2, fpcr
134         stp     w1, w2, [x0], #8
135
136         // Store the SIMD registers.
137         stp     q0, q1, [x0, #0]
138         stp     q2, q3, [x0, #32]
139         stp     q4, q5, [x0, #64]
140         stp     q6, q7, [x0, #96]
141         stp     q8, q9, [x0, #128]
142         stp     q10, q11, [x0, #160]
143         stp     q12, q13, [x0, #192]
144         stp     q14, q15, [x0, #224]
145         stp     q16, q17, [x0, #256]
146         stp     q18, q19, [x0, #288]
147         stp     q20, q21, [x0, #320]
148         stp     q22, q23, [x0, #352]
149         stp     q24, q25, [x0, #384]
150         stp     q26, q27, [x0, #416]
151         stp     q28, q29, [x0, #448]
152         stp     q30, q31, [x0, #480]
153
154         // Done.
155         ret
156
157 ENDFUNC
158
159 FUNC(regdump_xtrstr)
160   endprologue
161         // On entry, x21 points to a register-save map.  On exit, the
162         // extended registers are restored from the save area, x20 (pointing
163         // to the general-purpose save area) is preserved, and the other
164         // general registers are clobbered.
165
166         ldr     x0, [x21, #regmap_fp]
167
168         // Load the FP status and control registers.
169         ldp     w1, w2, [x0], #8
170         msr     fpsr, x1
171         msr     fpcr, x2
172
173         // Load the SIMD registers.
174         ldp     q0, q1, [x0, #0]
175         ldp     q2, q3, [x0, #32]
176         ldp     q4, q5, [x0, #64]
177         ldp     q6, q7, [x0, #96]
178         ldp     q8, q9, [x0, #128]
179         ldp     q10, q11, [x0, #160]
180         ldp     q12, q13, [x0, #192]
181         ldp     q14, q15, [x0, #224]
182         ldp     q16, q17, [x0, #256]
183         ldp     q18, q19, [x0, #288]
184         ldp     q20, q21, [x0, #320]
185         ldp     q22, q23, [x0, #352]
186         ldp     q24, q25, [x0, #384]
187         ldp     q26, q27, [x0, #416]
188         ldp     q28, q29, [x0, #448]
189         ldp     q30, q31, [x0, #480]
190
191         // Done.
192         ret
193
194 ENDFUNC
195
196 ///----- That's all, folks --------------------------------------------------