* m68k-tdep.c (m68k_ps_type): New.
[deliverable/binutils-gdb.git] / gdb / hppa-hpux-nat.c
CommitLineData
eeb8076c
MK
1/* Native-dependent code for PA-RISC HP-UX.
2
6aba47ca 3 Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
eeb8076c
MK
4
5 This file is part of GDB.
6
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.
11
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.
16
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
eeb8076c
MK
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
25#include "target.h"
26
27#include "gdb_assert.h"
28#include <sys/ptrace.h>
29#include <machine/save_state.h>
30
eee22bf8
MK
31#ifdef HAVE_TTRACE
32#include <sys/ttrace.h>
33#endif
34
eeb8076c
MK
35#include "hppa-tdep.h"
36#include "inf-ptrace.h"
eee22bf8
MK
37#include "inf-ttrace.h"
38
eeca586f
MK
39/* Non-zero if we should pretend not to be a runnable target. */
40int child_suppress_run = 0;
eeb8076c 41
eeca586f
MK
42/* Return the offset of register REGNUM within `struct save_state'.
43 The offset returns depends on the flags in the "flags" register and
44 the register size (32-bit or 64-bit). These are taken from
45 REGCACHE. */
3f6306ec 46
eeca586f
MK
47LONGEST
48hppa_hpux_save_state_offset (struct regcache *regcache, int regnum)
eeb8076c 49{
eeca586f 50 LONGEST offset;
eeb8076c 51
eeca586f
MK
52 if (regnum == HPPA_FLAGS_REGNUM)
53 return ssoff (ss_flags);
eeb8076c 54
eeca586f
MK
55 if (HPPA_R0_REGNUM < regnum && regnum < HPPA_FP0_REGNUM)
56 {
57 struct gdbarch *arch = get_regcache_arch (regcache);
58 size_t size = register_size (arch, HPPA_R1_REGNUM);
59 ULONGEST flags;
60
61 gdb_assert (size == 4 || size == 8);
62
63 regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags);
64 if (flags & SS_WIDEREGS)
65 offset = ssoff (ss_wide) + (8 - size) + (regnum - HPPA_R0_REGNUM) * 8;
66 else
67 offset = ssoff (ss_narrow) + (regnum - HPPA_R1_REGNUM) * 4;
68 }
69 else
70 {
71 struct gdbarch *arch = get_regcache_arch (regcache);
72 size_t size = register_size (arch, HPPA_FP0_REGNUM);
73
74 gdb_assert (size == 4 || size == 8);
75 gdb_assert (regnum >= HPPA_FP0_REGNUM);
76 offset = ssoff(ss_fpblock) + (regnum - HPPA_FP0_REGNUM) * size;
77 }
78
79 gdb_assert (offset < sizeof (save_state_t));
80 return offset;
eeb8076c
MK
81}
82
eee22bf8
MK
83/* Just in case a future version of PA-RISC HP-UX won't have ptrace(2)
84 at all. */
85#ifndef PTRACE_TYPE_RET
86#define PTRACE_TYPE_RET void
87#endif
88
eeb8076c 89static void
56be3814 90hppa_hpux_fetch_register (struct regcache *regcache, int regnum)
eeb8076c
MK
91{
92 CORE_ADDR addr;
93 size_t size;
94 PTRACE_TYPE_RET *buf;
95 pid_t pid;
96 int i;
97
eee22bf8 98 pid = ptid_get_pid (inferior_ptid);
eeb8076c 99
eeca586f 100 /* This isn't really an address, but ptrace thinks of it as one. */
56be3814 101 addr = hppa_hpux_save_state_offset (regcache, regnum);
eeb8076c
MK
102 size = register_size (current_gdbarch, regnum);
103
eee22bf8 104 gdb_assert (size == 4 || size == 8);
eeb8076c
MK
105 buf = alloca (size);
106
eee22bf8
MK
107#ifdef HAVE_TTRACE
108 {
109 lwpid_t lwp = ptid_get_lwp (inferior_ptid);
110
111 if (ttrace (TT_LWP_RUREGS, pid, lwp, addr, size, (uintptr_t)buf) == -1)
8a3fe4f8 112 error (_("Couldn't read register %s (#%d): %s"),
c9f4d572
UW
113 gdbarch_register_name (current_gdbarch, regnum),
114 regnum, safe_strerror (errno));
eee22bf8
MK
115 }
116#else
117 {
118 int i;
119
120 /* Read the register contents from the inferior a chuck at the time. */
121 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
122 {
123 errno = 0;
124 buf[i] = ptrace (PT_RUREGS, pid, (PTRACE_TYPE_ARG3) addr, 0, 0);
125 if (errno != 0)
8a3fe4f8 126 error (_("Couldn't read register %s (#%d): %s"),
c9f4d572
UW
127 gdbarch_register_name (current_gdbarch, regnum),
128 regnum, safe_strerror (errno));
eee22bf8
MK
129
130 addr += sizeof (PTRACE_TYPE_RET);
131 }
132 }
133#endif
eeb8076c 134
eeca586f
MK
135 /* Take care with the "flags" register. It's stored as an `int' in
136 `struct save_state', even for 64-bit code. */
137 if (regnum == HPPA_FLAGS_REGNUM && size == 8)
138 {
0d559b99
MK
139 ULONGEST flags = extract_unsigned_integer ((gdb_byte *)buf, 4);
140 store_unsigned_integer ((gdb_byte *)buf, 8, flags);
eeca586f
MK
141 }
142
56be3814 143 regcache_raw_supply (regcache, regnum, buf);
eeb8076c
MK
144}
145
146static void
56be3814 147hppa_hpux_fetch_inferior_registers (struct regcache *regcache, int regnum)
eeb8076c
MK
148{
149 if (regnum == -1)
f57d151a 150 for (regnum = 0; regnum < gdbarch_num_regs (current_gdbarch); regnum++)
56be3814 151 hppa_hpux_fetch_register (regcache, regnum);
eeb8076c 152 else
56be3814 153 hppa_hpux_fetch_register (regcache, regnum);
eeb8076c
MK
154}
155
156/* Store register REGNUM into the inferior. */
157
158static void
56be3814 159hppa_hpux_store_register (struct regcache *regcache, int regnum)
eeb8076c
MK
160{
161 CORE_ADDR addr;
162 size_t size;
163 PTRACE_TYPE_RET *buf;
164 pid_t pid;
eeb8076c 165
eee22bf8 166 pid = ptid_get_pid (inferior_ptid);
eeb8076c 167
eeca586f 168 /* This isn't really an address, but ptrace thinks of it as one. */
56be3814 169 addr = hppa_hpux_save_state_offset (regcache, regnum);
eeb8076c
MK
170 size = register_size (current_gdbarch, regnum);
171
eee22bf8 172 gdb_assert (size == 4 || size == 8);
eeb8076c
MK
173 buf = alloca (size);
174
56be3814 175 regcache_raw_collect (regcache, regnum, buf);
eeb8076c 176
eeca586f
MK
177 /* Take care with the "flags" register. It's stored as an `int' in
178 `struct save_state', even for 64-bit code. */
179 if (regnum == HPPA_FLAGS_REGNUM && size == 8)
180 {
0d559b99
MK
181 ULONGEST flags = extract_unsigned_integer ((gdb_byte *)buf, 8);
182 store_unsigned_integer ((gdb_byte *)buf, 4, flags);
eeca586f
MK
183 size = 4;
184 }
185
eee22bf8
MK
186#ifdef HAVE_TTRACE
187 {
188 lwpid_t lwp = ptid_get_lwp (inferior_ptid);
189
190 if (ttrace (TT_LWP_WUREGS, pid, lwp, addr, size, (uintptr_t)buf) == -1)
8a3fe4f8 191 error (_("Couldn't write register %s (#%d): %s"),
c9f4d572
UW
192 gdbarch_register_name (current_gdbarch, regnum),
193 regnum, safe_strerror (errno));
eee22bf8
MK
194 }
195#else
196 {
197 int i;
198
199 /* Write the register contents into the inferior a chunk at the time. */
200 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
201 {
202 errno = 0;
203 ptrace (PT_WUREGS, pid, (PTRACE_TYPE_ARG3) addr, buf[i], 0);
204 if (errno != 0)
8a3fe4f8 205 error (_("Couldn't write register %s (#%d): %s"),
c9f4d572
UW
206 gdbarch_register_name (current_gdbarch, regnum),
207 regnum, safe_strerror (errno));
eee22bf8
MK
208
209 addr += sizeof (PTRACE_TYPE_RET);
210 }
211 }
212#endif
eeb8076c
MK
213}
214
215/* Store register REGNUM back into the inferior. If REGNUM is -1, do
216 this for all registers (including the floating point registers). */
217
218static void
56be3814 219hppa_hpux_store_inferior_registers (struct regcache *regcache, int regnum)
eeb8076c
MK
220{
221 if (regnum == -1)
f57d151a 222 for (regnum = 0; regnum < gdbarch_num_regs (current_gdbarch); regnum++)
56be3814 223 hppa_hpux_store_register (regcache, regnum);
eeb8076c 224 else
56be3814 225 hppa_hpux_store_register (regcache, regnum);
eeb8076c 226}
3f6306ec
DA
227
228static int
229hppa_hpux_child_can_run (void)
230{
eeca586f 231 /* This variable is controlled by modules that layer their own
0d9b270c
MK
232 process structure atop that provided here. The code in
233 hpux-thread.c does this to support the HP-UX user-mode DCE
234 threads. */
3f6306ec
DA
235 return !child_suppress_run;
236}
eeb8076c
MK
237\f
238
239/* Prevent warning from -Wmissing-prototypes. */
240void _initialize_hppa_hpux_nat (void);
241
242void
243_initialize_hppa_hpux_nat (void)
244{
245 struct target_ops *t;
246
eee22bf8
MK
247#ifdef HAVE_TTRACE
248 t = inf_ttrace_target ();
249#else
eeb8076c 250 t = inf_ptrace_target ();
eee22bf8
MK
251#endif
252
eeb8076c
MK
253 t->to_fetch_registers = hppa_hpux_fetch_inferior_registers;
254 t->to_store_registers = hppa_hpux_store_inferior_registers;
3f6306ec 255 t->to_can_run = hppa_hpux_child_can_run;
eee22bf8 256
eeb8076c
MK
257 add_target (t);
258}
This page took 0.177601 seconds and 4 git commands to generate.