1 /* Native-dependent code for BSD Unix running on ARM's, for GDB.
3 Copyright (C) 1988-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_string.h"
27 #include <sys/types.h>
28 #include <sys/ptrace.h>
29 #include <machine/reg.h>
30 #include <machine/frame.h>
33 #include "inf-ptrace.h"
35 extern int arm_apcs_32;
38 arm_supply_gregset (struct regcache *regcache, struct reg *gregset)
43 /* Integer registers. */
44 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
45 regcache_raw_supply (regcache, regno, (char *) &gregset->r[regno]);
47 regcache_raw_supply (regcache, ARM_SP_REGNUM,
48 (char *) &gregset->r_sp);
49 regcache_raw_supply (regcache, ARM_LR_REGNUM,
50 (char *) &gregset->r_lr);
51 /* This is ok: we're running native... */
52 r_pc = gdbarch_addr_bits_remove (get_regcache_arch (regcache), gregset->r_pc);
53 regcache_raw_supply (regcache, ARM_PC_REGNUM, (char *) &r_pc);
56 regcache_raw_supply (regcache, ARM_PS_REGNUM,
57 (char *) &gregset->r_cpsr);
59 regcache_raw_supply (regcache, ARM_PS_REGNUM,
60 (char *) &gregset->r_pc);
64 arm_supply_fparegset (struct regcache *regcache, struct fpreg *fparegset)
68 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
69 regcache_raw_supply (regcache, regno,
70 (char *) &fparegset->fpr[regno - ARM_F0_REGNUM]);
72 regcache_raw_supply (regcache, ARM_FPS_REGNUM,
73 (char *) &fparegset->fpr_fpsr);
77 fetch_register (struct regcache *regcache, int regno)
79 struct reg inferior_registers;
82 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
83 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
87 warning (_("unable to fetch general register"));
94 regcache_raw_supply (regcache, ARM_SP_REGNUM,
95 (char *) &inferior_registers.r_sp);
99 regcache_raw_supply (regcache, ARM_LR_REGNUM,
100 (char *) &inferior_registers.r_lr);
104 /* This is ok: we're running native... */
105 inferior_registers.r_pc = gdbarch_addr_bits_remove
106 (get_regcache_arch (regcache),
107 inferior_registers.r_pc);
108 regcache_raw_supply (regcache, ARM_PC_REGNUM,
109 (char *) &inferior_registers.r_pc);
114 regcache_raw_supply (regcache, ARM_PS_REGNUM,
115 (char *) &inferior_registers.r_cpsr);
117 regcache_raw_supply (regcache, ARM_PS_REGNUM,
118 (char *) &inferior_registers.r_pc);
122 regcache_raw_supply (regcache, regno,
123 (char *) &inferior_registers.r[regno]);
129 fetch_regs (struct regcache *regcache)
131 struct reg inferior_registers;
135 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
136 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
140 warning (_("unable to fetch general registers"));
144 arm_supply_gregset (regcache, &inferior_registers);
148 fetch_fp_register (struct regcache *regcache, int regno)
150 struct fpreg inferior_fp_registers;
153 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
154 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
158 warning (_("unable to fetch floating-point register"));
165 regcache_raw_supply (regcache, ARM_FPS_REGNUM,
166 (char *) &inferior_fp_registers.fpr_fpsr);
170 regcache_raw_supply (regcache, regno,
171 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
177 fetch_fp_regs (struct regcache *regcache)
179 struct fpreg inferior_fp_registers;
183 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
184 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
188 warning (_("unable to fetch general registers"));
192 arm_supply_fparegset (regcache, &inferior_fp_registers);
196 armnbsd_fetch_registers (struct target_ops *ops,
197 struct regcache *regcache, int regno)
201 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
202 fetch_register (regcache, regno);
204 fetch_fp_register (regcache, regno);
208 fetch_regs (regcache);
209 fetch_fp_regs (regcache);
215 store_register (const struct regcache *regcache, int regno)
217 struct gdbarch *gdbarch = get_regcache_arch (regcache);
218 struct reg inferior_registers;
221 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
222 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
226 warning (_("unable to fetch general registers"));
233 regcache_raw_collect (regcache, ARM_SP_REGNUM,
234 (char *) &inferior_registers.r_sp);
238 regcache_raw_collect (regcache, ARM_LR_REGNUM,
239 (char *) &inferior_registers.r_lr);
244 regcache_raw_collect (regcache, ARM_PC_REGNUM,
245 (char *) &inferior_registers.r_pc);
250 regcache_raw_collect (regcache, ARM_PC_REGNUM,
253 pc_val = gdbarch_addr_bits_remove (gdbarch, pc_val);
254 inferior_registers.r_pc ^= gdbarch_addr_bits_remove
255 (gdbarch, inferior_registers.r_pc);
256 inferior_registers.r_pc |= pc_val;
262 regcache_raw_collect (regcache, ARM_PS_REGNUM,
263 (char *) &inferior_registers.r_cpsr);
268 regcache_raw_collect (regcache, ARM_PS_REGNUM,
271 psr_val ^= gdbarch_addr_bits_remove (gdbarch, psr_val);
272 inferior_registers.r_pc = gdbarch_addr_bits_remove
273 (gdbarch, inferior_registers.r_pc);
274 inferior_registers.r_pc |= psr_val;
279 regcache_raw_collect (regcache, regno,
280 (char *) &inferior_registers.r[regno]);
284 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
285 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
288 warning (_("unable to write register %d to inferior"), regno);
292 store_regs (const struct regcache *regcache)
294 struct gdbarch *gdbarch = get_regcache_arch (regcache);
295 struct reg inferior_registers;
300 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
301 regcache_raw_collect (regcache, regno,
302 (char *) &inferior_registers.r[regno]);
304 regcache_raw_collect (regcache, ARM_SP_REGNUM,
305 (char *) &inferior_registers.r_sp);
306 regcache_raw_collect (regcache, ARM_LR_REGNUM,
307 (char *) &inferior_registers.r_lr);
311 regcache_raw_collect (regcache, ARM_PC_REGNUM,
312 (char *) &inferior_registers.r_pc);
313 regcache_raw_collect (regcache, ARM_PS_REGNUM,
314 (char *) &inferior_registers.r_cpsr);
321 regcache_raw_collect (regcache, ARM_PC_REGNUM,
323 regcache_raw_collect (regcache, ARM_PS_REGNUM,
326 pc_val = gdbarch_addr_bits_remove (gdbarch, pc_val);
327 psr_val ^= gdbarch_addr_bits_remove (gdbarch, psr_val);
329 inferior_registers.r_pc = pc_val | psr_val;
332 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
333 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
336 warning (_("unable to store general registers"));
340 store_fp_register (const struct regcache *regcache, int regno)
342 struct fpreg inferior_fp_registers;
345 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
346 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
350 warning (_("unable to fetch floating-point registers"));
357 regcache_raw_collect (regcache, ARM_FPS_REGNUM,
358 (char *) &inferior_fp_registers.fpr_fpsr);
362 regcache_raw_collect (regcache, regno,
363 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
367 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
368 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
371 warning (_("unable to write register %d to inferior"), regno);
375 store_fp_regs (const struct regcache *regcache)
377 struct fpreg inferior_fp_registers;
382 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
383 regcache_raw_collect (regcache, regno,
384 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
386 regcache_raw_collect (regcache, ARM_FPS_REGNUM,
387 (char *) &inferior_fp_registers.fpr_fpsr);
389 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
390 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
393 warning (_("unable to store floating-point registers"));
397 armnbsd_store_registers (struct target_ops *ops,
398 struct regcache *regcache, int regno)
402 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
403 store_register (regcache, regno);
405 store_fp_register (regcache, regno);
409 store_regs (regcache);
410 store_fp_regs (regcache);
421 fetch_core_registers (struct regcache *regcache,
422 char *core_reg_sect, unsigned core_reg_size,
423 int which, CORE_ADDR ignore)
425 struct md_core *core_reg = (struct md_core *) core_reg_sect;
429 arm_supply_gregset (regcache, &core_reg->intreg);
430 arm_supply_fparegset (regcache, &core_reg->freg);
434 fetch_elfcore_registers (struct regcache *regcache,
435 char *core_reg_sect, unsigned core_reg_size,
436 int which, CORE_ADDR ignore)
439 struct fpreg fparegset;
443 case 0: /* Integer registers. */
444 if (core_reg_size != sizeof (struct reg))
445 warning (_("wrong size of register set in core file"));
448 /* The memcpy may be unnecessary, but we can't really be sure
449 of the alignment of the data in the core file. */
450 memcpy (&gregset, core_reg_sect, sizeof (gregset));
451 arm_supply_gregset (regcache, &gregset);
456 if (core_reg_size != sizeof (struct fpreg))
457 warning (_("wrong size of FPA register set in core file"));
460 /* The memcpy may be unnecessary, but we can't really be sure
461 of the alignment of the data in the core file. */
462 memcpy (&fparegset, core_reg_sect, sizeof (fparegset));
463 arm_supply_fparegset (regcache, &fparegset);
468 /* Don't know what kind of register request this is; just ignore it. */
473 static struct core_fns arm_netbsd_core_fns =
475 bfd_target_unknown_flavour, /* core_flovour. */
476 default_check_format, /* check_format. */
477 default_core_sniffer, /* core_sniffer. */
478 fetch_core_registers, /* core_read_registers. */
482 static struct core_fns arm_netbsd_elfcore_fns =
484 bfd_target_elf_flavour, /* core_flovour. */
485 default_check_format, /* check_format. */
486 default_core_sniffer, /* core_sniffer. */
487 fetch_elfcore_registers, /* core_read_registers. */
492 _initialize_arm_netbsd_nat (void)
494 struct target_ops *t;
496 t = inf_ptrace_target ();
497 t->to_fetch_registers = armnbsd_fetch_registers;
498 t->to_store_registers = armnbsd_store_registers;
501 deprecated_add_core_fns (&arm_netbsd_core_fns);
502 deprecated_add_core_fns (&arm_netbsd_elfcore_fns);