1 /* Functions specific to running GDB native on HPPA running GNU/Linux.
3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 3 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, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
27 #include "linux-nat.h"
29 #include <sys/procfs.h>
30 #include <sys/ptrace.h>
31 #include <linux/version.h>
33 #include <asm/ptrace.h>
34 #include "hppa-linux-offsets.h"
36 #include "hppa-tdep.h"
38 /* Prototypes for supply_gregset etc. */
41 /* These must match the order of the register names.
43 Some sort of lookup table is needed because the offsets associated
44 with the registers are all over the board. */
46 static const int u_offsets[] =
48 /* general registers */
117 /* Floating point regs. */
128 PT_FR10, PT_FR10 + 4,
129 PT_FR11, PT_FR11 + 4,
130 PT_FR12, PT_FR12 + 4,
131 PT_FR13, PT_FR13 + 4,
132 PT_FR14, PT_FR14 + 4,
133 PT_FR15, PT_FR15 + 4,
134 PT_FR16, PT_FR16 + 4,
135 PT_FR17, PT_FR17 + 4,
136 PT_FR18, PT_FR18 + 4,
137 PT_FR19, PT_FR19 + 4,
138 PT_FR20, PT_FR20 + 4,
139 PT_FR21, PT_FR21 + 4,
140 PT_FR22, PT_FR22 + 4,
141 PT_FR23, PT_FR23 + 4,
142 PT_FR24, PT_FR24 + 4,
143 PT_FR25, PT_FR25 + 4,
144 PT_FR26, PT_FR26 + 4,
145 PT_FR27, PT_FR27 + 4,
146 PT_FR28, PT_FR28 + 4,
147 PT_FR29, PT_FR29 + 4,
148 PT_FR30, PT_FR30 + 4,
149 PT_FR31, PT_FR31 + 4,
153 hppa_linux_register_addr (int regno, CORE_ADDR blockend)
157 if ((unsigned) regno >= ARRAY_SIZE (u_offsets))
158 error (_("Invalid register number %d."), regno);
160 if (u_offsets[regno] == -1)
164 addr = (CORE_ADDR) u_offsets[regno];
171 * Registers saved in a coredump:
176 * sar, iir, isr, ior, ipsw
181 #define GR_REGNUM(_n) (HPPA_R0_REGNUM+_n)
182 #define TR_REGNUM(_n) (HPPA_TR0_REGNUM+_n)
183 static const int greg_map[] =
185 GR_REGNUM(0), GR_REGNUM(1), GR_REGNUM(2), GR_REGNUM(3),
186 GR_REGNUM(4), GR_REGNUM(5), GR_REGNUM(6), GR_REGNUM(7),
187 GR_REGNUM(8), GR_REGNUM(9), GR_REGNUM(10), GR_REGNUM(11),
188 GR_REGNUM(12), GR_REGNUM(13), GR_REGNUM(14), GR_REGNUM(15),
189 GR_REGNUM(16), GR_REGNUM(17), GR_REGNUM(18), GR_REGNUM(19),
190 GR_REGNUM(20), GR_REGNUM(21), GR_REGNUM(22), GR_REGNUM(23),
191 GR_REGNUM(24), GR_REGNUM(25), GR_REGNUM(26), GR_REGNUM(27),
192 GR_REGNUM(28), GR_REGNUM(29), GR_REGNUM(30), GR_REGNUM(31),
194 HPPA_SR4_REGNUM+1, HPPA_SR4_REGNUM+2, HPPA_SR4_REGNUM+3, HPPA_SR4_REGNUM+4,
195 HPPA_SR4_REGNUM, HPPA_SR4_REGNUM+5, HPPA_SR4_REGNUM+6, HPPA_SR4_REGNUM+7,
197 HPPA_PCOQ_HEAD_REGNUM, HPPA_PCOQ_TAIL_REGNUM,
198 HPPA_PCSQ_HEAD_REGNUM, HPPA_PCSQ_TAIL_REGNUM,
200 HPPA_SAR_REGNUM, HPPA_IIR_REGNUM, HPPA_ISR_REGNUM, HPPA_IOR_REGNUM,
201 HPPA_IPSW_REGNUM, HPPA_RCR_REGNUM,
203 TR_REGNUM(0), TR_REGNUM(1), TR_REGNUM(2), TR_REGNUM(3),
204 TR_REGNUM(4), TR_REGNUM(5), TR_REGNUM(6), TR_REGNUM(7),
206 HPPA_PID0_REGNUM, HPPA_PID1_REGNUM, HPPA_PID2_REGNUM, HPPA_PID3_REGNUM,
207 HPPA_CCR_REGNUM, HPPA_EIEM_REGNUM,
212 /* Fetch one register. */
215 fetch_register (struct regcache *regcache, int regno)
217 struct gdbarch *gdbarch = get_regcache_arch (regcache);
221 if (gdbarch_cannot_fetch_register (gdbarch, regno))
223 regcache_raw_supply (regcache, regno, NULL);
227 /* GNU/Linux LWP ID's are process ID's. */
228 tid = TIDGET (inferior_ptid);
230 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
233 val = ptrace (PTRACE_PEEKUSER, tid, hppa_linux_register_addr (regno, 0), 0);
235 error (_("Couldn't read register %s (#%d): %s."),
236 gdbarch_register_name (gdbarch, regno),
237 regno, safe_strerror (errno));
239 regcache_raw_supply (regcache, regno, &val);
242 /* Store one register. */
245 store_register (const struct regcache *regcache, int regno)
247 struct gdbarch *gdbarch = get_regcache_arch (regcache);
251 if (gdbarch_cannot_store_register (gdbarch, regno))
254 /* GNU/Linux LWP ID's are process ID's. */
255 tid = TIDGET (inferior_ptid);
257 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
260 regcache_raw_collect (regcache, regno, &val);
261 ptrace (PTRACE_POKEUSER, tid, hppa_linux_register_addr (regno, 0), val);
263 error (_("Couldn't write register %s (#%d): %s."),
264 gdbarch_register_name (gdbarch, regno),
265 regno, safe_strerror (errno));
268 /* Fetch registers from the child process. Fetch all registers if
269 regno == -1, otherwise fetch all general registers or all floating
270 point registers depending upon the value of regno. */
273 hppa_linux_fetch_inferior_registers (struct target_ops *ops,
274 struct regcache *regcache, int regno)
279 regno < gdbarch_num_regs (get_regcache_arch (regcache));
281 fetch_register (regcache, regno);
285 fetch_register (regcache, regno);
289 /* Store registers back into the inferior. Store all registers if
290 regno == -1, otherwise store all general registers or all floating
291 point registers depending upon the value of regno. */
294 hppa_linux_store_inferior_registers (struct target_ops *ops,
295 struct regcache *regcache, int regno)
300 regno < gdbarch_num_regs (get_regcache_arch (regcache));
302 store_register (regcache, regno);
306 store_register (regcache, regno);
310 /* Fill GDB's register array with the general-purpose register values
314 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
317 const greg_t *regp = (const elf_greg_t *) gregsetp;
319 for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++, regp++)
321 int regno = greg_map[i];
322 regcache_raw_supply (regcache, regno, regp);
326 /* Fill register regno (if it is a general-purpose register) in
327 *gregsetp with the appropriate value from GDB's register array.
328 If regno is -1, do this for all registers. */
331 fill_gregset (const struct regcache *regcache,
332 gdb_gregset_t *gregsetp, int regno)
336 for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++)
338 int mregno = greg_map[i];
340 if (regno == -1 || regno == mregno)
342 regcache_raw_collect(regcache, mregno, &(*gregsetp)[i]);
347 /* Given a pointer to a floating point register set in /proc format
348 (fpregset_t *), unpack the register contents and supply them as gdb's
349 idea of the current floating point register values. */
352 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
357 for (regi = 0; regi <= 31; regi++)
359 from = (const char *) &((*fpregsetp)[regi]);
360 regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM, from);
361 regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM + 1, from + 4);
365 /* Given a pointer to a floating point register set in /proc format
366 (fpregset_t *), update the register specified by REGNO from gdb's idea
367 of the current floating point register set. If REGNO is -1, update
371 fill_fpregset (const struct regcache *regcache,
372 gdb_fpregset_t *fpregsetp, int regno)
376 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32 * 2; i++)
378 /* Gross. fpregset_t is double, registers[x] has single
380 char *to = (char *) &((*fpregsetp)[(i - HPPA_FP0_REGNUM) / 2]);
381 if ((i - HPPA_FP0_REGNUM) & 1)
383 regcache_raw_collect (regcache, i, to);
387 void _initialize_hppa_linux_nat (void);
390 _initialize_hppa_linux_nat (void)
392 struct target_ops *t;
394 /* Fill in the generic GNU/Linux methods. */
397 /* Add our register access methods. */
398 t->to_fetch_registers = hppa_linux_fetch_inferior_registers;
399 t->to_store_registers = hppa_linux_store_inferior_registers;
401 /* Register the target. */
402 linux_nat_add_target (t);