]>
Commit | Line | Data |
---|---|---|
07d021a6 JG |
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 | ||
99a7de40 | 6 | This program is free software; you can redistribute it and/or modify |
07d021a6 | 7 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
07d021a6 | 10 | |
99a7de40 | 11 | This program is distributed in the hope that it will be useful, |
07d021a6 JG |
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 | |
99a7de40 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
07d021a6 | 19 | |
07d021a6 | 20 | #include "defs.h" |
07d021a6 JG |
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 \ | |
e676a15f FF |
44 | (PT_RUAREA, inferior_pid, \ |
45 | (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0)) \ | |
07d021a6 JG |
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 | ||
e676a15f FF |
59 | ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
60 | 0)); | |
07d021a6 JG |
61 | regval = ps_val.s[0]; |
62 | supply_register (regno, ®val); | |
63 | } | |
64 | else | |
65 | #endif /* not HPUX_VERSION_5 */ | |
66 | { | |
67 | char buf[MAX_REGISTER_RAW_SIZE]; | |
68 | register int i; | |
69 | ||
70 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) | |
71 | { | |
e676a15f FF |
72 | *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid, |
73 | (PTRACE_ARG3_TYPE) regaddr, 0); | |
07d021a6 JG |
74 | regaddr += sizeof (int); |
75 | } | |
76 | supply_register (regno, buf); | |
77 | } | |
78 | return; | |
79 | } | |
80 | ||
81 | static void | |
82 | store_inferior_register_1 (regno, regaddr, value) | |
83 | int regno; | |
84 | unsigned int regaddr; | |
85 | int value; | |
86 | { | |
87 | errno = 0; | |
e676a15f | 88 | ptrace (PT_WUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, value); |
07d021a6 JG |
89 | #if 0 |
90 | /* HP-UX randomly sets errno to non-zero for regno == 25. | |
91 | However, the value is correctly written, so ignore errno. */ | |
92 | if (errno != 0) | |
93 | { | |
94 | char string_buf[64]; | |
95 | ||
96 | sprintf (string_buf, "writing register number %d", regno); | |
97 | perror_with_name (string_buf); | |
98 | } | |
99 | #endif | |
100 | return; | |
101 | } | |
102 | ||
103 | static void | |
104 | store_inferior_register (regno, regaddr) | |
105 | register int regno; | |
106 | register unsigned int regaddr; | |
107 | { | |
108 | #ifndef HPUX_VERSION_5 | |
109 | if (regno == PS_REGNUM) | |
110 | { | |
111 | union { int i; short s[2]; } ps_val; | |
112 | ||
e676a15f FF |
113 | ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
114 | 0)); | |
07d021a6 JG |
115 | ps_val.s[0] = (read_register (regno)); |
116 | store_inferior_register_1 (regno, regaddr, ps_val.i); | |
117 | } | |
118 | else | |
119 | #endif /* not HPUX_VERSION_5 */ | |
120 | { | |
121 | char buf[MAX_REGISTER_RAW_SIZE]; | |
122 | register int i; | |
123 | extern char registers[]; | |
124 | ||
125 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) | |
126 | { | |
127 | store_inferior_register_1 | |
128 | (regno, regaddr, | |
129 | (*(int *) ®isters[(REGISTER_BYTE (regno)) + i])); | |
130 | regaddr += sizeof (int); | |
131 | } | |
132 | } | |
133 | return; | |
134 | } | |
135 | ||
136 | void | |
137 | fetch_inferior_registers (regno) | |
138 | int regno; | |
139 | { | |
140 | struct user u; | |
07d021a6 JG |
141 | register unsigned int ar0_offset; |
142 | ||
143 | ar0_offset = (INFERIOR_AR0 (u)); | |
144 | if (regno == -1) | |
145 | { | |
146 | for (regno = 0; (regno < FP0_REGNUM); regno++) | |
147 | fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno))); | |
148 | for (; (regno < NUM_REGS); regno++) | |
149 | fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno))); | |
150 | } | |
151 | else | |
152 | fetch_inferior_register (regno, | |
153 | (regno < FP0_REGNUM | |
154 | ? REGISTER_ADDR (ar0_offset, regno) | |
155 | : FP_REGISTER_ADDR (u, regno))); | |
156 | } | |
157 | ||
158 | /* Store our register values back into the inferior. | |
159 | If REGNO is -1, do this for all registers. | |
160 | Otherwise, REGNO specifies which register (so we can save time). */ | |
161 | ||
1ab3bf1b | 162 | void |
07d021a6 JG |
163 | store_inferior_registers (regno) |
164 | register int regno; | |
165 | { | |
166 | struct user u; | |
167 | register unsigned int ar0_offset; | |
168 | extern char registers[]; | |
169 | ||
170 | if (regno >= FP0_REGNUM) | |
171 | { | |
172 | store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno))); | |
173 | return; | |
174 | } | |
175 | ||
176 | ar0_offset = (INFERIOR_AR0 (u)); | |
177 | if (regno >= 0) | |
178 | { | |
179 | store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno))); | |
180 | return; | |
181 | } | |
182 | ||
183 | for (regno = 0; (regno < FP0_REGNUM); regno++) | |
184 | store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno))); | |
185 | for (; (regno < NUM_REGS); regno++) | |
186 | store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno))); | |
187 | return; | |
188 | } | |
189 | ||
190 | \f | |
191 | /* Take the register values out of a core file and store | |
192 | them where `read_register' will find them. */ | |
193 | ||
194 | #ifdef HPUX_VERSION_5 | |
195 | #define e_PS e_regs[PS] | |
196 | #define e_PC e_regs[PC] | |
197 | #endif /* HPUX_VERSION_5 */ | |
198 | ||
199 | void | |
1ab3bf1b | 200 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) |
07d021a6 JG |
201 | char *core_reg_sect; |
202 | int core_reg_size; | |
203 | int which; | |
1ab3bf1b | 204 | unsigned int reg_addr; /* Unused in this version */ |
07d021a6 JG |
205 | { |
206 | int val, regno; | |
207 | struct user u; | |
208 | struct exception_stack *pes = (struct exception_stack *) core_reg_sect; | |
209 | #define es (*pes) | |
210 | char *buf; | |
211 | ||
212 | if (which == 0) { | |
213 | if (core_reg_size < | |
214 | ((char *) &es.e_offset - (char *) &es.e_regs[R0])) | |
215 | error ("Not enough registers in core file"); | |
216 | for (regno = 0; (regno < PS_REGNUM); regno++) | |
217 | supply_register (regno, &es.e_regs[regno + R0]); | |
218 | val = es.e_PS; | |
219 | supply_register (regno++, &val); | |
220 | supply_register (regno++, &es.e_PC); | |
221 | ||
222 | } else if (which == 2) { | |
223 | ||
224 | /* FIXME: This may not work if the float regs and control regs are | |
225 | discontinuous. */ | |
226 | for (regno = FP0_REGNUM, buf = core_reg_sect; | |
227 | (regno < NUM_REGS); | |
228 | buf += REGISTER_RAW_SIZE (regno), regno++) | |
229 | { | |
230 | supply_register (regno, buf); | |
231 | } | |
232 | } | |
233 | } |