1 /* PPC linux native support.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001
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, Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
28 #include <sys/param.h>
31 #include <sys/ioctl.h>
34 #include <sys/procfs.h>
35 #include <sys/ptrace.h>
37 /* Prototypes for supply_gregset etc. */
42 #define PT_READ_U PTRACE_PEEKUSR
45 #define PT_WRITE_U PTRACE_POKEUSR
48 /* Default the type of the ptrace transfer to int. */
49 #ifndef PTRACE_XFER_TYPE
50 #define PTRACE_XFER_TYPE int
56 return (sizeof (struct user
));
60 /* registers layout, as presented by the ptrace interface:
61 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
62 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
63 PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
64 PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
65 PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
66 PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
67 PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
68 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
69 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
73 ppc_register_u_addr (int regno
)
77 /* General purpose registers occupy 1 slot each in the buffer */
78 if (regno
>= gdbarch_tdep (current_gdbarch
)->ppc_gp0_regnum
79 && regno
<= gdbarch_tdep (current_gdbarch
)->ppc_gplast_regnum
)
80 u_addr
= ((PT_R0
+ regno
) * 4);
82 /* Floating point regs: 2 slots each */
83 if (regno
>= FP0_REGNUM
&& regno
<= FPLAST_REGNUM
)
84 u_addr
= ((PT_FPR0
+ (regno
- FP0_REGNUM
) * 2) * 4);
86 /* UISA special purpose registers: 1 slot each */
87 if (regno
== PC_REGNUM
)
89 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_lr_regnum
)
91 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_cr_regnum
)
93 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_xer_regnum
)
95 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_ctr_regnum
)
97 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
)
99 if (regno
== gdbarch_tdep (current_gdbarch
)->ppc_ps_regnum
)
106 ppc_ptrace_cannot_fetch_store_register (int regno
)
108 return (ppc_register_u_addr (regno
) == -1);
112 fetch_register (int regno
)
114 /* This isn't really an address. But ptrace thinks of it as one. */
115 char mess
[128]; /* For messages */
117 unsigned int offset
; /* Offset of registers within the u area. */
118 char *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
120 CORE_ADDR regaddr
= ppc_register_u_addr (regno
);
124 memset (buf
, '\0', REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
125 supply_register (regno
, buf
);
129 /* Overload thread id onto process id */
130 if ((tid
= TIDGET (inferior_ptid
)) == 0)
131 tid
= PIDGET (inferior_ptid
); /* no thread id, just use process id */
133 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
136 *(PTRACE_XFER_TYPE
*) & buf
[i
] = ptrace (PT_READ_U
, tid
,
137 (PTRACE_ARG3_TYPE
) regaddr
, 0);
138 regaddr
+= sizeof (PTRACE_XFER_TYPE
);
141 sprintf (mess
, "reading register %s (#%d)",
142 REGISTER_NAME (regno
), regno
);
143 perror_with_name (mess
);
146 supply_register (regno
, buf
);
150 fetch_ppc_registers (void)
153 int last_register
= gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
;
155 for (i
= 0; i
<= last_register
; i
++)
159 /* Fetch registers from the child process. Fetch all registers if
160 regno == -1, otherwise fetch all general registers or all floating
161 point registers depending upon the value of regno. */
163 fetch_inferior_registers (int regno
)
166 fetch_ppc_registers ();
168 fetch_register (regno
);
171 /* Store one register. */
173 store_register (int regno
)
175 /* This isn't really an address. But ptrace thinks of it as one. */
176 CORE_ADDR regaddr
= ppc_register_u_addr (regno
);
177 char mess
[128]; /* For messages */
179 unsigned int offset
; /* Offset of registers within the u area. */
181 char *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
188 /* Overload thread id onto process id */
189 if ((tid
= TIDGET (inferior_ptid
)) == 0)
190 tid
= PIDGET (inferior_ptid
); /* no thread id, just use process id */
192 regcache_collect (regno
, buf
);
193 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (PTRACE_XFER_TYPE
))
196 ptrace (PT_WRITE_U
, tid
, (PTRACE_ARG3_TYPE
) regaddr
,
197 *(PTRACE_XFER_TYPE
*) & buf
[i
]);
198 regaddr
+= sizeof (PTRACE_XFER_TYPE
);
201 sprintf (mess
, "writing register %s (#%d)",
202 REGISTER_NAME (regno
), regno
);
203 perror_with_name (mess
);
209 store_ppc_registers (void)
212 int last_register
= gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
;
214 for (i
= 0; i
<= last_register
; i
++)
219 store_inferior_registers (int regno
)
222 store_register (regno
);
224 store_ppc_registers ();
228 supply_gregset (gdb_gregset_t
*gregsetp
)
231 register elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
233 for (regi
= 0; regi
< 32; regi
++)
234 supply_register (regi
, (char *) (regp
+ regi
));
236 supply_register (PC_REGNUM
, (char *) (regp
+ PT_NIP
));
237 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_lr_regnum
,
238 (char *) (regp
+ PT_LNK
));
239 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_cr_regnum
,
240 (char *) (regp
+ PT_CCR
));
241 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_xer_regnum
,
242 (char *) (regp
+ PT_XER
));
243 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_ctr_regnum
,
244 (char *) (regp
+ PT_CTR
));
245 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
,
246 (char *) (regp
+ PT_MQ
));
247 supply_register (gdbarch_tdep (current_gdbarch
)->ppc_ps_regnum
,
248 (char *) (regp
+ PT_MSR
));
252 fill_gregset (gdb_gregset_t
*gregsetp
, int regno
)
255 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
257 for (regi
= 0; regi
< 32; regi
++)
259 if ((regno
== -1) || regno
== regi
)
260 regcache_collect (regi
, regp
+ PT_R0
+ regi
);
263 if ((regno
== -1) || regno
== PC_REGNUM
)
264 regcache_collect (PC_REGNUM
, regp
+ PT_NIP
);
266 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_lr_regnum
)
267 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_lr_regnum
,
270 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_cr_regnum
)
271 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_cr_regnum
,
274 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_xer_regnum
)
275 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_xer_regnum
,
278 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_ctr_regnum
)
279 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_ctr_regnum
,
282 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
)
283 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_mq_regnum
,
286 || regno
== gdbarch_tdep (current_gdbarch
)->ppc_ps_regnum
)
287 regcache_collect (gdbarch_tdep (current_gdbarch
)->ppc_ps_regnum
,
292 supply_fpregset (gdb_fpregset_t
* fpregsetp
)
295 for (regi
= 0; regi
< 32; regi
++)
297 supply_register (FP0_REGNUM
+ regi
, (char *) (*fpregsetp
+ regi
));
301 /* Given a pointer to a floating point register set in /proc format
302 (fpregset_t *), update the register specified by REGNO from gdb's idea
303 of the current floating point register set. If REGNO is -1, update
307 fill_fpregset (gdb_fpregset_t
*fpregsetp
, int regno
)
311 for (regi
= 0; regi
< 32; regi
++)
313 if ((regno
== -1) || (regno
== FP0_REGNUM
+ regi
))
314 regcache_collect (FP0_REGNUM
+ regi
, (char *) (*fpregsetp
+ regi
));
This page took 0.039423 seconds and 4 git commands to generate.