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 fetch_register (int regno
)
43 struct reg inferior_registers
;
46 ret
= ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
47 (PTRACE_ARG3_TYPE
) &inferior_registers
, 0);
51 warning ("unable to fetch general register");
58 supply_register (ARM_SP_REGNUM
, (char *) &inferior_registers
.r_sp
);
62 supply_register (ARM_LR_REGNUM
, (char *) &inferior_registers
.r_lr
);
66 /* This is ok: we're running native... */
67 inferior_registers
.r_pc
= ADDR_BITS_REMOVE (inferior_registers
.r_pc
);
68 supply_register (ARM_PC_REGNUM
, (char *) &inferior_registers
.r_pc
);
73 supply_register (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_cpsr
);
75 supply_register (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_pc
);
79 supply_register (regno
, (char *) &inferior_registers
.r
[regno
]);
87 struct reg inferior_registers
;
91 ret
= ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
92 (PTRACE_ARG3_TYPE
) &inferior_registers
, 0);
96 warning ("unable to fetch general registers");
100 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
101 supply_register (regno
, (char *) &inferior_registers
.r
[regno
]);
103 supply_register (ARM_SP_REGNUM
, (char *) &inferior_registers
.r_sp
);
104 supply_register (ARM_LR_REGNUM
, (char *) &inferior_registers
.r_lr
);
105 /* This is ok: we're running native... */
106 inferior_registers
.r_pc
= ADDR_BITS_REMOVE (inferior_registers
.r_pc
);
107 supply_register (ARM_PC_REGNUM
, (char *) &inferior_registers
.r_pc
);
110 supply_register (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_cpsr
);
112 supply_register (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_pc
);
116 fetch_fp_register (int regno
)
118 struct fpreg inferior_fp_registers
;
121 ret
= ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
122 (PTRACE_ARG3_TYPE
) &inferior_fp_registers
, 0);
126 warning ("unable to fetch floating-point register");
133 supply_register (ARM_FPS_REGNUM
,
134 (char *) &inferior_fp_registers
.fpr_fpsr
);
139 (regno
, (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
147 struct fpreg inferior_fp_registers
;
151 ret
= ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
152 (PTRACE_ARG3_TYPE
) &inferior_fp_registers
, 0);
156 warning ("unable to fetch general registers");
160 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
162 (regno
, (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
164 supply_register (ARM_FPS_REGNUM
, (char *) &inferior_fp_registers
.fpr_fpsr
);
168 fetch_inferior_registers (int regno
)
172 if (regno
< ARM_F0_REGNUM
|| regno
> ARM_FPS_REGNUM
)
173 fetch_register (regno
);
175 fetch_fp_register (regno
);
186 store_register (int regno
)
188 struct reg inferior_registers
;
191 ret
= ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
192 (PTRACE_ARG3_TYPE
) &inferior_registers
, 0);
196 warning ("unable to fetch general registers");
203 regcache_collect (ARM_SP_REGNUM
, (char *) &inferior_registers
.r_sp
);
207 regcache_collect (ARM_LR_REGNUM
, (char *) &inferior_registers
.r_lr
);
212 regcache_collect (ARM_PC_REGNUM
, (char *) &inferior_registers
.r_pc
);
217 regcache_collect (ARM_PC_REGNUM
, (char *) &pc_val
);
219 pc_val
= ADDR_BITS_REMOVE (pc_val
);
220 inferior_registers
.r_pc
221 ^= ADDR_BITS_REMOVE (inferior_registers
.r_pc
);
222 inferior_registers
.r_pc
|= pc_val
;
228 regcache_collect (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_cpsr
);
233 regcache_collect (ARM_PS_REGNUM
, (char *) &psr_val
);
235 psr_val
^= ADDR_BITS_REMOVE (psr_val
);
236 inferior_registers
.r_pc
= ADDR_BITS_REMOVE (inferior_registers
.r_pc
);
237 inferior_registers
.r_pc
|= psr_val
;
242 regcache_collect (regno
, (char *) &inferior_registers
.r
[regno
]);
246 ret
= ptrace (PT_SETREGS
, PIDGET (inferior_ptid
),
247 (PTRACE_ARG3_TYPE
) &inferior_registers
, 0);
250 warning ("unable to write register %d to inferior", regno
);
256 struct reg inferior_registers
;
261 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
262 regcache_collect (regno
, (char *) &inferior_registers
.r
[regno
]);
264 regcache_collect (ARM_SP_REGNUM
, (char *) &inferior_registers
.r_sp
);
265 regcache_collect (ARM_LR_REGNUM
, (char *) &inferior_registers
.r_lr
);
269 regcache_collect (ARM_PC_REGNUM
, (char *) &inferior_registers
.r_pc
);
270 regcache_collect (ARM_PS_REGNUM
, (char *) &inferior_registers
.r_cpsr
);
277 regcache_collect (ARM_PC_REGNUM
, (char *) &pc_val
);
278 regcache_collect (ARM_PS_REGNUM
, (char *) &psr_val
);
280 pc_val
= ADDR_BITS_REMOVE (pc_val
);
281 psr_val
^= ADDR_BITS_REMOVE (psr_val
);
283 inferior_registers
.r_pc
= pc_val
| psr_val
;
286 ret
= ptrace (PT_SETREGS
, PIDGET (inferior_ptid
),
287 (PTRACE_ARG3_TYPE
) &inferior_registers
, 0);
290 warning ("unable to store general registers");
294 store_fp_register (int regno
)
296 struct fpreg inferior_fp_registers
;
299 ret
= ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
300 (PTRACE_ARG3_TYPE
) &inferior_fp_registers
, 0);
304 warning ("unable to fetch floating-point registers");
311 regcache_collect (ARM_FPS_REGNUM
,
312 (char *) &inferior_fp_registers
.fpr_fpsr
);
317 (regno
, (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
321 ret
= ptrace (PT_SETFPREGS
, PIDGET (inferior_ptid
),
322 (PTRACE_ARG3_TYPE
) &inferior_fp_registers
, 0);
325 warning ("unable to write register %d to inferior", regno
);
331 struct fpreg inferior_fp_registers
;
336 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
338 (regno
, (char *) &inferior_fp_registers
.fpr
[regno
- ARM_F0_REGNUM
]);
340 regcache_collect (ARM_FPS_REGNUM
, (char *) &inferior_fp_registers
.fpr_fpsr
);
342 ret
= ptrace (PT_SETFPREGS
, PIDGET (inferior_ptid
),
343 (PTRACE_ARG3_TYPE
) &inferior_fp_registers
, 0);
346 warning ("unable to store floating-point registers");
350 store_inferior_registers (int regno
)
354 if (regno
< ARM_F0_REGNUM
|| regno
> ARM_FPS_REGNUM
)
355 store_register (regno
);
357 store_fp_register (regno
);
373 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
374 int which
, CORE_ADDR ignore
)
376 struct md_core
*core_reg
= (struct md_core
*) core_reg_sect
;
380 /* Integer registers. */
381 for (regno
= ARM_A1_REGNUM
; regno
< ARM_SP_REGNUM
; regno
++)
382 supply_register (regno
, (char *) &core_reg
->intreg
.r
[regno
]);
384 supply_register (ARM_SP_REGNUM
, (char *) &core_reg
->intreg
.r_sp
);
385 supply_register (ARM_LR_REGNUM
, (char *) &core_reg
->intreg
.r_lr
);
386 /* This is ok: we're running native... */
387 r_pc
= ADDR_BITS_REMOVE (core_reg
->intreg
.r_pc
);
388 supply_register (ARM_PC_REGNUM
, (char *) &r_pc
);
391 supply_register (ARM_PS_REGNUM
, (char *) &core_reg
->intreg
.r_cpsr
);
393 supply_register (ARM_PS_REGNUM
, (char *) &core_reg
->intreg
.r_pc
);
395 /* Floating-point registers. */
396 for (regno
= ARM_F0_REGNUM
; regno
<= ARM_F7_REGNUM
; regno
++)
398 (regno
, (char *) &core_reg
->freg
.fpr
[regno
- ARM_F0_REGNUM
]);
400 supply_register (ARM_FPS_REGNUM
, (char *) &core_reg
->freg
.fpr_fpsr
);
403 static struct core_fns arm_netbsd_core_fns
=
405 bfd_target_unknown_flavour
, /* core_flovour. */
406 default_check_format
, /* check_format. */
407 default_core_sniffer
, /* core_sniffer. */
408 fetch_core_registers
, /* core_read_registers. */
413 _initialize_arm_netbsd_nat (void)
415 add_core_fns (&arm_netbsd_core_fns
);