1 /* Native-dependent code for BSD Unix running on ARM's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 1999, 2002
3 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #ifndef FETCH_INFERIOR_REGISTERS
25 #error Not FETCH_INFERIOR_REGISTERS
26 #endif /* !FETCH_INFERIOR_REGISTERS */
30 #include <sys/types.h>
31 #include <sys/ptrace.h>
32 #include <machine/reg.h>
33 #include <machine/frame.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 supply_register (regno, (char *) &gregset->r[regno]);
50 supply_register (ARM_SP_REGNUM, (char *) &gregset->r_sp);
51 supply_register (ARM_LR_REGNUM, (char *) &gregset->r_lr);
52 /* This is ok: we're running native... */
53 r_pc = ADDR_BITS_REMOVE (gregset->r_pc);
54 supply_register (ARM_PC_REGNUM, (char *) &r_pc);
57 supply_register (ARM_PS_REGNUM, (char *) &gregset->r_cpsr);
59 supply_register (ARM_PS_REGNUM, (char *) &gregset->r_pc);
63 supply_fparegset (struct fpreg *fparegset)
67 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
69 (regno, (char *) &fparegset->fpr[regno - ARM_F0_REGNUM]);
71 supply_register (ARM_FPS_REGNUM, (char *) &fparegset->fpr_fpsr);
75 fetch_register (int regno)
77 struct reg inferior_registers;
80 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
81 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
85 warning ("unable to fetch general register");
92 supply_register (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
96 supply_register (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
100 /* This is ok: we're running native... */
101 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
102 supply_register (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
107 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
109 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_pc);
113 supply_register (regno, (char *) &inferior_registers.r[regno]);
121 struct reg inferior_registers;
125 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
126 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
130 warning ("unable to fetch general registers");
134 supply_gregset (&inferior_registers);
138 fetch_fp_register (int regno)
140 struct fpreg inferior_fp_registers;
143 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
144 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
148 warning ("unable to fetch floating-point register");
155 supply_register (ARM_FPS_REGNUM,
156 (char *) &inferior_fp_registers.fpr_fpsr);
161 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
169 struct fpreg inferior_fp_registers;
173 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
174 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
178 warning ("unable to fetch general registers");
182 supply_fparegset (&inferior_fp_registers);
186 fetch_inferior_registers (int regno)
190 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
191 fetch_register (regno);
193 fetch_fp_register (regno);
204 store_register (int regno)
206 struct reg inferior_registers;
209 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
210 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
214 warning ("unable to fetch general registers");
221 regcache_collect (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
225 regcache_collect (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
230 regcache_collect (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
235 regcache_collect (ARM_PC_REGNUM, (char *) &pc_val);
237 pc_val = ADDR_BITS_REMOVE (pc_val);
238 inferior_registers.r_pc
239 ^= ADDR_BITS_REMOVE (inferior_registers.r_pc);
240 inferior_registers.r_pc |= pc_val;
246 regcache_collect (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
251 regcache_collect (ARM_PS_REGNUM, (char *) &psr_val);
253 psr_val ^= ADDR_BITS_REMOVE (psr_val);
254 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
255 inferior_registers.r_pc |= psr_val;
260 regcache_collect (regno, (char *) &inferior_registers.r[regno]);
264 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
265 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
268 warning ("unable to write register %d to inferior", regno);
274 struct reg inferior_registers;
279 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
280 regcache_collect (regno, (char *) &inferior_registers.r[regno]);
282 regcache_collect (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
283 regcache_collect (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
287 regcache_collect (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
288 regcache_collect (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
295 regcache_collect (ARM_PC_REGNUM, (char *) &pc_val);
296 regcache_collect (ARM_PS_REGNUM, (char *) &psr_val);
298 pc_val = ADDR_BITS_REMOVE (pc_val);
299 psr_val ^= ADDR_BITS_REMOVE (psr_val);
301 inferior_registers.r_pc = pc_val | psr_val;
304 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
305 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
308 warning ("unable to store general registers");
312 store_fp_register (int regno)
314 struct fpreg inferior_fp_registers;
317 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
318 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
322 warning ("unable to fetch floating-point registers");
329 regcache_collect (ARM_FPS_REGNUM,
330 (char *) &inferior_fp_registers.fpr_fpsr);
335 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
339 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
340 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
343 warning ("unable to write register %d to inferior", regno);
349 struct fpreg inferior_fp_registers;
354 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
356 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
358 regcache_collect (ARM_FPS_REGNUM, (char *) &inferior_fp_registers.fpr_fpsr);
360 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
361 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
364 warning ("unable to store floating-point registers");
368 store_inferior_registers (int regno)
372 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
373 store_register (regno);
375 store_fp_register (regno);
391 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
392 int which, CORE_ADDR ignore)
394 struct md_core *core_reg = (struct md_core *) core_reg_sect;
398 supply_gregset (&core_reg->intreg);
399 supply_fparegset (&core_reg->freg);
403 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size,
404 int which, CORE_ADDR ignore)
407 struct fpreg fparegset;
411 case 0: /* Integer registers. */
412 if (core_reg_size != sizeof (struct reg))
413 warning ("wrong size of register set in core file");
416 /* The memcpy may be unnecessary, but we can't really be sure
417 of the alignment of the data in the core file. */
418 memcpy (&gregset, core_reg_sect, sizeof (gregset));
419 supply_gregset (&gregset);
424 if (core_reg_size != sizeof (struct fpreg))
425 warning ("wrong size of FPA register set in core file");
428 /* The memcpy may be unnecessary, but we can't really be sure
429 of the alignment of the data in the core file. */
430 memcpy (&fparegset, core_reg_sect, sizeof (fparegset));
431 supply_fparegset (&fparegset);
436 /* Don't know what kind of register request this is; just ignore it. */
441 static struct core_fns arm_netbsd_core_fns =
443 bfd_target_unknown_flavour, /* core_flovour. */
444 default_check_format, /* check_format. */
445 default_core_sniffer, /* core_sniffer. */
446 fetch_core_registers, /* core_read_registers. */
450 static struct core_fns arm_netbsd_elfcore_fns =
452 bfd_target_elf_flavour, /* core_flovour. */
453 default_check_format, /* check_format. */
454 default_core_sniffer, /* core_sniffer. */
455 fetch_elfcore_registers, /* core_read_registers. */
460 _initialize_arm_netbsd_nat (void)
462 add_core_fns (&arm_netbsd_core_fns);
463 add_core_fns (&arm_netbsd_elfcore_fns);