1 /* Native-dependent code for BSD Unix running on ARM's, for GDB.
3 Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 1999, 2002, 2004
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
29 #include "gdb_string.h"
30 #include <sys/types.h>
31 #include <sys/ptrace.h>
32 #include <machine/reg.h>
33 #include <machine/frame.h>
36 #include "inf-ptrace.h"
38 extern int arm_apcs_32;
41 supply_gregset (struct reg *gregset)
46 /* Integer registers. */
47 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
48 regcache_raw_supply (current_regcache, regno, (char *) &gregset->r[regno]);
50 regcache_raw_supply (current_regcache, ARM_SP_REGNUM,
51 (char *) &gregset->r_sp);
52 regcache_raw_supply (current_regcache, ARM_LR_REGNUM,
53 (char *) &gregset->r_lr);
54 /* This is ok: we're running native... */
55 r_pc = ADDR_BITS_REMOVE (gregset->r_pc);
56 regcache_raw_supply (current_regcache, ARM_PC_REGNUM, (char *) &r_pc);
59 regcache_raw_supply (current_regcache, ARM_PS_REGNUM,
60 (char *) &gregset->r_cpsr);
62 regcache_raw_supply (current_regcache, ARM_PS_REGNUM,
63 (char *) &gregset->r_pc);
67 supply_fparegset (struct fpreg *fparegset)
71 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
72 regcache_raw_supply (current_regcache, regno,
73 (char *) &fparegset->fpr[regno - ARM_F0_REGNUM]);
75 regcache_raw_supply (current_regcache, ARM_FPS_REGNUM,
76 (char *) &fparegset->fpr_fpsr);
80 fetch_register (int regno)
82 struct reg inferior_registers;
85 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
86 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
90 warning (_("unable to fetch general register"));
97 regcache_raw_supply (current_regcache, ARM_SP_REGNUM,
98 (char *) &inferior_registers.r_sp);
102 regcache_raw_supply (current_regcache, ARM_LR_REGNUM,
103 (char *) &inferior_registers.r_lr);
107 /* This is ok: we're running native... */
108 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
109 regcache_raw_supply (current_regcache, ARM_PC_REGNUM,
110 (char *) &inferior_registers.r_pc);
115 regcache_raw_supply (current_regcache, ARM_PS_REGNUM,
116 (char *) &inferior_registers.r_cpsr);
118 regcache_raw_supply (current_regcache, ARM_PS_REGNUM,
119 (char *) &inferior_registers.r_pc);
123 regcache_raw_supply (current_regcache, regno,
124 (char *) &inferior_registers.r[regno]);
132 struct reg inferior_registers;
136 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
137 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
141 warning (_("unable to fetch general registers"));
145 supply_gregset (&inferior_registers);
149 fetch_fp_register (int regno)
151 struct fpreg inferior_fp_registers;
154 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
155 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
159 warning (_("unable to fetch floating-point register"));
166 regcache_raw_supply (current_regcache, ARM_FPS_REGNUM,
167 (char *) &inferior_fp_registers.fpr_fpsr);
171 regcache_raw_supply (current_regcache, regno,
172 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
180 struct fpreg inferior_fp_registers;
184 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
185 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
189 warning (_("unable to fetch general registers"));
193 supply_fparegset (&inferior_fp_registers);
197 armnbsd_fetch_registers (int regno)
201 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
202 fetch_register (regno);
204 fetch_fp_register (regno);
215 store_register (int regno)
217 struct reg inferior_registers;
220 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
221 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
225 warning (_("unable to fetch general registers"));
232 regcache_raw_collect (current_regcache, ARM_SP_REGNUM,
233 (char *) &inferior_registers.r_sp);
237 regcache_raw_collect (current_regcache, ARM_LR_REGNUM,
238 (char *) &inferior_registers.r_lr);
243 regcache_raw_collect (current_regcache, ARM_PC_REGNUM,
244 (char *) &inferior_registers.r_pc);
249 regcache_raw_collect (current_regcache, ARM_PC_REGNUM,
252 pc_val = ADDR_BITS_REMOVE (pc_val);
253 inferior_registers.r_pc
254 ^= ADDR_BITS_REMOVE (inferior_registers.r_pc);
255 inferior_registers.r_pc |= pc_val;
261 regcache_raw_collect (current_regcache, ARM_PS_REGNUM,
262 (char *) &inferior_registers.r_cpsr);
267 regcache_raw_collect (current_regcache, ARM_PS_REGNUM,
270 psr_val ^= ADDR_BITS_REMOVE (psr_val);
271 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
272 inferior_registers.r_pc |= psr_val;
277 regcache_raw_collect (current_regcache, regno,
278 (char *) &inferior_registers.r[regno]);
282 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
283 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
286 warning (_("unable to write register %d to inferior"), regno);
292 struct reg inferior_registers;
297 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
298 regcache_raw_collect (current_regcache, regno,
299 (char *) &inferior_registers.r[regno]);
301 regcache_raw_collect (current_regcache, ARM_SP_REGNUM,
302 (char *) &inferior_registers.r_sp);
303 regcache_raw_collect (current_regcache, ARM_LR_REGNUM,
304 (char *) &inferior_registers.r_lr);
308 regcache_raw_collect (current_regcache, ARM_PC_REGNUM,
309 (char *) &inferior_registers.r_pc);
310 regcache_raw_collect (current_regcache, ARM_PS_REGNUM,
311 (char *) &inferior_registers.r_cpsr);
318 regcache_raw_collect (current_regcache, ARM_PC_REGNUM,
320 regcache_raw_collect (current_regcache, ARM_PS_REGNUM,
323 pc_val = ADDR_BITS_REMOVE (pc_val);
324 psr_val ^= ADDR_BITS_REMOVE (psr_val);
326 inferior_registers.r_pc = pc_val | psr_val;
329 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
330 (PTRACE_TYPE_ARG3) &inferior_registers, 0);
333 warning (_("unable to store general registers"));
337 store_fp_register (int regno)
339 struct fpreg inferior_fp_registers;
342 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
343 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
347 warning (_("unable to fetch floating-point registers"));
354 regcache_raw_collect (current_regcache, ARM_FPS_REGNUM,
355 (char *) &inferior_fp_registers.fpr_fpsr);
359 regcache_raw_collect (current_regcache, regno,
360 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
364 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
365 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
368 warning (_("unable to write register %d to inferior"), regno);
374 struct fpreg inferior_fp_registers;
379 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
380 regcache_raw_collect (current_regcache, regno,
381 (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
383 regcache_raw_collect (current_regcache, ARM_FPS_REGNUM,
384 (char *) &inferior_fp_registers.fpr_fpsr);
386 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
387 (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
390 warning (_("unable to store floating-point registers"));
394 armnbsd_store_registers (int regno)
398 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
399 store_register (regno);
401 store_fp_register (regno);
417 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
418 int which, CORE_ADDR ignore)
420 struct md_core *core_reg = (struct md_core *) core_reg_sect;
424 supply_gregset (&core_reg->intreg);
425 supply_fparegset (&core_reg->freg);
429 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size,
430 int which, CORE_ADDR ignore)
433 struct fpreg fparegset;
437 case 0: /* Integer registers. */
438 if (core_reg_size != sizeof (struct reg))
439 warning (_("wrong size of register set in core file"));
442 /* The memcpy may be unnecessary, but we can't really be sure
443 of the alignment of the data in the core file. */
444 memcpy (&gregset, core_reg_sect, sizeof (gregset));
445 supply_gregset (&gregset);
450 if (core_reg_size != sizeof (struct fpreg))
451 warning (_("wrong size of FPA register set in core file"));
454 /* The memcpy may be unnecessary, but we can't really be sure
455 of the alignment of the data in the core file. */
456 memcpy (&fparegset, core_reg_sect, sizeof (fparegset));
457 supply_fparegset (&fparegset);
462 /* Don't know what kind of register request this is; just ignore it. */
467 static struct core_fns arm_netbsd_core_fns =
469 bfd_target_unknown_flavour, /* core_flovour. */
470 default_check_format, /* check_format. */
471 default_core_sniffer, /* core_sniffer. */
472 fetch_core_registers, /* core_read_registers. */
476 static struct core_fns arm_netbsd_elfcore_fns =
478 bfd_target_elf_flavour, /* core_flovour. */
479 default_check_format, /* check_format. */
480 default_core_sniffer, /* core_sniffer. */
481 fetch_elfcore_registers, /* core_read_registers. */
486 _initialize_arm_netbsd_nat (void)
488 struct target_ops *t;
490 t = inf_ptrace_target ();
491 t->to_fetch_registers = armnbsd_fetch_registers;
492 t->to_store_registers = armnbsd_store_registers;
495 deprecated_add_core_fns (&arm_netbsd_core_fns);
496 deprecated_add_core_fns (&arm_netbsd_elfcore_fns);