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