1 /* Functions specific to running GDB native on HPPA running GNU/Linux.
3 Copyright (C) 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
25 #include "gdb_string.h"
28 #include "linux-nat.h"
30 #include <sys/procfs.h>
31 #include <sys/ptrace.h>
32 #include <linux/version.h>
34 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,43)
35 #include <asm/offset.h>
37 #include <asm/offsets.h>
40 #include "hppa-tdep.h"
42 /* Prototypes for supply_gregset etc. */
45 /* These must match the order of the register names.
47 Some sort of lookup table is needed because the offsets associated
48 with the registers are all over the board. */
50 static const int u_offsets
[] =
52 /* general registers */
121 /* Floating point regs. */
132 PT_FR10
, PT_FR10
+ 4,
133 PT_FR11
, PT_FR11
+ 4,
134 PT_FR12
, PT_FR12
+ 4,
135 PT_FR13
, PT_FR13
+ 4,
136 PT_FR14
, PT_FR14
+ 4,
137 PT_FR15
, PT_FR15
+ 4,
138 PT_FR16
, PT_FR16
+ 4,
139 PT_FR17
, PT_FR17
+ 4,
140 PT_FR18
, PT_FR18
+ 4,
141 PT_FR19
, PT_FR19
+ 4,
142 PT_FR20
, PT_FR20
+ 4,
143 PT_FR21
, PT_FR21
+ 4,
144 PT_FR22
, PT_FR22
+ 4,
145 PT_FR23
, PT_FR23
+ 4,
146 PT_FR24
, PT_FR24
+ 4,
147 PT_FR25
, PT_FR25
+ 4,
148 PT_FR26
, PT_FR26
+ 4,
149 PT_FR27
, PT_FR27
+ 4,
150 PT_FR28
, PT_FR28
+ 4,
151 PT_FR29
, PT_FR29
+ 4,
152 PT_FR30
, PT_FR30
+ 4,
153 PT_FR31
, PT_FR31
+ 4,
157 register_addr (int regno
, CORE_ADDR blockend
)
161 if ((unsigned) regno
>= NUM_REGS
)
162 error (_("Invalid register number %d."), regno
);
164 if (u_offsets
[regno
] == -1)
168 addr
= (CORE_ADDR
) u_offsets
[regno
];
175 * Registers saved in a coredump:
180 * sar, iir, isr, ior, ipsw
185 #define GR_REGNUM(_n) (HPPA_R0_REGNUM+_n)
186 #define TR_REGNUM(_n) (HPPA_TR0_REGNUM+_n)
187 static const int greg_map
[] =
189 GR_REGNUM(0), GR_REGNUM(1), GR_REGNUM(2), GR_REGNUM(3),
190 GR_REGNUM(4), GR_REGNUM(5), GR_REGNUM(6), GR_REGNUM(7),
191 GR_REGNUM(8), GR_REGNUM(9), GR_REGNUM(10), GR_REGNUM(11),
192 GR_REGNUM(12), GR_REGNUM(13), GR_REGNUM(14), GR_REGNUM(15),
193 GR_REGNUM(16), GR_REGNUM(17), GR_REGNUM(18), GR_REGNUM(19),
194 GR_REGNUM(20), GR_REGNUM(21), GR_REGNUM(22), GR_REGNUM(23),
195 GR_REGNUM(24), GR_REGNUM(25), GR_REGNUM(26), GR_REGNUM(27),
196 GR_REGNUM(28), GR_REGNUM(29), GR_REGNUM(30), GR_REGNUM(31),
198 HPPA_SR4_REGNUM
+1, HPPA_SR4_REGNUM
+2, HPPA_SR4_REGNUM
+3, HPPA_SR4_REGNUM
+4,
199 HPPA_SR4_REGNUM
, HPPA_SR4_REGNUM
+5, HPPA_SR4_REGNUM
+6, HPPA_SR4_REGNUM
+7,
201 HPPA_PCOQ_HEAD_REGNUM
, HPPA_PCOQ_TAIL_REGNUM
,
202 HPPA_PCSQ_HEAD_REGNUM
, HPPA_PCSQ_TAIL_REGNUM
,
204 HPPA_SAR_REGNUM
, HPPA_IIR_REGNUM
, HPPA_ISR_REGNUM
, HPPA_IOR_REGNUM
,
205 HPPA_IPSW_REGNUM
, HPPA_RCR_REGNUM
,
207 TR_REGNUM(0), TR_REGNUM(1), TR_REGNUM(2), TR_REGNUM(3),
208 TR_REGNUM(4), TR_REGNUM(5), TR_REGNUM(6), TR_REGNUM(7),
210 HPPA_PID0_REGNUM
, HPPA_PID1_REGNUM
, HPPA_PID2_REGNUM
, HPPA_PID3_REGNUM
,
211 HPPA_CCR_REGNUM
, HPPA_EIEM_REGNUM
,
216 /* Fetch one register. */
219 fetch_register (int regno
)
224 if (CANNOT_FETCH_REGISTER (regno
))
226 regcache_raw_supply (current_regcache
, regno
, NULL
);
230 /* GNU/Linux LWP ID's are process ID's. */
231 tid
= TIDGET (inferior_ptid
);
233 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
236 val
= ptrace (PTRACE_PEEKUSER
, tid
, register_addr (regno
, 0), 0);
238 error (_("Couldn't read register %s (#%d): %s."), REGISTER_NAME (regno
),
239 regno
, safe_strerror (errno
));
241 regcache_raw_supply (current_regcache
, regno
, &val
);
244 /* Store one register. */
247 store_register (int regno
)
252 if (CANNOT_STORE_REGISTER (regno
))
255 /* GNU/Linux LWP ID's are process ID's. */
256 tid
= TIDGET (inferior_ptid
);
258 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
261 regcache_raw_collect (current_regcache
, regno
, &val
);
262 ptrace (PTRACE_POKEUSER
, tid
, register_addr (regno
, 0), val
);
264 error (_("Couldn't write register %s (#%d): %s."), REGISTER_NAME (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 (int regno
)
277 for (regno
= 0; regno
< NUM_REGS
; regno
++)
278 fetch_register (regno
);
282 fetch_register (regno
);
286 /* Store registers back into the inferior. Store all registers if
287 regno == -1, otherwise store all general registers or all floating
288 point registers depending upon the value of regno. */
291 hppa_linux_store_inferior_registers (int regno
)
295 for (regno
= 0; regno
< NUM_REGS
; regno
++)
296 store_register (regno
);
300 store_register (regno
);
304 /* Fill GDB's register array with the general-purpose register values
308 supply_gregset (gdb_gregset_t
*gregsetp
)
311 greg_t
*regp
= (elf_greg_t
*) gregsetp
;
313 for (i
= 0; i
< sizeof (greg_map
) / sizeof (greg_map
[0]); i
++, regp
++)
315 int regno
= greg_map
[i
];
316 regcache_raw_supply (current_regcache
, regno
, regp
);
320 /* Fill register regno (if it is a general-purpose register) in
321 *gregsetp with the appropriate value from GDB's register array.
322 If regno is -1, do this for all registers. */
325 fill_gregset (gdb_gregset_t
*gregsetp
, int regno
)
329 for (i
= 0; i
< sizeof (greg_map
) / sizeof (greg_map
[0]); i
++)
331 int mregno
= greg_map
[i
];
333 if (regno
== -1 || regno
== mregno
)
335 regcache_raw_collect(current_regcache
, mregno
, &(*gregsetp
)[i
]);
340 /* Given a pointer to a floating point register set in /proc format
341 (fpregset_t *), unpack the register contents and supply them as gdb's
342 idea of the current floating point register values. */
345 supply_fpregset (gdb_fpregset_t
*fpregsetp
)
350 for (regi
= 0; regi
<= 31; regi
++)
352 from
= (char *) &((*fpregsetp
)[regi
]);
353 regcache_raw_supply (current_regcache
, 2*regi
+ HPPA_FP0_REGNUM
, from
);
354 regcache_raw_supply (current_regcache
, 2*regi
+ HPPA_FP0_REGNUM
+ 1,
359 /* Given a pointer to a floating point register set in /proc format
360 (fpregset_t *), update the register specified by REGNO from gdb's idea
361 of the current floating point register set. If REGNO is -1, update
365 fill_fpregset (gdb_fpregset_t
*fpregsetp
, int regno
)
369 for (i
= HPPA_FP0_REGNUM
; i
< HPPA_FP0_REGNUM
+ 32 * 2; i
++)
371 /* Gross. fpregset_t is double, registers[x] has single
373 char *to
= (char *) &((*fpregsetp
)[(i
- HPPA_FP0_REGNUM
) / 2]);
374 if ((i
- HPPA_FP0_REGNUM
) & 1)
376 regcache_raw_collect (current_regcache
, i
, to
);
380 void _initialize_hppa_linux_nat (void);
383 _initialize_hppa_linux_nat (void)
385 struct target_ops
*t
;
387 /* Fill in the generic GNU/Linux methods. */
390 /* Add our register access methods. */
391 t
->to_fetch_registers
= hppa_linux_fetch_inferior_registers
;
392 t
->to_store_registers
= hppa_linux_store_inferior_registers
;
394 /* Register the target. */
395 linux_nat_add_target (t
);