| 1 | /* Intel 387 floating point stuff. |
| 2 | Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 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. |
| 10 | |
| 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. |
| 15 | |
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | #include "defs.h" |
| 21 | #include "frame.h" |
| 22 | #include "inferior.h" |
| 23 | #include "language.h" |
| 24 | #include "gdbcore.h" |
| 25 | #include "ieee-float.h" |
| 26 | |
| 27 | struct ext_format ext_format_i387 = { |
| 28 | /* tot sbyte smask expbyte manbyte */ |
| 29 | 10, 9, 0x80, 9,8, 4,0 /* i387 */ |
| 30 | }; |
| 31 | |
| 32 | /* FIXME: Eliminate these routines when we have the time to change all |
| 33 | the callers. */ |
| 34 | |
| 35 | void |
| 36 | i387_to_double (from, to) |
| 37 | char *from; |
| 38 | char *to; |
| 39 | { |
| 40 | ieee_extended_to_double (&ext_format_i387, from, (double *)to); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | double_to_i387 (from, to) |
| 45 | char *from; |
| 46 | char *to; |
| 47 | { |
| 48 | double_to_ieee_extended (&ext_format_i387, (double *)from, to); |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | print_387_control_word (control) |
| 53 | unsigned int control; |
| 54 | { |
| 55 | printf_unfiltered ("control %s: ", local_hex_string(control)); |
| 56 | printf_unfiltered ("compute to "); |
| 57 | switch ((control >> 8) & 3) |
| 58 | { |
| 59 | case 0: printf_unfiltered ("24 bits; "); break; |
| 60 | case 1: printf_unfiltered ("(bad); "); break; |
| 61 | case 2: printf_unfiltered ("53 bits; "); break; |
| 62 | case 3: printf_unfiltered ("64 bits; "); break; |
| 63 | } |
| 64 | printf_unfiltered ("round "); |
| 65 | switch ((control >> 10) & 3) |
| 66 | { |
| 67 | case 0: printf_unfiltered ("NEAREST; "); break; |
| 68 | case 1: printf_unfiltered ("DOWN; "); break; |
| 69 | case 2: printf_unfiltered ("UP; "); break; |
| 70 | case 3: printf_unfiltered ("CHOP; "); break; |
| 71 | } |
| 72 | if (control & 0x3f) |
| 73 | { |
| 74 | printf_unfiltered ("mask:"); |
| 75 | if (control & 0x0001) printf_unfiltered (" INVALID"); |
| 76 | if (control & 0x0002) printf_unfiltered (" DENORM"); |
| 77 | if (control & 0x0004) printf_unfiltered (" DIVZ"); |
| 78 | if (control & 0x0008) printf_unfiltered (" OVERF"); |
| 79 | if (control & 0x0010) printf_unfiltered (" UNDERF"); |
| 80 | if (control & 0x0020) printf_unfiltered (" LOS"); |
| 81 | printf_unfiltered (";"); |
| 82 | } |
| 83 | printf_unfiltered ("\n"); |
| 84 | if (control & 0xe080) warning ("reserved bits on: %s\n", |
| 85 | local_hex_string(control & 0xe080)); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | print_387_status_word (status) |
| 90 | unsigned int status; |
| 91 | { |
| 92 | printf_unfiltered ("status %s: ", local_hex_string (status)); |
| 93 | if (status & 0xff) |
| 94 | { |
| 95 | printf_unfiltered ("exceptions:"); |
| 96 | if (status & 0x0001) printf_unfiltered (" INVALID"); |
| 97 | if (status & 0x0002) printf_unfiltered (" DENORM"); |
| 98 | if (status & 0x0004) printf_unfiltered (" DIVZ"); |
| 99 | if (status & 0x0008) printf_unfiltered (" OVERF"); |
| 100 | if (status & 0x0010) printf_unfiltered (" UNDERF"); |
| 101 | if (status & 0x0020) printf_unfiltered (" LOS"); |
| 102 | if (status & 0x0040) printf_unfiltered (" FPSTACK"); |
| 103 | printf_unfiltered ("; "); |
| 104 | } |
| 105 | printf_unfiltered ("flags: %d%d%d%d; ", |
| 106 | (status & 0x4000) != 0, |
| 107 | (status & 0x0400) != 0, |
| 108 | (status & 0x0200) != 0, |
| 109 | (status & 0x0100) != 0); |
| 110 | |
| 111 | printf_unfiltered ("top %d\n", (status >> 11) & 7); |
| 112 | } |