1 /* Native-dependent code for BSD Unix running on ARM's, for GDB.
3 Copyright (C) 1988-2017 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/>. */
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <machine/reg.h>
28 #include <machine/frame.h>
31 #include "inf-ptrace.h"
33 extern int arm_apcs_32
;
36 arm_supply_gregset (struct regcache
*regcache
, struct reg
*gregset
)
41 /* Integer registers. */
42 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
43 regcache_raw_supply (regcache
, regno
, (char *) &gregset
->r
[regno
]);
45 regcache_raw_supply (regcache
, ARM_SP_REGNUM
,
46 (char *) &gregset
->r_sp
);
47 regcache_raw_supply (regcache
, ARM_LR_REGNUM
,
48 (char *) &gregset
->r_lr
);
49 /* This is ok: we're running native... */
50 r_pc
= gdbarch_addr_bits_remove (regcache
->arch (), gregset
->r_pc
);
51 regcache_raw_supply (regcache
, ARM_PC_REGNUM
, (char *) &r_pc
);
54 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
55 (char *) &gregset
->r_cpsr
);
57 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
58 (char *) &gregset
->r_pc
);
62 arm_supply_fparegset (struct regcache
*regcache
, struct fpreg
*fparegset
)
66 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
67 regcache_raw_supply (regcache
, regno
,
68 (char *) &fparegset
->fpr
[regno
- ARM_F0_REGNUM
]);
70 regcache_raw_supply (regcache
, ARM_FPS_REGNUM
,
71 (char *) &fparegset
->fpr_fpsr
);
75 fetch_register (struct regcache
*regcache
, int regno
)
77 struct reg inferior_registers
;
80 ret
= ptrace (PT_GETREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
81 (PTRACE_TYPE_ARG3
) &inferior_registers
, 0);
85 warning (_("unable to fetch general register"));
92 regcache_raw_supply (regcache
, ARM_SP_REGNUM
,
93 (char *) &inferior_registers
.r_sp
);
97 regcache_raw_supply (regcache
, ARM_LR_REGNUM
,
98 (char *) &inferior_registers
.r_lr
);
102 /* This is ok: we're running native... */
103 inferior_registers
.r_pc
= gdbarch_addr_bits_remove
105 inferior_registers
.r_pc
);
106 regcache_raw_supply (regcache
, ARM_PC_REGNUM
,
107 (char *) &inferior_registers
.r_pc
);
112 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
113 (char *) &inferior_registers
.r_cpsr
);
115 regcache_raw_supply (regcache
, ARM_PS_REGNUM
,
116 (char *) &inferior_registers
.r_pc
);
120 regcache_raw_supply (regcache
, regno
,
121 (char *) &inferior_registers
.r
[regno
]);
127 fetch_regs (struct regcache
*regcache
)
129 struct reg inferior_registers
;
133 ret
= ptrace (PT_GETREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
134 (PTRACE_TYPE_ARG3
) &inferior_registers
, 0);
138 warning (_("unable to fetch general registers"));
142 arm_supply_gregset (regcache
, &inferior_registers
);
146 fetch_fp_register (struct regcache
*regcache
, int regno
)
148 struct fpreg inferior_fp_registers
;
151 ret
= ptrace (PT_GETFPREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
152 (PTRACE_TYPE_ARG3
) &inferior_fp_registers
, 0);
156 warning (_("unable to fetch floating-point register"));
163 regcache_raw_supply (regcache
, ARM_FPS_REGNUM
,
164 (char *) &inferior_fp_registers
.fpr_fpsr
);
168 regcache_raw_supply (regcache
, regno
,
169 (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
175 fetch_fp_regs (struct regcache
*regcache
)
177 struct fpreg inferior_fp_registers
;
181 ret
= ptrace (PT_GETFPREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
182 (PTRACE_TYPE_ARG3
) &inferior_fp_registers
, 0);
186 warning (_("unable to fetch general registers"));
190 arm_supply_fparegset (regcache
, &inferior_fp_registers
);
194 armnbsd_fetch_registers (struct target_ops
*ops
,
195 struct regcache
*regcache
, int regno
)
199 if (regno
< ARM_F0_REGNUM
|| regno
> ARM_FPS_REGNUM
)
200 fetch_register (regcache
, regno
);
202 fetch_fp_register (regcache
, regno
);
206 fetch_regs (regcache
);
207 fetch_fp_regs (regcache
);
213 store_register (const struct regcache
*regcache
, int regno
)
215 struct gdbarch
*gdbarch
= regcache
->arch ();
216 struct reg inferior_registers
;
219 ret
= ptrace (PT_GETREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
220 (PTRACE_TYPE_ARG3
) &inferior_registers
, 0);
224 warning (_("unable to fetch general registers"));
231 regcache_raw_collect (regcache
, ARM_SP_REGNUM
,
232 (char *) &inferior_registers
.r_sp
);
236 regcache_raw_collect (regcache
, ARM_LR_REGNUM
,
237 (char *) &inferior_registers
.r_lr
);
242 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
243 (char *) &inferior_registers
.r_pc
);
248 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
251 pc_val
= gdbarch_addr_bits_remove (gdbarch
, pc_val
);
252 inferior_registers
.r_pc
^= gdbarch_addr_bits_remove
253 (gdbarch
, inferior_registers
.r_pc
);
254 inferior_registers
.r_pc
|= pc_val
;
260 regcache_raw_collect (regcache
, ARM_PS_REGNUM
,
261 (char *) &inferior_registers
.r_cpsr
);
266 regcache_raw_collect (regcache
, ARM_PS_REGNUM
,
269 psr_val
^= gdbarch_addr_bits_remove (gdbarch
, psr_val
);
270 inferior_registers
.r_pc
= gdbarch_addr_bits_remove
271 (gdbarch
, 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
, ptid_get_pid (regcache_get_ptid (regcache
)),
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 gdbarch
*gdbarch
= regcache
->arch ();
293 struct reg inferior_registers
;
298 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
299 regcache_raw_collect (regcache
, regno
,
300 (char *) &inferior_registers
.r
[regno
]);
302 regcache_raw_collect (regcache
, ARM_SP_REGNUM
,
303 (char *) &inferior_registers
.r_sp
);
304 regcache_raw_collect (regcache
, ARM_LR_REGNUM
,
305 (char *) &inferior_registers
.r_lr
);
309 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
310 (char *) &inferior_registers
.r_pc
);
311 regcache_raw_collect (regcache
, ARM_PS_REGNUM
,
312 (char *) &inferior_registers
.r_cpsr
);
319 regcache_raw_collect (regcache
, ARM_PC_REGNUM
,
321 regcache_raw_collect (regcache
, ARM_PS_REGNUM
,
324 pc_val
= gdbarch_addr_bits_remove (gdbarch
, pc_val
);
325 psr_val
^= gdbarch_addr_bits_remove (gdbarch
, psr_val
);
327 inferior_registers
.r_pc
= pc_val
| psr_val
;
330 ret
= ptrace (PT_SETREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
331 (PTRACE_TYPE_ARG3
) &inferior_registers
, 0);
334 warning (_("unable to store general registers"));
338 store_fp_register (const struct regcache
*regcache
, int regno
)
340 struct fpreg inferior_fp_registers
;
343 ret
= ptrace (PT_GETFPREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
344 (PTRACE_TYPE_ARG3
) &inferior_fp_registers
, 0);
348 warning (_("unable to fetch floating-point registers"));
355 regcache_raw_collect (regcache
, ARM_FPS_REGNUM
,
356 (char *) &inferior_fp_registers
.fpr_fpsr
);
360 regcache_raw_collect (regcache
, regno
,
361 (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
365 ret
= ptrace (PT_SETFPREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
366 (PTRACE_TYPE_ARG3
) &inferior_fp_registers
, 0);
369 warning (_("unable to write register %d to inferior"), regno
);
373 store_fp_regs (const struct regcache
*regcache
)
375 struct fpreg inferior_fp_registers
;
380 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
381 regcache_raw_collect (regcache
, regno
,
382 (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
384 regcache_raw_collect (regcache
, ARM_FPS_REGNUM
,
385 (char *) &inferior_fp_registers
.fpr_fpsr
);
387 ret
= ptrace (PT_SETFPREGS
, ptid_get_pid (regcache_get_ptid (regcache
)),
388 (PTRACE_TYPE_ARG3
) &inferior_fp_registers
, 0);
391 warning (_("unable to store floating-point registers"));
395 armnbsd_store_registers (struct target_ops
*ops
,
396 struct regcache
*regcache
, int regno
)
400 if (regno
< ARM_F0_REGNUM
|| regno
> ARM_FPS_REGNUM
)
401 store_register (regcache
, regno
);
403 store_fp_register (regcache
, regno
);
407 store_regs (regcache
);
408 store_fp_regs (regcache
);
413 fetch_elfcore_registers (struct regcache
*regcache
,
414 char *core_reg_sect
, unsigned core_reg_size
,
415 int which
, CORE_ADDR ignore
)
418 struct fpreg fparegset
;
422 case 0: /* Integer registers. */
423 if (core_reg_size
!= sizeof (struct reg
))
424 warning (_("wrong size of register set in core file"));
427 /* The memcpy may be unnecessary, but we can't really be sure
428 of the alignment of the data in the core file. */
429 memcpy (&gregset
, core_reg_sect
, sizeof (gregset
));
430 arm_supply_gregset (regcache
, &gregset
);
435 if (core_reg_size
!= sizeof (struct fpreg
))
436 warning (_("wrong size of FPA register set in core file"));
439 /* The memcpy may be unnecessary, but we can't really be sure
440 of the alignment of the data in the core file. */
441 memcpy (&fparegset
, core_reg_sect
, sizeof (fparegset
));
442 arm_supply_fparegset (regcache
, &fparegset
);
447 /* Don't know what kind of register request this is; just ignore it. */
452 static struct core_fns arm_netbsd_elfcore_fns
=
454 bfd_target_elf_flavour
, /* core_flovour. */
455 default_check_format
, /* check_format. */
456 default_core_sniffer
, /* core_sniffer. */
457 fetch_elfcore_registers
, /* core_read_registers. */
462 _initialize_arm_netbsd_nat (void)
464 struct target_ops
*t
;
466 t
= inf_ptrace_target ();
467 t
->to_fetch_registers
= armnbsd_fetch_registers
;
468 t
->to_store_registers
= armnbsd_store_registers
;
471 deprecated_add_core_fns (&arm_netbsd_elfcore_fns
);