* Check in Fred Fish's changes in these modules. Fred
[deliverable/binutils-gdb.git] / gdb / hp300ux-xdep.c
1 /* HP/UX interface for HP 300's, for GDB when running under Unix.
2 Copyright (C) 1986, 1987, 1989, 1991 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 <stdio.h>
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 <sys/dir.h>
29 #include <signal.h>
30 #include <sys/user.h>
31 #include <sys/ioctl.h>
32 #include <fcntl.h>
33
34 #include <sys/ptrace.h>
35 #include <sys/reg.h>
36 #include <sys/trap.h>
37
38 #include "gdbcore.h"
39
40 #include <sys/file.h>
41 #include <sys/stat.h>
42
43 #define INFERIOR_AR0(u) \
44 ((ptrace \
45 (PT_RUAREA, inferior_pid, ((char *) &u.u_ar0 - (char *) &u), 0)) \
46 - KERNEL_U_ADDR)
47
48 static void
49 fetch_inferior_register (regno, regaddr)
50 register int regno;
51 register unsigned int regaddr;
52 {
53 #ifndef HPUX_VERSION_5
54 if (regno == PS_REGNUM)
55 {
56 union { int i; short s[2]; } ps_val;
57 int regval;
58
59 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, regaddr, 0));
60 regval = ps_val.s[0];
61 supply_register (regno, &regval);
62 }
63 else
64 #endif /* not HPUX_VERSION_5 */
65 {
66 char buf[MAX_REGISTER_RAW_SIZE];
67 register int i;
68
69 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
70 {
71 *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid, regaddr, 0);
72 regaddr += sizeof (int);
73 }
74 supply_register (regno, buf);
75 }
76 return;
77 }
78
79 static void
80 store_inferior_register_1 (regno, regaddr, value)
81 int regno;
82 unsigned int regaddr;
83 int value;
84 {
85 errno = 0;
86 ptrace (PT_WUAREA, inferior_pid, regaddr, value);
87 #if 0
88 /* HP-UX randomly sets errno to non-zero for regno == 25.
89 However, the value is correctly written, so ignore errno. */
90 if (errno != 0)
91 {
92 char string_buf[64];
93
94 sprintf (string_buf, "writing register number %d", regno);
95 perror_with_name (string_buf);
96 }
97 #endif
98 return;
99 }
100
101 static void
102 store_inferior_register (regno, regaddr)
103 register int regno;
104 register unsigned int regaddr;
105 {
106 #ifndef HPUX_VERSION_5
107 if (regno == PS_REGNUM)
108 {
109 union { int i; short s[2]; } ps_val;
110
111 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, regaddr, 0));
112 ps_val.s[0] = (read_register (regno));
113 store_inferior_register_1 (regno, regaddr, ps_val.i);
114 }
115 else
116 #endif /* not HPUX_VERSION_5 */
117 {
118 char buf[MAX_REGISTER_RAW_SIZE];
119 register int i;
120 extern char registers[];
121
122 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
123 {
124 store_inferior_register_1
125 (regno, regaddr,
126 (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
127 regaddr += sizeof (int);
128 }
129 }
130 return;
131 }
132
133 void
134 fetch_inferior_registers (regno)
135 int regno;
136 {
137 struct user u;
138 register unsigned int ar0_offset;
139
140 ar0_offset = (INFERIOR_AR0 (u));
141 if (regno == -1)
142 {
143 for (regno = 0; (regno < FP0_REGNUM); regno++)
144 fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
145 for (; (regno < NUM_REGS); regno++)
146 fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
147 }
148 else
149 fetch_inferior_register (regno,
150 (regno < FP0_REGNUM
151 ? REGISTER_ADDR (ar0_offset, regno)
152 : FP_REGISTER_ADDR (u, regno)));
153 }
154
155 /* Store our register values back into the inferior.
156 If REGNO is -1, do this for all registers.
157 Otherwise, REGNO specifies which register (so we can save time). */
158
159 void
160 store_inferior_registers (regno)
161 register int regno;
162 {
163 struct user u;
164 register unsigned int ar0_offset;
165 extern char registers[];
166
167 if (regno >= FP0_REGNUM)
168 {
169 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
170 return;
171 }
172
173 ar0_offset = (INFERIOR_AR0 (u));
174 if (regno >= 0)
175 {
176 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
177 return;
178 }
179
180 for (regno = 0; (regno < FP0_REGNUM); regno++)
181 store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
182 for (; (regno < NUM_REGS); regno++)
183 store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
184 return;
185 }
186
187 \f
188 /* Take the register values out of a core file and store
189 them where `read_register' will find them. */
190
191 #ifdef HPUX_VERSION_5
192 #define e_PS e_regs[PS]
193 #define e_PC e_regs[PC]
194 #endif /* HPUX_VERSION_5 */
195
196 void
197 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
198 char *core_reg_sect;
199 int core_reg_size;
200 int which;
201 unsigned int reg_addr; /* Unused in this version */
202 {
203 int val, regno;
204 struct user u;
205 struct exception_stack *pes = (struct exception_stack *) core_reg_sect;
206 #define es (*pes)
207 char *buf;
208
209 if (which == 0) {
210 if (core_reg_size <
211 ((char *) &es.e_offset - (char *) &es.e_regs[R0]))
212 error ("Not enough registers in core file");
213 for (regno = 0; (regno < PS_REGNUM); regno++)
214 supply_register (regno, &es.e_regs[regno + R0]);
215 val = es.e_PS;
216 supply_register (regno++, &val);
217 supply_register (regno++, &es.e_PC);
218
219 } else if (which == 2) {
220
221 /* FIXME: This may not work if the float regs and control regs are
222 discontinuous. */
223 for (regno = FP0_REGNUM, buf = core_reg_sect;
224 (regno < NUM_REGS);
225 buf += REGISTER_RAW_SIZE (regno), regno++)
226 {
227 supply_register (regno, buf);
228 }
229 }
230 }
This page took 0.036217 seconds and 5 git commands to generate.