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, 2007
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 arm_supply_gregset (struct regcache
*regcache
, struct reg
*gregset
)
46 /* Integer registers. */
47 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
48 regcache_raw_supply (regcache
, regno
, (char *) &gregset
->r
[regno
]);
50 regcache_raw_supply (regcache
, ARM_SP_REGNUM
,
51 (char *) &gregset
->r_sp
);
52 regcache_raw_supply (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 (regcache
, ARM_PC_REGNUM
, (char *) &r_pc
);
59 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
60 (char *) &gregset
->r_cpsr
);
62 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
63 (char *) &gregset
->r_pc
);
67 arm_supply_fparegset (struct regcache
*regcache
, struct fpreg
*fparegset
)
71 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
72 regcache_raw_supply (regcache
, regno
,
73 (char *) &fparegset
->fpr
[regno
- ARM_F0_REGNUM
]);
75 regcache_raw_supply (regcache
, ARM_FPS_REGNUM
,
76 (char *) &fparegset
->fpr_fpsr
);
80 fetch_register (struct regcache
*regcache
, 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 (regcache
, ARM_SP_REGNUM
,
98 (char *) &inferior_registers
.r_sp
);
102 regcache_raw_supply (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 (regcache
, ARM_PC_REGNUM
,
110 (char *) &inferior_registers
.r_pc
);
115 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
116 (char *) &inferior_registers
.r_cpsr
);
118 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
119 (char *) &inferior_registers
.r_pc
);
123 regcache_raw_supply (regcache
, regno
,
124 (char *) &inferior_registers
.r
[regno
]);
130 fetch_regs (struct regcache
*regcache
)
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 arm_supply_gregset (regcache
, &inferior_registers
);
149 fetch_fp_register (struct regcache
*regcache
, 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 (regcache
, ARM_FPS_REGNUM
,
167 (char *) &inferior_fp_registers
.fpr_fpsr
);
171 regcache_raw_supply (regcache
, regno
,
172 (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
178 fetch_fp_regs (struct regcache
*regcache
)
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 arm_supply_fparegset (regcache
, &inferior_fp_registers
);
197 armnbsd_fetch_registers (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 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 (regcache
, ARM_SP_REGNUM
,
233 (char *) &inferior_registers
.r_sp
);
237 regcache_raw_collect (regcache
, ARM_LR_REGNUM
,
238 (char *) &inferior_registers
.r_lr
);
243 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
244 (char *) &inferior_registers
.r_pc
);
249 regcache_raw_collect (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 (regcache
, ARM_PS_REGNUM
,
262 (char *) &inferior_registers
.r_cpsr
);
267 regcache_raw_collect (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 (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
);
290 store_regs (const struct regcache
*regcache
)
292 struct reg inferior_registers
;
297 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
298 regcache_raw_collect (regcache
, regno
,
299 (char *) &inferior_registers
.r
[regno
]);
301 regcache_raw_collect (regcache
, ARM_SP_REGNUM
,
302 (char *) &inferior_registers
.r_sp
);
303 regcache_raw_collect (regcache
, ARM_LR_REGNUM
,
304 (char *) &inferior_registers
.r_lr
);
308 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
309 (char *) &inferior_registers
.r_pc
);
310 regcache_raw_collect (regcache
, ARM_PS_REGNUM
,
311 (char *) &inferior_registers
.r_cpsr
);
318 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
320 regcache_raw_collect (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 (const struct regcache
*regcache
, 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 (regcache
, ARM_FPS_REGNUM
,
355 (char *) &inferior_fp_registers
.fpr_fpsr
);
359 regcache_raw_collect (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
);
372 store_fp_regs (const struct regcache
*regcache
)
374 struct fpreg inferior_fp_registers
;
379 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
380 regcache_raw_collect (regcache
, regno
,
381 (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
383 regcache_raw_collect (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 (struct regcache
*regcache
, int regno
)
398 if (regno
< ARM_F0_REGNUM
|| regno
> ARM_FPS_REGNUM
)
399 store_register (regcache
, regno
);
401 store_fp_register (regcache
, regno
);
405 store_regs (regcache
);
406 store_fp_regs (regcache
);
417 fetch_core_registers (struct regcache
*regcache
,
418 char *core_reg_sect
, unsigned core_reg_size
,
419 int which
, CORE_ADDR ignore
)
421 struct md_core
*core_reg
= (struct md_core
*) core_reg_sect
;
425 arm_supply_gregset (regcache
, &core_reg
->intreg
);
426 arm_supply_fparegset (regcache
, &core_reg
->freg
);
430 fetch_elfcore_registers (struct regcache
*regcache
,
431 char *core_reg_sect
, unsigned core_reg_size
,
432 int which
, CORE_ADDR ignore
)
435 struct fpreg fparegset
;
439 case 0: /* Integer registers. */
440 if (core_reg_size
!= sizeof (struct reg
))
441 warning (_("wrong size of register set in core file"));
444 /* The memcpy may be unnecessary, but we can't really be sure
445 of the alignment of the data in the core file. */
446 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
447 arm_supply_gregset (regcache
, &gregset
);
452 if (core_reg_size
!= sizeof (struct fpreg
))
453 warning (_("wrong size of FPA register set in core file"));
456 /* The memcpy may be unnecessary, but we can't really be sure
457 of the alignment of the data in the core file. */
458 memcpy (&fparegset
, core_reg_sect
, sizeof (fparegset
));
459 arm_supply_fparegset (regcache
, &fparegset
);
464 /* Don't know what kind of register request this is; just ignore it. */
469 static struct core_fns arm_netbsd_core_fns
=
471 bfd_target_unknown_flavour
, /* core_flovour. */
472 default_check_format
, /* check_format. */
473 default_core_sniffer
, /* core_sniffer. */
474 fetch_core_registers
, /* core_read_registers. */
478 static struct core_fns arm_netbsd_elfcore_fns
=
480 bfd_target_elf_flavour
, /* core_flovour. */
481 default_check_format
, /* check_format. */
482 default_core_sniffer
, /* core_sniffer. */
483 fetch_elfcore_registers
, /* core_read_registers. */
488 _initialize_arm_netbsd_nat (void)
490 struct target_ops
*t
;
492 t
= inf_ptrace_target ();
493 t
->to_fetch_registers
= armnbsd_fetch_registers
;
494 t
->to_store_registers
= armnbsd_store_registers
;
497 deprecated_add_core_fns (&arm_netbsd_core_fns
);
498 deprecated_add_core_fns (&arm_netbsd_elfcore_fns
);