* gdb.base/corefile.exp: Recognize the message saying that GDB
[deliverable/binutils-gdb.git] / gdb / hp300ux-nat.c
CommitLineData
c906108c 1/* HP/UX native interface for HP 300's, for GDB when running under Unix.
b6ba6518
KB
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1996, 1999, 2000,
3 2001 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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.
c906108c 11
c5aa993b
JM
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
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include "frame.h"
24#include "inferior.h"
4e052eda 25#include "regcache.h"
c906108c
SS
26
27/* Defining this means some system include files define some extra stuff. */
28#define WOPR
29#include <sys/param.h>
30#include <signal.h>
31#include <sys/user.h>
32#include <fcntl.h>
33
34#include <sys/ptrace.h>
35#include <sys/reg.h>
36#include <sys/trap.h>
37
38#include <sys/file.h>
39
a14ed312 40static void fetch_inferior_register (int, unsigned int);
c906108c 41
a14ed312 42static void store_inferior_register_1 (int, unsigned int, int);
c906108c 43
a14ed312 44static void store_inferior_register (int, unsigned int);
c906108c
SS
45
46/* Get kernel_u_addr using HPUX-style nlist(). */
47CORE_ADDR kernel_u_addr;
48
c5aa993b
JM
49struct hpnlist
50 {
51 char *n_name;
52 long n_value;
53 unsigned char n_type;
54 unsigned char n_length;
55 short n_almod;
56 short n_unused;
57 };
58static struct hpnlist nl[] =
59{
60 {"_u", -1,},
61 {(char *) 0,}};
c906108c
SS
62
63/* read the value of the u area from the hp-ux kernel */
64void
fba45db2 65_initialize_hp300ux_nat (void)
c906108c
SS
66{
67#ifndef HPUX_VERSION_5
c5aa993b
JM
68 nlist ("/hp-ux", nl);
69 kernel_u_addr = nl[0].n_value;
c906108c 70#else /* HPUX version 5. */
c5aa993b 71 kernel_u_addr = (CORE_ADDR) 0x0097900;
c906108c
SS
72#endif
73}
74
75#define INFERIOR_AR0(u) \
76 ((ptrace \
39f77062
KB
77 (PT_RUAREA, PIDGET (inferior_ptid), \
78 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
c906108c
SS
79 - kernel_u_addr)
80
81static void
fba45db2 82fetch_inferior_register (register int regno, register unsigned int regaddr)
c906108c
SS
83{
84#ifndef HPUX_VERSION_5
85 if (regno == PS_REGNUM)
86 {
c5aa993b
JM
87 union
88 {
89 int i;
90 short s[2];
91 }
92 ps_val;
c906108c 93 int regval;
c5aa993b 94
39f77062
KB
95 ps_val.i = (ptrace (PT_RUAREA, PIDGET (inferior_ptid),
96 (PTRACE_ARG3_TYPE) regaddr, 0, 0));
c906108c 97 regval = ps_val.s[0];
c5aa993b 98 supply_register (regno, (char *) &regval);
c906108c
SS
99 }
100 else
101#endif /* not HPUX_VERSION_5 */
102 {
103 char buf[MAX_REGISTER_RAW_SIZE];
104 register int i;
c5aa993b 105
c906108c
SS
106 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
107 {
39f77062 108 *(int *) &buf[i] = ptrace (PT_RUAREA, PIDGET (inferior_ptid),
c906108c
SS
109 (PTRACE_ARG3_TYPE) regaddr, 0, 0);
110 regaddr += sizeof (int);
111 }
112 supply_register (regno, buf);
113 }
114 return;
115}
116
117static void
fba45db2 118store_inferior_register_1 (int regno, unsigned int regaddr, int val)
c906108c
SS
119{
120 errno = 0;
39f77062
KB
121 ptrace (PT_WUAREA, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) regaddr,
122 val, 0);
c906108c
SS
123#if 0
124 /* HP-UX randomly sets errno to non-zero for regno == 25.
125 However, the value is correctly written, so ignore errno. */
126 if (errno != 0)
127 {
128 char string_buf[64];
c5aa993b 129
c906108c
SS
130 sprintf (string_buf, "writing register number %d", regno);
131 perror_with_name (string_buf);
132 }
133#endif
134 return;
135}
136
137static void
fba45db2 138store_inferior_register (register int regno, register unsigned int regaddr)
c906108c
SS
139{
140#ifndef HPUX_VERSION_5
141 if (regno == PS_REGNUM)
142 {
c5aa993b
JM
143 union
144 {
145 int i;
146 short s[2];
147 }
148 ps_val;
149
39f77062
KB
150 ps_val.i = (ptrace (PT_RUAREA, PIDGET (inferior_ptid),
151 (PTRACE_ARG3_TYPE) regaddr, 0, 0));
c906108c
SS
152 ps_val.s[0] = (read_register (regno));
153 store_inferior_register_1 (regno, regaddr, ps_val.i);
154 }
155 else
156#endif /* not HPUX_VERSION_5 */
157 {
158 register int i;
c5aa993b 159
c906108c
SS
160 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
161 {
162 store_inferior_register_1
163 (regno, regaddr,
164 (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
165 regaddr += sizeof (int);
166 }
167 }
168 return;
169}
170
171void
fba45db2 172fetch_inferior_registers (int regno)
c906108c
SS
173{
174 struct user u;
175 register unsigned int ar0_offset;
c5aa993b 176
c906108c
SS
177 ar0_offset = (INFERIOR_AR0 (u));
178 if (regno == -1)
179 {
180 for (regno = 0; (regno < FP0_REGNUM); regno++)
181 fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
182 for (; (regno < NUM_REGS); regno++)
183 fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
184 }
185 else
186 fetch_inferior_register (regno,
187 (regno < FP0_REGNUM
188 ? REGISTER_ADDR (ar0_offset, regno)
189 : FP_REGISTER_ADDR (u, regno)));
190}
191
192/* Store our register values back into the inferior.
193 If REGNO is -1, do this for all registers.
194 Otherwise, REGNO specifies which register (so we can save time). */
195
196void
fba45db2 197store_inferior_registers (register int regno)
c906108c
SS
198{
199 struct user u;
200 register unsigned int ar0_offset;
201
202 if (regno >= FP0_REGNUM)
203 {
204 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
205 return;
206 }
c5aa993b 207
c906108c
SS
208 ar0_offset = (INFERIOR_AR0 (u));
209 if (regno >= 0)
210 {
211 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
212 return;
213 }
214
215 for (regno = 0; (regno < FP0_REGNUM); regno++)
216 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
217 for (; (regno < NUM_REGS); regno++)
218 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
219 return;
220}
221
222int
fba45db2 223getpagesize (void)
c906108c
SS
224{
225 return 4096;
226}
This page took 0.159003 seconds and 4 git commands to generate.