Update/correct copyright notices.
[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 \
77 (PT_RUAREA, inferior_pid, \
78 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
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
c906108c
SS
95 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
96 0, 0));
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 {
108 *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid,
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;
121 ptrace (PT_WUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, val, 0);
122#if 0
123 /* HP-UX randomly sets errno to non-zero for regno == 25.
124 However, the value is correctly written, so ignore errno. */
125 if (errno != 0)
126 {
127 char string_buf[64];
c5aa993b 128
c906108c
SS
129 sprintf (string_buf, "writing register number %d", regno);
130 perror_with_name (string_buf);
131 }
132#endif
133 return;
134}
135
136static void
fba45db2 137store_inferior_register (register int regno, register unsigned int regaddr)
c906108c
SS
138{
139#ifndef HPUX_VERSION_5
140 if (regno == PS_REGNUM)
141 {
c5aa993b
JM
142 union
143 {
144 int i;
145 short s[2];
146 }
147 ps_val;
148
c906108c
SS
149 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
150 0, 0));
151 ps_val.s[0] = (read_register (regno));
152 store_inferior_register_1 (regno, regaddr, ps_val.i);
153 }
154 else
155#endif /* not HPUX_VERSION_5 */
156 {
157 register int i;
c5aa993b 158
c906108c
SS
159 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
160 {
161 store_inferior_register_1
162 (regno, regaddr,
163 (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
164 regaddr += sizeof (int);
165 }
166 }
167 return;
168}
169
170void
fba45db2 171fetch_inferior_registers (int regno)
c906108c
SS
172{
173 struct user u;
174 register unsigned int ar0_offset;
c5aa993b 175
c906108c
SS
176 ar0_offset = (INFERIOR_AR0 (u));
177 if (regno == -1)
178 {
179 for (regno = 0; (regno < FP0_REGNUM); regno++)
180 fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
181 for (; (regno < NUM_REGS); regno++)
182 fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
183 }
184 else
185 fetch_inferior_register (regno,
186 (regno < FP0_REGNUM
187 ? REGISTER_ADDR (ar0_offset, regno)
188 : FP_REGISTER_ADDR (u, regno)));
189}
190
191/* Store our register values back into the inferior.
192 If REGNO is -1, do this for all registers.
193 Otherwise, REGNO specifies which register (so we can save time). */
194
195void
fba45db2 196store_inferior_registers (register int regno)
c906108c
SS
197{
198 struct user u;
199 register unsigned int ar0_offset;
200
201 if (regno >= FP0_REGNUM)
202 {
203 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
204 return;
205 }
c5aa993b 206
c906108c
SS
207 ar0_offset = (INFERIOR_AR0 (u));
208 if (regno >= 0)
209 {
210 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
211 return;
212 }
213
214 for (regno = 0; (regno < FP0_REGNUM); regno++)
215 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
216 for (; (regno < NUM_REGS); regno++)
217 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
218 return;
219}
220
221int
fba45db2 222getpagesize (void)
c906108c
SS
223{
224 return 4096;
225}
This page took 0.09839 seconds and 4 git commands to generate.