]> Git Repo - binutils.git/blob - gdb/i386m3-nat.c
2002-10-24 Michal Ludvig <[email protected]>
[binutils.git] / gdb / i386m3-nat.c
1 // OBSOLETE /* Low level interface to I386 running mach 3.0.
2 // OBSOLETE    Copyright 1992, 1993, 1994, 1996, 2000, 2001
3 // OBSOLETE    Free Software Foundation, Inc.
4 // OBSOLETE 
5 // OBSOLETE    This file is part of GDB.
6 // OBSOLETE 
7 // OBSOLETE    This program is free software; you can redistribute it and/or modify
8 // OBSOLETE    it under the terms of the GNU General Public License as published by
9 // OBSOLETE    the Free Software Foundation; either version 2 of the License, or
10 // OBSOLETE    (at your option) any later version.
11 // OBSOLETE 
12 // OBSOLETE    This program is distributed in the hope that it will be useful,
13 // OBSOLETE    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // OBSOLETE    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // OBSOLETE    GNU General Public License for more details.
16 // OBSOLETE 
17 // OBSOLETE    You should have received a copy of the GNU General Public License
18 // OBSOLETE    along with this program; if not, write to the Free Software
19 // OBSOLETE    Foundation, Inc., 59 Temple Place - Suite 330,
20 // OBSOLETE    Boston, MA 02111-1307, USA.  */
21 // OBSOLETE 
22 // OBSOLETE #include "defs.h"
23 // OBSOLETE #include "inferior.h"
24 // OBSOLETE #include "floatformat.h"
25 // OBSOLETE #include "regcache.h"
26 // OBSOLETE 
27 // OBSOLETE #include <stdio.h>
28 // OBSOLETE 
29 // OBSOLETE #include <mach.h>
30 // OBSOLETE #include <mach/message.h>
31 // OBSOLETE #include <mach/exception.h>
32 // OBSOLETE #include <mach_error.h>
33 // OBSOLETE 
34 // OBSOLETE /* Hmmm... Should this not be here?
35 // OBSOLETE  * Now for i386_float_info() target_has_execution
36 // OBSOLETE  */
37 // OBSOLETE #include <target.h>
38 // OBSOLETE 
39 // OBSOLETE /* This mess is duplicated in bfd/i386mach3.h
40 // OBSOLETE 
41 // OBSOLETE  * This is an ugly way to hack around the incorrect
42 // OBSOLETE  * definition of UPAGES in i386/machparam.h.
43 // OBSOLETE  *
44 // OBSOLETE  * The definition should specify the size reserved
45 // OBSOLETE  * for "struct user" in core files in PAGES,
46 // OBSOLETE  * but instead it gives it in 512-byte core-clicks
47 // OBSOLETE  * for i386 and i860.
48 // OBSOLETE  */
49 // OBSOLETE #include <sys/param.h>
50 // OBSOLETE #if UPAGES == 16
51 // OBSOLETE #define UAREA_SIZE ctob(UPAGES)
52 // OBSOLETE #elif UPAGES == 2
53 // OBSOLETE #define UAREA_SIZE (NBPG*UPAGES)
54 // OBSOLETE #else
55 // OBSOLETE FIXME ! !UPAGES is neither 2 nor 16
56 // OBSOLETE #endif
57 // OBSOLETE 
58 // OBSOLETE /* @@@ Should move print_387_status() to i387-tdep.c */
59 // OBSOLETE extern void print_387_control_word ();              /* i387-tdep.h */
60 // OBSOLETE extern void print_387_status_word ();
61 // OBSOLETE 
62 // OBSOLETE #define private static
63 // OBSOLETE \f
64 // OBSOLETE 
65 // OBSOLETE /* Find offsets to thread states at compile time.
66 // OBSOLETE  * If your compiler does not grok this, calculate offsets
67 // OBSOLETE  * offsets yourself and use them (or get a compatible compiler :-)
68 // OBSOLETE  */
69 // OBSOLETE 
70 // OBSOLETE #define  REG_OFFSET(reg) (int)(&((struct i386_thread_state *)0)->reg)
71 // OBSOLETE 
72 // OBSOLETE /* at reg_offset[i] is the offset to the i386_thread_state
73 // OBSOLETE  * location where the gdb registers[i] is stored.
74 // OBSOLETE  */
75 // OBSOLETE 
76 // OBSOLETE static int reg_offset[] =
77 // OBSOLETE {
78 // OBSOLETE   REG_OFFSET (eax), REG_OFFSET (ecx), REG_OFFSET (edx), REG_OFFSET (ebx),
79 // OBSOLETE   REG_OFFSET (uesp), REG_OFFSET (ebp), REG_OFFSET (esi), REG_OFFSET (edi),
80 // OBSOLETE   REG_OFFSET (eip), REG_OFFSET (efl), REG_OFFSET (cs), REG_OFFSET (ss),
81 // OBSOLETE   REG_OFFSET (ds), REG_OFFSET (es), REG_OFFSET (fs), REG_OFFSET (gs)
82 // OBSOLETE };
83 // OBSOLETE 
84 // OBSOLETE #define REG_ADDRESS(state,regnum) ((char *)(state)+reg_offset[regnum])
85 // OBSOLETE 
86 // OBSOLETE /* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
87 // OBSOLETE  * Caller knows that the regs handled in one transaction are of same size.
88 // OBSOLETE  */
89 // OBSOLETE #define FETCH_REGS(state, regnum, count) \
90 // OBSOLETE   memcpy (&registers[REGISTER_BYTE (regnum)], \
91 // OBSOLETE       REG_ADDRESS (state, regnum), \
92 // OBSOLETE       count*REGISTER_SIZE)
93 // OBSOLETE 
94 // OBSOLETE /* Store COUNT contiguous registers to thread STATE starting from REGNUM */
95 // OBSOLETE #define STORE_REGS(state, regnum, count) \
96 // OBSOLETE   memcpy (REG_ADDRESS (state, regnum), \
97 // OBSOLETE       &registers[REGISTER_BYTE (regnum)], \
98 // OBSOLETE       count*REGISTER_SIZE)
99 // OBSOLETE \f
100 // OBSOLETE /*
101 // OBSOLETE  * Fetch inferiors registers for gdb.
102 // OBSOLETE  * REGNO specifies which (as gdb views it) register, -1 for all.
103 // OBSOLETE  */
104 // OBSOLETE 
105 // OBSOLETE void
106 // OBSOLETE fetch_inferior_registers (int regno)
107 // OBSOLETE {
108 // OBSOLETE   kern_return_t ret;
109 // OBSOLETE   thread_state_data_t state;
110 // OBSOLETE   unsigned int stateCnt = i386_THREAD_STATE_COUNT;
111 // OBSOLETE   int index;
112 // OBSOLETE 
113 // OBSOLETE   if (!MACH_PORT_VALID (current_thread))
114 // OBSOLETE     error ("fetch inferior registers: Invalid thread");
115 // OBSOLETE 
116 // OBSOLETE   if (must_suspend_thread)
117 // OBSOLETE     setup_thread (current_thread, 1);
118 // OBSOLETE 
119 // OBSOLETE   ret = thread_get_state (current_thread,
120 // OBSOLETE                       i386_THREAD_STATE,
121 // OBSOLETE                       state,
122 // OBSOLETE                       &stateCnt);
123 // OBSOLETE 
124 // OBSOLETE   if (ret != KERN_SUCCESS)
125 // OBSOLETE     warning ("fetch_inferior_registers: %s ",
126 // OBSOLETE          mach_error_string (ret));
127 // OBSOLETE #if 0
128 // OBSOLETE   /* It may be more effective to store validate all of them,
129 // OBSOLETE    * since we fetched them all anyway
130 // OBSOLETE    */
131 // OBSOLETE   else if (regno != -1)
132 // OBSOLETE     supply_register (regno, (char *) state + reg_offset[regno]);
133 // OBSOLETE #endif
134 // OBSOLETE   else
135 // OBSOLETE     {
136 // OBSOLETE       for (index = 0; index < NUM_REGS; index++)
137 // OBSOLETE     supply_register (index, (char *) state + reg_offset[index]);
138 // OBSOLETE     }
139 // OBSOLETE 
140 // OBSOLETE   if (must_suspend_thread)
141 // OBSOLETE     setup_thread (current_thread, 0);
142 // OBSOLETE }
143 // OBSOLETE \f
144 // OBSOLETE /* Store our register values back into the inferior.
145 // OBSOLETE  * If REGNO is -1, do this for all registers.
146 // OBSOLETE  * Otherwise, REGNO specifies which register
147 // OBSOLETE  *
148 // OBSOLETE  * On mach3 all registers are always saved in one call.
149 // OBSOLETE  */
150 // OBSOLETE void
151 // OBSOLETE store_inferior_registers (int regno)
152 // OBSOLETE {
153 // OBSOLETE   kern_return_t ret;
154 // OBSOLETE   thread_state_data_t state;
155 // OBSOLETE   unsigned int stateCnt = i386_THREAD_STATE_COUNT;
156 // OBSOLETE   register int index;
157 // OBSOLETE 
158 // OBSOLETE   if (!MACH_PORT_VALID (current_thread))
159 // OBSOLETE     error ("store inferior registers: Invalid thread");
160 // OBSOLETE 
161 // OBSOLETE   if (must_suspend_thread)
162 // OBSOLETE     setup_thread (current_thread, 1);
163 // OBSOLETE 
164 // OBSOLETE   /* Fetch the state of the current thread */
165 // OBSOLETE   ret = thread_get_state (current_thread,
166 // OBSOLETE                       i386_THREAD_STATE,
167 // OBSOLETE                       state,
168 // OBSOLETE                       &stateCnt);
169 // OBSOLETE 
170 // OBSOLETE   if (ret != KERN_SUCCESS)
171 // OBSOLETE     {
172 // OBSOLETE       warning ("store_inferior_registers (get): %s",
173 // OBSOLETE            mach_error_string (ret));
174 // OBSOLETE       if (must_suspend_thread)
175 // OBSOLETE     setup_thread (current_thread, 0);
176 // OBSOLETE       return;
177 // OBSOLETE     }
178 // OBSOLETE 
179 // OBSOLETE   /* move gdb's registers to thread's state
180 // OBSOLETE 
181 // OBSOLETE    * Since we save all registers anyway, save the ones
182 // OBSOLETE    * that gdb thinks are valid (e.g. ignore the regno
183 // OBSOLETE    * parameter)
184 // OBSOLETE    */
185 // OBSOLETE #if 0
186 // OBSOLETE   if (regno != -1)
187 // OBSOLETE     STORE_REGS (state, regno, 1);
188 // OBSOLETE   else
189 // OBSOLETE #endif
190 // OBSOLETE     {
191 // OBSOLETE       for (index = 0; index < NUM_REGS; index++)
192 // OBSOLETE     STORE_REGS (state, index, 1);
193 // OBSOLETE     }
194 // OBSOLETE 
195 // OBSOLETE   /* Write gdb's current view of register to the thread
196 // OBSOLETE    */
197 // OBSOLETE   ret = thread_set_state (current_thread,
198 // OBSOLETE                       i386_THREAD_STATE,
199 // OBSOLETE                       state,
200 // OBSOLETE                       i386_THREAD_STATE_COUNT);
201 // OBSOLETE 
202 // OBSOLETE   if (ret != KERN_SUCCESS)
203 // OBSOLETE     warning ("store_inferior_registers (set): %s",
204 // OBSOLETE          mach_error_string (ret));
205 // OBSOLETE 
206 // OBSOLETE   if (must_suspend_thread)
207 // OBSOLETE     setup_thread (current_thread, 0);
208 // OBSOLETE }
209 // OBSOLETE \f
210 // OBSOLETE 
211 // OBSOLETE 
212 // OBSOLETE /* Return the address in the core dump or inferior of register REGNO.
213 // OBSOLETE  * BLOCKEND should be the address of the end of the UPAGES area read
214 // OBSOLETE  * in memory, but it's not?
215 // OBSOLETE  *
216 // OBSOLETE  * Currently our UX server dumps the whole thread state to the
217 // OBSOLETE  * core file. If your UX does something else, adapt the routine
218 // OBSOLETE  * below to return the offset to the given register.
219 // OBSOLETE  * 
220 // OBSOLETE  * Called by core-aout.c(fetch_core_registers)
221 // OBSOLETE  */
222 // OBSOLETE 
223 // OBSOLETE CORE_ADDR
224 // OBSOLETE register_addr (int regno, CORE_ADDR blockend)
225 // OBSOLETE {
226 // OBSOLETE   CORE_ADDR addr;
227 // OBSOLETE 
228 // OBSOLETE   if (regno < 0 || regno >= NUM_REGS)
229 // OBSOLETE     error ("Invalid register number %d.", regno);
230 // OBSOLETE 
231 // OBSOLETE   /* UAREA_SIZE == 8 kB in i386 */
232 // OBSOLETE   addr = (unsigned int) REG_ADDRESS (UAREA_SIZE - sizeof (struct i386_thread_state), regno);
233 // OBSOLETE 
234 // OBSOLETE   return addr;
235 // OBSOLETE }
236 // OBSOLETE 
237 // OBSOLETE /* [email protected]: I copied and modified this 387 code from
238 // OBSOLETE  * gdb/i386-xdep.c. Modifications for Mach 3.0.
239 // OBSOLETE  *
240 // OBSOLETE  * i387 status dumper. See also i387-tdep.c
241 // OBSOLETE  */
242 // OBSOLETE struct env387
243 // OBSOLETE {
244 // OBSOLETE   unsigned short control;
245 // OBSOLETE   unsigned short r0;
246 // OBSOLETE   unsigned short status;
247 // OBSOLETE   unsigned short r1;
248 // OBSOLETE   unsigned short tag;
249 // OBSOLETE   unsigned short r2;
250 // OBSOLETE   unsigned long eip;
251 // OBSOLETE   unsigned short code_seg;
252 // OBSOLETE   unsigned short opcode;
253 // OBSOLETE   unsigned long operand;
254 // OBSOLETE   unsigned short operand_seg;
255 // OBSOLETE   unsigned short r3;
256 // OBSOLETE   unsigned char regs[8][10];
257 // OBSOLETE };
258 // OBSOLETE /* This routine is machine independent?
259 // OBSOLETE  * Should move it to i387-tdep.c but you need to export struct env387
260 // OBSOLETE  */
261 // OBSOLETE private
262 // OBSOLETE print_387_status (unsigned short status, struct env387 *ep)
263 // OBSOLETE {
264 // OBSOLETE   int i;
265 // OBSOLETE   int bothstatus;
266 // OBSOLETE   int top;
267 // OBSOLETE   int fpreg;
268 // OBSOLETE   unsigned char *p;
269 // OBSOLETE 
270 // OBSOLETE   bothstatus = ((status != 0) && (ep->status != 0));
271 // OBSOLETE   if (status != 0)
272 // OBSOLETE     {
273 // OBSOLETE       if (bothstatus)
274 // OBSOLETE     printf_unfiltered ("u: ");
275 // OBSOLETE       print_387_status_word (status);
276 // OBSOLETE     }
277 // OBSOLETE 
278 // OBSOLETE   if (ep->status != 0)
279 // OBSOLETE     {
280 // OBSOLETE       if (bothstatus)
281 // OBSOLETE     printf_unfiltered ("e: ");
282 // OBSOLETE       print_387_status_word (ep->status);
283 // OBSOLETE     }
284 // OBSOLETE 
285 // OBSOLETE   print_387_control_word (ep->control);
286 // OBSOLETE   printf_unfiltered ("last exception: ");
287 // OBSOLETE   printf_unfiltered ("opcode %s; ", local_hex_string (ep->opcode));
288 // OBSOLETE   printf_unfiltered ("pc %s:", local_hex_string (ep->code_seg));
289 // OBSOLETE   printf_unfiltered ("%s; ", local_hex_string (ep->eip));
290 // OBSOLETE   printf_unfiltered ("operand %s", local_hex_string (ep->operand_seg));
291 // OBSOLETE   printf_unfiltered (":%s\n", local_hex_string (ep->operand));
292 // OBSOLETE 
293 // OBSOLETE   top = (ep->status >> 11) & 7;
294 // OBSOLETE 
295 // OBSOLETE   printf_unfiltered ("regno  tag  msb              lsb  value\n");
296 // OBSOLETE   for (fpreg = 7; fpreg >= 0; fpreg--)
297 // OBSOLETE     {
298 // OBSOLETE       double val;
299 // OBSOLETE 
300 // OBSOLETE       printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : "  ", fpreg);
301 // OBSOLETE 
302 // OBSOLETE       switch ((ep->tag >> (fpreg * 2)) & 3)
303 // OBSOLETE     {
304 // OBSOLETE     case 0:
305 // OBSOLETE       printf_unfiltered ("valid ");
306 // OBSOLETE       break;
307 // OBSOLETE     case 1:
308 // OBSOLETE       printf_unfiltered ("zero  ");
309 // OBSOLETE       break;
310 // OBSOLETE     case 2:
311 // OBSOLETE       printf_unfiltered ("trap  ");
312 // OBSOLETE       break;
313 // OBSOLETE     case 3:
314 // OBSOLETE       printf_unfiltered ("empty ");
315 // OBSOLETE       break;
316 // OBSOLETE     }
317 // OBSOLETE       for (i = 9; i >= 0; i--)
318 // OBSOLETE     printf_unfiltered ("%02x", ep->regs[fpreg][i]);
319 // OBSOLETE 
320 // OBSOLETE       floatformat_to_double (&floatformat_i387_ext, (char *) ep->regs[fpreg],
321 // OBSOLETE                          &val);
322 // OBSOLETE       printf_unfiltered ("  %g\n", val);
323 // OBSOLETE     }
324 // OBSOLETE   if (ep->r0)
325 // OBSOLETE     printf_unfiltered ("warning: reserved0 is %s\n", local_hex_string (ep->r0));
326 // OBSOLETE   if (ep->r1)
327 // OBSOLETE     printf_unfiltered ("warning: reserved1 is %s\n", local_hex_string (ep->r1));
328 // OBSOLETE   if (ep->r2)
329 // OBSOLETE     printf_unfiltered ("warning: reserved2 is %s\n", local_hex_string (ep->r2));
330 // OBSOLETE   if (ep->r3)
331 // OBSOLETE     printf_unfiltered ("warning: reserved3 is %s\n", local_hex_string (ep->r3));
332 // OBSOLETE }
333 // OBSOLETE 
334 // OBSOLETE /*
335 // OBSOLETE  * values that go into fp_kind (from <i386/fpreg.h>)
336 // OBSOLETE  */
337 // OBSOLETE #define FP_NO   0           /* no fp chip, no emulator (no fp support)      */
338 // OBSOLETE #define FP_SW   1           /* no fp chip, using software emulator          */
339 // OBSOLETE #define FP_HW   2           /* chip present bit                             */
340 // OBSOLETE #define FP_287  2           /* 80287 chip present                           */
341 // OBSOLETE #define FP_387  3           /* 80387 chip present                           */
342 // OBSOLETE 
343 // OBSOLETE typedef struct fpstate
344 // OBSOLETE {
345 // OBSOLETE #if 1
346 // OBSOLETE   unsigned char state[FP_STATE_BYTES];      /* "hardware" state */
347 // OBSOLETE #else
348 // OBSOLETE   struct env387 state;              /* Actually this */
349 // OBSOLETE #endif
350 // OBSOLETE   int status;                       /* Duplicate status */
351 // OBSOLETE }
352 // OBSOLETE  *fpstate_t;
353 // OBSOLETE 
354 // OBSOLETE /* Mach 3 specific routines.
355 // OBSOLETE  */
356 // OBSOLETE private boolean_t
357 // OBSOLETE get_i387_state (struct fpstate *fstate)
358 // OBSOLETE {
359 // OBSOLETE   kern_return_t ret;
360 // OBSOLETE   thread_state_data_t state;
361 // OBSOLETE   unsigned int fsCnt = i386_FLOAT_STATE_COUNT;
362 // OBSOLETE   struct i386_float_state *fsp;
363 // OBSOLETE 
364 // OBSOLETE   ret = thread_get_state (current_thread,
365 // OBSOLETE                       i386_FLOAT_STATE,
366 // OBSOLETE                       state,
367 // OBSOLETE                       &fsCnt);
368 // OBSOLETE 
369 // OBSOLETE   if (ret != KERN_SUCCESS)
370 // OBSOLETE     {
371 // OBSOLETE       warning ("Can not get live floating point state: %s",
372 // OBSOLETE            mach_error_string (ret));
373 // OBSOLETE       return FALSE;
374 // OBSOLETE     }
375 // OBSOLETE 
376 // OBSOLETE   fsp = (struct i386_float_state *) state;
377 // OBSOLETE   /* The 387 chip (also 486 counts) or a software emulator? */
378 // OBSOLETE   if (!fsp->initialized || (fsp->fpkind != FP_387 && fsp->fpkind != FP_SW))
379 // OBSOLETE     return FALSE;
380 // OBSOLETE 
381 // OBSOLETE   /* Clear the target then copy thread's float state there.
382 // OBSOLETE      Make a copy of the status word, for some reason?
383 // OBSOLETE    */
384 // OBSOLETE   memset (fstate, 0, sizeof (struct fpstate));
385 // OBSOLETE 
386 // OBSOLETE   fstate->status = fsp->exc_status;
387 // OBSOLETE 
388 // OBSOLETE   memcpy (fstate->state, (char *) &fsp->hw_state, FP_STATE_BYTES);
389 // OBSOLETE 
390 // OBSOLETE   return TRUE;
391 // OBSOLETE }
392 // OBSOLETE 
393 // OBSOLETE private boolean_t
394 // OBSOLETE get_i387_core_state (struct fpstate *fstate)
395 // OBSOLETE {
396 // OBSOLETE   /* Not implemented yet. Core files do not contain float state. */
397 // OBSOLETE   return FALSE;
398 // OBSOLETE }
399 // OBSOLETE 
400 // OBSOLETE /*
401 // OBSOLETE  * This is called by "info float" command
402 // OBSOLETE  */
403 // OBSOLETE void
404 // OBSOLETE i386_mach3_float_info (void)
405 // OBSOLETE {
406 // OBSOLETE   char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
407 // OBSOLETE   boolean_t valid = FALSE;
408 // OBSOLETE   fpstate_t fps;
409 // OBSOLETE 
410 // OBSOLETE   if (target_has_execution)
411 // OBSOLETE     valid = get_i387_state (buf);
412 // OBSOLETE #if 0
413 // OBSOLETE   else if (WE HAVE CORE FILE)       /* @@@@ Core files not supported */
414 // OBSOLETE     valid = get_i387_core_state (buf);
415 // OBSOLETE #endif
416 // OBSOLETE 
417 // OBSOLETE   if (!valid)
418 // OBSOLETE     {
419 // OBSOLETE       warning ("no floating point status saved");
420 // OBSOLETE       return;
421 // OBSOLETE     }
422 // OBSOLETE 
423 // OBSOLETE   fps = (fpstate_t) buf;
424 // OBSOLETE 
425 // OBSOLETE   print_387_status (fps->status, (struct env387 *) fps->state);
426 // OBSOLETE }
This page took 0.046254 seconds and 4 git commands to generate.