OSDN Git Service

Update/correct copyright notices.
[pf3gnuchains/pf3gnuchains4x.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, 1994, 1996, 1999, 2000,
3    2001 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "regcache.h"
26
27 /* Defining this means some system include files define some extra stuff.  */
28 #define WOPR
29 #include <sys/param.h>
30 #include <signal.h>
31 #include <sys/user.h>
32 #include <fcntl.h>
33
34 #include <sys/ptrace.h>
35 #include <sys/reg.h>
36 #include <sys/trap.h>
37
38 #include <sys/file.h>
39
40 static void fetch_inferior_register (int, unsigned int);
41
42 static void store_inferior_register_1 (int, unsigned int, int);
43
44 static void store_inferior_register (int, unsigned int);
45
46 /* Get kernel_u_addr using HPUX-style nlist().  */
47 CORE_ADDR kernel_u_addr;
48
49 struct hpnlist
50   {
51     char *n_name;
52     long n_value;
53     unsigned char n_type;
54     unsigned char n_length;
55     short n_almod;
56     short n_unused;
57   };
58 static struct hpnlist nl[] =
59 {
60   {"_u", -1,},
61   {(char *) 0,}};
62
63 /* read the value of the u area from the hp-ux kernel */
64 void
65 _initialize_hp300ux_nat (void)
66 {
67 #ifndef HPUX_VERSION_5
68   nlist ("/hp-ux", nl);
69   kernel_u_addr = nl[0].n_value;
70 #else /* HPUX version 5.  */
71   kernel_u_addr = (CORE_ADDR) 0x0097900;
72 #endif
73 }
74
75 #define INFERIOR_AR0(u)                                                 \
76   ((ptrace                                                              \
77     (PT_RUAREA, inferior_pid,                                           \
78      (PTRACE_ARG3_TYPE) ((char *) &u.u_ar0 - (char *) &u), 0, 0))               \
79    - kernel_u_addr)
80
81 static void
82 fetch_inferior_register (register int regno, register unsigned int regaddr)
83 {
84 #ifndef HPUX_VERSION_5
85   if (regno == PS_REGNUM)
86     {
87       union
88         {
89           int i;
90           short s[2];
91         }
92       ps_val;
93       int regval;
94
95       ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
96                           0, 0));
97       regval = ps_val.s[0];
98       supply_register (regno, (char *) &regval);
99     }
100   else
101 #endif /* not HPUX_VERSION_5 */
102     {
103       char buf[MAX_REGISTER_RAW_SIZE];
104       register int i;
105
106       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
107         {
108           *(int *) &buf[i] = ptrace (PT_RUAREA, inferior_pid,
109                                      (PTRACE_ARG3_TYPE) regaddr, 0, 0);
110           regaddr += sizeof (int);
111         }
112       supply_register (regno, buf);
113     }
114   return;
115 }
116
117 static void
118 store_inferior_register_1 (int regno, unsigned int regaddr, int val)
119 {
120   errno = 0;
121   ptrace (PT_WUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, val, 0);
122 #if 0
123   /* HP-UX randomly sets errno to non-zero for regno == 25.
124      However, the value is correctly written, so ignore errno. */
125   if (errno != 0)
126     {
127       char string_buf[64];
128
129       sprintf (string_buf, "writing register number %d", regno);
130       perror_with_name (string_buf);
131     }
132 #endif
133   return;
134 }
135
136 static void
137 store_inferior_register (register int regno, register unsigned int regaddr)
138 {
139 #ifndef HPUX_VERSION_5
140   if (regno == PS_REGNUM)
141     {
142       union
143         {
144           int i;
145           short s[2];
146         }
147       ps_val;
148
149       ps_val.i = (ptrace (PT_RUAREA, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
150                           0, 0));
151       ps_val.s[0] = (read_register (regno));
152       store_inferior_register_1 (regno, regaddr, ps_val.i);
153     }
154   else
155 #endif /* not HPUX_VERSION_5 */
156     {
157       register int i;
158
159       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
160         {
161           store_inferior_register_1
162             (regno, regaddr,
163              (*(int *) &registers[(REGISTER_BYTE (regno)) + i]));
164           regaddr += sizeof (int);
165         }
166     }
167   return;
168 }
169
170 void
171 fetch_inferior_registers (int regno)
172 {
173   struct user u;
174   register unsigned int ar0_offset;
175
176   ar0_offset = (INFERIOR_AR0 (u));
177   if (regno == -1)
178     {
179       for (regno = 0; (regno < FP0_REGNUM); regno++)
180         fetch_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
181       for (; (regno < NUM_REGS); regno++)
182         fetch_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
183     }
184   else
185     fetch_inferior_register (regno,
186                              (regno < FP0_REGNUM
187                               ? REGISTER_ADDR (ar0_offset, regno)
188                               : FP_REGISTER_ADDR (u, regno)));
189 }
190
191 /* Store our register values back into the inferior.
192    If REGNO is -1, do this for all registers.
193    Otherwise, REGNO specifies which register (so we can save time).  */
194
195 void
196 store_inferior_registers (register int regno)
197 {
198   struct user u;
199   register unsigned int ar0_offset;
200
201   if (regno >= FP0_REGNUM)
202     {
203       store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
204       return;
205     }
206
207   ar0_offset = (INFERIOR_AR0 (u));
208   if (regno >= 0)
209     {
210       store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
211       return;
212     }
213
214   for (regno = 0; (regno < FP0_REGNUM); regno++)
215     store_inferior_register (regno, (REGISTER_ADDR (ar0_offset, regno)));
216   for (; (regno < NUM_REGS); regno++)
217     store_inferior_register (regno, (FP_REGISTER_ADDR (u, regno)));
218   return;
219 }
220
221 int
222 getpagesize (void)
223 {
224   return 4096;
225 }