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>
31 #include "hppa-tdep.h"
32 #include "inf-ptrace.h"
34 static int hppa_hpux_save_state_offset
[] =
37 ssoff(ss_narrow
.ss_gr1
),
38 ssoff(ss_narrow
.ss_rp
),
39 ssoff(ss_narrow
.ss_gr3
),
40 ssoff(ss_narrow
.ss_gr4
),
41 ssoff(ss_narrow
.ss_gr5
),
42 ssoff(ss_narrow
.ss_gr6
),
43 ssoff(ss_narrow
.ss_gr7
),
44 ssoff(ss_narrow
.ss_gr8
),
45 ssoff(ss_narrow
.ss_gr9
),
46 ssoff(ss_narrow
.ss_gr10
),
47 ssoff(ss_narrow
.ss_gr11
),
48 ssoff(ss_narrow
.ss_gr12
),
49 ssoff(ss_narrow
.ss_gr13
),
50 ssoff(ss_narrow
.ss_gr14
),
51 ssoff(ss_narrow
.ss_gr15
),
52 ssoff(ss_narrow
.ss_gr16
),
53 ssoff(ss_narrow
.ss_gr17
),
54 ssoff(ss_narrow
.ss_gr18
),
55 ssoff(ss_narrow
.ss_gr19
),
56 ssoff(ss_narrow
.ss_gr20
),
57 ssoff(ss_narrow
.ss_gr21
),
58 ssoff(ss_narrow
.ss_gr22
),
59 ssoff(ss_narrow
.ss_arg3
),
60 ssoff(ss_narrow
.ss_arg2
),
61 ssoff(ss_narrow
.ss_arg1
),
62 ssoff(ss_narrow
.ss_arg0
),
63 ssoff(ss_narrow
.ss_dp
),
64 ssoff(ss_narrow
.ss_ret0
),
65 ssoff(ss_narrow
.ss_ret1
),
66 ssoff(ss_narrow
.ss_sp
),
67 ssoff(ss_narrow
.ss_gr31
),
68 ssoff(ss_narrow
.ss_cr11
),
69 ssoff(ss_narrow
.ss_pcoq_head
),
70 ssoff(ss_narrow
.ss_pcsq_head
),
71 ssoff(ss_narrow
.ss_pcoq_tail
),
72 ssoff(ss_narrow
.ss_pcsq_tail
),
73 ssoff(ss_narrow
.ss_cr15
),
74 ssoff(ss_narrow
.ss_cr19
),
75 ssoff(ss_narrow
.ss_cr20
),
76 ssoff(ss_narrow
.ss_cr21
),
77 ssoff(ss_narrow
.ss_cr22
),
78 ssoff(ss_narrow
.ss_cpustate
),
79 ssoff(ss_narrow
.ss_sr4
),
80 ssoff(ss_narrow
.ss_sr0
),
81 ssoff(ss_narrow
.ss_sr1
),
82 ssoff(ss_narrow
.ss_sr2
),
83 ssoff(ss_narrow
.ss_sr3
),
84 ssoff(ss_narrow
.ss_sr5
),
85 ssoff(ss_narrow
.ss_sr6
),
86 ssoff(ss_narrow
.ss_sr7
),
87 ssoff(ss_narrow
.ss_cr0
),
88 ssoff(ss_narrow
.ss_cr8
),
89 ssoff(ss_narrow
.ss_cr9
),
90 ssoff(ss_narrow
.ss_cr10
),
91 ssoff(ss_narrow
.ss_cr12
),
92 ssoff(ss_narrow
.ss_cr13
),
93 ssoff(ss_narrow
.ss_cr24
),
94 ssoff(ss_narrow
.ss_cr25
),
95 ssoff(ss_narrow
.ss_cr26
),
96 ssoff(ss_narrow
.ss_mpsfu_high
),
97 ssoff(ss_narrow
.ss_mpsfu_low
),
98 ssoff(ss_narrow
.ss_mpsfu_ovflo
),
167 hppa_hpux_cannot_fetch_register (int regnum
)
169 gdb_assert (regnum
>= 0 && regnum
< NUM_REGS
);
170 return (regnum
>= ARRAY_SIZE(hppa_hpux_save_state_offset
));
174 hppa_hpux_cannot_store_register (int regnum
)
176 return hppa_hpux_cannot_fetch_register (regnum
);
180 hppa_hpux_fetch_register (int regnum
)
184 PTRACE_TYPE_RET
*buf
;
188 if (hppa_hpux_cannot_fetch_register (regnum
))
190 regcache_raw_supply (current_regcache
, regnum
, NULL
);
194 pid
= PIDGET (inferior_ptid
);
196 /* This isn't really an address. But ptrace thinks of it as one. */
197 addr
= hppa_hpux_save_state_offset
[regnum
];
198 size
= register_size (current_gdbarch
, regnum
);
200 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
203 /* Read the register contents from the inferior a chuck at the time. */
204 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
207 buf
[i
] = ptrace (PT_RUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, 0, 0);
209 error ("Couldn't read register %s (#%d): %s.", REGISTER_NAME (regnum
),
210 regnum
, safe_strerror (errno
));
212 addr
+= sizeof (PTRACE_TYPE_RET
);
214 regcache_raw_supply (current_regcache
, regnum
, buf
);
218 hppa_hpux_fetch_inferior_registers (int regnum
)
221 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
222 hppa_hpux_fetch_register (regnum
);
224 hppa_hpux_fetch_register (regnum
);
227 /* Store register REGNUM into the inferior. */
230 hppa_hpux_store_register (int regnum
)
234 PTRACE_TYPE_RET
*buf
;
238 if (hppa_hpux_cannot_store_register (regnum
))
241 pid
= PIDGET (inferior_ptid
);
243 /* This isn't really an address. But ptrace thinks of it as one. */
244 addr
= hppa_hpux_save_state_offset
[regnum
];
245 size
= register_size (current_gdbarch
, regnum
);
247 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
250 /* Write the register contents into the inferior a chunk at the time. */
251 regcache_raw_collect (current_regcache
, regnum
, buf
);
252 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
255 ptrace (PT_WUREGS
, pid
, (PTRACE_TYPE_ARG3
) addr
, buf
[i
], 0);
257 error ("Couldn't write register %s (#%d): %s.", REGISTER_NAME (regnum
),
258 regnum
, safe_strerror (errno
));
260 addr
+= sizeof (PTRACE_TYPE_RET
);
264 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
265 this for all registers (including the floating point registers). */
268 hppa_hpux_store_inferior_registers (int regnum
)
271 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
272 hppa_hpux_store_register (regnum
);
274 hppa_hpux_store_register (regnum
);
278 /* Prevent warning from -Wmissing-prototypes. */
279 void _initialize_hppa_hpux_nat (void);
282 _initialize_hppa_hpux_nat (void)
284 struct target_ops
*t
;
286 t
= inf_ptrace_target ();
287 t
->to_fetch_registers
= hppa_hpux_fetch_inferior_registers
;
288 t
->to_store_registers
= hppa_hpux_store_inferior_registers
;