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