1 /* Native-dependent code for PA-RISC HP-UX.
3 Copyright (C) 2004-2005, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_assert.h"
26 #include <sys/ptrace.h>
27 #include <sys/utsname.h>
28 #include <machine/save_state.h>
31 #include <sys/ttrace.h>
34 #include "hppa-tdep.h"
35 #include "solib-som.h"
36 #include "inf-ptrace.h"
37 #include "inf-ttrace.h"
39 /* Return the offset of register REGNUM within `struct save_state'.
40 The offset returns depends on the flags in the "flags" register and
41 the register size (32-bit or 64-bit). These are taken from
45 hppa_hpux_save_state_offset (struct regcache
*regcache
, int regnum
)
49 if (regnum
== HPPA_FLAGS_REGNUM
)
50 return ssoff (ss_flags
);
52 if (HPPA_R0_REGNUM
< regnum
&& regnum
< HPPA_FP0_REGNUM
)
54 struct gdbarch
*arch
= get_regcache_arch (regcache
);
55 size_t size
= register_size (arch
, HPPA_R1_REGNUM
);
58 gdb_assert (size
== 4 || size
== 8);
60 regcache_cooked_read_unsigned (regcache
, HPPA_FLAGS_REGNUM
, &flags
);
61 if (flags
& SS_WIDEREGS
)
62 offset
= ssoff (ss_wide
) + (8 - size
) + (regnum
- HPPA_R0_REGNUM
) * 8;
64 offset
= ssoff (ss_narrow
) + (regnum
- HPPA_R1_REGNUM
) * 4;
68 struct gdbarch
*arch
= get_regcache_arch (regcache
);
69 size_t size
= register_size (arch
, HPPA_FP0_REGNUM
);
71 gdb_assert (size
== 4 || size
== 8);
72 gdb_assert (regnum
>= HPPA_FP0_REGNUM
);
73 offset
= ssoff(ss_fpblock
) + (regnum
- HPPA_FP0_REGNUM
) * size
;
76 gdb_assert (offset
< sizeof (save_state_t
));
80 /* Just in case a future version of PA-RISC HP-UX won't have ptrace(2)
82 #ifndef PTRACE_TYPE_RET
83 #define PTRACE_TYPE_RET void
87 hppa_hpux_fetch_register (struct regcache
*regcache
, int regnum
)
89 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
90 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
97 pid
= ptid_get_pid (inferior_ptid
);
99 /* This isn't really an address, but ptrace thinks of it as one. */
100 addr
= hppa_hpux_save_state_offset (regcache
, regnum
);
101 size
= register_size (gdbarch
, regnum
);
103 gdb_assert (size
== 4 || size
== 8);
108 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
110 if (ttrace (TT_LWP_RUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
111 error (_("Couldn't read register %s (#%d): %s"),
112 gdbarch_register_name (gdbarch
, regnum
),
113 regnum
, safe_strerror (errno
));
119 /* Read the register contents from the inferior a chuck at the time. */
120 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
123 buf
[i
] = ptrace (PT_RUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, 0, 0);
125 error (_("Couldn't read register %s (#%d): %s"),
126 gdbarch_register_name (gdbarch
, regnum
),
127 regnum
, safe_strerror (errno
));
129 addr
+= sizeof (PTRACE_TYPE_RET
);
134 /* Take care with the "flags" register. It's stored as an `int' in
135 `struct save_state', even for 64-bit code. */
136 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
139 flags
= extract_unsigned_integer ((gdb_byte
*)buf
, 4, byte_order
);
140 store_unsigned_integer ((gdb_byte
*)buf
, 8, byte_order
, flags
);
143 regcache_raw_supply (regcache
, regnum
, buf
);
147 hppa_hpux_fetch_inferior_registers (struct target_ops
*ops
,
148 struct regcache
*regcache
, int regnum
)
152 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
154 hppa_hpux_fetch_register (regcache
, regnum
);
156 hppa_hpux_fetch_register (regcache
, regnum
);
159 /* Store register REGNUM into the inferior. */
162 hppa_hpux_store_register (struct regcache
*regcache
, int regnum
)
164 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
165 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
168 PTRACE_TYPE_RET
*buf
;
171 pid
= ptid_get_pid (inferior_ptid
);
173 /* This isn't really an address, but ptrace thinks of it as one. */
174 addr
= hppa_hpux_save_state_offset (regcache
, regnum
);
175 size
= register_size (gdbarch
, regnum
);
177 gdb_assert (size
== 4 || size
== 8);
180 regcache_raw_collect (regcache
, regnum
, buf
);
182 /* Take care with the "flags" register. It's stored as an `int' in
183 `struct save_state', even for 64-bit code. */
184 if (regnum
== HPPA_FLAGS_REGNUM
&& size
== 8)
187 flags
= extract_unsigned_integer ((gdb_byte
*)buf
, 8, byte_order
);
188 store_unsigned_integer ((gdb_byte
*)buf
, 4, byte_order
, flags
);
194 lwpid_t lwp
= ptid_get_lwp (inferior_ptid
);
196 if (ttrace (TT_LWP_WUREGS
, pid
, lwp
, addr
, size
, (uintptr_t)buf
) == -1)
197 error (_("Couldn't write register %s (#%d): %s"),
198 gdbarch_register_name (gdbarch
, regnum
),
199 regnum
, safe_strerror (errno
));
205 /* Write the register contents into the inferior a chunk at the time. */
206 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
209 ptrace (PT_WUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, buf
[i
], 0);
211 error (_("Couldn't write register %s (#%d): %s"),
212 gdbarch_register_name (gdbarch
, regnum
),
213 regnum
, safe_strerror (errno
));
215 addr
+= sizeof (PTRACE_TYPE_RET
);
221 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
222 this for all registers (including the floating point registers). */
225 hppa_hpux_store_inferior_registers (struct target_ops
*ops
,
226 struct regcache
*regcache
, int regnum
)
230 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
232 hppa_hpux_store_register (regcache
, regnum
);
234 hppa_hpux_store_register (regcache
, regnum
);
237 /* Set hpux_major_release variable to the value retrieved from a call to
241 set_hpux_major_release (void)
247 p
= strchr (x
.release
, '.');
249 hpux_major_release
= atoi (p
+ 1);
254 /* Prevent warning from -Wmissing-prototypes. */
255 void _initialize_hppa_hpux_nat (void);
258 _initialize_hppa_hpux_nat (void)
260 struct target_ops
*t
;
262 set_hpux_major_release ();
265 t
= inf_ttrace_target ();
267 t
= inf_ptrace_target ();
270 t
->to_fetch_registers
= hppa_hpux_fetch_inferior_registers
;
271 t
->to_store_registers
= hppa_hpux_store_inferior_registers
;