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