1 /* Low level interface to I386 running the GNU Hurd
2 Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
23 #include "floatformat.h"
29 #include <mach/message.h>
30 #include <mach/exception.h>
31 #include <mach_error.h>
35 /* Hmmm... Should this not be here?
36 * Now for i386_float_info() target_has_execution
40 /* @@@ Should move print_387_status() to i387-tdep.c */
41 extern void print_387_control_word (); /* i387-tdep.h */
42 extern void print_387_status_word ();
44 /* Find offsets to thread states at compile time.
45 * If your compiler does not grok this, calculate offsets
46 * offsets yourself and use them (or get a compatible compiler :-)
49 #define REG_OFFSET(reg) (int)(&((struct i386_thread_state *)0)->reg)
51 /* at reg_offset[i] is the offset to the i386_thread_state
52 * location where the gdb registers[i] is stored.
55 static int reg_offset
[] =
57 REG_OFFSET (eax
), REG_OFFSET (ecx
), REG_OFFSET (edx
), REG_OFFSET (ebx
),
58 REG_OFFSET (uesp
), REG_OFFSET (ebp
), REG_OFFSET (esi
), REG_OFFSET (edi
),
59 REG_OFFSET (eip
), REG_OFFSET (efl
), REG_OFFSET (cs
), REG_OFFSET (ss
),
60 REG_OFFSET (ds
), REG_OFFSET (es
), REG_OFFSET (fs
), REG_OFFSET (gs
)
63 #define REG_ADDR(state,regnum) ((char *)(state)+reg_offset[regnum])
65 /* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
66 * Caller knows that the regs handled in one transaction are of same size.
68 #define FETCH_REGS(state, regnum, count) \
69 memcpy (®isters[REGISTER_BYTE (regnum)], \
70 REG_ADDR (state, regnum), \
71 count * REGISTER_RAW_SIZE (regnum))
73 /* Store COUNT contiguous registers to thread STATE starting from REGNUM */
74 #define STORE_REGS(state, regnum, count) \
75 memcpy (REG_ADDR (state, regnum), \
76 ®isters[REGISTER_BYTE (regnum)], \
77 count * REGISTER_RAW_SIZE (regnum))
80 * Fetch inferiors registers for gdb.
81 * REG specifies which (as gdb views it) register, -1 for all.
84 gnu_fetch_registers (int reg
)
89 inf_update_procs (current_inferior
); /* Make sure we know about new threads. */
91 thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
93 error ("fetch inferior registers: %d: Invalid thread", inferior_pid
);
95 state
= proc_get_state (thread
, 0);
98 warning ("Couldn't fetch register %s from %s (invalid thread).",
99 REGISTER_NAME (reg
), proc_string (thread
));
102 proc_debug (thread
, "fetching register: %s", REGISTER_NAME (reg
));
103 supply_register (reg
, REG_ADDR (state
, reg
));
104 thread
->fetched_regs
|= (1 << reg
);
108 proc_debug (thread
, "fetching all registers");
109 for (reg
= 0; reg
< NUM_REGS
; reg
++)
110 supply_register (reg
, REG_ADDR (state
, reg
));
111 thread
->fetched_regs
= ~0;
115 /* Store our register values back into the inferior.
116 * If REG is -1, do this for all registers.
117 * Otherwise, REG specifies which register
119 * On mach3 all registers are always saved in one call.
122 gnu_store_registers (reg
)
126 int was_aborted
, was_valid
;
127 thread_state_t state
;
128 thread_state_data_t old_state
;
130 inf_update_procs (current_inferior
); /* Make sure we know about new threads. */
132 thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
134 error ("store inferior registers: %d: Invalid thread", inferior_pid
);
136 proc_debug (thread
, "storing register %s.", REGISTER_NAME (reg
));
138 was_aborted
= thread
->aborted
;
139 was_valid
= thread
->state_valid
;
140 if (!was_aborted
&& was_valid
)
141 bcopy (&thread
->state
, &old_state
, sizeof (old_state
));
143 state
= proc_get_state (thread
, 1);
146 warning ("Couldn't store register %s from %s (invalid thread).",
147 REGISTER_NAME (reg
), proc_string (thread
));
150 if (!was_aborted
&& was_valid
)
151 /* See which registers have changed after aborting the thread. */
154 for (check_reg
= 0; check_reg
< NUM_REGS
; check_reg
++)
155 if ((thread
->fetched_regs
& (1 << check_reg
))
156 && bcmp (REG_ADDR (&old_state
, check_reg
),
157 REG_ADDR (state
, check_reg
),
158 REGISTER_RAW_SIZE (check_reg
)))
159 /* Register CHECK_REG has changed! Ack! */
161 warning ("Register %s changed after thread was aborted.",
162 REGISTER_NAME (check_reg
));
163 if (reg
>= 0 && reg
!= check_reg
)
164 /* Update gdb's copy of the register. */
165 supply_register (check_reg
, REG_ADDR (state
, check_reg
));
167 warning ("... also writing this register! Suspicious...");
173 proc_debug (thread
, "storing register: %s", REGISTER_NAME (reg
));
174 STORE_REGS (state
, reg
, 1);
178 proc_debug (thread
, "storing all registers");
179 for (reg
= 0; reg
< NUM_REGS
; reg
++)
180 STORE_REGS (state
, reg
, 1);
185 /* jtv@hut.fi: I copied and modified this 387 code from
186 * gdb/i386-xdep.c. Modifications for Mach 3.0.
188 * i387 status dumper. See also i387-tdep.c
192 unsigned short control
;
194 unsigned short status
;
199 unsigned short code_seg
;
200 unsigned short opcode
;
201 unsigned long operand
;
202 unsigned short operand_seg
;
204 unsigned char regs
[8][10];
206 /* This routine is machine independent?
207 * Should move it to i387-tdep.c but you need to export struct env387
210 print_387_status (status
, ep
)
211 unsigned short status
;
220 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
224 printf_unfiltered ("u: ");
225 print_387_status_word (status
);
231 printf_unfiltered ("e: ");
232 print_387_status_word (ep
->status
);
235 print_387_control_word (ep
->control
);
236 printf_unfiltered ("last exception: ");
237 printf_unfiltered ("opcode %s; ", local_hex_string (ep
->opcode
));
238 printf_unfiltered ("pc %s:", local_hex_string (ep
->code_seg
));
239 printf_unfiltered ("%s; ", local_hex_string (ep
->eip
));
240 printf_unfiltered ("operand %s", local_hex_string (ep
->operand_seg
));
241 printf_unfiltered (":%s\n", local_hex_string (ep
->operand
));
243 top
= (ep
->status
>> 11) & 7;
245 printf_unfiltered ("regno tag msb lsb value\n");
246 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
250 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
252 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
255 printf_unfiltered ("valid ");
258 printf_unfiltered ("zero ");
261 printf_unfiltered ("trap ");
264 printf_unfiltered ("empty ");
267 for (i
= 9; i
>= 0; i
--)
268 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
270 floatformat_to_double (&floatformat_i387_ext
, (char *) ep
->regs
[fpreg
],
272 printf_unfiltered (" %g\n", val
);
275 printf_unfiltered ("warning: reserved0 is %s\n", local_hex_string (ep
->r0
));
277 printf_unfiltered ("warning: reserved1 is %s\n", local_hex_string (ep
->r1
));
279 printf_unfiltered ("warning: reserved2 is %s\n", local_hex_string (ep
->r2
));
281 printf_unfiltered ("warning: reserved3 is %s\n", local_hex_string (ep
->r3
));
285 * values that go into fp_kind (from <i386/fpreg.h>)
287 #define FP_NO 0 /* no fp chip, no emulator (no fp support) */
288 #define FP_SW 1 /* no fp chip, using software emulator */
289 #define FP_HW 2 /* chip present bit */
290 #define FP_287 2 /* 80287 chip present */
291 #define FP_387 3 /* 80387 chip present */
293 typedef struct fpstate
296 unsigned char state
[FP_STATE_BYTES
]; /* "hardware" state */
298 struct env387 state
; /* Actually this */
300 int status
; /* Duplicate status */
304 /* Mach 3 specific routines.
307 get_i387_state (fstate
)
308 struct fpstate
*fstate
;
311 thread_state_data_t state
;
312 unsigned int fsCnt
= i386_FLOAT_STATE_COUNT
;
313 struct i386_float_state
*fsp
;
314 struct proc
*thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
317 error ("get_i387_state: Invalid thread");
319 proc_abort (thread
, 0); /* Make sure THREAD's in a reasonable state. */
321 err
= thread_get_state (thread
->port
, i386_FLOAT_STATE
, state
, &fsCnt
);
324 warning ("Can not get live floating point state: %s",
325 mach_error_string (err
));
329 fsp
= (struct i386_float_state
*) state
;
330 /* The 387 chip (also 486 counts) or a software emulator? */
331 if (!fsp
->initialized
|| (fsp
->fpkind
!= FP_387
&& fsp
->fpkind
!= FP_SW
))
334 /* Clear the target then copy thread's float state there.
335 Make a copy of the status word, for some reason?
337 memset (fstate
, 0, sizeof (struct fpstate
));
339 fstate
->status
= fsp
->exc_status
;
341 memcpy (fstate
->state
, (char *) &fsp
->hw_state
, FP_STATE_BYTES
);
347 * This is called by "info float" command
350 i386_mach3_float_info ()
352 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
356 if (target_has_execution
)
357 valid
= get_i387_state (buf
);
361 warning ("no floating point status saved");
365 fps
= (fpstate_t
) buf
;
367 print_387_status (fps
->status
, (struct env387
*) fps
->state
);