* hp300ux-nat.c: Cast second arg to supply_register calls.
[deliverable/binutils-gdb.git] / gdb / hp300ux-nat.c
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.
3
4 This file is part of GDB.
5
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.
10
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23
24 /* Defining this means some system include files define some extra stuff. */
25 #define WOPR
26 #include <sys/param.h>
27 #include <sys/dir.h>
28 #include <signal.h>
29 #include <sys/user.h>
30 #include <sys/ioctl.h>
31 #include <fcntl.h>
32
33 #include <sys/ptrace.h>
34 #include <sys/reg.h>
35 #include <sys/trap.h>
36
37 #include "gdbcore.h"
38
39 #include <sys/file.h>
40 #include <sys/stat.h>
41
42 /* Get kernel_u_addr using HPUX-style nlist(). */
43 CORE_ADDR kernel_u_addr;
44
45 struct hpnlist {
46 char * n_name;
47 long n_value;
48 unsigned char n_type;
49 unsigned char n_length;
50 short n_almod;
51 short n_unused;
52 };
53 static struct hpnlist nl[] = {{ "_u", -1, }, { (char *) 0, }};
54
55 /* read the value of the u area from the hp-ux kernel */
56 void _initialize_kernel_u_addr ()
57 {
58 #ifndef HPUX_VERSION_5
59 nlist ("/hp-ux", nl);
60 kernel_u_addr = nl[0].n_value;
61 #else /* HPUX version 5. */
62 kernel_u_addr = (CORE_ADDR) 0x0097900;
63 #endif
64 }
65
66 #define INFERIOR_AR0(u) \
67 ((ptrace \
68 (PT_RUAREA, inferior_pid, \
69 (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0)) \
70 - kernel_u_addr)
71
72 static void
73 fetch_inferior_register (regno, regaddr)
74 register int regno;
75 register unsigned int regaddr;
76 {
77 #ifndef HPUX_VERSION_5
78 if (regno == PS_REGNUM)
79 {
80 union { int i; short s[2]; } ps_val;
81 int regval;
82
83 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
84 0, 0));
85 regval = ps_val.s[0];
86 supply_register (regno, (char *)&regval);
87 }
88 else
89 #endif /* not HPUX_VERSION_5 */
90 {
91 char buf[MAX_REGISTER_RAW_SIZE];
92 register int i;
93
94 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
95 {
96 *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid,
97 (PTRACE_ARG3_TYPE) regaddr, 0, 0);
98 regaddr += sizeof (int);
99 }
100 supply_register (regno, buf);
101 }
102 return;
103 }
104
105 static void
106 store_inferior_register_1 (regno, regaddr, val)
107 int regno;
108 unsigned int regaddr;
109 int val;
110 {
111 errno = 0;
112 ptrace (PT_WUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, val, 0);
113 #if 0
114 /* HP-UX randomly sets errno to non-zero for regno == 25.
115 However, the value is correctly written, so ignore errno. */
116 if (errno != 0)
117 {
118 char string_buf[64];
119
120 sprintf (string_buf, "writing register number %d", regno);
121 perror_with_name (string_buf);
122 }
123 #endif
124 return;
125 }
126
127 static void
128 store_inferior_register (regno, regaddr)
129 register int regno;
130 register unsigned int regaddr;
131 {
132 #ifndef HPUX_VERSION_5
133 if (regno == PS_REGNUM)
134 {
135 union { int i; short s[2]; } ps_val;
136
137 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
138 0, 0));
139 ps_val.s[0] = (read_register (regno));
140 store_inferior_register_1 (regno, regaddr, ps_val.i);
141 }
142 else
143 #endif /* not HPUX_VERSION_5 */
144 {
145 char buf[MAX_REGISTER_RAW_SIZE];
146 register int i;
147 extern char registers[];
148
149 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
150 {
151 store_inferior_register_1
152 (regno, regaddr,
153 (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
154 regaddr += sizeof (int);
155 }
156 }
157 return;
158 }
159
160 void
161 fetch_inferior_registers (regno)
162 int regno;
163 {
164 struct user u;
165 register unsigned int ar0_offset;
166
167 ar0_offset = (INFERIOR_AR0 (u));
168 if (regno == -1)
169 {
170 for (regno = 0; (regno < FP0_REGNUM); regno++)
171 fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
172 for (; (regno < NUM_REGS); regno++)
173 fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
174 }
175 else
176 fetch_inferior_register (regno,
177 (regno < FP0_REGNUM
178 ? REGISTER_ADDR (ar0_offset, regno)
179 : FP_REGISTER_ADDR (u, regno)));
180 }
181
182 /* Store our register values back into the inferior.
183 If REGNO is -1, do this for all registers.
184 Otherwise, REGNO specifies which register (so we can save time). */
185
186 void
187 store_inferior_registers (regno)
188 register int regno;
189 {
190 struct user u;
191 register unsigned int ar0_offset;
192 extern char registers[];
193
194 if (regno >= FP0_REGNUM)
195 {
196 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
197 return;
198 }
199
200 ar0_offset = (INFERIOR_AR0 (u));
201 if (regno >= 0)
202 {
203 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
204 return;
205 }
206
207 for (regno = 0; (regno < FP0_REGNUM); regno++)
208 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
209 for (; (regno < NUM_REGS); regno++)
210 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
211 return;
212 }
213
214 \f
215 /* Take the register values out of a core file and store
216 them where `read_register' will find them. */
217
218 #ifdef HPUX_VERSION_5
219 #define e_PS e_regs[PS]
220 #define e_PC e_regs[PC]
221 #endif /* HPUX_VERSION_5 */
222
223 void
224 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
225 char *core_reg_sect;
226 unsigned int core_reg_size;
227 int which;
228 unsigned int reg_addr; /* Unused in this version */
229 {
230 int val, regno;
231 struct user u;
232 struct exception_stack *pes = (struct exception_stack *) core_reg_sect;
233 #define es (*pes)
234 char *buf;
235
236 if (which == 0) {
237 if (core_reg_size <
238 ((char *) &es.e_offset - (char *) &es.e_regs[R0]))
239 error ("Not enough registers in core file");
240 for (regno = 0; (regno < PS_REGNUM); regno++)
241 supply_register (regno, (char *) &es.e_regs[regno + R0]);
242 val = es.e_PS;
243 supply_register (regno++, (char *) &val);
244 supply_register (regno++, (char *) &es.e_PC);
245
246 } else if (which == 2) {
247
248 /* FIXME: This may not work if the float regs and control regs are
249 discontinuous. */
250 for (regno = FP0_REGNUM, buf = core_reg_sect;
251 (regno < NUM_REGS);
252 buf += REGISTER_RAW_SIZE (regno), regno++)
253 {
254 supply_register (regno, buf);
255 }
256 }
257 }
258
259 int
260 getpagesize ()
261 {
262 return 4096;
263 }
This page took 0.034854 seconds and 4 git commands to generate.