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, Boston, MA 02111-1307, USA. */
22 #include "floatformat.h"
28 #include <mach/message.h>
29 #include <mach/exception.h>
30 #include <mach_error.h>
34 /* Hmmm... Should this not be here?
35 * Now for i386_float_info() target_has_execution
39 /* @@@ Should move print_387_status() to i387-tdep.c */
40 extern void print_387_control_word (); /* i387-tdep.h */
41 extern void print_387_status_word ();
43 /* Find offsets to thread states at compile time.
44 * If your compiler does not grok this, calculate offsets
45 * offsets yourself and use them (or get a compatible compiler :-)
48 #define REG_OFFSET(reg) (int)(&((struct i386_thread_state *)0)->reg)
50 /* at reg_offset[i] is the offset to the i386_thread_state
51 * location where the gdb registers[i] is stored.
54 static int reg_offset
[] =
56 REG_OFFSET(eax
), REG_OFFSET(ecx
), REG_OFFSET(edx
), REG_OFFSET(ebx
),
57 REG_OFFSET(uesp
), REG_OFFSET(ebp
), REG_OFFSET(esi
), REG_OFFSET(edi
),
58 REG_OFFSET(eip
), REG_OFFSET(efl
), REG_OFFSET(cs
), REG_OFFSET(ss
),
59 REG_OFFSET(ds
), REG_OFFSET(es
), REG_OFFSET(fs
), REG_OFFSET(gs
)
62 #define REG_ADDR(state,regnum) ((char *)(state)+reg_offset[regnum])
64 /* Fetch COUNT contiguous registers from thread STATE starting from REGNUM
65 * Caller knows that the regs handled in one transaction are of same size.
67 #define FETCH_REGS(state, regnum, count) \
68 memcpy (®isters[REGISTER_BYTE (regnum)], \
69 REG_ADDR (state, regnum), \
70 count * REGISTER_RAW_SIZE (regnum))
72 /* Store COUNT contiguous registers to thread STATE starting from REGNUM */
73 #define STORE_REGS(state, regnum, count) \
74 memcpy (REG_ADDR (state, regnum), \
75 ®isters[REGISTER_BYTE (regnum)], \
76 count * REGISTER_RAW_SIZE (regnum))
79 * Fetch inferiors registers for gdb.
80 * REG specifies which (as gdb views it) register, -1 for all.
83 gnu_fetch_registers (int reg
)
88 inf_update_procs (current_inferior
); /* Make sure we know about new threads. */
90 thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
92 error ("fetch inferior registers: %d: Invalid thread", inferior_pid
);
94 state
= proc_get_state (thread
, 0);
97 warning ("Couldn't fetch register %s from %s (invalid thread).",
98 REGISTER_NAME (reg
), proc_string (thread
));
101 proc_debug (thread
, "fetching register: %s", REGISTER_NAME (reg
));
102 supply_register (reg
, REG_ADDR(state
, reg
));
103 thread
->fetched_regs
|= (1 << reg
);
107 proc_debug (thread
, "fetching all registers");
108 for (reg
= 0; reg
< NUM_REGS
; reg
++)
109 supply_register (reg
, REG_ADDR(state
, reg
));
110 thread
->fetched_regs
= ~0;
114 /* Store our register values back into the inferior.
115 * If REG is -1, do this for all registers.
116 * Otherwise, REG specifies which register
118 * On mach3 all registers are always saved in one call.
121 gnu_store_registers (reg
)
125 int was_aborted
, was_valid
;
126 thread_state_t state
;
127 thread_state_data_t old_state
;
129 inf_update_procs (current_inferior
); /* Make sure we know about new threads. */
131 thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
133 error ("store inferior registers: %d: Invalid thread", inferior_pid
);
135 proc_debug (thread
, "storing register %s.", REGISTER_NAME (reg
));
137 was_aborted
= thread
->aborted
;
138 was_valid
= thread
->state_valid
;
139 if (! was_aborted
&& was_valid
)
140 bcopy (&thread
->state
, &old_state
, sizeof (old_state
));
142 state
= proc_get_state (thread
, 1);
145 warning ("Couldn't store register %s from %s (invalid thread).",
146 REGISTER_NAME (reg
), proc_string (thread
));
149 if (! was_aborted
&& was_valid
)
150 /* See which registers have changed after aborting the thread. */
153 for (check_reg
= 0; check_reg
< NUM_REGS
; check_reg
++)
154 if ((thread
->fetched_regs
& (1 << check_reg
))
155 && bcmp (REG_ADDR (&old_state
, check_reg
),
156 REG_ADDR (state
, check_reg
),
157 REGISTER_RAW_SIZE (check_reg
)))
158 /* Register CHECK_REG has changed! Ack! */
160 warning ("Register %s changed after thread was aborted.",
161 REGISTER_NAME (check_reg
));
162 if (reg
>= 0 && reg
!= check_reg
)
163 /* Update gdb's copy of the register. */
164 supply_register (check_reg
, REG_ADDR (state
, check_reg
));
166 warning ("... also writing this register! Suspicious...");
172 proc_debug (thread
, "storing register: %s", REGISTER_NAME (reg
));
173 STORE_REGS (state
, reg
, 1);
177 proc_debug (thread
, "storing all registers");
178 for (reg
= 0; reg
< NUM_REGS
; reg
++)
179 STORE_REGS (state
, reg
, 1);
184 /* jtv@hut.fi: I copied and modified this 387 code from
185 * gdb/i386-xdep.c. Modifications for Mach 3.0.
187 * i387 status dumper. See also i387-tdep.c
191 unsigned short control
;
193 unsigned short status
;
198 unsigned short code_seg
;
199 unsigned short opcode
;
200 unsigned long operand
;
201 unsigned short operand_seg
;
203 unsigned char regs
[8][10];
205 /* This routine is machine independent?
206 * Should move it to i387-tdep.c but you need to export struct env387
209 print_387_status (status
, ep
)
210 unsigned short status
;
219 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
223 printf_unfiltered ("u: ");
224 print_387_status_word (status
);
230 printf_unfiltered ("e: ");
231 print_387_status_word (ep
->status
);
234 print_387_control_word (ep
->control
);
235 printf_unfiltered ("last exception: ");
236 printf_unfiltered ("opcode %s; ", local_hex_string(ep
->opcode
));
237 printf_unfiltered ("pc %s:", local_hex_string(ep
->code_seg
));
238 printf_unfiltered ("%s; ", local_hex_string(ep
->eip
));
239 printf_unfiltered ("operand %s", local_hex_string(ep
->operand_seg
));
240 printf_unfiltered (":%s\n", local_hex_string(ep
->operand
));
242 top
= (ep
->status
>> 11) & 7;
244 printf_unfiltered ("regno tag msb lsb value\n");
245 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
249 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
251 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
253 case 0: printf_unfiltered ("valid "); break;
254 case 1: printf_unfiltered ("zero "); break;
255 case 2: printf_unfiltered ("trap "); break;
256 case 3: printf_unfiltered ("empty "); break;
258 for (i
= 9; i
>= 0; i
--)
259 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
261 floatformat_to_double (&floatformat_i387_ext
, (char *)ep
->regs
[fpreg
],
263 printf_unfiltered (" %g\n", val
);
266 printf_unfiltered ("warning: reserved0 is %s\n", local_hex_string(ep
->r0
));
268 printf_unfiltered ("warning: reserved1 is %s\n", local_hex_string(ep
->r1
));
270 printf_unfiltered ("warning: reserved2 is %s\n", local_hex_string(ep
->r2
));
272 printf_unfiltered ("warning: reserved3 is %s\n", local_hex_string(ep
->r3
));
276 * values that go into fp_kind (from <i386/fpreg.h>)
278 #define FP_NO 0 /* no fp chip, no emulator (no fp support) */
279 #define FP_SW 1 /* no fp chip, using software emulator */
280 #define FP_HW 2 /* chip present bit */
281 #define FP_287 2 /* 80287 chip present */
282 #define FP_387 3 /* 80387 chip present */
284 typedef struct fpstate
{
286 unsigned char state
[FP_STATE_BYTES
]; /* "hardware" state */
288 struct env387 state
; /* Actually this */
290 int status
; /* Duplicate status */
293 /* Mach 3 specific routines.
296 get_i387_state (fstate
)
297 struct fpstate
*fstate
;
300 thread_state_data_t state
;
301 unsigned int fsCnt
= i386_FLOAT_STATE_COUNT
;
302 struct i386_float_state
*fsp
;
303 struct proc
*thread
= inf_tid_to_thread (current_inferior
, inferior_pid
);
306 error ("get_i387_state: Invalid thread");
308 proc_abort (thread
, 0); /* Make sure THREAD's in a reasonable state. */
310 err
= thread_get_state (thread
->port
, i386_FLOAT_STATE
, state
, &fsCnt
);
313 warning ("Can not get live floating point state: %s",
314 mach_error_string (err
));
318 fsp
= (struct i386_float_state
*)state
;
319 /* The 387 chip (also 486 counts) or a software emulator? */
320 if (!fsp
->initialized
|| (fsp
->fpkind
!= FP_387
&& fsp
->fpkind
!= FP_SW
))
323 /* Clear the target then copy thread's float state there.
324 Make a copy of the status word, for some reason?
326 memset (fstate
, 0, sizeof (struct fpstate
));
328 fstate
->status
= fsp
->exc_status
;
330 memcpy (fstate
->state
, (char *)&fsp
->hw_state
, FP_STATE_BYTES
);
336 * This is called by "info float" command
339 i386_mach3_float_info()
341 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
345 if (target_has_execution
)
346 valid
= get_i387_state (buf
);
350 warning ("no floating point status saved");
354 fps
= (fpstate_t
) buf
;
356 print_387_status (fps
->status
, (struct env387
*)fps
->state
);