* i387-tdep.c (fxsave_offset): Add entries for %xmm8-%xmm15.
[deliverable/binutils-gdb.git] / gdb / i387-tdep.c
1 /* Intel 387 floating point stuff.
2
3 Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1998, 1999, 2000,
4 2001, 2002, 2003 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "frame.h"
25 #include "inferior.h"
26 #include "language.h"
27 #include "value.h"
28 #include "gdbcore.h"
29 #include "floatformat.h"
30 #include "regcache.h"
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
33 #include "doublest.h"
34
35 #include "i386-tdep.h"
36
37 \f
38 /* FIXME: The functions on this page are used by the old `info float'
39 implementations that a few of the i386 targets provide. These
40 functions should be removed if all of these have been converted to
41 use the generic implementation based on the new register file
42 layout. */
43
44 static void print_387_control_bits (unsigned int control);
45 static void print_387_status_bits (unsigned int status);
46
47 static void
48 print_387_control_bits (unsigned int control)
49 {
50 switch ((control >> 8) & 3)
51 {
52 case 0:
53 puts_unfiltered (" 24 bit; ");
54 break;
55 case 1:
56 puts_unfiltered (" (bad); ");
57 break;
58 case 2:
59 puts_unfiltered (" 53 bit; ");
60 break;
61 case 3:
62 puts_unfiltered (" 64 bit; ");
63 break;
64 }
65 switch ((control >> 10) & 3)
66 {
67 case 0:
68 puts_unfiltered ("NEAR; ");
69 break;
70 case 1:
71 puts_unfiltered ("DOWN; ");
72 break;
73 case 2:
74 puts_unfiltered ("UP; ");
75 break;
76 case 3:
77 puts_unfiltered ("CHOP; ");
78 break;
79 }
80 if (control & 0x3f)
81 {
82 puts_unfiltered ("mask");
83 if (control & 0x0001)
84 puts_unfiltered (" INVAL");
85 if (control & 0x0002)
86 puts_unfiltered (" DENOR");
87 if (control & 0x0004)
88 puts_unfiltered (" DIVZ");
89 if (control & 0x0008)
90 puts_unfiltered (" OVERF");
91 if (control & 0x0010)
92 puts_unfiltered (" UNDER");
93 if (control & 0x0020)
94 puts_unfiltered (" LOS");
95 puts_unfiltered (";");
96 }
97
98 if (control & 0xe080)
99 warning ("\nreserved bits on: %s",
100 local_hex_string (control & 0xe080));
101 }
102
103 void
104 print_387_control_word (unsigned int control)
105 {
106 printf_filtered ("control %s:", local_hex_string(control & 0xffff));
107 print_387_control_bits (control);
108 puts_unfiltered ("\n");
109 }
110
111 static void
112 print_387_status_bits (unsigned int status)
113 {
114 printf_unfiltered (" flags %d%d%d%d; ",
115 (status & 0x4000) != 0,
116 (status & 0x0400) != 0,
117 (status & 0x0200) != 0,
118 (status & 0x0100) != 0);
119 printf_unfiltered ("top %d; ", (status >> 11) & 7);
120 if (status & 0xff)
121 {
122 puts_unfiltered ("excep");
123 if (status & 0x0001) puts_unfiltered (" INVAL");
124 if (status & 0x0002) puts_unfiltered (" DENOR");
125 if (status & 0x0004) puts_unfiltered (" DIVZ");
126 if (status & 0x0008) puts_unfiltered (" OVERF");
127 if (status & 0x0010) puts_unfiltered (" UNDER");
128 if (status & 0x0020) puts_unfiltered (" LOS");
129 if (status & 0x0040) puts_unfiltered (" STACK");
130 }
131 }
132
133 void
134 print_387_status_word (unsigned int status)
135 {
136 printf_filtered ("status %s:", local_hex_string (status & 0xffff));
137 print_387_status_bits (status);
138 puts_unfiltered ("\n");
139 }
140
141 \f
142 /* Implement the `info float' layout based on the register definitions
143 in `tm-i386.h'. */
144
145 /* Print the floating point number specified by RAW. */
146 static void
147 print_i387_value (char *raw, struct ui_file *file)
148 {
149 DOUBLEST value;
150
151 /* Using extract_typed_floating here might affect the representation
152 of certain numbers such as NaNs, even if GDB is running natively.
153 This is fine since our caller already detects such special
154 numbers and we print the hexadecimal representation anyway. */
155 value = extract_typed_floating (raw, builtin_type_i387_ext);
156
157 /* We try to print 19 digits. The last digit may or may not contain
158 garbage, but we'd better print one too many. We need enough room
159 to print the value, 1 position for the sign, 1 for the decimal
160 point, 19 for the digits and 6 for the exponent adds up to 27. */
161 #ifdef PRINTF_HAS_LONG_DOUBLE
162 fprintf_filtered (file, " %-+27.19Lg", (long double) value);
163 #else
164 fprintf_filtered (file, " %-+27.19g", (double) value);
165 #endif
166 }
167
168 /* Print the classification for the register contents RAW. */
169 static void
170 print_i387_ext (unsigned char *raw, struct ui_file *file)
171 {
172 int sign;
173 int integer;
174 unsigned int exponent;
175 unsigned long fraction[2];
176
177 sign = raw[9] & 0x80;
178 integer = raw[7] & 0x80;
179 exponent = (((raw[9] & 0x7f) << 8) | raw[8]);
180 fraction[0] = ((raw[3] << 24) | (raw[2] << 16) | (raw[1] << 8) | raw[0]);
181 fraction[1] = (((raw[7] & 0x7f) << 24) | (raw[6] << 16)
182 | (raw[5] << 8) | raw[4]);
183
184 if (exponent == 0x7fff && integer)
185 {
186 if (fraction[0] == 0x00000000 && fraction[1] == 0x00000000)
187 /* Infinity. */
188 fprintf_filtered (file, " %cInf", (sign ? '-' : '+'));
189 else if (sign && fraction[0] == 0x00000000 && fraction[1] == 0x40000000)
190 /* Real Indefinite (QNaN). */
191 fputs_unfiltered (" Real Indefinite (QNaN)", file);
192 else if (fraction[1] & 0x40000000)
193 /* QNaN. */
194 fputs_filtered (" QNaN", file);
195 else
196 /* SNaN. */
197 fputs_filtered (" SNaN", file);
198 }
199 else if (exponent < 0x7fff && exponent > 0x0000 && integer)
200 /* Normal. */
201 print_i387_value (raw, file);
202 else if (exponent == 0x0000)
203 {
204 /* Denormal or zero. */
205 print_i387_value (raw, file);
206
207 if (integer)
208 /* Pseudo-denormal. */
209 fputs_filtered (" Pseudo-denormal", file);
210 else if (fraction[0] || fraction[1])
211 /* Denormal. */
212 fputs_filtered (" Denormal", file);
213 }
214 else
215 /* Unsupported. */
216 fputs_filtered (" Unsupported", file);
217 }
218
219 /* Print the status word STATUS. */
220 static void
221 print_i387_status_word (unsigned int status, struct ui_file *file)
222 {
223 fprintf_filtered (file, "Status Word: %s",
224 local_hex_string_custom (status, "04"));
225 fputs_filtered (" ", file);
226 fprintf_filtered (file, " %s", (status & 0x0001) ? "IE" : " ");
227 fprintf_filtered (file, " %s", (status & 0x0002) ? "DE" : " ");
228 fprintf_filtered (file, " %s", (status & 0x0004) ? "ZE" : " ");
229 fprintf_filtered (file, " %s", (status & 0x0008) ? "OE" : " ");
230 fprintf_filtered (file, " %s", (status & 0x0010) ? "UE" : " ");
231 fprintf_filtered (file, " %s", (status & 0x0020) ? "PE" : " ");
232 fputs_filtered (" ", file);
233 fprintf_filtered (file, " %s", (status & 0x0080) ? "ES" : " ");
234 fputs_filtered (" ", file);
235 fprintf_filtered (file, " %s", (status & 0x0040) ? "SF" : " ");
236 fputs_filtered (" ", file);
237 fprintf_filtered (file, " %s", (status & 0x0100) ? "C0" : " ");
238 fprintf_filtered (file, " %s", (status & 0x0200) ? "C1" : " ");
239 fprintf_filtered (file, " %s", (status & 0x0400) ? "C2" : " ");
240 fprintf_filtered (file, " %s", (status & 0x4000) ? "C3" : " ");
241
242 fputs_filtered ("\n", file);
243
244 fprintf_filtered (file,
245 " TOP: %d\n", ((status >> 11) & 7));
246 }
247
248 /* Print the control word CONTROL. */
249 static void
250 print_i387_control_word (unsigned int control, struct ui_file *file)
251 {
252 fprintf_filtered (file, "Control Word: %s",
253 local_hex_string_custom (control, "04"));
254 fputs_filtered (" ", file);
255 fprintf_filtered (file, " %s", (control & 0x0001) ? "IM" : " ");
256 fprintf_filtered (file, " %s", (control & 0x0002) ? "DM" : " ");
257 fprintf_filtered (file, " %s", (control & 0x0004) ? "ZM" : " ");
258 fprintf_filtered (file, " %s", (control & 0x0008) ? "OM" : " ");
259 fprintf_filtered (file, " %s", (control & 0x0010) ? "UM" : " ");
260 fprintf_filtered (file, " %s", (control & 0x0020) ? "PM" : " ");
261
262 fputs_filtered ("\n", file);
263
264 fputs_filtered (" PC: ", file);
265 switch ((control >> 8) & 3)
266 {
267 case 0:
268 fputs_filtered ("Single Precision (24-bits)\n", file);
269 break;
270 case 1:
271 fputs_filtered ("Reserved\n", file);
272 break;
273 case 2:
274 fputs_filtered ("Double Precision (53-bits)\n", file);
275 break;
276 case 3:
277 fputs_filtered ("Extended Precision (64-bits)\n", file);
278 break;
279 }
280
281 fputs_filtered (" RC: ", file);
282 switch ((control >> 10) & 3)
283 {
284 case 0:
285 fputs_filtered ("Round to nearest\n", file);
286 break;
287 case 1:
288 fputs_filtered ("Round down\n", file);
289 break;
290 case 2:
291 fputs_filtered ("Round up\n", file);
292 break;
293 case 3:
294 fputs_filtered ("Round toward zero\n", file);
295 break;
296 }
297 }
298
299 /* Print out the i387 floating point state. Note that we ignore FRAME
300 in the code below. That's OK since floating-point registers are
301 never saved on the stack. */
302
303 void
304 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
305 struct frame_info *frame, const char *args)
306 {
307 char buf[4];
308 ULONGEST fctrl;
309 ULONGEST fstat;
310 ULONGEST ftag;
311 ULONGEST fiseg;
312 ULONGEST fioff;
313 ULONGEST foseg;
314 ULONGEST fooff;
315 ULONGEST fop;
316 int fpreg;
317 int top;
318
319 frame_register_read (frame, FCTRL_REGNUM, buf);
320 fctrl = extract_unsigned_integer (buf, 4);
321 frame_register_read (frame, FSTAT_REGNUM, buf);
322 fstat = extract_unsigned_integer (buf, 4);
323 frame_register_read (frame, FTAG_REGNUM, buf);
324 ftag = extract_unsigned_integer (buf, 4);
325 frame_register_read (frame, FISEG_REGNUM, buf);
326 fiseg = extract_unsigned_integer (buf, 4);
327 frame_register_read (frame, FIOFF_REGNUM, buf);
328 fioff = extract_unsigned_integer (buf, 4);
329 frame_register_read (frame, FOSEG_REGNUM, buf);
330 foseg = extract_unsigned_integer (buf, 4);
331 frame_register_read (frame, FOOFF_REGNUM, buf);
332 fooff = extract_unsigned_integer (buf, 4);
333 frame_register_read (frame, FOP_REGNUM, buf);
334 fop = extract_unsigned_integer (buf, 4);
335
336 top = ((fstat >> 11) & 7);
337
338 for (fpreg = 7; fpreg >= 0; fpreg--)
339 {
340 unsigned char raw[FPU_REG_RAW_SIZE];
341 int tag = (ftag >> (fpreg * 2)) & 3;
342 int i;
343
344 fprintf_filtered (file, "%sR%d: ", fpreg == top ? "=>" : " ", fpreg);
345
346 switch (tag)
347 {
348 case 0:
349 fputs_filtered ("Valid ", file);
350 break;
351 case 1:
352 fputs_filtered ("Zero ", file);
353 break;
354 case 2:
355 fputs_filtered ("Special ", file);
356 break;
357 case 3:
358 fputs_filtered ("Empty ", file);
359 break;
360 }
361
362 frame_register_read (frame, (fpreg + 8 - top) % 8 + FP0_REGNUM, raw);
363
364 fputs_filtered ("0x", file);
365 for (i = 9; i >= 0; i--)
366 fprintf_filtered (file, "%02x", raw[i]);
367
368 if (tag != 3)
369 print_i387_ext (raw, file);
370
371 fputs_filtered ("\n", file);
372 }
373
374 fputs_filtered ("\n", file);
375
376 print_i387_status_word (fstat, file);
377 print_i387_control_word (fctrl, file);
378 fprintf_filtered (file, "Tag Word: %s\n",
379 local_hex_string_custom (ftag, "04"));
380 fprintf_filtered (file, "Instruction Pointer: %s:",
381 local_hex_string_custom (fiseg, "02"));
382 fprintf_filtered (file, "%s\n", local_hex_string_custom (fioff, "08"));
383 fprintf_filtered (file, "Operand Pointer: %s:",
384 local_hex_string_custom (foseg, "02"));
385 fprintf_filtered (file, "%s\n", local_hex_string_custom (fooff, "08"));
386 fprintf_filtered (file, "Opcode: %s\n",
387 local_hex_string_custom (fop ? (fop | 0xd800) : 0, "04"));
388 }
389
390 /* FIXME: kettenis/2000-05-21: Right now more than a few i386 targets
391 define their own routines to manage the floating-point registers in
392 GDB's register array. Most (if not all) of these targets use the
393 format used by the "fsave" instruction in their communication with
394 the OS. They should all be converted to use the routines below. */
395
396 /* At fsave_offset[REGNUM] you'll find the offset to the location in
397 the data structure used by the "fsave" instruction where GDB
398 register REGNUM is stored. */
399
400 static int fsave_offset[] =
401 {
402 28 + 0 * FPU_REG_RAW_SIZE, /* FP0_REGNUM through ... */
403 28 + 1 * FPU_REG_RAW_SIZE,
404 28 + 2 * FPU_REG_RAW_SIZE,
405 28 + 3 * FPU_REG_RAW_SIZE,
406 28 + 4 * FPU_REG_RAW_SIZE,
407 28 + 5 * FPU_REG_RAW_SIZE,
408 28 + 6 * FPU_REG_RAW_SIZE,
409 28 + 7 * FPU_REG_RAW_SIZE, /* ... FP7_REGNUM. */
410 0, /* FCTRL_REGNUM (16 bits). */
411 4, /* FSTAT_REGNUM (16 bits). */
412 8, /* FTAG_REGNUM (16 bits). */
413 16, /* FISEG_REGNUM (16 bits). */
414 12, /* FIOFF_REGNUM. */
415 24, /* FOSEG_REGNUM. */
416 20, /* FOOFF_REGNUM. */
417 18 /* FOP_REGNUM (bottom 11 bits). */
418 };
419
420 #define FSAVE_ADDR(fsave, regnum) (fsave + fsave_offset[regnum - FP0_REGNUM])
421 \f
422
423 /* Fill register REGNUM in GDB's register array with the appropriate
424 value from *FSAVE. This function masks off any of the reserved
425 bits in *FSAVE. */
426
427 void
428 i387_supply_register (int regnum, char *fsave)
429 {
430 if (fsave == NULL)
431 {
432 supply_register (regnum, NULL);
433 return;
434 }
435
436 /* Most of the FPU control registers occupy only 16 bits in
437 the fsave area. Give those a special treatment. */
438 if (regnum >= FPC_REGNUM
439 && regnum != FIOFF_REGNUM && regnum != FOOFF_REGNUM)
440 {
441 unsigned char val[4];
442
443 memcpy (val, FSAVE_ADDR (fsave, regnum), 2);
444 val[2] = val[3] = 0;
445 if (regnum == FOP_REGNUM)
446 val[1] &= ((1 << 3) - 1);
447 supply_register (regnum, val);
448 }
449 else
450 supply_register (regnum, FSAVE_ADDR (fsave, regnum));
451 }
452
453 /* Fill GDB's register array with the floating-point register values
454 in *FSAVE. This function masks off any of the reserved
455 bits in *FSAVE. */
456
457 void
458 i387_supply_fsave (char *fsave)
459 {
460 int i;
461
462 for (i = FP0_REGNUM; i < XMM0_REGNUM; i++)
463 i387_supply_register (i, fsave);
464 }
465
466 /* Fill register REGNUM (if it is a floating-point register) in *FSAVE
467 with the value in GDB's register array. If REGNUM is -1, do this
468 for all registers. This function doesn't touch any of the reserved
469 bits in *FSAVE. */
470
471 void
472 i387_fill_fsave (char *fsave, int regnum)
473 {
474 int i;
475
476 for (i = FP0_REGNUM; i < XMM0_REGNUM; i++)
477 if (regnum == -1 || regnum == i)
478 {
479 /* Most of the FPU control registers occupy only 16 bits in
480 the fsave area. Give those a special treatment. */
481 if (i >= FPC_REGNUM
482 && i != FIOFF_REGNUM && i != FOOFF_REGNUM)
483 {
484 unsigned char buf[4];
485
486 regcache_collect (i, buf);
487
488 if (i == FOP_REGNUM)
489 {
490 /* The opcode occupies only 11 bits. Make sure we
491 don't touch the other bits. */
492 buf[1] &= ((1 << 3) - 1);
493 buf[1] |= ((FSAVE_ADDR (fsave, i))[1] & ~((1 << 3) - 1));
494 }
495 memcpy (FSAVE_ADDR (fsave, i), buf, 2);
496 }
497 else
498 regcache_collect (i, FSAVE_ADDR (fsave, i));
499 }
500 }
501 \f
502
503 /* At fxsave_offset[REGNUM] you'll find the offset to the location in
504 the data structure used by the "fxsave" instruction where GDB
505 register REGNUM is stored. */
506
507 static int fxsave_offset[] =
508 {
509 32, /* FP0_REGNUM through ... */
510 48,
511 64,
512 80,
513 96,
514 112,
515 128,
516 144, /* ... FP7_REGNUM (80 bits each). */
517 0, /* FCTRL_REGNUM (16 bits). */
518 2, /* FSTAT_REGNUM (16 bits). */
519 4, /* FTAG_REGNUM (16 bits). */
520 12, /* FISEG_REGNUM (16 bits). */
521 8, /* FIOFF_REGNUM. */
522 20, /* FOSEG_REGNUM (16 bits). */
523 16, /* FOOFF_REGNUM. */
524 6, /* FOP_REGNUM (bottom 11 bits). */
525 160 + 0 * 16, /* XMM0_REGNUM through ... */
526 160 + 1 * 16,
527 160 + 2 * 16,
528 160 + 3 * 16,
529 160 + 4 * 16,
530 160 + 5 * 16,
531 160 + 6 * 16,
532 160 + 7 * 16,
533 160 + 8 * 16,
534 160 + 9 * 16,
535 160 + 10 * 16,
536 160 + 11 * 16,
537 160 + 12 * 16,
538 160 + 13 * 16,
539 160 + 14 * 16,
540 160 + 15 * 16, /* ... XMM15_REGNUM (128 bits each). */
541 24 /* MXCSR_REGNUM. */
542 };
543
544 /* FIXME: kettenis/20030430: We made an unfortunate choice in putting
545 %mxcsr after the SSE registers %xmm0-%xmm7 instead of before, since
546 it makes supporting the registers %xmm8-%xmm15 on x86-64 a bit
547 involved. Hack around it by explicitly overriding the offset for
548 %mxcsr here. */
549
550 #define FXSAVE_ADDR(fxsave, regnum) \
551 ((regnum == MXCSR_REGNUM) ? (fxsave + 24) : \
552 (fxsave + fxsave_offset[regnum - FP0_REGNUM]))
553
554 static int i387_tag (unsigned char *raw);
555 \f
556
557 /* Fill GDB's register array with the floating-point and SSE register
558 values in *FXSAVE. This function masks off any of the reserved
559 bits in *FXSAVE. */
560
561 void
562 i387_supply_fxsave (char *fxsave)
563 {
564 int i, last_regnum = MXCSR_REGNUM;
565
566 if (gdbarch_tdep (current_gdbarch)->num_xmm_regs == 0)
567 last_regnum = FOP_REGNUM;
568
569 for (i = FP0_REGNUM; i <= last_regnum; i++)
570 {
571 if (fxsave == NULL)
572 {
573 supply_register (i, NULL);
574 continue;
575 }
576
577 /* Most of the FPU control registers occupy only 16 bits in
578 the fxsave area. Give those a special treatment. */
579 if (i >= FPC_REGNUM && i < XMM0_REGNUM
580 && i != FIOFF_REGNUM && i != FOOFF_REGNUM)
581 {
582 unsigned char val[4];
583
584 memcpy (val, FXSAVE_ADDR (fxsave, i), 2);
585 val[2] = val[3] = 0;
586 if (i == FOP_REGNUM)
587 val[1] &= ((1 << 3) - 1);
588 else if (i== FTAG_REGNUM)
589 {
590 /* The fxsave area contains a simplified version of the
591 tag word. We have to look at the actual 80-bit FP
592 data to recreate the traditional i387 tag word. */
593
594 unsigned long ftag = 0;
595 int fpreg;
596 int top;
597
598 top = (((FXSAVE_ADDR (fxsave, FSTAT_REGNUM))[1] >> 3) & 0x7);
599
600 for (fpreg = 7; fpreg >= 0; fpreg--)
601 {
602 int tag;
603
604 if (val[0] & (1 << fpreg))
605 {
606 int regnum = (fpreg + 8 - top) % 8 + FP0_REGNUM;
607 tag = i387_tag (FXSAVE_ADDR (fxsave, regnum));
608 }
609 else
610 tag = 3; /* Empty */
611
612 ftag |= tag << (2 * fpreg);
613 }
614 val[0] = ftag & 0xff;
615 val[1] = (ftag >> 8) & 0xff;
616 }
617 supply_register (i, val);
618 }
619 else
620 supply_register (i, FXSAVE_ADDR (fxsave, i));
621 }
622 }
623
624 /* Fill register REGNUM (if it is a floating-point or SSE register) in
625 *FXSAVE with the value in GDB's register array. If REGNUM is -1, do
626 this for all registers. This function doesn't touch any of the
627 reserved bits in *FXSAVE. */
628
629 void
630 i387_fill_fxsave (char *fxsave, int regnum)
631 {
632 int i, last_regnum = MXCSR_REGNUM;
633
634 if (gdbarch_tdep (current_gdbarch)->num_xmm_regs == 0)
635 last_regnum = FOP_REGNUM;
636
637 for (i = FP0_REGNUM; i <= last_regnum; i++)
638 if (regnum == -1 || regnum == i)
639 {
640 /* Most of the FPU control registers occupy only 16 bits in
641 the fxsave area. Give those a special treatment. */
642 if (i >= FPC_REGNUM && i < XMM0_REGNUM
643 && i != FIOFF_REGNUM && i != FOOFF_REGNUM)
644 {
645 unsigned char buf[4];
646
647 regcache_collect (i, buf);
648
649 if (i == FOP_REGNUM)
650 {
651 /* The opcode occupies only 11 bits. Make sure we
652 don't touch the other bits. */
653 buf[1] &= ((1 << 3) - 1);
654 buf[1] |= ((FXSAVE_ADDR (fxsave, i))[1] & ~((1 << 3) - 1));
655 }
656 else if (i == FTAG_REGNUM)
657 {
658 /* Converting back is much easier. */
659
660 unsigned short ftag;
661 int fpreg;
662
663 ftag = (buf[1] << 8) | buf[0];
664 buf[0] = 0;
665 buf[1] = 0;
666
667 for (fpreg = 7; fpreg >= 0; fpreg--)
668 {
669 int tag = (ftag >> (fpreg * 2)) & 3;
670
671 if (tag != 3)
672 buf[0] |= (1 << fpreg);
673 }
674 }
675 memcpy (FXSAVE_ADDR (fxsave, i), buf, 2);
676 }
677 else
678 regcache_collect (i, FXSAVE_ADDR (fxsave, i));
679 }
680 }
681
682 /* Recreate the FTW (tag word) valid bits from the 80-bit FP data in
683 *RAW. */
684
685 static int
686 i387_tag (unsigned char *raw)
687 {
688 int integer;
689 unsigned int exponent;
690 unsigned long fraction[2];
691
692 integer = raw[7] & 0x80;
693 exponent = (((raw[9] & 0x7f) << 8) | raw[8]);
694 fraction[0] = ((raw[3] << 24) | (raw[2] << 16) | (raw[1] << 8) | raw[0]);
695 fraction[1] = (((raw[7] & 0x7f) << 24) | (raw[6] << 16)
696 | (raw[5] << 8) | raw[4]);
697
698 if (exponent == 0x7fff)
699 {
700 /* Special. */
701 return (2);
702 }
703 else if (exponent == 0x0000)
704 {
705 if (fraction[0] == 0x0000 && fraction[1] == 0x0000 && !integer)
706 {
707 /* Zero. */
708 return (1);
709 }
710 else
711 {
712 /* Special. */
713 return (2);
714 }
715 }
716 else
717 {
718 if (integer)
719 {
720 /* Valid. */
721 return (0);
722 }
723 else
724 {
725 /* Special. */
726 return (2);
727 }
728 }
729 }
This page took 0.046539 seconds and 4 git commands to generate.