Commit | Line | Data |
---|---|---|
1ae3db19 MS |
1 | /* Target-dependent code for GNU/Linux AArch64. |
2 | ||
11bc5fe4 | 3 | Copyright (C) 2009-2020 Free Software Foundation, Inc. |
1ae3db19 MS |
4 | Contributed by ARM Ltd. |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "defs.h" | |
22 | ||
d55e5aa6 | 23 | #include "gdbarch.h" |
1ae3db19 MS |
24 | #include "glibc-tdep.h" |
25 | #include "linux-tdep.h" | |
4de283e4 TT |
26 | #include "aarch64-tdep.h" |
27 | #include "aarch64-linux-tdep.h" | |
1ae3db19 | 28 | #include "osabi.h" |
d55e5aa6 | 29 | #include "solib-svr4.h" |
d55e5aa6 | 30 | #include "symtab.h" |
d55e5aa6 | 31 | #include "tramp-frame.h" |
4de283e4 | 32 | #include "trad-frame.h" |
be155ebb | 33 | #include "target/target.h" |
4de283e4 | 34 | |
4de283e4 TT |
35 | #include "regcache.h" |
36 | #include "regset.h" | |
37 | ||
4de283e4 TT |
38 | #include "stap-probe.h" |
39 | #include "parser-defs.h" | |
08248ca9 | 40 | #include "user-regs.h" |
f68f11b7 | 41 | #include "xml-syscall.h" |
4de283e4 TT |
42 | #include <ctype.h> |
43 | ||
44 | #include "record-full.h" | |
45 | #include "linux-record.h" | |
99afc88b | 46 | |
1ae3db19 MS |
47 | /* Signal frame handling. |
48 | ||
f2205de0 HZ |
49 | +------------+ ^ |
50 | | saved lr | | | |
51 | +->| saved fp |--+ | |
52 | | | | | |
53 | | | | | |
54 | | +------------+ | |
55 | | | saved lr | | |
56 | +--| saved fp | | |
57 | ^ | | | |
58 | | | | | |
59 | | +------------+ | |
60 | ^ | | | |
61 | | | signal | | |
62 | | | | SIGTRAMP_FRAME (struct rt_sigframe) | |
63 | | | saved regs | | |
64 | +--| saved sp |--> interrupted_sp | |
65 | | | saved pc |--> interrupted_pc | |
66 | | | | | |
67 | | +------------+ | |
68 | | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0) | |
69 | +--| saved fp |<- FP | |
70 | | | NORMAL_FRAME | |
71 | | |<- SP | |
72 | +------------+ | |
1ae3db19 MS |
73 | |
74 | On signal delivery, the kernel will create a signal handler stack | |
75 | frame and setup the return address in LR to point at restorer stub. | |
76 | The signal stack frame is defined by: | |
77 | ||
78 | struct rt_sigframe | |
79 | { | |
80 | siginfo_t info; | |
81 | struct ucontext uc; | |
82 | }; | |
83 | ||
1ae3db19 MS |
84 | The ucontext has the following form: |
85 | struct ucontext | |
86 | { | |
87 | unsigned long uc_flags; | |
88 | struct ucontext *uc_link; | |
89 | stack_t uc_stack; | |
90 | sigset_t uc_sigmask; | |
91 | struct sigcontext uc_mcontext; | |
92 | }; | |
93 | ||
1ae3db19 MS |
94 | struct sigcontext |
95 | { | |
96 | unsigned long fault_address; | |
97 | unsigned long regs[31]; | |
98 | unsigned long sp; / * 31 * / | |
99 | unsigned long pc; / * 32 * / | |
100 | unsigned long pstate; / * 33 * / | |
101 | __u8 __reserved[4096] | |
102 | }; | |
103 | ||
05c71722 AH |
104 | The reserved space in sigcontext contains additional structures, each starting |
105 | with a aarch64_ctx, which specifies a unique identifier and the total size of | |
106 | the structure. The final structure in reserved will start will a null | |
107 | aarch64_ctx. The penultimate entry in reserved may be a extra_context which | |
108 | then points to a further block of reserved space. | |
109 | ||
110 | struct aarch64_ctx { | |
111 | u32 magic; | |
112 | u32 size; | |
113 | }; | |
114 | ||
1ae3db19 MS |
115 | The restorer stub will always have the form: |
116 | ||
117 | d28015a8 movz x8, #0xad | |
118 | d4000001 svc #0x0 | |
119 | ||
f2205de0 HZ |
120 | This is a system call sys_rt_sigreturn. |
121 | ||
1ae3db19 MS |
122 | We detect signal frames by snooping the return code for the restorer |
123 | instruction sequence. | |
124 | ||
125 | The handler then needs to recover the saved register set from | |
126 | ucontext.uc_mcontext. */ | |
127 | ||
128 | /* These magic numbers need to reflect the layout of the kernel | |
129 | defined struct rt_sigframe and ucontext. */ | |
130 | #define AARCH64_SIGCONTEXT_REG_SIZE 8 | |
131 | #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128 | |
132 | #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176 | |
133 | #define AARCH64_SIGCONTEXT_XO_OFFSET 8 | |
05c71722 AH |
134 | #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288 |
135 | ||
74b3c713 AH |
136 | #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096 |
137 | ||
05c71722 AH |
138 | /* Unique identifiers that may be used for aarch64_ctx.magic. */ |
139 | #define AARCH64_EXTRA_MAGIC 0x45585401 | |
140 | #define AARCH64_FPSIMD_MAGIC 0x46508001 | |
141 | #define AARCH64_SVE_MAGIC 0x53564501 | |
142 | ||
143 | /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */ | |
144 | #define AARCH64_EXTRA_DATAP_OFFSET 8 | |
145 | ||
146 | /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */ | |
147 | #define AARCH64_FPSIMD_FPSR_OFFSET 8 | |
148 | #define AARCH64_FPSIMD_FPCR_OFFSET 12 | |
149 | #define AARCH64_FPSIMD_V0_OFFSET 16 | |
150 | #define AARCH64_FPSIMD_VREG_SIZE 16 | |
151 | ||
152 | /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */ | |
153 | #define AARCH64_SVE_CONTEXT_VL_OFFSET 8 | |
154 | #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16 | |
155 | #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16) | |
156 | #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \ | |
157 | (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2)) | |
158 | #define AARCH64_SVE_CONTEXT_SIZE(vq) \ | |
159 | (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2)) | |
160 | ||
161 | ||
162 | /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the | |
163 | size, or return 0 on error. */ | |
164 | ||
165 | static uint32_t | |
166 | read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order, | |
167 | uint32_t *size) | |
168 | { | |
169 | uint32_t magic = 0; | |
170 | gdb_byte buf[4]; | |
171 | ||
172 | if (target_read_memory (ctx_addr, buf, 4) != 0) | |
173 | return 0; | |
174 | magic = extract_unsigned_integer (buf, 4, byte_order); | |
175 | ||
176 | if (target_read_memory (ctx_addr + 4, buf, 4) != 0) | |
177 | return 0; | |
178 | *size = extract_unsigned_integer (buf, 4, byte_order); | |
179 | ||
180 | return magic; | |
181 | } | |
1ae3db19 MS |
182 | |
183 | /* Implement the "init" method of struct tramp_frame. */ | |
184 | ||
185 | static void | |
186 | aarch64_linux_sigframe_init (const struct tramp_frame *self, | |
187 | struct frame_info *this_frame, | |
188 | struct trad_frame_cache *this_cache, | |
189 | CORE_ADDR func) | |
190 | { | |
05c71722 AH |
191 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
192 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
193 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1ae3db19 | 194 | CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); |
05c71722 AH |
195 | CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET |
196 | + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET ); | |
197 | CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET; | |
74b3c713 | 198 | CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE; |
05c71722 AH |
199 | CORE_ADDR fpsimd = 0; |
200 | CORE_ADDR sve_regs = 0; | |
201 | uint32_t size, magic; | |
74b3c713 | 202 | bool extra_found = false; |
05c71722 AH |
203 | int num_regs = gdbarch_num_regs (gdbarch); |
204 | ||
205 | /* Read in the integer registers. */ | |
1ae3db19 | 206 | |
05c71722 | 207 | for (int i = 0; i < 31; i++) |
1ae3db19 MS |
208 | { |
209 | trad_frame_set_reg_addr (this_cache, | |
210 | AARCH64_X0_REGNUM + i, | |
211 | sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET | |
05c71722 | 212 | + i * AARCH64_SIGCONTEXT_REG_SIZE); |
1ae3db19 | 213 | } |
f2205de0 HZ |
214 | trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, |
215 | sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET | |
216 | + 31 * AARCH64_SIGCONTEXT_REG_SIZE); | |
217 | trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, | |
218 | sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET | |
219 | + 32 * AARCH64_SIGCONTEXT_REG_SIZE); | |
220 | ||
74b3c713 AH |
221 | /* Search for the FP and SVE sections, stopping at null. */ |
222 | while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0 | |
223 | && size != 0) | |
05c71722 AH |
224 | { |
225 | switch (magic) | |
226 | { | |
227 | case AARCH64_FPSIMD_MAGIC: | |
228 | fpsimd = section; | |
229 | section += size; | |
230 | break; | |
231 | ||
232 | case AARCH64_SVE_MAGIC: | |
233 | { | |
234 | /* Check if the section is followed by a full SVE dump, and set | |
235 | sve_regs if it is. */ | |
236 | gdb_byte buf[4]; | |
237 | uint16_t vq; | |
238 | ||
239 | if (!tdep->has_sve ()) | |
240 | break; | |
241 | ||
242 | if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET, | |
243 | buf, 2) != 0) | |
244 | { | |
245 | section += size; | |
246 | break; | |
247 | } | |
248 | vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order)); | |
249 | ||
250 | if (vq != tdep->vq) | |
2398abf8 TT |
251 | error (_("Invalid vector length in signal frame %d vs %s."), vq, |
252 | pulongest (tdep->vq)); | |
05c71722 AH |
253 | |
254 | if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) | |
255 | sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; | |
256 | ||
257 | section += size; | |
258 | break; | |
259 | } | |
260 | ||
261 | case AARCH64_EXTRA_MAGIC: | |
262 | { | |
263 | /* Extra is always the last valid section in reserved and points to | |
264 | an additional block of memory filled with more sections. Reset | |
265 | the address to the extra section and continue looking for more | |
266 | structures. */ | |
267 | gdb_byte buf[8]; | |
268 | ||
269 | if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET, | |
270 | buf, 8) != 0) | |
271 | { | |
272 | section += size; | |
273 | break; | |
274 | } | |
275 | ||
276 | section = extract_unsigned_integer (buf, 8, byte_order); | |
74b3c713 | 277 | extra_found = true; |
05c71722 AH |
278 | break; |
279 | } | |
280 | ||
281 | default: | |
74b3c713 | 282 | section += size; |
05c71722 AH |
283 | break; |
284 | } | |
74b3c713 AH |
285 | |
286 | /* Prevent searching past the end of the reserved section. The extra | |
287 | section does not have a hard coded limit - we have to rely on it ending | |
288 | with nulls. */ | |
289 | if (!extra_found && section > section_end) | |
290 | break; | |
05c71722 AH |
291 | } |
292 | ||
293 | if (sve_regs != 0) | |
294 | { | |
295 | CORE_ADDR offset; | |
296 | ||
297 | for (int i = 0; i < 32; i++) | |
298 | { | |
299 | offset = sve_regs + (i * tdep->vq * 16); | |
300 | trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i, | |
301 | offset); | |
302 | trad_frame_set_reg_addr (this_cache, | |
303 | num_regs + AARCH64_SVE_V0_REGNUM + i, | |
304 | offset); | |
305 | trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_Q0_REGNUM + i, | |
306 | offset); | |
307 | trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_D0_REGNUM + i, | |
308 | offset); | |
309 | trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_S0_REGNUM + i, | |
310 | offset); | |
311 | trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_H0_REGNUM + i, | |
312 | offset); | |
313 | trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_B0_REGNUM + i, | |
314 | offset); | |
315 | } | |
316 | ||
317 | offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq); | |
318 | for (int i = 0; i < 16; i++) | |
319 | trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i, | |
320 | offset + (i * tdep->vq * 2)); | |
321 | ||
322 | offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq); | |
323 | trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset); | |
324 | } | |
325 | ||
326 | if (fpsimd != 0) | |
327 | { | |
328 | trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM, | |
329 | fpsimd + AARCH64_FPSIMD_FPSR_OFFSET); | |
330 | trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM, | |
331 | fpsimd + AARCH64_FPSIMD_FPCR_OFFSET); | |
332 | ||
333 | /* If there was no SVE section then set up the V registers. */ | |
334 | if (sve_regs == 0) | |
335 | for (int i = 0; i < 32; i++) | |
336 | { | |
337 | CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET | |
338 | + (i * AARCH64_FPSIMD_VREG_SIZE)); | |
339 | ||
340 | trad_frame_set_reg_addr (this_cache, AARCH64_V0_REGNUM + i, offset); | |
341 | trad_frame_set_reg_addr (this_cache, | |
342 | num_regs + AARCH64_Q0_REGNUM + i, offset); | |
343 | trad_frame_set_reg_addr (this_cache, | |
344 | num_regs + AARCH64_D0_REGNUM + i, offset); | |
345 | trad_frame_set_reg_addr (this_cache, | |
346 | num_regs + AARCH64_S0_REGNUM + i, offset); | |
347 | trad_frame_set_reg_addr (this_cache, | |
348 | num_regs + AARCH64_H0_REGNUM + i, offset); | |
349 | trad_frame_set_reg_addr (this_cache, | |
350 | num_regs + AARCH64_B0_REGNUM + i, offset); | |
351 | if (tdep->has_sve ()) | |
352 | trad_frame_set_reg_addr (this_cache, | |
353 | num_regs + AARCH64_SVE_V0_REGNUM + i, | |
354 | offset); | |
355 | } | |
356 | } | |
357 | ||
f2205de0 | 358 | trad_frame_set_id (this_cache, frame_id_build (sp, func)); |
1ae3db19 MS |
359 | } |
360 | ||
361 | static const struct tramp_frame aarch64_linux_rt_sigframe = | |
362 | { | |
363 | SIGTRAMP_FRAME, | |
364 | 4, | |
365 | { | |
366 | /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8) | |
367 | Soo1 0010 1hhi iiii iiii iiii iiir rrrr */ | |
7bc02706 | 368 | {0xd2801168, ULONGEST_MAX}, |
1ae3db19 MS |
369 | |
370 | /* svc 0x0 (o=0, l=1) | |
371 | 1101 0100 oooi iiii iiii iiii iii0 00ll */ | |
7bc02706 TT |
372 | {0xd4000001, ULONGEST_MAX}, |
373 | {TRAMP_SENTINEL_INSN, ULONGEST_MAX} | |
1ae3db19 MS |
374 | }, |
375 | aarch64_linux_sigframe_init | |
376 | }; | |
377 | ||
d4d793bf | 378 | /* Register maps. */ |
1ae3db19 | 379 | |
d4d793bf AA |
380 | static const struct regcache_map_entry aarch64_linux_gregmap[] = |
381 | { | |
382 | { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */ | |
383 | { 1, AARCH64_SP_REGNUM, 8 }, | |
384 | { 1, AARCH64_PC_REGNUM, 8 }, | |
385 | { 1, AARCH64_CPSR_REGNUM, 8 }, | |
386 | { 0 } | |
387 | }; | |
1ae3db19 | 388 | |
d4d793bf AA |
389 | static const struct regcache_map_entry aarch64_linux_fpregmap[] = |
390 | { | |
391 | { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */ | |
392 | { 1, AARCH64_FPSR_REGNUM, 4 }, | |
393 | { 1, AARCH64_FPCR_REGNUM, 4 }, | |
394 | { 0 } | |
395 | }; | |
1ae3db19 | 396 | |
d4d793bf | 397 | /* Register set definitions. */ |
a069a2bd | 398 | |
d4d793bf | 399 | const struct regset aarch64_linux_gregset = |
a069a2bd | 400 | { |
d4d793bf AA |
401 | aarch64_linux_gregmap, |
402 | regcache_supply_regset, regcache_collect_regset | |
a069a2bd AA |
403 | }; |
404 | ||
d4d793bf | 405 | const struct regset aarch64_linux_fpregset = |
a069a2bd | 406 | { |
d4d793bf AA |
407 | aarch64_linux_fpregmap, |
408 | regcache_supply_regset, regcache_collect_regset | |
a069a2bd AA |
409 | }; |
410 | ||
b7fd65b9 AH |
411 | /* The fields in an SVE header at the start of a SVE regset. */ |
412 | ||
413 | #define SVE_HEADER_SIZE_LENGTH 4 | |
414 | #define SVE_HEADER_MAX_SIZE_LENGTH 4 | |
415 | #define SVE_HEADER_VL_LENGTH 2 | |
416 | #define SVE_HEADER_MAX_VL_LENGTH 2 | |
417 | #define SVE_HEADER_FLAGS_LENGTH 2 | |
418 | #define SVE_HEADER_RESERVED_LENGTH 2 | |
419 | ||
420 | #define SVE_HEADER_SIZE_OFFSET 0 | |
421 | #define SVE_HEADER_MAX_SIZE_OFFSET \ | |
422 | (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH) | |
423 | #define SVE_HEADER_VL_OFFSET \ | |
424 | (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH) | |
425 | #define SVE_HEADER_MAX_VL_OFFSET \ | |
426 | (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH) | |
427 | #define SVE_HEADER_FLAGS_OFFSET \ | |
428 | (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH) | |
429 | #define SVE_HEADER_RESERVED_OFFSET \ | |
430 | (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH) | |
431 | #define SVE_HEADER_SIZE \ | |
432 | (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH) | |
433 | ||
0c76e06d AH |
434 | #define SVE_HEADER_FLAG_SVE 1 |
435 | ||
b7fd65b9 AH |
436 | /* Get VQ value from SVE section in the core dump. */ |
437 | ||
438 | static uint64_t | |
439 | aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd) | |
440 | { | |
441 | gdb_byte header[SVE_HEADER_SIZE]; | |
442 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
443 | asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve"); | |
444 | ||
445 | if (sve_section == nullptr) | |
446 | { | |
447 | /* No SVE state. */ | |
448 | return 0; | |
449 | } | |
450 | ||
fd361982 | 451 | size_t size = bfd_section_size (sve_section); |
b7fd65b9 AH |
452 | |
453 | /* Check extended state size. */ | |
454 | if (size < SVE_HEADER_SIZE) | |
455 | { | |
456 | warning (_("'.reg-aarch-sve' section in core file too small.")); | |
457 | return 0; | |
458 | } | |
459 | ||
460 | if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE)) | |
461 | { | |
462 | warning (_("Couldn't read sve header from " | |
463 | "'.reg-aarch-sve' section in core file.")); | |
464 | return 0; | |
465 | } | |
466 | ||
467 | uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET, | |
468 | SVE_HEADER_VL_LENGTH, byte_order); | |
469 | uint64_t vq = sve_vq_from_vl (vl); | |
470 | ||
471 | if (vq > AARCH64_MAX_SVE_VQ) | |
472 | { | |
473 | warning (_("SVE Vector length in core file not supported by this version" | |
49514353 | 474 | " of GDB. (VQ=%s)"), pulongest (vq)); |
b7fd65b9 AH |
475 | return 0; |
476 | } | |
477 | else if (vq == 0) | |
478 | { | |
49514353 TT |
479 | warning (_("SVE Vector length in core file is invalid. (VQ=%s"), |
480 | pulongest (vq)); | |
b7fd65b9 AH |
481 | return 0; |
482 | } | |
483 | ||
484 | return vq; | |
485 | } | |
486 | ||
0c76e06d AH |
487 | /* Supply register REGNUM from BUF to REGCACHE, using the register map |
488 | in REGSET. If REGNUM is -1, do this for all registers in REGSET. | |
489 | If BUF is NULL, set the registers to "unavailable" status. */ | |
490 | ||
491 | static void | |
492 | aarch64_linux_supply_sve_regset (const struct regset *regset, | |
493 | struct regcache *regcache, | |
494 | int regnum, const void *buf, size_t size) | |
495 | { | |
496 | gdb_byte *header = (gdb_byte *) buf; | |
497 | struct gdbarch *gdbarch = regcache->arch (); | |
498 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
499 | ||
500 | if (buf == nullptr) | |
501 | return regcache->supply_regset (regset, regnum, nullptr, size); | |
502 | gdb_assert (size > SVE_HEADER_SIZE); | |
503 | ||
504 | /* BUF contains an SVE header followed by a register dump of either the | |
505 | passed in SVE regset or a NEON fpregset. */ | |
506 | ||
507 | /* Extract required fields from the header. */ | |
0c0a40e0 | 508 | ULONGEST vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET, |
0c76e06d AH |
509 | SVE_HEADER_VL_LENGTH, byte_order); |
510 | uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, | |
511 | SVE_HEADER_FLAGS_LENGTH, | |
512 | byte_order); | |
513 | ||
514 | if (regnum == -1 || regnum == AARCH64_SVE_VG_REGNUM) | |
515 | { | |
516 | gdb_byte vg_target[8]; | |
517 | store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order, | |
518 | sve_vg_from_vl (vl)); | |
519 | regcache->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_target); | |
520 | } | |
521 | ||
522 | if (flags & SVE_HEADER_FLAG_SVE) | |
523 | { | |
524 | /* Register dump is a SVE structure. */ | |
525 | regcache->supply_regset (regset, regnum, | |
526 | (gdb_byte *) buf + SVE_HEADER_SIZE, | |
527 | size - SVE_HEADER_SIZE); | |
528 | } | |
529 | else | |
530 | { | |
531 | /* Register dump is a fpsimd structure. First clear the SVE | |
532 | registers. */ | |
533 | for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) | |
534 | regcache->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM + i); | |
535 | for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) | |
536 | regcache->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM + i); | |
537 | regcache->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM); | |
538 | ||
539 | /* Then supply the fpsimd registers. */ | |
540 | regcache->supply_regset (&aarch64_linux_fpregset, regnum, | |
541 | (gdb_byte *) buf + SVE_HEADER_SIZE, | |
542 | size - SVE_HEADER_SIZE); | |
543 | } | |
544 | } | |
545 | ||
546 | /* Collect register REGNUM from REGCACHE to BUF, using the register | |
547 | map in REGSET. If REGNUM is -1, do this for all registers in | |
548 | REGSET. */ | |
549 | ||
550 | static void | |
551 | aarch64_linux_collect_sve_regset (const struct regset *regset, | |
552 | const struct regcache *regcache, | |
553 | int regnum, void *buf, size_t size) | |
554 | { | |
555 | gdb_byte *header = (gdb_byte *) buf; | |
556 | struct gdbarch *gdbarch = regcache->arch (); | |
557 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
558 | uint64_t vq = gdbarch_tdep (gdbarch)->vq; | |
559 | ||
560 | gdb_assert (buf != NULL); | |
561 | gdb_assert (size > SVE_HEADER_SIZE); | |
562 | ||
563 | /* BUF starts with a SVE header prior to the register dump. */ | |
564 | ||
565 | store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET, | |
566 | SVE_HEADER_SIZE_LENGTH, byte_order, size); | |
567 | store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET, | |
568 | SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size); | |
569 | store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH, | |
570 | byte_order, sve_vl_from_vq (vq)); | |
571 | store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET, | |
572 | SVE_HEADER_MAX_VL_LENGTH, byte_order, | |
573 | sve_vl_from_vq (vq)); | |
574 | store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, | |
575 | SVE_HEADER_FLAGS_LENGTH, byte_order, | |
576 | SVE_HEADER_FLAG_SVE); | |
577 | store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET, | |
578 | SVE_HEADER_RESERVED_LENGTH, byte_order, 0); | |
579 | ||
580 | /* The SVE register dump follows. */ | |
581 | regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE, | |
582 | size - SVE_HEADER_SIZE); | |
583 | } | |
584 | ||
1ae3db19 MS |
585 | /* Implement the "regset_from_core_section" gdbarch method. */ |
586 | ||
4108500a AA |
587 | static void |
588 | aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
589 | iterate_over_regset_sections_cb *cb, | |
590 | void *cb_data, | |
591 | const struct regcache *regcache) | |
1ae3db19 | 592 | { |
0c76e06d AH |
593 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
594 | ||
a616bb94 AH |
595 | cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET, |
596 | &aarch64_linux_gregset, NULL, cb_data); | |
0c76e06d AH |
597 | |
598 | if (tdep->has_sve ()) | |
599 | { | |
600 | /* Create this on the fly in order to handle vector register sizes. */ | |
601 | const struct regcache_map_entry sve_regmap[] = | |
602 | { | |
1885053b TT |
603 | { 32, AARCH64_SVE_Z0_REGNUM, (int) (tdep->vq * 16) }, |
604 | { 16, AARCH64_SVE_P0_REGNUM, (int) (tdep->vq * 16 / 8) }, | |
0c76e06d AH |
605 | { 1, AARCH64_SVE_FFR_REGNUM, 4 }, |
606 | { 1, AARCH64_FPSR_REGNUM, 4 }, | |
607 | { 1, AARCH64_FPCR_REGNUM, 4 }, | |
608 | { 0 } | |
609 | }; | |
610 | ||
611 | const struct regset aarch64_linux_sve_regset = | |
612 | { | |
613 | sve_regmap, | |
614 | aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_regset, | |
615 | REGSET_VARIABLE_SIZE | |
616 | }; | |
617 | ||
618 | cb (".reg-aarch-sve", | |
619 | SVE_HEADER_SIZE + regcache_map_entry_size (aarch64_linux_fpregmap), | |
620 | SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap), | |
621 | &aarch64_linux_sve_regset, "SVE registers", cb_data); | |
622 | } | |
623 | else | |
624 | cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET, | |
625 | &aarch64_linux_fpregset, NULL, cb_data); | |
59c28372 AH |
626 | |
627 | ||
628 | if (tdep->has_pauth ()) | |
629 | { | |
630 | /* Create this on the fly in order to handle the variable location. */ | |
631 | const struct regcache_map_entry pauth_regmap[] = | |
632 | { | |
633 | { 2, AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base), 8}, | |
634 | { 0 } | |
635 | }; | |
636 | ||
637 | const struct regset aarch64_linux_pauth_regset = | |
638 | { | |
639 | pauth_regmap, regcache_supply_regset, regcache_collect_regset | |
640 | }; | |
641 | ||
642 | cb (".reg-aarch-pauth", AARCH64_LINUX_SIZEOF_PAUTH, | |
643 | AARCH64_LINUX_SIZEOF_PAUTH, &aarch64_linux_pauth_regset, | |
644 | "pauth registers", cb_data); | |
645 | } | |
1ae3db19 MS |
646 | } |
647 | ||
b7fd65b9 | 648 | /* Implement the "core_read_description" gdbarch method. */ |
cd3af38d JW |
649 | |
650 | static const struct target_desc * | |
651 | aarch64_linux_core_read_description (struct gdbarch *gdbarch, | |
652 | struct target_ops *target, bfd *abfd) | |
653 | { | |
0f83012e | 654 | CORE_ADDR hwcap = linux_get_hwcap (target); |
cd3af38d | 655 | |
6dc0ebde | 656 | return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd), |
0f83012e | 657 | hwcap & AARCH64_HWCAP_PACA); |
cd3af38d JW |
658 | } |
659 | ||
08248ca9 SDJ |
660 | /* Implementation of `gdbarch_stap_is_single_operand', as defined in |
661 | gdbarch.h. */ | |
662 | ||
663 | static int | |
664 | aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) | |
665 | { | |
666 | return (*s == '#' || isdigit (*s) /* Literal number. */ | |
667 | || *s == '[' /* Register indirection. */ | |
668 | || isalpha (*s)); /* Register value. */ | |
669 | } | |
670 | ||
671 | /* This routine is used to parse a special token in AArch64's assembly. | |
672 | ||
673 | The special tokens parsed by it are: | |
674 | ||
675 | - Register displacement (e.g, [fp, #-8]) | |
676 | ||
677 | It returns one if the special token has been parsed successfully, | |
678 | or zero if the current token is not considered special. */ | |
679 | ||
680 | static int | |
681 | aarch64_stap_parse_special_token (struct gdbarch *gdbarch, | |
682 | struct stap_parse_info *p) | |
683 | { | |
684 | if (*p->arg == '[') | |
685 | { | |
686 | /* Temporary holder for lookahead. */ | |
687 | const char *tmp = p->arg; | |
688 | char *endp; | |
689 | /* Used to save the register name. */ | |
690 | const char *start; | |
691 | char *regname; | |
692 | int len; | |
693 | int got_minus = 0; | |
694 | long displacement; | |
695 | struct stoken str; | |
696 | ||
697 | ++tmp; | |
698 | start = tmp; | |
699 | ||
700 | /* Register name. */ | |
701 | while (isalnum (*tmp)) | |
702 | ++tmp; | |
703 | ||
704 | if (*tmp != ',') | |
705 | return 0; | |
706 | ||
707 | len = tmp - start; | |
224c3ddb | 708 | regname = (char *) alloca (len + 2); |
08248ca9 SDJ |
709 | |
710 | strncpy (regname, start, len); | |
711 | regname[len] = '\0'; | |
712 | ||
713 | if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1) | |
714 | error (_("Invalid register name `%s' on expression `%s'."), | |
715 | regname, p->saved_arg); | |
716 | ||
717 | ++tmp; | |
f1735a53 | 718 | tmp = skip_spaces (tmp); |
08248ca9 SDJ |
719 | /* Now we expect a number. It can begin with '#' or simply |
720 | a digit. */ | |
721 | if (*tmp == '#') | |
722 | ++tmp; | |
723 | ||
724 | if (*tmp == '-') | |
725 | { | |
726 | ++tmp; | |
727 | got_minus = 1; | |
728 | } | |
729 | else if (*tmp == '+') | |
730 | ++tmp; | |
731 | ||
732 | if (!isdigit (*tmp)) | |
733 | return 0; | |
734 | ||
735 | displacement = strtol (tmp, &endp, 10); | |
736 | tmp = endp; | |
737 | ||
738 | /* Skipping last `]'. */ | |
739 | if (*tmp++ != ']') | |
740 | return 0; | |
741 | ||
742 | /* The displacement. */ | |
410a0ff2 SDJ |
743 | write_exp_elt_opcode (&p->pstate, OP_LONG); |
744 | write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long); | |
745 | write_exp_elt_longcst (&p->pstate, displacement); | |
746 | write_exp_elt_opcode (&p->pstate, OP_LONG); | |
08248ca9 | 747 | if (got_minus) |
410a0ff2 | 748 | write_exp_elt_opcode (&p->pstate, UNOP_NEG); |
08248ca9 SDJ |
749 | |
750 | /* The register name. */ | |
410a0ff2 | 751 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); |
08248ca9 SDJ |
752 | str.ptr = regname; |
753 | str.length = len; | |
410a0ff2 SDJ |
754 | write_exp_string (&p->pstate, str); |
755 | write_exp_elt_opcode (&p->pstate, OP_REGISTER); | |
08248ca9 | 756 | |
410a0ff2 | 757 | write_exp_elt_opcode (&p->pstate, BINOP_ADD); |
08248ca9 SDJ |
758 | |
759 | /* Casting to the expected type. */ | |
410a0ff2 SDJ |
760 | write_exp_elt_opcode (&p->pstate, UNOP_CAST); |
761 | write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type)); | |
762 | write_exp_elt_opcode (&p->pstate, UNOP_CAST); | |
08248ca9 | 763 | |
410a0ff2 | 764 | write_exp_elt_opcode (&p->pstate, UNOP_IND); |
08248ca9 SDJ |
765 | |
766 | p->arg = tmp; | |
767 | } | |
768 | else | |
769 | return 0; | |
770 | ||
771 | return 1; | |
772 | } | |
773 | ||
99afc88b OJ |
774 | /* AArch64 process record-replay constructs: syscall, signal etc. */ |
775 | ||
776 | struct linux_record_tdep aarch64_linux_record_tdep; | |
777 | ||
778 | /* Enum that defines the AArch64 linux specific syscall identifiers used for | |
779 | process record/replay. */ | |
780 | ||
781 | enum aarch64_syscall { | |
782 | aarch64_sys_io_setup = 0, | |
783 | aarch64_sys_io_destroy = 1, | |
784 | aarch64_sys_io_submit = 2, | |
785 | aarch64_sys_io_cancel = 3, | |
786 | aarch64_sys_io_getevents = 4, | |
787 | aarch64_sys_setxattr = 5, | |
788 | aarch64_sys_lsetxattr = 6, | |
789 | aarch64_sys_fsetxattr = 7, | |
790 | aarch64_sys_getxattr = 8, | |
791 | aarch64_sys_lgetxattr = 9, | |
792 | aarch64_sys_fgetxattr = 10, | |
793 | aarch64_sys_listxattr = 11, | |
794 | aarch64_sys_llistxattr = 12, | |
795 | aarch64_sys_flistxattr = 13, | |
796 | aarch64_sys_removexattr = 14, | |
797 | aarch64_sys_lremovexattr = 15, | |
798 | aarch64_sys_fremovexattr = 16, | |
799 | aarch64_sys_getcwd = 17, | |
800 | aarch64_sys_lookup_dcookie = 18, | |
801 | aarch64_sys_eventfd2 = 19, | |
802 | aarch64_sys_epoll_create1 = 20, | |
803 | aarch64_sys_epoll_ctl = 21, | |
804 | aarch64_sys_epoll_pwait = 22, | |
805 | aarch64_sys_dup = 23, | |
806 | aarch64_sys_dup3 = 24, | |
807 | aarch64_sys_fcntl = 25, | |
808 | aarch64_sys_inotify_init1 = 26, | |
809 | aarch64_sys_inotify_add_watch = 27, | |
810 | aarch64_sys_inotify_rm_watch = 28, | |
811 | aarch64_sys_ioctl = 29, | |
812 | aarch64_sys_ioprio_set = 30, | |
813 | aarch64_sys_ioprio_get = 31, | |
814 | aarch64_sys_flock = 32, | |
c955ae73 YQ |
815 | aarch64_sys_mknodat = 33, |
816 | aarch64_sys_mkdirat = 34, | |
817 | aarch64_sys_unlinkat = 35, | |
818 | aarch64_sys_symlinkat = 36, | |
819 | aarch64_sys_linkat = 37, | |
820 | aarch64_sys_renameat = 38, | |
99afc88b OJ |
821 | aarch64_sys_umount2 = 39, |
822 | aarch64_sys_mount = 40, | |
823 | aarch64_sys_pivot_root = 41, | |
824 | aarch64_sys_nfsservctl = 42, | |
825 | aarch64_sys_statfs = 43, | |
826 | aarch64_sys_fstatfs = 44, | |
827 | aarch64_sys_truncate = 45, | |
828 | aarch64_sys_ftruncate = 46, | |
829 | aarch64_sys_fallocate = 47, | |
c955ae73 | 830 | aarch64_sys_faccessat = 48, |
99afc88b OJ |
831 | aarch64_sys_chdir = 49, |
832 | aarch64_sys_fchdir = 50, | |
833 | aarch64_sys_chroot = 51, | |
834 | aarch64_sys_fchmod = 52, | |
835 | aarch64_sys_fchmodat = 53, | |
836 | aarch64_sys_fchownat = 54, | |
837 | aarch64_sys_fchown = 55, | |
c955ae73 | 838 | aarch64_sys_openat = 56, |
99afc88b OJ |
839 | aarch64_sys_close = 57, |
840 | aarch64_sys_vhangup = 58, | |
841 | aarch64_sys_pipe2 = 59, | |
842 | aarch64_sys_quotactl = 60, | |
843 | aarch64_sys_getdents64 = 61, | |
844 | aarch64_sys_lseek = 62, | |
845 | aarch64_sys_read = 63, | |
846 | aarch64_sys_write = 64, | |
847 | aarch64_sys_readv = 65, | |
848 | aarch64_sys_writev = 66, | |
849 | aarch64_sys_pread64 = 67, | |
850 | aarch64_sys_pwrite64 = 68, | |
851 | aarch64_sys_preadv = 69, | |
852 | aarch64_sys_pwritev = 70, | |
853 | aarch64_sys_sendfile = 71, | |
854 | aarch64_sys_pselect6 = 72, | |
855 | aarch64_sys_ppoll = 73, | |
856 | aarch64_sys_signalfd4 = 74, | |
857 | aarch64_sys_vmsplice = 75, | |
858 | aarch64_sys_splice = 76, | |
859 | aarch64_sys_tee = 77, | |
c955ae73 YQ |
860 | aarch64_sys_readlinkat = 78, |
861 | aarch64_sys_newfstatat = 79, | |
99afc88b OJ |
862 | aarch64_sys_fstat = 80, |
863 | aarch64_sys_sync = 81, | |
864 | aarch64_sys_fsync = 82, | |
865 | aarch64_sys_fdatasync = 83, | |
866 | aarch64_sys_sync_file_range2 = 84, | |
867 | aarch64_sys_sync_file_range = 84, | |
868 | aarch64_sys_timerfd_create = 85, | |
869 | aarch64_sys_timerfd_settime = 86, | |
870 | aarch64_sys_timerfd_gettime = 87, | |
871 | aarch64_sys_utimensat = 88, | |
872 | aarch64_sys_acct = 89, | |
873 | aarch64_sys_capget = 90, | |
874 | aarch64_sys_capset = 91, | |
875 | aarch64_sys_personality = 92, | |
876 | aarch64_sys_exit = 93, | |
877 | aarch64_sys_exit_group = 94, | |
878 | aarch64_sys_waitid = 95, | |
879 | aarch64_sys_set_tid_address = 96, | |
880 | aarch64_sys_unshare = 97, | |
881 | aarch64_sys_futex = 98, | |
882 | aarch64_sys_set_robust_list = 99, | |
883 | aarch64_sys_get_robust_list = 100, | |
884 | aarch64_sys_nanosleep = 101, | |
885 | aarch64_sys_getitimer = 102, | |
886 | aarch64_sys_setitimer = 103, | |
887 | aarch64_sys_kexec_load = 104, | |
888 | aarch64_sys_init_module = 105, | |
889 | aarch64_sys_delete_module = 106, | |
890 | aarch64_sys_timer_create = 107, | |
891 | aarch64_sys_timer_gettime = 108, | |
892 | aarch64_sys_timer_getoverrun = 109, | |
893 | aarch64_sys_timer_settime = 110, | |
894 | aarch64_sys_timer_delete = 111, | |
895 | aarch64_sys_clock_settime = 112, | |
896 | aarch64_sys_clock_gettime = 113, | |
897 | aarch64_sys_clock_getres = 114, | |
898 | aarch64_sys_clock_nanosleep = 115, | |
899 | aarch64_sys_syslog = 116, | |
900 | aarch64_sys_ptrace = 117, | |
901 | aarch64_sys_sched_setparam = 118, | |
902 | aarch64_sys_sched_setscheduler = 119, | |
903 | aarch64_sys_sched_getscheduler = 120, | |
904 | aarch64_sys_sched_getparam = 121, | |
905 | aarch64_sys_sched_setaffinity = 122, | |
906 | aarch64_sys_sched_getaffinity = 123, | |
907 | aarch64_sys_sched_yield = 124, | |
908 | aarch64_sys_sched_get_priority_max = 125, | |
909 | aarch64_sys_sched_get_priority_min = 126, | |
910 | aarch64_sys_sched_rr_get_interval = 127, | |
911 | aarch64_sys_kill = 129, | |
912 | aarch64_sys_tkill = 130, | |
913 | aarch64_sys_tgkill = 131, | |
914 | aarch64_sys_sigaltstack = 132, | |
915 | aarch64_sys_rt_sigsuspend = 133, | |
916 | aarch64_sys_rt_sigaction = 134, | |
917 | aarch64_sys_rt_sigprocmask = 135, | |
918 | aarch64_sys_rt_sigpending = 136, | |
919 | aarch64_sys_rt_sigtimedwait = 137, | |
920 | aarch64_sys_rt_sigqueueinfo = 138, | |
921 | aarch64_sys_rt_sigreturn = 139, | |
922 | aarch64_sys_setpriority = 140, | |
923 | aarch64_sys_getpriority = 141, | |
924 | aarch64_sys_reboot = 142, | |
925 | aarch64_sys_setregid = 143, | |
926 | aarch64_sys_setgid = 144, | |
927 | aarch64_sys_setreuid = 145, | |
928 | aarch64_sys_setuid = 146, | |
929 | aarch64_sys_setresuid = 147, | |
930 | aarch64_sys_getresuid = 148, | |
931 | aarch64_sys_setresgid = 149, | |
932 | aarch64_sys_getresgid = 150, | |
933 | aarch64_sys_setfsuid = 151, | |
934 | aarch64_sys_setfsgid = 152, | |
935 | aarch64_sys_times = 153, | |
936 | aarch64_sys_setpgid = 154, | |
937 | aarch64_sys_getpgid = 155, | |
938 | aarch64_sys_getsid = 156, | |
939 | aarch64_sys_setsid = 157, | |
940 | aarch64_sys_getgroups = 158, | |
941 | aarch64_sys_setgroups = 159, | |
942 | aarch64_sys_uname = 160, | |
943 | aarch64_sys_sethostname = 161, | |
944 | aarch64_sys_setdomainname = 162, | |
945 | aarch64_sys_getrlimit = 163, | |
946 | aarch64_sys_setrlimit = 164, | |
947 | aarch64_sys_getrusage = 165, | |
948 | aarch64_sys_umask = 166, | |
949 | aarch64_sys_prctl = 167, | |
950 | aarch64_sys_getcpu = 168, | |
951 | aarch64_sys_gettimeofday = 169, | |
952 | aarch64_sys_settimeofday = 170, | |
953 | aarch64_sys_adjtimex = 171, | |
954 | aarch64_sys_getpid = 172, | |
955 | aarch64_sys_getppid = 173, | |
956 | aarch64_sys_getuid = 174, | |
957 | aarch64_sys_geteuid = 175, | |
958 | aarch64_sys_getgid = 176, | |
959 | aarch64_sys_getegid = 177, | |
960 | aarch64_sys_gettid = 178, | |
961 | aarch64_sys_sysinfo = 179, | |
962 | aarch64_sys_mq_open = 180, | |
963 | aarch64_sys_mq_unlink = 181, | |
964 | aarch64_sys_mq_timedsend = 182, | |
965 | aarch64_sys_mq_timedreceive = 183, | |
966 | aarch64_sys_mq_notify = 184, | |
967 | aarch64_sys_mq_getsetattr = 185, | |
968 | aarch64_sys_msgget = 186, | |
969 | aarch64_sys_msgctl = 187, | |
970 | aarch64_sys_msgrcv = 188, | |
971 | aarch64_sys_msgsnd = 189, | |
972 | aarch64_sys_semget = 190, | |
973 | aarch64_sys_semctl = 191, | |
974 | aarch64_sys_semtimedop = 192, | |
975 | aarch64_sys_semop = 193, | |
976 | aarch64_sys_shmget = 194, | |
977 | aarch64_sys_shmctl = 195, | |
978 | aarch64_sys_shmat = 196, | |
979 | aarch64_sys_shmdt = 197, | |
980 | aarch64_sys_socket = 198, | |
981 | aarch64_sys_socketpair = 199, | |
982 | aarch64_sys_bind = 200, | |
983 | aarch64_sys_listen = 201, | |
984 | aarch64_sys_accept = 202, | |
985 | aarch64_sys_connect = 203, | |
986 | aarch64_sys_getsockname = 204, | |
987 | aarch64_sys_getpeername = 205, | |
988 | aarch64_sys_sendto = 206, | |
989 | aarch64_sys_recvfrom = 207, | |
990 | aarch64_sys_setsockopt = 208, | |
991 | aarch64_sys_getsockopt = 209, | |
992 | aarch64_sys_shutdown = 210, | |
993 | aarch64_sys_sendmsg = 211, | |
994 | aarch64_sys_recvmsg = 212, | |
995 | aarch64_sys_readahead = 213, | |
996 | aarch64_sys_brk = 214, | |
997 | aarch64_sys_munmap = 215, | |
998 | aarch64_sys_mremap = 216, | |
999 | aarch64_sys_add_key = 217, | |
1000 | aarch64_sys_request_key = 218, | |
1001 | aarch64_sys_keyctl = 219, | |
1002 | aarch64_sys_clone = 220, | |
1003 | aarch64_sys_execve = 221, | |
1004 | aarch64_sys_mmap = 222, | |
1005 | aarch64_sys_fadvise64 = 223, | |
1006 | aarch64_sys_swapon = 224, | |
1007 | aarch64_sys_swapoff = 225, | |
1008 | aarch64_sys_mprotect = 226, | |
1009 | aarch64_sys_msync = 227, | |
1010 | aarch64_sys_mlock = 228, | |
1011 | aarch64_sys_munlock = 229, | |
1012 | aarch64_sys_mlockall = 230, | |
1013 | aarch64_sys_munlockall = 231, | |
1014 | aarch64_sys_mincore = 232, | |
1015 | aarch64_sys_madvise = 233, | |
1016 | aarch64_sys_remap_file_pages = 234, | |
1017 | aarch64_sys_mbind = 235, | |
1018 | aarch64_sys_get_mempolicy = 236, | |
1019 | aarch64_sys_set_mempolicy = 237, | |
1020 | aarch64_sys_migrate_pages = 238, | |
1021 | aarch64_sys_move_pages = 239, | |
1022 | aarch64_sys_rt_tgsigqueueinfo = 240, | |
1023 | aarch64_sys_perf_event_open = 241, | |
1024 | aarch64_sys_accept4 = 242, | |
1025 | aarch64_sys_recvmmsg = 243, | |
1026 | aarch64_sys_wait4 = 260, | |
1027 | aarch64_sys_prlimit64 = 261, | |
1028 | aarch64_sys_fanotify_init = 262, | |
1029 | aarch64_sys_fanotify_mark = 263, | |
1030 | aarch64_sys_name_to_handle_at = 264, | |
1031 | aarch64_sys_open_by_handle_at = 265, | |
1032 | aarch64_sys_clock_adjtime = 266, | |
1033 | aarch64_sys_syncfs = 267, | |
1034 | aarch64_sys_setns = 268, | |
1035 | aarch64_sys_sendmmsg = 269, | |
1036 | aarch64_sys_process_vm_readv = 270, | |
1037 | aarch64_sys_process_vm_writev = 271, | |
1038 | aarch64_sys_kcmp = 272, | |
1039 | aarch64_sys_finit_module = 273, | |
1040 | aarch64_sys_sched_setattr = 274, | |
1041 | aarch64_sys_sched_getattr = 275, | |
1042 | }; | |
1043 | ||
1044 | /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64 | |
1045 | linux set of syscall ids into a canonical set of syscall ids used by | |
1046 | process record. */ | |
1047 | ||
1048 | static enum gdb_syscall | |
1049 | aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number) | |
1050 | { | |
1051 | #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \ | |
1052 | return gdb_sys_##SYSCALL | |
1053 | ||
c955ae73 YQ |
1054 | #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \ |
1055 | return gdb_sys_no_syscall | |
1056 | ||
99afc88b OJ |
1057 | switch (syscall_number) |
1058 | { | |
1059 | SYSCALL_MAP (io_setup); | |
1060 | SYSCALL_MAP (io_destroy); | |
1061 | SYSCALL_MAP (io_submit); | |
1062 | SYSCALL_MAP (io_cancel); | |
1063 | SYSCALL_MAP (io_getevents); | |
1064 | ||
1065 | SYSCALL_MAP (setxattr); | |
1066 | SYSCALL_MAP (lsetxattr); | |
1067 | SYSCALL_MAP (fsetxattr); | |
1068 | SYSCALL_MAP (getxattr); | |
1069 | SYSCALL_MAP (lgetxattr); | |
1070 | SYSCALL_MAP (fgetxattr); | |
1071 | SYSCALL_MAP (listxattr); | |
1072 | SYSCALL_MAP (llistxattr); | |
1073 | SYSCALL_MAP (flistxattr); | |
1074 | SYSCALL_MAP (removexattr); | |
1075 | SYSCALL_MAP (lremovexattr); | |
1076 | SYSCALL_MAP (fremovexattr); | |
1077 | SYSCALL_MAP (getcwd); | |
1078 | SYSCALL_MAP (lookup_dcookie); | |
d5219069 YQ |
1079 | SYSCALL_MAP (eventfd2); |
1080 | SYSCALL_MAP (epoll_create1); | |
99afc88b OJ |
1081 | SYSCALL_MAP (epoll_ctl); |
1082 | SYSCALL_MAP (epoll_pwait); | |
1083 | SYSCALL_MAP (dup); | |
d5219069 | 1084 | SYSCALL_MAP (dup3); |
99afc88b | 1085 | SYSCALL_MAP (fcntl); |
d5219069 | 1086 | SYSCALL_MAP (inotify_init1); |
99afc88b OJ |
1087 | SYSCALL_MAP (inotify_add_watch); |
1088 | SYSCALL_MAP (inotify_rm_watch); | |
1089 | SYSCALL_MAP (ioctl); | |
1090 | SYSCALL_MAP (ioprio_set); | |
1091 | SYSCALL_MAP (ioprio_get); | |
1092 | SYSCALL_MAP (flock); | |
c955ae73 YQ |
1093 | SYSCALL_MAP (mknodat); |
1094 | SYSCALL_MAP (mkdirat); | |
1095 | SYSCALL_MAP (unlinkat); | |
1096 | SYSCALL_MAP (symlinkat); | |
1097 | SYSCALL_MAP (linkat); | |
1098 | SYSCALL_MAP (renameat); | |
1099 | UNSUPPORTED_SYSCALL_MAP (umount2); | |
99afc88b | 1100 | SYSCALL_MAP (mount); |
c955ae73 | 1101 | SYSCALL_MAP (pivot_root); |
99afc88b OJ |
1102 | SYSCALL_MAP (nfsservctl); |
1103 | SYSCALL_MAP (statfs); | |
1104 | SYSCALL_MAP (truncate); | |
1105 | SYSCALL_MAP (ftruncate); | |
d5219069 | 1106 | SYSCALL_MAP (fallocate); |
c955ae73 | 1107 | SYSCALL_MAP (faccessat); |
99afc88b OJ |
1108 | SYSCALL_MAP (fchdir); |
1109 | SYSCALL_MAP (chroot); | |
1110 | SYSCALL_MAP (fchmod); | |
1111 | SYSCALL_MAP (fchmodat); | |
1112 | SYSCALL_MAP (fchownat); | |
1113 | SYSCALL_MAP (fchown); | |
c955ae73 | 1114 | SYSCALL_MAP (openat); |
99afc88b OJ |
1115 | SYSCALL_MAP (close); |
1116 | SYSCALL_MAP (vhangup); | |
d5219069 | 1117 | SYSCALL_MAP (pipe2); |
99afc88b OJ |
1118 | SYSCALL_MAP (quotactl); |
1119 | SYSCALL_MAP (getdents64); | |
1120 | SYSCALL_MAP (lseek); | |
1121 | SYSCALL_MAP (read); | |
1122 | SYSCALL_MAP (write); | |
1123 | SYSCALL_MAP (readv); | |
1124 | SYSCALL_MAP (writev); | |
1125 | SYSCALL_MAP (pread64); | |
1126 | SYSCALL_MAP (pwrite64); | |
c955ae73 YQ |
1127 | UNSUPPORTED_SYSCALL_MAP (preadv); |
1128 | UNSUPPORTED_SYSCALL_MAP (pwritev); | |
99afc88b OJ |
1129 | SYSCALL_MAP (sendfile); |
1130 | SYSCALL_MAP (pselect6); | |
1131 | SYSCALL_MAP (ppoll); | |
c955ae73 | 1132 | UNSUPPORTED_SYSCALL_MAP (signalfd4); |
99afc88b OJ |
1133 | SYSCALL_MAP (vmsplice); |
1134 | SYSCALL_MAP (splice); | |
1135 | SYSCALL_MAP (tee); | |
c955ae73 YQ |
1136 | SYSCALL_MAP (readlinkat); |
1137 | SYSCALL_MAP (newfstatat); | |
1138 | ||
99afc88b OJ |
1139 | SYSCALL_MAP (fstat); |
1140 | SYSCALL_MAP (sync); | |
1141 | SYSCALL_MAP (fsync); | |
1142 | SYSCALL_MAP (fdatasync); | |
1143 | SYSCALL_MAP (sync_file_range); | |
c955ae73 YQ |
1144 | UNSUPPORTED_SYSCALL_MAP (timerfd_create); |
1145 | UNSUPPORTED_SYSCALL_MAP (timerfd_settime); | |
1146 | UNSUPPORTED_SYSCALL_MAP (timerfd_gettime); | |
1147 | UNSUPPORTED_SYSCALL_MAP (utimensat); | |
99afc88b OJ |
1148 | SYSCALL_MAP (acct); |
1149 | SYSCALL_MAP (capget); | |
1150 | SYSCALL_MAP (capset); | |
1151 | SYSCALL_MAP (personality); | |
1152 | SYSCALL_MAP (exit); | |
1153 | SYSCALL_MAP (exit_group); | |
1154 | SYSCALL_MAP (waitid); | |
1155 | SYSCALL_MAP (set_tid_address); | |
1156 | SYSCALL_MAP (unshare); | |
1157 | SYSCALL_MAP (futex); | |
1158 | SYSCALL_MAP (set_robust_list); | |
1159 | SYSCALL_MAP (get_robust_list); | |
1160 | SYSCALL_MAP (nanosleep); | |
1161 | ||
1162 | SYSCALL_MAP (getitimer); | |
1163 | SYSCALL_MAP (setitimer); | |
1164 | SYSCALL_MAP (kexec_load); | |
1165 | SYSCALL_MAP (init_module); | |
1166 | SYSCALL_MAP (delete_module); | |
1167 | SYSCALL_MAP (timer_create); | |
1168 | SYSCALL_MAP (timer_settime); | |
1169 | SYSCALL_MAP (timer_gettime); | |
1170 | SYSCALL_MAP (timer_getoverrun); | |
1171 | SYSCALL_MAP (timer_delete); | |
1172 | SYSCALL_MAP (clock_settime); | |
1173 | SYSCALL_MAP (clock_gettime); | |
1174 | SYSCALL_MAP (clock_getres); | |
1175 | SYSCALL_MAP (clock_nanosleep); | |
1176 | SYSCALL_MAP (syslog); | |
1177 | SYSCALL_MAP (ptrace); | |
1178 | SYSCALL_MAP (sched_setparam); | |
1179 | SYSCALL_MAP (sched_setscheduler); | |
1180 | SYSCALL_MAP (sched_getscheduler); | |
1181 | SYSCALL_MAP (sched_getparam); | |
1182 | SYSCALL_MAP (sched_setaffinity); | |
1183 | SYSCALL_MAP (sched_getaffinity); | |
1184 | SYSCALL_MAP (sched_yield); | |
1185 | SYSCALL_MAP (sched_get_priority_max); | |
1186 | SYSCALL_MAP (sched_get_priority_min); | |
1187 | SYSCALL_MAP (sched_rr_get_interval); | |
1188 | SYSCALL_MAP (kill); | |
1189 | SYSCALL_MAP (tkill); | |
1190 | SYSCALL_MAP (tgkill); | |
1191 | SYSCALL_MAP (sigaltstack); | |
1192 | SYSCALL_MAP (rt_sigsuspend); | |
1193 | SYSCALL_MAP (rt_sigaction); | |
1194 | SYSCALL_MAP (rt_sigprocmask); | |
1195 | SYSCALL_MAP (rt_sigpending); | |
1196 | SYSCALL_MAP (rt_sigtimedwait); | |
1197 | SYSCALL_MAP (rt_sigqueueinfo); | |
1198 | SYSCALL_MAP (rt_sigreturn); | |
1199 | SYSCALL_MAP (setpriority); | |
1200 | SYSCALL_MAP (getpriority); | |
1201 | SYSCALL_MAP (reboot); | |
1202 | SYSCALL_MAP (setregid); | |
1203 | SYSCALL_MAP (setgid); | |
1204 | SYSCALL_MAP (setreuid); | |
1205 | SYSCALL_MAP (setuid); | |
1206 | SYSCALL_MAP (setresuid); | |
1207 | SYSCALL_MAP (getresuid); | |
1208 | SYSCALL_MAP (setresgid); | |
1209 | SYSCALL_MAP (getresgid); | |
1210 | SYSCALL_MAP (setfsuid); | |
1211 | SYSCALL_MAP (setfsgid); | |
1212 | SYSCALL_MAP (times); | |
1213 | SYSCALL_MAP (setpgid); | |
1214 | SYSCALL_MAP (getpgid); | |
1215 | SYSCALL_MAP (getsid); | |
1216 | SYSCALL_MAP (setsid); | |
1217 | SYSCALL_MAP (getgroups); | |
1218 | SYSCALL_MAP (setgroups); | |
1219 | SYSCALL_MAP (uname); | |
1220 | SYSCALL_MAP (sethostname); | |
1221 | SYSCALL_MAP (setdomainname); | |
1222 | SYSCALL_MAP (getrlimit); | |
1223 | SYSCALL_MAP (setrlimit); | |
1224 | SYSCALL_MAP (getrusage); | |
1225 | SYSCALL_MAP (umask); | |
1226 | SYSCALL_MAP (prctl); | |
c955ae73 | 1227 | SYSCALL_MAP (getcpu); |
99afc88b OJ |
1228 | SYSCALL_MAP (gettimeofday); |
1229 | SYSCALL_MAP (settimeofday); | |
1230 | SYSCALL_MAP (adjtimex); | |
1231 | SYSCALL_MAP (getpid); | |
1232 | SYSCALL_MAP (getppid); | |
1233 | SYSCALL_MAP (getuid); | |
1234 | SYSCALL_MAP (geteuid); | |
1235 | SYSCALL_MAP (getgid); | |
1236 | SYSCALL_MAP (getegid); | |
1237 | SYSCALL_MAP (gettid); | |
1238 | SYSCALL_MAP (sysinfo); | |
1239 | SYSCALL_MAP (mq_open); | |
1240 | SYSCALL_MAP (mq_unlink); | |
1241 | SYSCALL_MAP (mq_timedsend); | |
1242 | SYSCALL_MAP (mq_timedreceive); | |
1243 | SYSCALL_MAP (mq_notify); | |
1244 | SYSCALL_MAP (mq_getsetattr); | |
1245 | SYSCALL_MAP (msgget); | |
1246 | SYSCALL_MAP (msgctl); | |
1247 | SYSCALL_MAP (msgrcv); | |
1248 | SYSCALL_MAP (msgsnd); | |
1249 | SYSCALL_MAP (semget); | |
1250 | SYSCALL_MAP (semctl); | |
1251 | SYSCALL_MAP (semtimedop); | |
1252 | SYSCALL_MAP (semop); | |
1253 | SYSCALL_MAP (shmget); | |
1254 | SYSCALL_MAP (shmctl); | |
1255 | SYSCALL_MAP (shmat); | |
1256 | SYSCALL_MAP (shmdt); | |
1257 | SYSCALL_MAP (socket); | |
1258 | SYSCALL_MAP (socketpair); | |
1259 | SYSCALL_MAP (bind); | |
1260 | SYSCALL_MAP (listen); | |
1261 | SYSCALL_MAP (accept); | |
1262 | SYSCALL_MAP (connect); | |
1263 | SYSCALL_MAP (getsockname); | |
1264 | SYSCALL_MAP (getpeername); | |
1265 | SYSCALL_MAP (sendto); | |
1266 | SYSCALL_MAP (recvfrom); | |
1267 | SYSCALL_MAP (setsockopt); | |
1268 | SYSCALL_MAP (getsockopt); | |
1269 | SYSCALL_MAP (shutdown); | |
1270 | SYSCALL_MAP (sendmsg); | |
1271 | SYSCALL_MAP (recvmsg); | |
1272 | SYSCALL_MAP (readahead); | |
1273 | SYSCALL_MAP (brk); | |
1274 | SYSCALL_MAP (munmap); | |
1275 | SYSCALL_MAP (mremap); | |
1276 | SYSCALL_MAP (add_key); | |
1277 | SYSCALL_MAP (request_key); | |
1278 | SYSCALL_MAP (keyctl); | |
1279 | SYSCALL_MAP (clone); | |
1280 | SYSCALL_MAP (execve); | |
1281 | ||
1282 | case aarch64_sys_mmap: | |
1283 | return gdb_sys_mmap2; | |
1284 | ||
1285 | SYSCALL_MAP (fadvise64); | |
1286 | SYSCALL_MAP (swapon); | |
1287 | SYSCALL_MAP (swapoff); | |
1288 | SYSCALL_MAP (mprotect); | |
1289 | SYSCALL_MAP (msync); | |
1290 | SYSCALL_MAP (mlock); | |
1291 | SYSCALL_MAP (munlock); | |
1292 | SYSCALL_MAP (mlockall); | |
1293 | SYSCALL_MAP (munlockall); | |
1294 | SYSCALL_MAP (mincore); | |
1295 | SYSCALL_MAP (madvise); | |
1296 | SYSCALL_MAP (remap_file_pages); | |
1297 | SYSCALL_MAP (mbind); | |
1298 | SYSCALL_MAP (get_mempolicy); | |
1299 | SYSCALL_MAP (set_mempolicy); | |
1300 | SYSCALL_MAP (migrate_pages); | |
1301 | SYSCALL_MAP (move_pages); | |
c955ae73 YQ |
1302 | UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo); |
1303 | UNSUPPORTED_SYSCALL_MAP (perf_event_open); | |
1304 | UNSUPPORTED_SYSCALL_MAP (accept4); | |
1305 | UNSUPPORTED_SYSCALL_MAP (recvmmsg); | |
1306 | ||
1307 | SYSCALL_MAP (wait4); | |
1308 | ||
1309 | UNSUPPORTED_SYSCALL_MAP (prlimit64); | |
1310 | UNSUPPORTED_SYSCALL_MAP (fanotify_init); | |
1311 | UNSUPPORTED_SYSCALL_MAP (fanotify_mark); | |
1312 | UNSUPPORTED_SYSCALL_MAP (name_to_handle_at); | |
1313 | UNSUPPORTED_SYSCALL_MAP (open_by_handle_at); | |
1314 | UNSUPPORTED_SYSCALL_MAP (clock_adjtime); | |
1315 | UNSUPPORTED_SYSCALL_MAP (syncfs); | |
1316 | UNSUPPORTED_SYSCALL_MAP (setns); | |
1317 | UNSUPPORTED_SYSCALL_MAP (sendmmsg); | |
1318 | UNSUPPORTED_SYSCALL_MAP (process_vm_readv); | |
1319 | UNSUPPORTED_SYSCALL_MAP (process_vm_writev); | |
1320 | UNSUPPORTED_SYSCALL_MAP (kcmp); | |
1321 | UNSUPPORTED_SYSCALL_MAP (finit_module); | |
1322 | UNSUPPORTED_SYSCALL_MAP (sched_setattr); | |
1323 | UNSUPPORTED_SYSCALL_MAP (sched_getattr); | |
99afc88b | 1324 | default: |
cb65d272 | 1325 | return gdb_sys_no_syscall; |
99afc88b OJ |
1326 | } |
1327 | } | |
1328 | ||
ea638c43 AH |
1329 | /* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry |
1330 | or exit. Return -1 upon error. */ | |
1331 | ||
1332 | static LONGEST | |
1333 | aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread) | |
1334 | { | |
1335 | struct regcache *regs = get_thread_regcache (thread); | |
1336 | LONGEST ret; | |
1337 | ||
1338 | /* Get the system call number from register x8. */ | |
1339 | regs->cooked_read (AARCH64_X0_REGNUM + 8, &ret); | |
1340 | ||
1341 | /* On exit from a successful execve, we will be in a new process and all the | |
1342 | registers will be cleared - x0 to x30 will be 0, except for a 1 in x7. | |
1343 | This function will only ever get called when stopped at the entry or exit | |
1344 | of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8 | |
1345 | (syscall), x29 (FP) and x30 (LR) we can infer: | |
30baf67b | 1346 | 1) Either inferior is at exit from successful execve. |
ea638c43 AH |
1347 | 2) Or inferior is at entry to a call to io_setup with invalid arguments and |
1348 | a corrupted FP and LR. | |
1349 | It should be safe enough to assume case 1. */ | |
1350 | if (ret == 0) | |
1351 | { | |
1352 | LONGEST x1 = -1, fp = -1, lr = -1; | |
1353 | regs->cooked_read (AARCH64_X0_REGNUM + 1, &x1); | |
1354 | regs->cooked_read (AARCH64_FP_REGNUM, &fp); | |
1355 | regs->cooked_read (AARCH64_LR_REGNUM, &lr); | |
1356 | if (x1 == 0 && fp ==0 && lr == 0) | |
1357 | return aarch64_sys_execve; | |
1358 | } | |
1359 | ||
1360 | return ret; | |
1361 | } | |
1362 | ||
99afc88b OJ |
1363 | /* Record all registers but PC register for process-record. */ |
1364 | ||
1365 | static int | |
1366 | aarch64_all_but_pc_registers_record (struct regcache *regcache) | |
1367 | { | |
1368 | int i; | |
1369 | ||
1370 | for (i = AARCH64_X0_REGNUM; i < AARCH64_PC_REGNUM; i++) | |
1371 | if (record_full_arch_list_add_reg (regcache, i)) | |
1372 | return -1; | |
1373 | ||
1374 | if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM)) | |
1375 | return -1; | |
1376 | ||
1377 | return 0; | |
1378 | } | |
1379 | ||
1380 | /* Handler for aarch64 system call instruction recording. */ | |
1381 | ||
1382 | static int | |
1383 | aarch64_linux_syscall_record (struct regcache *regcache, | |
1384 | unsigned long svc_number) | |
1385 | { | |
1386 | int ret = 0; | |
1387 | enum gdb_syscall syscall_gdb; | |
1388 | ||
1f713e48 SM |
1389 | syscall_gdb = |
1390 | aarch64_canonicalize_syscall ((enum aarch64_syscall) svc_number); | |
99afc88b OJ |
1391 | |
1392 | if (syscall_gdb < 0) | |
1393 | { | |
1394 | printf_unfiltered (_("Process record and replay target doesn't " | |
1395 | "support syscall number %s\n"), | |
1396 | plongest (svc_number)); | |
1397 | return -1; | |
1398 | } | |
1399 | ||
1400 | if (syscall_gdb == gdb_sys_sigreturn | |
1401 | || syscall_gdb == gdb_sys_rt_sigreturn) | |
1402 | { | |
1403 | if (aarch64_all_but_pc_registers_record (regcache)) | |
1404 | return -1; | |
1405 | return 0; | |
1406 | } | |
1407 | ||
1408 | ret = record_linux_system_call (syscall_gdb, regcache, | |
1409 | &aarch64_linux_record_tdep); | |
1410 | if (ret != 0) | |
1411 | return ret; | |
1412 | ||
1413 | /* Record the return value of the system call. */ | |
1414 | if (record_full_arch_list_add_reg (regcache, AARCH64_X0_REGNUM)) | |
1415 | return -1; | |
1416 | /* Record LR. */ | |
1417 | if (record_full_arch_list_add_reg (regcache, AARCH64_LR_REGNUM)) | |
1418 | return -1; | |
1419 | /* Record CPSR. */ | |
1420 | if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM)) | |
1421 | return -1; | |
1422 | ||
1423 | return 0; | |
1424 | } | |
1425 | ||
7045b1ca YQ |
1426 | /* Implement the "gcc_target_options" gdbarch method. */ |
1427 | ||
953cff56 | 1428 | static std::string |
7045b1ca YQ |
1429 | aarch64_linux_gcc_target_options (struct gdbarch *gdbarch) |
1430 | { | |
1431 | /* GCC doesn't know "-m64". */ | |
953cff56 | 1432 | return {}; |
7045b1ca YQ |
1433 | } |
1434 | ||
1ae3db19 MS |
1435 | static void |
1436 | aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1437 | { | |
08248ca9 SDJ |
1438 | static const char *const stap_integer_prefixes[] = { "#", "", NULL }; |
1439 | static const char *const stap_register_prefixes[] = { "", NULL }; | |
1440 | static const char *const stap_register_indirection_prefixes[] = { "[", | |
1441 | NULL }; | |
1442 | static const char *const stap_register_indirection_suffixes[] = { "]", | |
1443 | NULL }; | |
1ae3db19 MS |
1444 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1445 | ||
1446 | tdep->lowest_pc = 0x8000; | |
1447 | ||
05feb193 WN |
1448 | linux_init_abi (info, gdbarch); |
1449 | ||
1ae3db19 MS |
1450 | set_solib_svr4_fetch_link_map_offsets (gdbarch, |
1451 | svr4_lp64_fetch_link_map_offsets); | |
1452 | ||
45e25a36 MS |
1453 | /* Enable TLS support. */ |
1454 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
1455 | svr4_fetch_objfile_link_map); | |
1456 | ||
1ae3db19 MS |
1457 | /* Shared library handling. */ |
1458 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); | |
6dcaef99 | 1459 | set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); |
1ae3db19 | 1460 | |
1ae3db19 MS |
1461 | tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe); |
1462 | ||
1463 | /* Enable longjmp. */ | |
1464 | tdep->jb_pc = 11; | |
1465 | ||
4108500a AA |
1466 | set_gdbarch_iterate_over_regset_sections |
1467 | (gdbarch, aarch64_linux_iterate_over_regset_sections); | |
cd3af38d JW |
1468 | set_gdbarch_core_read_description |
1469 | (gdbarch, aarch64_linux_core_read_description); | |
08248ca9 SDJ |
1470 | |
1471 | /* SystemTap related. */ | |
1472 | set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes); | |
1473 | set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes); | |
1474 | set_gdbarch_stap_register_indirection_prefixes (gdbarch, | |
1475 | stap_register_indirection_prefixes); | |
1476 | set_gdbarch_stap_register_indirection_suffixes (gdbarch, | |
1477 | stap_register_indirection_suffixes); | |
1478 | set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand); | |
1479 | set_gdbarch_stap_parse_special_token (gdbarch, | |
1480 | aarch64_stap_parse_special_token); | |
f68f11b7 | 1481 | |
99afc88b OJ |
1482 | /* Reversible debugging, process record. */ |
1483 | set_gdbarch_process_record (gdbarch, aarch64_process_record); | |
1484 | /* Syscall record. */ | |
1485 | tdep->aarch64_syscall_record = aarch64_linux_syscall_record; | |
1486 | ||
8727de56 OJ |
1487 | /* The top byte of a user space address known as the "tag", |
1488 | is ignored by the kernel and can be regarded as additional | |
1489 | data associated with the address. */ | |
1490 | set_gdbarch_significant_addr_bit (gdbarch, 56); | |
1491 | ||
99afc88b OJ |
1492 | /* Initialize the aarch64_linux_record_tdep. */ |
1493 | /* These values are the size of the type that will be used in a system | |
1494 | call. They are obtained from Linux Kernel source. */ | |
1495 | aarch64_linux_record_tdep.size_pointer | |
1496 | = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; | |
1497 | aarch64_linux_record_tdep.size__old_kernel_stat = 32; | |
1498 | aarch64_linux_record_tdep.size_tms = 32; | |
1499 | aarch64_linux_record_tdep.size_loff_t = 8; | |
1500 | aarch64_linux_record_tdep.size_flock = 32; | |
1501 | aarch64_linux_record_tdep.size_oldold_utsname = 45; | |
1502 | aarch64_linux_record_tdep.size_ustat = 32; | |
7571f7f2 MK |
1503 | aarch64_linux_record_tdep.size_old_sigaction = 32; |
1504 | aarch64_linux_record_tdep.size_old_sigset_t = 8; | |
99afc88b OJ |
1505 | aarch64_linux_record_tdep.size_rlimit = 16; |
1506 | aarch64_linux_record_tdep.size_rusage = 144; | |
1507 | aarch64_linux_record_tdep.size_timeval = 16; | |
1508 | aarch64_linux_record_tdep.size_timezone = 8; | |
1509 | aarch64_linux_record_tdep.size_old_gid_t = 2; | |
1510 | aarch64_linux_record_tdep.size_old_uid_t = 2; | |
1511 | aarch64_linux_record_tdep.size_fd_set = 128; | |
72aded86 | 1512 | aarch64_linux_record_tdep.size_old_dirent = 280; |
99afc88b OJ |
1513 | aarch64_linux_record_tdep.size_statfs = 120; |
1514 | aarch64_linux_record_tdep.size_statfs64 = 120; | |
1515 | aarch64_linux_record_tdep.size_sockaddr = 16; | |
1516 | aarch64_linux_record_tdep.size_int | |
1517 | = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT; | |
1518 | aarch64_linux_record_tdep.size_long | |
1519 | = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; | |
1520 | aarch64_linux_record_tdep.size_ulong | |
1521 | = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; | |
1522 | aarch64_linux_record_tdep.size_msghdr = 56; | |
1523 | aarch64_linux_record_tdep.size_itimerval = 32; | |
1524 | aarch64_linux_record_tdep.size_stat = 144; | |
1525 | aarch64_linux_record_tdep.size_old_utsname = 325; | |
1526 | aarch64_linux_record_tdep.size_sysinfo = 112; | |
1527 | aarch64_linux_record_tdep.size_msqid_ds = 120; | |
1528 | aarch64_linux_record_tdep.size_shmid_ds = 112; | |
1529 | aarch64_linux_record_tdep.size_new_utsname = 390; | |
1530 | aarch64_linux_record_tdep.size_timex = 208; | |
1531 | aarch64_linux_record_tdep.size_mem_dqinfo = 24; | |
1532 | aarch64_linux_record_tdep.size_if_dqblk = 72; | |
1533 | aarch64_linux_record_tdep.size_fs_quota_stat = 80; | |
1534 | aarch64_linux_record_tdep.size_timespec = 16; | |
1535 | aarch64_linux_record_tdep.size_pollfd = 8; | |
1536 | aarch64_linux_record_tdep.size_NFS_FHSIZE = 32; | |
1537 | aarch64_linux_record_tdep.size_knfsd_fh = 132; | |
1538 | aarch64_linux_record_tdep.size_TASK_COMM_LEN = 16; | |
7571f7f2 MK |
1539 | aarch64_linux_record_tdep.size_sigaction = 32; |
1540 | aarch64_linux_record_tdep.size_sigset_t = 8; | |
99afc88b OJ |
1541 | aarch64_linux_record_tdep.size_siginfo_t = 128; |
1542 | aarch64_linux_record_tdep.size_cap_user_data_t = 8; | |
1543 | aarch64_linux_record_tdep.size_stack_t = 24; | |
1544 | aarch64_linux_record_tdep.size_off_t = 8; | |
1545 | aarch64_linux_record_tdep.size_stat64 = 144; | |
1546 | aarch64_linux_record_tdep.size_gid_t = 4; | |
1547 | aarch64_linux_record_tdep.size_uid_t = 4; | |
1548 | aarch64_linux_record_tdep.size_PAGE_SIZE = 4096; | |
1549 | aarch64_linux_record_tdep.size_flock64 = 32; | |
1550 | aarch64_linux_record_tdep.size_user_desc = 16; | |
1551 | aarch64_linux_record_tdep.size_io_event = 32; | |
1552 | aarch64_linux_record_tdep.size_iocb = 64; | |
1553 | aarch64_linux_record_tdep.size_epoll_event = 12; | |
1554 | aarch64_linux_record_tdep.size_itimerspec = 32; | |
1555 | aarch64_linux_record_tdep.size_mq_attr = 64; | |
d9b19c49 | 1556 | aarch64_linux_record_tdep.size_termios = 36; |
99afc88b OJ |
1557 | aarch64_linux_record_tdep.size_termios2 = 44; |
1558 | aarch64_linux_record_tdep.size_pid_t = 4; | |
1559 | aarch64_linux_record_tdep.size_winsize = 8; | |
1560 | aarch64_linux_record_tdep.size_serial_struct = 72; | |
1561 | aarch64_linux_record_tdep.size_serial_icounter_struct = 80; | |
1562 | aarch64_linux_record_tdep.size_hayes_esp_config = 12; | |
1563 | aarch64_linux_record_tdep.size_size_t = 8; | |
1564 | aarch64_linux_record_tdep.size_iovec = 16; | |
b80d067f | 1565 | aarch64_linux_record_tdep.size_time_t = 8; |
99afc88b OJ |
1566 | |
1567 | /* These values are the second argument of system call "sys_ioctl". | |
1568 | They are obtained from Linux Kernel source. */ | |
1569 | aarch64_linux_record_tdep.ioctl_TCGETS = 0x5401; | |
1570 | aarch64_linux_record_tdep.ioctl_TCSETS = 0x5402; | |
1571 | aarch64_linux_record_tdep.ioctl_TCSETSW = 0x5403; | |
1572 | aarch64_linux_record_tdep.ioctl_TCSETSF = 0x5404; | |
1573 | aarch64_linux_record_tdep.ioctl_TCGETA = 0x5405; | |
1574 | aarch64_linux_record_tdep.ioctl_TCSETA = 0x5406; | |
1575 | aarch64_linux_record_tdep.ioctl_TCSETAW = 0x5407; | |
1576 | aarch64_linux_record_tdep.ioctl_TCSETAF = 0x5408; | |
1577 | aarch64_linux_record_tdep.ioctl_TCSBRK = 0x5409; | |
1578 | aarch64_linux_record_tdep.ioctl_TCXONC = 0x540a; | |
1579 | aarch64_linux_record_tdep.ioctl_TCFLSH = 0x540b; | |
1580 | aarch64_linux_record_tdep.ioctl_TIOCEXCL = 0x540c; | |
1581 | aarch64_linux_record_tdep.ioctl_TIOCNXCL = 0x540d; | |
1582 | aarch64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e; | |
1583 | aarch64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f; | |
1584 | aarch64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410; | |
1585 | aarch64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411; | |
1586 | aarch64_linux_record_tdep.ioctl_TIOCSTI = 0x5412; | |
1587 | aarch64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413; | |
1588 | aarch64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414; | |
1589 | aarch64_linux_record_tdep.ioctl_TIOCMGET = 0x5415; | |
1590 | aarch64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416; | |
1591 | aarch64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417; | |
1592 | aarch64_linux_record_tdep.ioctl_TIOCMSET = 0x5418; | |
1593 | aarch64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419; | |
1594 | aarch64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a; | |
1595 | aarch64_linux_record_tdep.ioctl_FIONREAD = 0x541b; | |
1596 | aarch64_linux_record_tdep.ioctl_TIOCINQ = 0x541b; | |
1597 | aarch64_linux_record_tdep.ioctl_TIOCLINUX = 0x541c; | |
1598 | aarch64_linux_record_tdep.ioctl_TIOCCONS = 0x541d; | |
1599 | aarch64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e; | |
1600 | aarch64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f; | |
1601 | aarch64_linux_record_tdep.ioctl_TIOCPKT = 0x5420; | |
1602 | aarch64_linux_record_tdep.ioctl_FIONBIO = 0x5421; | |
1603 | aarch64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422; | |
1604 | aarch64_linux_record_tdep.ioctl_TIOCSETD = 0x5423; | |
1605 | aarch64_linux_record_tdep.ioctl_TIOCGETD = 0x5424; | |
1606 | aarch64_linux_record_tdep.ioctl_TCSBRKP = 0x5425; | |
1607 | aarch64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426; | |
1608 | aarch64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427; | |
1609 | aarch64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428; | |
1610 | aarch64_linux_record_tdep.ioctl_TIOCGSID = 0x5429; | |
1611 | aarch64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a; | |
1612 | aarch64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b; | |
1613 | aarch64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c; | |
1614 | aarch64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d; | |
1615 | aarch64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430; | |
1616 | aarch64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431; | |
1617 | aarch64_linux_record_tdep.ioctl_FIONCLEX = 0x5450; | |
1618 | aarch64_linux_record_tdep.ioctl_FIOCLEX = 0x5451; | |
1619 | aarch64_linux_record_tdep.ioctl_FIOASYNC = 0x5452; | |
1620 | aarch64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453; | |
1621 | aarch64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454; | |
1622 | aarch64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455; | |
1623 | aarch64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456; | |
1624 | aarch64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457; | |
1625 | aarch64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458; | |
1626 | aarch64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459; | |
1627 | aarch64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a; | |
1628 | aarch64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b; | |
1629 | aarch64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c; | |
1630 | aarch64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d; | |
1631 | aarch64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e; | |
1632 | aarch64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f; | |
1633 | aarch64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460; | |
1634 | ||
1635 | /* These values are the second argument of system call "sys_fcntl" | |
1636 | and "sys_fcntl64". They are obtained from Linux Kernel source. */ | |
1637 | aarch64_linux_record_tdep.fcntl_F_GETLK = 5; | |
1638 | aarch64_linux_record_tdep.fcntl_F_GETLK64 = 12; | |
1639 | aarch64_linux_record_tdep.fcntl_F_SETLK64 = 13; | |
1640 | aarch64_linux_record_tdep.fcntl_F_SETLKW64 = 14; | |
1641 | ||
1642 | /* The AArch64 syscall calling convention: reg x0-x6 for arguments, | |
1643 | reg x8 for syscall number and return value in reg x0. */ | |
1644 | aarch64_linux_record_tdep.arg1 = AARCH64_X0_REGNUM + 0; | |
1645 | aarch64_linux_record_tdep.arg2 = AARCH64_X0_REGNUM + 1; | |
1646 | aarch64_linux_record_tdep.arg3 = AARCH64_X0_REGNUM + 2; | |
1647 | aarch64_linux_record_tdep.arg4 = AARCH64_X0_REGNUM + 3; | |
1648 | aarch64_linux_record_tdep.arg5 = AARCH64_X0_REGNUM + 4; | |
1649 | aarch64_linux_record_tdep.arg6 = AARCH64_X0_REGNUM + 5; | |
1650 | aarch64_linux_record_tdep.arg7 = AARCH64_X0_REGNUM + 6; | |
1651 | ||
f68f11b7 YQ |
1652 | /* `catch syscall' */ |
1653 | set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml"); | |
1654 | set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number); | |
b6542f81 YQ |
1655 | |
1656 | /* Displaced stepping. */ | |
e935475c | 1657 | set_gdbarch_max_insn_length (gdbarch, 4 * AARCH64_DISPLACED_MODIFIED_INSNS); |
b6542f81 YQ |
1658 | set_gdbarch_displaced_step_copy_insn (gdbarch, |
1659 | aarch64_displaced_step_copy_insn); | |
1660 | set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup); | |
b6542f81 YQ |
1661 | set_gdbarch_displaced_step_location (gdbarch, linux_displaced_step_location); |
1662 | set_gdbarch_displaced_step_hw_singlestep (gdbarch, | |
1663 | aarch64_displaced_step_hw_singlestep); | |
7045b1ca YQ |
1664 | |
1665 | set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options); | |
1ae3db19 MS |
1666 | } |
1667 | ||
1ae3db19 MS |
1668 | void |
1669 | _initialize_aarch64_linux_tdep (void) | |
1670 | { | |
1671 | gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX, | |
1672 | aarch64_linux_init_abi); | |
1673 | } |