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.
5 // OBSOLETE This file is part of GDB.
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.
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.
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. */
22 // OBSOLETE #include "defs.h"
23 // OBSOLETE #include "inferior.h"
24 // OBSOLETE #include "floatformat.h"
25 // OBSOLETE #include "regcache.h"
27 // OBSOLETE #include <stdio.h>
29 // OBSOLETE #include <mach.h>
30 // OBSOLETE #include <mach/message.h>
31 // OBSOLETE #include <mach/exception.h>
32 // OBSOLETE #include <mach_error.h>
34 // OBSOLETE /* Hmmm... Should this not be here?
35 // OBSOLETE * Now for i386_float_info() target_has_execution
37 // OBSOLETE #include <target.h>
39 // OBSOLETE /* This mess is duplicated in bfd/i386mach3.h
41 // OBSOLETE * This is an ugly way to hack around the incorrect
42 // OBSOLETE * definition of UPAGES in i386/machparam.h.
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.
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)
55 // OBSOLETE FIXME ! !UPAGES is neither 2 nor 16
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 ();
62 // OBSOLETE #define private static
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 :-)
70 // OBSOLETE #define REG_OFFSET(reg) (int)(&((struct i386_thread_state *)0)->reg)
72 // OBSOLETE /* at reg_offset[i] is the offset to the i386_thread_state
73 // OBSOLETE * location where the gdb registers[i] is stored.
76 // OBSOLETE static int reg_offset[] =
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)
84 // OBSOLETE #define REG_ADDRESS(state,regnum) ((char *)(state)+reg_offset[regnum])
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.
89 // OBSOLETE #define FETCH_REGS(state, regnum, count) \
90 // OBSOLETE memcpy (®isters[REGISTER_BYTE (regnum)], \
91 // OBSOLETE REG_ADDRESS (state, regnum), \
92 // OBSOLETE count*REGISTER_SIZE)
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 ®isters[REGISTER_BYTE (regnum)], \
98 // OBSOLETE count*REGISTER_SIZE)
101 // OBSOLETE * Fetch inferiors registers for gdb.
102 // OBSOLETE * REGNO specifies which (as gdb views it) register, -1 for all.
106 // OBSOLETE fetch_inferior_registers (int regno)
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;
113 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
114 // OBSOLETE error ("fetch inferior registers: Invalid thread");
116 // OBSOLETE if (must_suspend_thread)
117 // OBSOLETE setup_thread (current_thread, 1);
119 // OBSOLETE ret = thread_get_state (current_thread,
120 // OBSOLETE i386_THREAD_STATE,
122 // OBSOLETE &stateCnt);
124 // OBSOLETE if (ret != KERN_SUCCESS)
125 // OBSOLETE warning ("fetch_inferior_registers: %s ",
126 // OBSOLETE mach_error_string (ret));
128 // OBSOLETE /* It may be more effective to store validate all of them,
129 // OBSOLETE * since we fetched them all anyway
131 // OBSOLETE else if (regno != -1)
132 // OBSOLETE supply_register (regno, (char *) state + reg_offset[regno]);
136 // OBSOLETE for (index = 0; index < NUM_REGS; index++)
137 // OBSOLETE supply_register (index, (char *) state + reg_offset[index]);
140 // OBSOLETE if (must_suspend_thread)
141 // OBSOLETE setup_thread (current_thread, 0);
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
148 // OBSOLETE * On mach3 all registers are always saved in one call.
151 // OBSOLETE store_inferior_registers (int regno)
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;
158 // OBSOLETE if (!MACH_PORT_VALID (current_thread))
159 // OBSOLETE error ("store inferior registers: Invalid thread");
161 // OBSOLETE if (must_suspend_thread)
162 // OBSOLETE setup_thread (current_thread, 1);
164 // OBSOLETE /* Fetch the state of the current thread */
165 // OBSOLETE ret = thread_get_state (current_thread,
166 // OBSOLETE i386_THREAD_STATE,
168 // OBSOLETE &stateCnt);
170 // OBSOLETE if (ret != KERN_SUCCESS)
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);
179 // OBSOLETE /* move gdb's registers to thread's state
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)
186 // OBSOLETE if (regno != -1)
187 // OBSOLETE STORE_REGS (state, regno, 1);
191 // OBSOLETE for (index = 0; index < NUM_REGS; index++)
192 // OBSOLETE STORE_REGS (state, index, 1);
195 // OBSOLETE /* Write gdb's current view of register to the thread
197 // OBSOLETE ret = thread_set_state (current_thread,
198 // OBSOLETE i386_THREAD_STATE,
200 // OBSOLETE i386_THREAD_STATE_COUNT);
202 // OBSOLETE if (ret != KERN_SUCCESS)
203 // OBSOLETE warning ("store_inferior_registers (set): %s",
204 // OBSOLETE mach_error_string (ret));
206 // OBSOLETE if (must_suspend_thread)
207 // OBSOLETE setup_thread (current_thread, 0);
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?
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.
220 // OBSOLETE * Called by core-aout.c(fetch_core_registers)
223 // OBSOLETE CORE_ADDR
224 // OBSOLETE register_addr (int regno, CORE_ADDR blockend)
226 // OBSOLETE CORE_ADDR addr;
228 // OBSOLETE if (regno < 0 || regno >= NUM_REGS)
229 // OBSOLETE error ("Invalid register number %d.", regno);
231 // OBSOLETE /* UAREA_SIZE == 8 kB in i386 */
232 // OBSOLETE addr = (unsigned int) REG_ADDRESS (UAREA_SIZE - sizeof (struct i386_thread_state), regno);
234 // OBSOLETE return addr;
238 // OBSOLETE * gdb/i386-xdep.c. Modifications for Mach 3.0.
240 // OBSOLETE * i387 status dumper. See also i387-tdep.c
242 // OBSOLETE struct env387
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];
258 // OBSOLETE /* This routine is machine independent?
259 // OBSOLETE * Should move it to i387-tdep.c but you need to export struct env387
262 // OBSOLETE print_387_status (unsigned short status, struct env387 *ep)
265 // OBSOLETE int bothstatus;
267 // OBSOLETE int fpreg;
268 // OBSOLETE unsigned char *p;
270 // OBSOLETE bothstatus = ((status != 0) && (ep->status != 0));
271 // OBSOLETE if (status != 0)
273 // OBSOLETE if (bothstatus)
274 // OBSOLETE printf_unfiltered ("u: ");
275 // OBSOLETE print_387_status_word (status);
278 // OBSOLETE if (ep->status != 0)
280 // OBSOLETE if (bothstatus)
281 // OBSOLETE printf_unfiltered ("e: ");
282 // OBSOLETE print_387_status_word (ep->status);
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));
293 // OBSOLETE top = (ep->status >> 11) & 7;
295 // OBSOLETE printf_unfiltered ("regno tag msb lsb value\n");
296 // OBSOLETE for (fpreg = 7; fpreg >= 0; fpreg--)
298 // OBSOLETE double val;
300 // OBSOLETE printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
302 // OBSOLETE switch ((ep->tag >> (fpreg * 2)) & 3)
305 // OBSOLETE printf_unfiltered ("valid ");
308 // OBSOLETE printf_unfiltered ("zero ");
311 // OBSOLETE printf_unfiltered ("trap ");
314 // OBSOLETE printf_unfiltered ("empty ");
317 // OBSOLETE for (i = 9; i >= 0; i--)
318 // OBSOLETE printf_unfiltered ("%02x", ep->regs[fpreg][i]);
320 // OBSOLETE floatformat_to_double (&floatformat_i387_ext, (char *) ep->regs[fpreg],
322 // OBSOLETE printf_unfiltered (" %g\n", val);
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));
335 // OBSOLETE * values that go into fp_kind (from <i386/fpreg.h>)
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 */
343 // OBSOLETE typedef struct fpstate
346 // OBSOLETE unsigned char state[FP_STATE_BYTES]; /* "hardware" state */
348 // OBSOLETE struct env387 state; /* Actually this */
350 // OBSOLETE int status; /* Duplicate status */
352 // OBSOLETE *fpstate_t;
354 // OBSOLETE /* Mach 3 specific routines.
356 // OBSOLETE private boolean_t
357 // OBSOLETE get_i387_state (struct fpstate *fstate)
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;
364 // OBSOLETE ret = thread_get_state (current_thread,
365 // OBSOLETE i386_FLOAT_STATE,
369 // OBSOLETE if (ret != KERN_SUCCESS)
371 // OBSOLETE warning ("Can not get live floating point state: %s",
372 // OBSOLETE mach_error_string (ret));
373 // OBSOLETE return FALSE;
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;
381 // OBSOLETE /* Clear the target then copy thread's float state there.
382 // OBSOLETE Make a copy of the status word, for some reason?
384 // OBSOLETE memset (fstate, 0, sizeof (struct fpstate));
386 // OBSOLETE fstate->status = fsp->exc_status;
388 // OBSOLETE memcpy (fstate->state, (char *) &fsp->hw_state, FP_STATE_BYTES);
390 // OBSOLETE return TRUE;
393 // OBSOLETE private boolean_t
394 // OBSOLETE get_i387_core_state (struct fpstate *fstate)
396 // OBSOLETE /* Not implemented yet. Core files do not contain float state. */
397 // OBSOLETE return FALSE;
401 // OBSOLETE * This is called by "info float" command
404 // OBSOLETE i386_mach3_float_info (void)
406 // OBSOLETE char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
407 // OBSOLETE boolean_t valid = FALSE;
408 // OBSOLETE fpstate_t fps;
410 // OBSOLETE if (target_has_execution)
411 // OBSOLETE valid = get_i387_state (buf);
413 // OBSOLETE else if (WE HAVE CORE FILE) /* @@@@ Core files not supported */
414 // OBSOLETE valid = get_i387_core_state (buf);
417 // OBSOLETE if (!valid)
419 // OBSOLETE warning ("no floating point status saved");
423 // OBSOLETE fps = (fpstate_t) buf;
425 // OBSOLETE print_387_status (fps->status, (struct env387 *) fps->state);