Fix bug in sh_elf_reloc_loop
[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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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
38 static void fetch_inferior_register (int, unsigned int);
39
40 static void store_inferior_register_1 (int, unsigned int, int);
41
42 static void store_inferior_register (int, unsigned int);
43
44 /* Get kernel_u_addr using HPUX-style nlist(). */
45 CORE_ADDR kernel_u_addr;
46
47 struct 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 };
56 static struct hpnlist nl[] =
57 {
58 {"_u", -1,},
59 {(char *) 0,}};
60
61 /* read the value of the u area from the hp-ux kernel */
62 void
63 _initialize_hp300ux_nat (void)
64 {
65 #ifndef HPUX_VERSION_5
66 nlist ("/hp-ux", nl);
67 kernel_u_addr = nl[0].n_value;
68 #else /* HPUX version 5. */
69 kernel_u_addr = (CORE_ADDR) 0x0097900;
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
79 static void
80 fetch_inferior_register (register int regno, register unsigned int regaddr)
81 {
82 #ifndef HPUX_VERSION_5
83 if (regno == PS_REGNUM)
84 {
85 union
86 {
87 int i;
88 short s[2];
89 }
90 ps_val;
91 int regval;
92
93 ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
94 0, 0));
95 regval = ps_val.s[0];
96 supply_register (regno, (char *) &regval);
97 }
98 else
99 #endif /* not HPUX_VERSION_5 */
100 {
101 char buf[MAX_REGISTER_RAW_SIZE];
102 register int i;
103
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
115 static void
116 store_inferior_register_1 (int regno, unsigned int regaddr, int val)
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];
126
127 sprintf (string_buf, "writing register number %d", regno);
128 perror_with_name (string_buf);
129 }
130 #endif
131 return;
132 }
133
134 static void
135 store_inferior_register (register int regno, register unsigned int regaddr)
136 {
137 #ifndef HPUX_VERSION_5
138 if (regno == PS_REGNUM)
139 {
140 union
141 {
142 int i;
143 short s[2];
144 }
145 ps_val;
146
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;
156
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
168 void
169 fetch_inferior_registers (int regno)
170 {
171 struct user u;
172 register unsigned int ar0_offset;
173
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
193 void
194 store_inferior_registers (register int regno)
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 }
204
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
219 int
220 getpagesize (void)
221 {
222 return 4096;
223 }
This page took 0.035921 seconds and 4 git commands to generate.