1 /* Native-dependent code for PA-RISC HP-UX.
3 Copyright 2004 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. */
27 #include "gdb_assert.h"
28 #include <sys/ptrace.h>
29 #include <machine/save_state.h>
32 #include <sys/ttrace.h>
35 #include "hppa-tdep.h"
36 #include "inf-ptrace.h"
37 #include "inf-ttrace.h"
39 /* HP-UX 10.20 has a different name than HP-UX 11.00 and later.
40 Apparently, the intended usage changed. Unfortunately HP didn't
41 care about backwards compatibility. */
43 #define ss_mpsfu_high ss_tlsp
46 int child_suppress_run = 0; /* Non-zero if we should pretend not to be
49 static int hppa_hpux_save_state_offset[] =
52 ssoff(ss_narrow.ss_gr1),
53 ssoff(ss_narrow.ss_rp),
54 ssoff(ss_narrow.ss_gr3),
55 ssoff(ss_narrow.ss_gr4),
56 ssoff(ss_narrow.ss_gr5),
57 ssoff(ss_narrow.ss_gr6),
58 ssoff(ss_narrow.ss_gr7),
59 ssoff(ss_narrow.ss_gr8),
60 ssoff(ss_narrow.ss_gr9),
61 ssoff(ss_narrow.ss_gr10),
62 ssoff(ss_narrow.ss_gr11),
63 ssoff(ss_narrow.ss_gr12),
64 ssoff(ss_narrow.ss_gr13),
65 ssoff(ss_narrow.ss_gr14),
66 ssoff(ss_narrow.ss_gr15),
67 ssoff(ss_narrow.ss_gr16),
68 ssoff(ss_narrow.ss_gr17),
69 ssoff(ss_narrow.ss_gr18),
70 ssoff(ss_narrow.ss_gr19),
71 ssoff(ss_narrow.ss_gr20),
72 ssoff(ss_narrow.ss_gr21),
73 ssoff(ss_narrow.ss_gr22),
74 ssoff(ss_narrow.ss_arg3),
75 ssoff(ss_narrow.ss_arg2),
76 ssoff(ss_narrow.ss_arg1),
77 ssoff(ss_narrow.ss_arg0),
78 ssoff(ss_narrow.ss_dp),
79 ssoff(ss_narrow.ss_ret0),
80 ssoff(ss_narrow.ss_ret1),
81 ssoff(ss_narrow.ss_sp),
82 ssoff(ss_narrow.ss_gr31),
83 ssoff(ss_narrow.ss_cr11),
84 ssoff(ss_narrow.ss_pcoq_head),
85 ssoff(ss_narrow.ss_pcsq_head),
86 ssoff(ss_narrow.ss_pcoq_tail),
87 ssoff(ss_narrow.ss_pcsq_tail),
88 ssoff(ss_narrow.ss_cr15),
89 ssoff(ss_narrow.ss_cr19),
90 ssoff(ss_narrow.ss_cr20),
91 ssoff(ss_narrow.ss_cr21),
92 ssoff(ss_narrow.ss_cr22),
93 ssoff(ss_narrow.ss_cpustate),
94 ssoff(ss_narrow.ss_sr4),
95 ssoff(ss_narrow.ss_sr0),
96 ssoff(ss_narrow.ss_sr1),
97 ssoff(ss_narrow.ss_sr2),
98 ssoff(ss_narrow.ss_sr3),
99 ssoff(ss_narrow.ss_sr5),
100 ssoff(ss_narrow.ss_sr6),
101 ssoff(ss_narrow.ss_sr7),
102 ssoff(ss_narrow.ss_cr0),
103 ssoff(ss_narrow.ss_cr8),
104 ssoff(ss_narrow.ss_cr9),
105 ssoff(ss_narrow.ss_cr10),
106 ssoff(ss_narrow.ss_cr12),
107 ssoff(ss_narrow.ss_cr13),
108 ssoff(ss_narrow.ss_cr24),
109 ssoff(ss_narrow.ss_cr25),
110 ssoff(ss_narrow.ss_cr26),
111 ssoff(ss_narrow.ss_mpsfu_high),
112 ssoff(ss_narrow.ss_mpsfu_low),
113 ssoff(ss_narrow.ss_mpsfu_ovflo),
182 hppa_hpux_cannot_fetch_register (int regnum)
184 gdb_assert (regnum >= 0 && regnum < NUM_REGS);
185 return (regnum >= ARRAY_SIZE(hppa_hpux_save_state_offset));
189 hppa_hpux_cannot_store_register (int regnum)
191 return hppa_hpux_cannot_fetch_register (regnum);
194 /* Just in case a future version of PA-RISC HP-UX won't have ptrace(2)
196 #ifndef PTRACE_TYPE_RET
197 #define PTRACE_TYPE_RET void
201 hppa_hpux_fetch_register (int regnum)
205 PTRACE_TYPE_RET *buf;
209 if (hppa_hpux_cannot_fetch_register (regnum))
211 regcache_raw_supply (current_regcache, regnum, NULL);
215 pid = ptid_get_pid (inferior_ptid);
217 /* This isn't really an address. But ptrace thinks of it as one. */
218 addr = hppa_hpux_save_state_offset[regnum];
219 size = register_size (current_gdbarch, regnum);
221 gdb_assert (size == 4 || size == 8);
226 lwpid_t lwp = ptid_get_lwp (inferior_ptid);
228 if (ttrace (TT_LWP_RUREGS, pid, lwp, addr, size, (uintptr_t)buf) == -1)
229 error ("Couldn't read register %s (#%d): %s",
230 REGISTER_NAME (regnum), regnum, safe_strerror (errno));
236 /* Read the register contents from the inferior a chuck at the time. */
237 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
240 buf[i] = ptrace (PT_RUREGS, pid, (PTRACE_TYPE_ARG3) addr, 0, 0);
242 error ("Couldn't read register %s (#%d): %s",
243 REGISTER_NAME (regnum), regnum, safe_strerror (errno));
245 addr += sizeof (PTRACE_TYPE_RET);
250 regcache_raw_supply (current_regcache, regnum, buf);
254 hppa_hpux_fetch_inferior_registers (int regnum)
257 for (regnum = 0; regnum < NUM_REGS; regnum++)
258 hppa_hpux_fetch_register (regnum);
260 hppa_hpux_fetch_register (regnum);
263 /* Store register REGNUM into the inferior. */
266 hppa_hpux_store_register (int regnum)
270 PTRACE_TYPE_RET *buf;
273 if (hppa_hpux_cannot_store_register (regnum))
276 pid = ptid_get_pid (inferior_ptid);
278 /* This isn't really an address. But ptrace thinks of it as one. */
279 addr = hppa_hpux_save_state_offset[regnum];
280 size = register_size (current_gdbarch, regnum);
282 gdb_assert (size == 4 || size == 8);
285 regcache_raw_collect (current_regcache, regnum, buf);
289 lwpid_t lwp = ptid_get_lwp (inferior_ptid);
291 if (ttrace (TT_LWP_WUREGS, pid, lwp, addr, size, (uintptr_t)buf) == -1)
292 error ("Couldn't write register %s (#%d): %s",
293 REGISTER_NAME (regnum), regnum, safe_strerror (errno));
299 /* Write the register contents into the inferior a chunk at the time. */
300 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
303 ptrace (PT_WUREGS, pid, (PTRACE_TYPE_ARG3) addr, buf[i], 0);
305 error ("Couldn't write register %s (#%d): %s",
306 REGISTER_NAME (regnum), regnum, safe_strerror (errno));
308 addr += sizeof (PTRACE_TYPE_RET);
314 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
315 this for all registers (including the floating point registers). */
318 hppa_hpux_store_inferior_registers (int regnum)
321 for (regnum = 0; regnum < NUM_REGS; regnum++)
322 hppa_hpux_store_register (regnum);
324 hppa_hpux_store_register (regnum);
328 hppa_hpux_child_can_run (void)
330 /* This variable is controlled by modules that layer their own process
331 structure atop that provided here. hpux-thread.c does this because
332 of the HP-UX user-mode level thread model. */
334 return !child_suppress_run;
338 /* Prevent warning from -Wmissing-prototypes. */
339 void _initialize_hppa_hpux_nat (void);
342 _initialize_hppa_hpux_nat (void)
344 struct target_ops *t;
347 t = inf_ttrace_target ();
349 t = inf_ptrace_target ();
352 t->to_fetch_registers = hppa_hpux_fetch_inferior_registers;
353 t->to_store_registers = hppa_hpux_store_inferior_registers;
354 t->to_can_run = hppa_hpux_child_can_run;