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. */
26 #ifdef FETCH_INFERIOR_REGISTERS
27 #include <sys/types.h>
28 #include <sys/ptrace.h>
29 #include <machine/reg.h>
30 #include <machine/frame.h>
34 extern int arm_apcs_32;
37 fetch_register (int regno)
39 struct reg inferior_registers;
42 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
43 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
47 warning ("unable to fetch general register");
54 supply_register (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
58 supply_register (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
62 /* This is ok: we're running native... */
63 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
64 supply_register (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
69 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
71 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_pc);
75 supply_register (regno, (char *) &inferior_registers.r[regno]);
83 struct reg inferior_registers;
87 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
88 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
92 warning ("unable to fetch general registers");
96 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
97 supply_register (regno, (char *) &inferior_registers.r[regno]);
99 supply_register (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
100 supply_register (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
101 /* This is ok: we're running native... */
102 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
103 supply_register (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
106 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
108 supply_register (ARM_PS_REGNUM, (char *) &inferior_registers.r_pc);
112 fetch_fp_register (int regno)
114 struct fpreg inferior_fp_registers;
117 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
118 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
122 warning ("unable to fetch floating-point register");
129 supply_register (ARM_FPS_REGNUM,
130 (char *) &inferior_fp_registers.fpr_fpsr);
135 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
143 struct fpreg inferior_fp_registers;
147 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
148 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
152 warning ("unable to fetch general registers");
156 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
158 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
160 supply_register (ARM_FPS_REGNUM, (char *) &inferior_fp_registers.fpr_fpsr);
164 fetch_inferior_registers (int regno)
168 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
169 fetch_register (regno);
171 fetch_fp_register (regno);
182 store_register (int regno)
184 struct reg inferior_registers;
187 ret = ptrace (PT_GETREGS, PIDGET (inferior_ptid),
188 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
192 warning ("unable to fetch general registers");
199 regcache_collect (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
203 regcache_collect (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
208 regcache_collect (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
213 regcache_collect (ARM_PC_REGNUM, (char *) &pc_val);
215 pc_val = ADDR_BITS_REMOVE (pc_val);
216 inferior_registers.r_pc
217 ^= ADDR_BITS_REMOVE (inferior_registers.r_pc);
218 inferior_registers.r_pc |= pc_val;
224 regcache_collect (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
229 regcache_collect (ARM_PS_REGNUM, (char *) &psr_val);
231 psr_val ^= ADDR_BITS_REMOVE (psr_val);
232 inferior_registers.r_pc = ADDR_BITS_REMOVE (inferior_registers.r_pc);
233 inferior_registers.r_pc |= psr_val;
238 regcache_collect (regno, (char *) &inferior_registers.r[regno]);
242 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
243 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
246 warning ("unable to write register %d to inferior", regno);
252 struct reg inferior_registers;
257 for (regno = ARM_A1_REGNUM; regno < ARM_SP_REGNUM; regno++)
258 regcache_collect (regno, (char *) &inferior_registers.r[regno]);
260 regcache_collect (ARM_SP_REGNUM, (char *) &inferior_registers.r_sp);
261 regcache_collect (ARM_LR_REGNUM, (char *) &inferior_registers.r_lr);
265 regcache_collect (ARM_PC_REGNUM, (char *) &inferior_registers.r_pc);
266 regcache_collect (ARM_PS_REGNUM, (char *) &inferior_registers.r_cpsr);
273 regcache_collect (ARM_PC_REGNUM, (char *) &pc_val);
274 regcache_collect (ARM_PS_REGNUM, (char *) &psr_val);
276 pc_val = ADDR_BITS_REMOVE (pc_val);
277 psr_val ^= ADDR_BITS_REMOVE (psr_val);
279 inferior_registers.r_pc = pc_val | psr_val;
282 ret = ptrace (PT_SETREGS, PIDGET (inferior_ptid),
283 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
286 warning ("unable to store general registers");
290 store_fp_register (int regno)
292 struct fpreg inferior_fp_registers;
295 ret = ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
296 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
300 warning ("unable to fetch floating-point registers");
307 regcache_collect (ARM_FPS_REGNUM,
308 (char *) &inferior_fp_registers.fpr_fpsr);
313 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
317 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
318 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
321 warning ("unable to write register %d to inferior", regno);
327 struct fpreg inferior_fp_registers;
332 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
334 (regno, (char *) &inferior_fp_registers.fpr[regno - ARM_F0_REGNUM]);
336 regcache_collect (ARM_FPS_REGNUM, (char *) &inferior_fp_registers.fpr_fpsr);
338 ret = ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
339 (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0);
342 warning ("unable to store floating-point registers");
346 store_inferior_registers (int regno)
350 if (regno < ARM_F0_REGNUM || regno > ARM_FPS_REGNUM)
351 store_register (regno);
353 store_fp_register (regno);
369 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
370 int which, CORE_ADDR ignore)
372 struct md_core *core_reg = (struct md_core *) core_reg_sect;
374 /* integer registers */
375 memcpy (®isters[REGISTER_BYTE (0)], &core_reg->intreg,
376 sizeof (struct reg));
377 /* floating point registers */
382 #error Not FETCH_INFERIOR_REGISTERS
383 #endif /* !FETCH_INFERIOR_REGISTERS */