Commit | Line | Data |
---|---|---|
176eb98c MS |
1 | /* GNU/Linux/AArch64 specific low level interface, for the remote server for |
2 | GDB. | |
3 | ||
32d0add0 | 4 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
176eb98c MS |
5 | Contributed by ARM Ltd. |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "server.h" | |
23 | #include "linux-low.h" | |
554717a3 | 24 | #include "nat/aarch64-linux-hw-point.h" |
3b53ae99 | 25 | #include "linux-aarch32-low.h" |
176eb98c MS |
26 | #include "elf/common.h" |
27 | ||
28 | #include <signal.h> | |
29 | #include <sys/user.h> | |
5826e159 | 30 | #include "nat/gdb_ptrace.h" |
e9dae05e | 31 | #include <asm/ptrace.h> |
176eb98c MS |
32 | #include <sys/uio.h> |
33 | ||
34 | #include "gdb_proc_service.h" | |
35 | ||
36 | /* Defined in auto-generated files. */ | |
37 | void init_registers_aarch64 (void); | |
3aee8918 | 38 | extern const struct target_desc *tdesc_aarch64; |
176eb98c | 39 | |
176eb98c MS |
40 | #ifdef HAVE_SYS_REG_H |
41 | #include <sys/reg.h> | |
42 | #endif | |
43 | ||
44 | #define AARCH64_X_REGS_NUM 31 | |
45 | #define AARCH64_V_REGS_NUM 32 | |
46 | #define AARCH64_X0_REGNO 0 | |
47 | #define AARCH64_SP_REGNO 31 | |
48 | #define AARCH64_PC_REGNO 32 | |
49 | #define AARCH64_CPSR_REGNO 33 | |
50 | #define AARCH64_V0_REGNO 34 | |
bf330350 CU |
51 | #define AARCH64_FPSR_REGNO (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM) |
52 | #define AARCH64_FPCR_REGNO (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM + 1) | |
176eb98c | 53 | |
bf330350 | 54 | #define AARCH64_NUM_REGS (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM + 2) |
176eb98c | 55 | |
176eb98c MS |
56 | /* Per-process arch-specific data we want to keep. */ |
57 | ||
58 | struct arch_process_info | |
59 | { | |
60 | /* Hardware breakpoint/watchpoint data. | |
61 | The reason for them to be per-process rather than per-thread is | |
62 | due to the lack of information in the gdbserver environment; | |
63 | gdbserver is not told that whether a requested hardware | |
64 | breakpoint/watchpoint is thread specific or not, so it has to set | |
65 | each hw bp/wp for every thread in the current process. The | |
66 | higher level bp/wp management in gdb will resume a thread if a hw | |
67 | bp/wp trap is not expected for it. Since the hw bp/wp setting is | |
68 | same for each thread, it is reasonable for the data to live here. | |
69 | */ | |
70 | struct aarch64_debug_reg_state debug_reg_state; | |
71 | }; | |
72 | ||
3b53ae99 YQ |
73 | /* Return true if the size of register 0 is 8 byte. */ |
74 | ||
75 | static int | |
76 | is_64bit_tdesc (void) | |
77 | { | |
78 | struct regcache *regcache = get_thread_regcache (current_thread, 0); | |
79 | ||
80 | return register_size (regcache->tdesc, 0) == 8; | |
81 | } | |
82 | ||
421530db PL |
83 | /* Implementation of linux_target_ops method "cannot_store_register". */ |
84 | ||
176eb98c MS |
85 | static int |
86 | aarch64_cannot_store_register (int regno) | |
87 | { | |
88 | return regno >= AARCH64_NUM_REGS; | |
89 | } | |
90 | ||
421530db PL |
91 | /* Implementation of linux_target_ops method "cannot_fetch_register". */ |
92 | ||
176eb98c MS |
93 | static int |
94 | aarch64_cannot_fetch_register (int regno) | |
95 | { | |
96 | return regno >= AARCH64_NUM_REGS; | |
97 | } | |
98 | ||
99 | static void | |
100 | aarch64_fill_gregset (struct regcache *regcache, void *buf) | |
101 | { | |
102 | struct user_pt_regs *regset = buf; | |
103 | int i; | |
104 | ||
105 | for (i = 0; i < AARCH64_X_REGS_NUM; i++) | |
106 | collect_register (regcache, AARCH64_X0_REGNO + i, ®set->regs[i]); | |
107 | collect_register (regcache, AARCH64_SP_REGNO, ®set->sp); | |
108 | collect_register (regcache, AARCH64_PC_REGNO, ®set->pc); | |
109 | collect_register (regcache, AARCH64_CPSR_REGNO, ®set->pstate); | |
110 | } | |
111 | ||
112 | static void | |
113 | aarch64_store_gregset (struct regcache *regcache, const void *buf) | |
114 | { | |
115 | const struct user_pt_regs *regset = buf; | |
116 | int i; | |
117 | ||
118 | for (i = 0; i < AARCH64_X_REGS_NUM; i++) | |
119 | supply_register (regcache, AARCH64_X0_REGNO + i, ®set->regs[i]); | |
120 | supply_register (regcache, AARCH64_SP_REGNO, ®set->sp); | |
121 | supply_register (regcache, AARCH64_PC_REGNO, ®set->pc); | |
122 | supply_register (regcache, AARCH64_CPSR_REGNO, ®set->pstate); | |
123 | } | |
124 | ||
125 | static void | |
126 | aarch64_fill_fpregset (struct regcache *regcache, void *buf) | |
127 | { | |
128 | struct user_fpsimd_state *regset = buf; | |
129 | int i; | |
130 | ||
131 | for (i = 0; i < AARCH64_V_REGS_NUM; i++) | |
132 | collect_register (regcache, AARCH64_V0_REGNO + i, ®set->vregs[i]); | |
bf330350 CU |
133 | collect_register (regcache, AARCH64_FPSR_REGNO, ®set->fpsr); |
134 | collect_register (regcache, AARCH64_FPCR_REGNO, ®set->fpcr); | |
176eb98c MS |
135 | } |
136 | ||
137 | static void | |
138 | aarch64_store_fpregset (struct regcache *regcache, const void *buf) | |
139 | { | |
140 | const struct user_fpsimd_state *regset = buf; | |
141 | int i; | |
142 | ||
143 | for (i = 0; i < AARCH64_V_REGS_NUM; i++) | |
144 | supply_register (regcache, AARCH64_V0_REGNO + i, ®set->vregs[i]); | |
bf330350 CU |
145 | supply_register (regcache, AARCH64_FPSR_REGNO, ®set->fpsr); |
146 | supply_register (regcache, AARCH64_FPCR_REGNO, ®set->fpcr); | |
176eb98c MS |
147 | } |
148 | ||
176eb98c MS |
149 | /* Enable miscellaneous debugging output. The name is historical - it |
150 | was originally used to debug LinuxThreads support. */ | |
151 | extern int debug_threads; | |
152 | ||
421530db PL |
153 | /* Implementation of linux_target_ops method "get_pc". */ |
154 | ||
176eb98c MS |
155 | static CORE_ADDR |
156 | aarch64_get_pc (struct regcache *regcache) | |
157 | { | |
8a7e4587 YQ |
158 | if (register_size (regcache->tdesc, 0) == 8) |
159 | { | |
160 | unsigned long pc; | |
161 | ||
162 | collect_register_by_name (regcache, "pc", &pc); | |
163 | if (debug_threads) | |
164 | debug_printf ("stop pc is %08lx\n", pc); | |
165 | return pc; | |
166 | } | |
167 | else | |
168 | { | |
169 | unsigned int pc; | |
170 | ||
171 | collect_register_by_name (regcache, "pc", &pc); | |
172 | if (debug_threads) | |
173 | debug_printf ("stop pc is %04x\n", pc); | |
174 | return pc; | |
175 | } | |
176eb98c MS |
176 | } |
177 | ||
421530db PL |
178 | /* Implementation of linux_target_ops method "set_pc". */ |
179 | ||
176eb98c MS |
180 | static void |
181 | aarch64_set_pc (struct regcache *regcache, CORE_ADDR pc) | |
182 | { | |
8a7e4587 YQ |
183 | if (register_size (regcache->tdesc, 0) == 8) |
184 | { | |
185 | unsigned long newpc = pc; | |
186 | supply_register_by_name (regcache, "pc", &newpc); | |
187 | } | |
188 | else | |
189 | { | |
190 | unsigned int newpc = pc; | |
191 | supply_register_by_name (regcache, "pc", &newpc); | |
192 | } | |
176eb98c MS |
193 | } |
194 | ||
176eb98c MS |
195 | #define aarch64_breakpoint_len 4 |
196 | ||
37d66942 PL |
197 | /* AArch64 BRK software debug mode instruction. |
198 | This instruction needs to match gdb/aarch64-tdep.c | |
199 | (aarch64_default_breakpoint). */ | |
200 | static const gdb_byte aarch64_breakpoint[] = {0x00, 0x00, 0x20, 0xd4}; | |
176eb98c | 201 | |
421530db PL |
202 | /* Implementation of linux_target_ops method "breakpoint_at". */ |
203 | ||
176eb98c MS |
204 | static int |
205 | aarch64_breakpoint_at (CORE_ADDR where) | |
206 | { | |
37d66942 | 207 | gdb_byte insn[aarch64_breakpoint_len]; |
176eb98c | 208 | |
37d66942 PL |
209 | (*the_target->read_memory) (where, (unsigned char *) &insn, |
210 | aarch64_breakpoint_len); | |
211 | if (memcmp (insn, aarch64_breakpoint, aarch64_breakpoint_len) == 0) | |
176eb98c MS |
212 | return 1; |
213 | ||
214 | return 0; | |
215 | } | |
216 | ||
176eb98c MS |
217 | static void |
218 | aarch64_init_debug_reg_state (struct aarch64_debug_reg_state *state) | |
219 | { | |
220 | int i; | |
221 | ||
222 | for (i = 0; i < AARCH64_HBP_MAX_NUM; ++i) | |
223 | { | |
224 | state->dr_addr_bp[i] = 0; | |
225 | state->dr_ctrl_bp[i] = 0; | |
226 | state->dr_ref_count_bp[i] = 0; | |
227 | } | |
228 | ||
229 | for (i = 0; i < AARCH64_HWP_MAX_NUM; ++i) | |
230 | { | |
231 | state->dr_addr_wp[i] = 0; | |
232 | state->dr_ctrl_wp[i] = 0; | |
233 | state->dr_ref_count_wp[i] = 0; | |
234 | } | |
235 | } | |
236 | ||
176eb98c MS |
237 | /* Return the pointer to the debug register state structure in the |
238 | current process' arch-specific data area. */ | |
239 | ||
240 | static struct aarch64_debug_reg_state * | |
88e2cf7e | 241 | aarch64_get_debug_reg_state (pid_t pid) |
176eb98c | 242 | { |
88e2cf7e | 243 | struct process_info *proc = find_process_pid (pid); |
176eb98c | 244 | |
fe978cb0 | 245 | return &proc->priv->arch_private->debug_reg_state; |
176eb98c MS |
246 | } |
247 | ||
421530db PL |
248 | /* Implementation of linux_target_ops method "supports_z_point_type". */ |
249 | ||
4ff0d3d8 PA |
250 | static int |
251 | aarch64_supports_z_point_type (char z_type) | |
252 | { | |
253 | switch (z_type) | |
254 | { | |
96c97461 | 255 | case Z_PACKET_SW_BP: |
6085d6f6 YQ |
256 | { |
257 | if (!extended_protocol && is_64bit_tdesc ()) | |
258 | { | |
259 | /* Only enable Z0 packet in non-multi-arch debugging. If | |
260 | extended protocol is used, don't enable Z0 packet because | |
261 | GDBserver may attach to 32-bit process. */ | |
262 | return 1; | |
263 | } | |
264 | else | |
265 | { | |
266 | /* Disable Z0 packet so that GDBserver doesn't have to handle | |
267 | different breakpoint instructions (aarch64, arm, thumb etc) | |
268 | in multi-arch debugging. */ | |
269 | return 0; | |
270 | } | |
271 | } | |
4ff0d3d8 PA |
272 | case Z_PACKET_HW_BP: |
273 | case Z_PACKET_WRITE_WP: | |
274 | case Z_PACKET_READ_WP: | |
275 | case Z_PACKET_ACCESS_WP: | |
276 | return 1; | |
277 | default: | |
4ff0d3d8 PA |
278 | return 0; |
279 | } | |
280 | } | |
281 | ||
421530db | 282 | /* Implementation of linux_target_ops method "insert_point". |
176eb98c | 283 | |
421530db PL |
284 | It actually only records the info of the to-be-inserted bp/wp; |
285 | the actual insertion will happen when threads are resumed. */ | |
176eb98c MS |
286 | |
287 | static int | |
802e8e6d PA |
288 | aarch64_insert_point (enum raw_bkpt_type type, CORE_ADDR addr, |
289 | int len, struct raw_breakpoint *bp) | |
176eb98c MS |
290 | { |
291 | int ret; | |
4ff0d3d8 | 292 | enum target_hw_bp_type targ_type; |
88e2cf7e YQ |
293 | struct aarch64_debug_reg_state *state |
294 | = aarch64_get_debug_reg_state (pid_of (current_thread)); | |
4ff0d3d8 | 295 | |
c5e92cca | 296 | if (show_debug_regs) |
176eb98c MS |
297 | fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n", |
298 | (unsigned long) addr, len); | |
299 | ||
802e8e6d PA |
300 | /* Determine the type from the raw breakpoint type. */ |
301 | targ_type = raw_bkpt_type_to_target_hw_bp_type (type); | |
176eb98c MS |
302 | |
303 | if (targ_type != hw_execute) | |
304 | ret = | |
c67ca4de YQ |
305 | aarch64_handle_watchpoint (targ_type, addr, len, 1 /* is_insert */, |
306 | state); | |
176eb98c MS |
307 | else |
308 | ret = | |
c67ca4de YQ |
309 | aarch64_handle_breakpoint (targ_type, addr, len, 1 /* is_insert */, |
310 | state); | |
176eb98c | 311 | |
60a191ed | 312 | if (show_debug_regs) |
88e2cf7e YQ |
313 | aarch64_show_debug_reg_state (state, "insert_point", addr, len, |
314 | targ_type); | |
176eb98c MS |
315 | |
316 | return ret; | |
317 | } | |
318 | ||
421530db | 319 | /* Implementation of linux_target_ops method "remove_point". |
176eb98c | 320 | |
421530db PL |
321 | It actually only records the info of the to-be-removed bp/wp, |
322 | the actual removal will be done when threads are resumed. */ | |
176eb98c MS |
323 | |
324 | static int | |
802e8e6d PA |
325 | aarch64_remove_point (enum raw_bkpt_type type, CORE_ADDR addr, |
326 | int len, struct raw_breakpoint *bp) | |
176eb98c MS |
327 | { |
328 | int ret; | |
4ff0d3d8 | 329 | enum target_hw_bp_type targ_type; |
88e2cf7e YQ |
330 | struct aarch64_debug_reg_state *state |
331 | = aarch64_get_debug_reg_state (pid_of (current_thread)); | |
4ff0d3d8 | 332 | |
c5e92cca | 333 | if (show_debug_regs) |
176eb98c MS |
334 | fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n", |
335 | (unsigned long) addr, len); | |
336 | ||
802e8e6d PA |
337 | /* Determine the type from the raw breakpoint type. */ |
338 | targ_type = raw_bkpt_type_to_target_hw_bp_type (type); | |
176eb98c MS |
339 | |
340 | /* Set up state pointers. */ | |
341 | if (targ_type != hw_execute) | |
342 | ret = | |
c67ca4de YQ |
343 | aarch64_handle_watchpoint (targ_type, addr, len, 0 /* is_insert */, |
344 | state); | |
176eb98c MS |
345 | else |
346 | ret = | |
c67ca4de YQ |
347 | aarch64_handle_breakpoint (targ_type, addr, len, 0 /* is_insert */, |
348 | state); | |
176eb98c | 349 | |
60a191ed | 350 | if (show_debug_regs) |
88e2cf7e YQ |
351 | aarch64_show_debug_reg_state (state, "remove_point", addr, len, |
352 | targ_type); | |
176eb98c MS |
353 | |
354 | return ret; | |
355 | } | |
356 | ||
421530db | 357 | /* Implementation of linux_target_ops method "stopped_data_address". */ |
176eb98c MS |
358 | |
359 | static CORE_ADDR | |
360 | aarch64_stopped_data_address (void) | |
361 | { | |
362 | siginfo_t siginfo; | |
363 | int pid, i; | |
364 | struct aarch64_debug_reg_state *state; | |
365 | ||
0bfdf32f | 366 | pid = lwpid_of (current_thread); |
176eb98c MS |
367 | |
368 | /* Get the siginfo. */ | |
369 | if (ptrace (PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) | |
370 | return (CORE_ADDR) 0; | |
371 | ||
372 | /* Need to be a hardware breakpoint/watchpoint trap. */ | |
373 | if (siginfo.si_signo != SIGTRAP | |
374 | || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */) | |
375 | return (CORE_ADDR) 0; | |
376 | ||
377 | /* Check if the address matches any watched address. */ | |
88e2cf7e | 378 | state = aarch64_get_debug_reg_state (pid_of (current_thread)); |
176eb98c MS |
379 | for (i = aarch64_num_wp_regs - 1; i >= 0; --i) |
380 | { | |
381 | const unsigned int len = aarch64_watchpoint_length (state->dr_ctrl_wp[i]); | |
382 | const CORE_ADDR addr_trap = (CORE_ADDR) siginfo.si_addr; | |
383 | const CORE_ADDR addr_watch = state->dr_addr_wp[i]; | |
384 | if (state->dr_ref_count_wp[i] | |
385 | && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i]) | |
386 | && addr_trap >= addr_watch | |
387 | && addr_trap < addr_watch + len) | |
388 | return addr_trap; | |
389 | } | |
390 | ||
391 | return (CORE_ADDR) 0; | |
392 | } | |
393 | ||
421530db | 394 | /* Implementation of linux_target_ops method "stopped_by_watchpoint". */ |
176eb98c MS |
395 | |
396 | static int | |
397 | aarch64_stopped_by_watchpoint (void) | |
398 | { | |
399 | if (aarch64_stopped_data_address () != 0) | |
400 | return 1; | |
401 | else | |
402 | return 0; | |
403 | } | |
404 | ||
405 | /* Fetch the thread-local storage pointer for libthread_db. */ | |
406 | ||
407 | ps_err_e | |
55fac6e0 | 408 | ps_get_thread_area (const struct ps_prochandle *ph, |
176eb98c MS |
409 | lwpid_t lwpid, int idx, void **base) |
410 | { | |
55fac6e0 MS |
411 | struct iovec iovec; |
412 | uint64_t reg; | |
413 | ||
414 | iovec.iov_base = ® | |
415 | iovec.iov_len = sizeof (reg); | |
416 | ||
417 | if (ptrace (PTRACE_GETREGSET, lwpid, NT_ARM_TLS, &iovec) != 0) | |
176eb98c MS |
418 | return PS_ERR; |
419 | ||
420 | /* IDX is the bias from the thread pointer to the beginning of the | |
421 | thread descriptor. It has to be subtracted due to implementation | |
422 | quirks in libthread_db. */ | |
55fac6e0 | 423 | *base = (void *) (reg - idx); |
176eb98c MS |
424 | |
425 | return PS_OK; | |
426 | } | |
427 | ||
421530db | 428 | /* Implementation of linux_target_ops method "linux_new_process". */ |
176eb98c MS |
429 | |
430 | static struct arch_process_info * | |
431 | aarch64_linux_new_process (void) | |
432 | { | |
433 | struct arch_process_info *info = xcalloc (1, sizeof (*info)); | |
434 | ||
435 | aarch64_init_debug_reg_state (&info->debug_reg_state); | |
436 | ||
437 | return info; | |
438 | } | |
439 | ||
421530db | 440 | /* Implementation of linux_target_ops method "linux_new_thread". */ |
176eb98c | 441 | |
34c703da GB |
442 | static void |
443 | aarch64_linux_new_thread (struct lwp_info *lwp) | |
176eb98c MS |
444 | { |
445 | struct arch_lwp_info *info = xcalloc (1, sizeof (*info)); | |
446 | ||
447 | /* Mark that all the hardware breakpoint/watchpoint register pairs | |
448 | for this thread need to be initialized (with data from | |
449 | aarch_process_info.debug_reg_state). */ | |
450 | DR_MARK_ALL_CHANGED (info->dr_changed_bp, aarch64_num_bp_regs); | |
451 | DR_MARK_ALL_CHANGED (info->dr_changed_wp, aarch64_num_wp_regs); | |
452 | ||
34c703da | 453 | lwp->arch_private = info; |
176eb98c MS |
454 | } |
455 | ||
421530db PL |
456 | /* Implementation of linux_target_ops method "linux_new_fork". */ |
457 | ||
3a8a0396 DB |
458 | static void |
459 | aarch64_linux_new_fork (struct process_info *parent, | |
460 | struct process_info *child) | |
461 | { | |
462 | /* These are allocated by linux_add_process. */ | |
61a7418c DB |
463 | gdb_assert (parent->priv != NULL |
464 | && parent->priv->arch_private != NULL); | |
465 | gdb_assert (child->priv != NULL | |
466 | && child->priv->arch_private != NULL); | |
3a8a0396 DB |
467 | |
468 | /* Linux kernel before 2.6.33 commit | |
469 | 72f674d203cd230426437cdcf7dd6f681dad8b0d | |
470 | will inherit hardware debug registers from parent | |
471 | on fork/vfork/clone. Newer Linux kernels create such tasks with | |
472 | zeroed debug registers. | |
473 | ||
474 | GDB core assumes the child inherits the watchpoints/hw | |
475 | breakpoints of the parent, and will remove them all from the | |
476 | forked off process. Copy the debug registers mirrors into the | |
477 | new process so that all breakpoints and watchpoints can be | |
478 | removed together. The debug registers mirror will become zeroed | |
479 | in the end before detaching the forked off process, thus making | |
480 | this compatible with older Linux kernels too. */ | |
481 | ||
61a7418c | 482 | *child->priv->arch_private = *parent->priv->arch_private; |
3a8a0396 DB |
483 | } |
484 | ||
421530db PL |
485 | /* Implementation of linux_target_ops method "linux_prepare_to_resume". |
486 | ||
176eb98c MS |
487 | If the debug regs have changed, update the thread's copies. */ |
488 | ||
489 | static void | |
490 | aarch64_linux_prepare_to_resume (struct lwp_info *lwp) | |
491 | { | |
d86d4aaf DE |
492 | struct thread_info *thread = get_lwp_thread (lwp); |
493 | ptid_t ptid = ptid_of (thread); | |
176eb98c MS |
494 | struct arch_lwp_info *info = lwp->arch_private; |
495 | ||
496 | if (DR_HAS_CHANGED (info->dr_changed_bp) | |
497 | || DR_HAS_CHANGED (info->dr_changed_wp)) | |
498 | { | |
499 | int tid = ptid_get_lwp (ptid); | |
500 | struct process_info *proc = find_process_pid (ptid_get_pid (ptid)); | |
501 | struct aarch64_debug_reg_state *state | |
fe978cb0 | 502 | = &proc->priv->arch_private->debug_reg_state; |
176eb98c | 503 | |
c5e92cca | 504 | if (show_debug_regs) |
d86d4aaf | 505 | fprintf (stderr, "prepare_to_resume thread %ld\n", lwpid_of (thread)); |
176eb98c MS |
506 | |
507 | /* Watchpoints. */ | |
508 | if (DR_HAS_CHANGED (info->dr_changed_wp)) | |
509 | { | |
510 | aarch64_linux_set_debug_regs (state, tid, 1); | |
511 | DR_CLEAR_CHANGED (info->dr_changed_wp); | |
512 | } | |
513 | ||
514 | /* Breakpoints. */ | |
515 | if (DR_HAS_CHANGED (info->dr_changed_bp)) | |
516 | { | |
517 | aarch64_linux_set_debug_regs (state, tid, 0); | |
518 | DR_CLEAR_CHANGED (info->dr_changed_bp); | |
519 | } | |
520 | } | |
521 | } | |
522 | ||
3b53ae99 YQ |
523 | /* Return the right target description according to the ELF file of |
524 | current thread. */ | |
525 | ||
526 | static const struct target_desc * | |
527 | aarch64_linux_read_description (void) | |
528 | { | |
529 | unsigned int machine; | |
530 | int is_elf64; | |
531 | int tid; | |
532 | ||
533 | tid = lwpid_of (current_thread); | |
534 | ||
535 | is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine); | |
536 | ||
537 | if (is_elf64) | |
538 | return tdesc_aarch64; | |
539 | else | |
540 | return tdesc_arm_with_neon; | |
541 | } | |
542 | ||
421530db PL |
543 | /* Implementation of linux_target_ops method "arch_setup". */ |
544 | ||
176eb98c MS |
545 | static void |
546 | aarch64_arch_setup (void) | |
547 | { | |
3b53ae99 | 548 | current_process ()->tdesc = aarch64_linux_read_description (); |
176eb98c | 549 | |
af1b22f3 | 550 | aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread)); |
176eb98c MS |
551 | } |
552 | ||
3aee8918 | 553 | static struct regset_info aarch64_regsets[] = |
176eb98c MS |
554 | { |
555 | { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, | |
556 | sizeof (struct user_pt_regs), GENERAL_REGS, | |
557 | aarch64_fill_gregset, aarch64_store_gregset }, | |
558 | { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_FPREGSET, | |
559 | sizeof (struct user_fpsimd_state), FP_REGS, | |
560 | aarch64_fill_fpregset, aarch64_store_fpregset | |
561 | }, | |
562 | { 0, 0, 0, -1, -1, NULL, NULL } | |
563 | }; | |
564 | ||
3aee8918 PA |
565 | static struct regsets_info aarch64_regsets_info = |
566 | { | |
567 | aarch64_regsets, /* regsets */ | |
568 | 0, /* num_regsets */ | |
569 | NULL, /* disabled_regsets */ | |
570 | }; | |
571 | ||
3b53ae99 | 572 | static struct regs_info regs_info_aarch64 = |
3aee8918 PA |
573 | { |
574 | NULL, /* regset_bitmap */ | |
c2d65f38 | 575 | NULL, /* usrregs */ |
3aee8918 PA |
576 | &aarch64_regsets_info, |
577 | }; | |
578 | ||
421530db PL |
579 | /* Implementation of linux_target_ops method "regs_info". */ |
580 | ||
3aee8918 PA |
581 | static const struct regs_info * |
582 | aarch64_regs_info (void) | |
583 | { | |
3b53ae99 YQ |
584 | if (is_64bit_tdesc ()) |
585 | return ®s_info_aarch64; | |
586 | else | |
587 | return ®s_info_aarch32; | |
3aee8918 PA |
588 | } |
589 | ||
7671bf47 PL |
590 | /* Implementation of linux_target_ops method "supports_tracepoints". */ |
591 | ||
592 | static int | |
593 | aarch64_supports_tracepoints (void) | |
594 | { | |
524b57e6 YQ |
595 | if (current_thread == NULL) |
596 | return 1; | |
597 | else | |
598 | { | |
599 | /* We don't support tracepoints on aarch32 now. */ | |
600 | return is_64bit_tdesc (); | |
601 | } | |
7671bf47 PL |
602 | } |
603 | ||
d1d0aea1 PL |
604 | /* Implementation of linux_target_ops method "supports_range_stepping". */ |
605 | ||
606 | static int | |
607 | aarch64_supports_range_stepping (void) | |
608 | { | |
609 | return 1; | |
610 | } | |
611 | ||
176eb98c MS |
612 | struct linux_target_ops the_low_target = |
613 | { | |
614 | aarch64_arch_setup, | |
3aee8918 | 615 | aarch64_regs_info, |
176eb98c MS |
616 | aarch64_cannot_fetch_register, |
617 | aarch64_cannot_store_register, | |
421530db | 618 | NULL, /* fetch_register */ |
176eb98c MS |
619 | aarch64_get_pc, |
620 | aarch64_set_pc, | |
621 | (const unsigned char *) &aarch64_breakpoint, | |
622 | aarch64_breakpoint_len, | |
421530db PL |
623 | NULL, /* breakpoint_reinsert_addr */ |
624 | 0, /* decr_pc_after_break */ | |
176eb98c | 625 | aarch64_breakpoint_at, |
802e8e6d | 626 | aarch64_supports_z_point_type, |
176eb98c MS |
627 | aarch64_insert_point, |
628 | aarch64_remove_point, | |
629 | aarch64_stopped_by_watchpoint, | |
630 | aarch64_stopped_data_address, | |
421530db PL |
631 | NULL, /* collect_ptrace_register */ |
632 | NULL, /* supply_ptrace_register */ | |
633 | NULL, /* siginfo_fixup */ | |
176eb98c MS |
634 | aarch64_linux_new_process, |
635 | aarch64_linux_new_thread, | |
3a8a0396 | 636 | aarch64_linux_new_fork, |
176eb98c | 637 | aarch64_linux_prepare_to_resume, |
421530db | 638 | NULL, /* process_qsupported */ |
7671bf47 | 639 | aarch64_supports_tracepoints, |
d1d0aea1 PL |
640 | NULL, /* get_thread_area */ |
641 | NULL, /* install_fast_tracepoint_jump_pad */ | |
642 | NULL, /* emit_ops */ | |
643 | NULL, /* get_min_fast_tracepoint_insn_len */ | |
644 | aarch64_supports_range_stepping, | |
176eb98c | 645 | }; |
3aee8918 PA |
646 | |
647 | void | |
648 | initialize_low_arch (void) | |
649 | { | |
650 | init_registers_aarch64 (); | |
651 | ||
3b53ae99 YQ |
652 | initialize_low_arch_aarch32 (); |
653 | ||
3aee8918 PA |
654 | initialize_regsets_info (&aarch64_regsets_info); |
655 | } |