sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin guest_generic_x87.h ---*/ |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 9 | |
sewardj | e6c53e0 | 2011-10-23 07:33:43 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2011 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 29 | |
| 30 | Neither the names of the U.S. Department of Energy nor the |
| 31 | University of California nor the names of its contributors may be |
| 32 | used to endorse or promote products derived from this software |
| 33 | without prior written permission. |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | /* This file contains functions for doing some x87-specific |
| 37 | operations. Both the amd64 and x86 front ends (guests) indirectly |
| 38 | call these functions via guest helper calls. By putting them here, |
| 39 | code duplication is avoided. Some of these functions are tricky |
| 40 | and hard to verify, so there is much to be said for only having one |
| 41 | copy thereof. |
| 42 | */ |
| 43 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 44 | #ifndef __VEX_GUEST_GENERIC_X87_H |
| 45 | #define __VEX_GUEST_GENERIC_X87_H |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 46 | |
| 47 | #include "libvex_basictypes.h" |
| 48 | |
| 49 | |
| 50 | /* Convert an IEEE754 double (64-bit) into an x87 extended double |
| 51 | (80-bit), mimicing the hardware fairly closely. Both numbers are |
| 52 | stored little-endian. Limitations, all of which could be fixed, |
| 53 | given some level of hassle: |
| 54 | |
| 55 | * Identity of NaNs is not preserved. |
| 56 | |
| 57 | See comments in the code for more details. |
| 58 | */ |
| 59 | extern |
| 60 | void convert_f64le_to_f80le ( /*IN*/UChar* f64, /*OUT*/UChar* f80 ); |
| 61 | |
| 62 | |
| 63 | /* Convert an x87 extended double (80-bit) into an IEEE 754 double |
| 64 | (64-bit), mimicking the hardware fairly closely. Both numbers are |
| 65 | stored little-endian. Limitations, both of which could be fixed, |
| 66 | given some level of hassle: |
| 67 | |
| 68 | * Rounding following truncation could be a bit better. |
| 69 | |
| 70 | * Identity of NaNs is not preserved. |
| 71 | |
| 72 | See comments in the code for more details. |
| 73 | */ |
| 74 | extern |
| 75 | void convert_f80le_to_f64le ( /*IN*/UChar* f80, /*OUT*/UChar* f64 ); |
| 76 | |
| 77 | |
sewardj | 4017a3b | 2005-06-13 12:17:27 +0000 | [diff] [blame] | 78 | /* Layout of the real x87 state. */ |
| 79 | typedef |
| 80 | struct { |
| 81 | UShort env[14]; |
| 82 | UChar reg[80]; |
| 83 | } |
| 84 | Fpu_State; |
| 85 | |
| 86 | /* Offsets, in 16-bit ints, into the FPU environment (env) area. */ |
| 87 | #define FP_ENV_CTRL 0 |
| 88 | #define FP_ENV_STAT 2 |
| 89 | #define FP_ENV_TAG 4 |
| 90 | #define FP_ENV_IP 6 /* and 7 */ |
| 91 | #define FP_ENV_CS 8 |
sewardj | 9ae42a7 | 2012-02-16 14:18:56 +0000 | [diff] [blame] | 92 | #define FP_ENV_LSTOP 9 |
sewardj | 4017a3b | 2005-06-13 12:17:27 +0000 | [diff] [blame] | 93 | #define FP_ENV_OPOFF 10 /* and 11 */ |
| 94 | #define FP_ENV_OPSEL 12 |
| 95 | #define FP_REG(ii) (10*(7-(ii))) |
| 96 | |
| 97 | |
sewardj | 9ae42a7 | 2012-02-16 14:18:56 +0000 | [diff] [blame] | 98 | /* Layout of the 16-bit FNSAVE x87 state. */ |
| 99 | typedef |
| 100 | struct { |
| 101 | UShort env[7]; |
| 102 | UChar reg[80]; |
| 103 | } |
| 104 | Fpu_State_16; |
| 105 | |
| 106 | /* Offsets, in 16-bit ints, into the FPU environment (env) area. */ |
| 107 | #define FPS_ENV_CTRL 0 |
| 108 | #define FPS_ENV_STAT 1 |
| 109 | #define FPS_ENV_TAG 2 |
| 110 | #define FPS_ENV_IP 3 |
| 111 | #define FPS_ENV_CS 4 |
| 112 | #define FPS_ENV_OPOFF 5 |
| 113 | #define FPS_ENV_OPSEL 6 |
| 114 | |
| 115 | |
sewardj | 0b2d3fe | 2010-08-06 07:59:38 +0000 | [diff] [blame] | 116 | /* Do the computations for x86/amd64 FXTRACT. Called directly from |
| 117 | generated code. CLEAN HELPER. */ |
sewardj | 879cee0 | 2006-03-07 01:15:50 +0000 | [diff] [blame] | 118 | extern ULong x86amd64g_calculate_FXTRACT ( ULong arg, HWord getExp ); |
| 119 | |
sewardj | 3c3d6d6 | 2012-02-16 15:21:08 +0000 | [diff] [blame] | 120 | /* Compute result and new OSZACP flags for all 8-bit PCMP{E,I}STR{I,M} |
sewardj | acfbd7d | 2010-08-17 22:52:08 +0000 | [diff] [blame] | 121 | variants. See bigger comment on implementation of this function |
| 122 | for details on call/return conventions. */ |
| 123 | extern Bool compute_PCMPxSTRx ( /*OUT*/V128* resV, |
| 124 | /*OUT*/UInt* resOSZACP, |
| 125 | V128* argLV, V128* argRV, |
| 126 | UInt zmaskL, UInt zmaskR, |
| 127 | UInt imm8, Bool isxSTRM ); |
sewardj | 4017a3b | 2005-06-13 12:17:27 +0000 | [diff] [blame] | 128 | |
sewardj | 3c3d6d6 | 2012-02-16 15:21:08 +0000 | [diff] [blame] | 129 | /* Compute result and new OSZACP flags for all 16-bit PCMP{E,I}STR{I,M} |
| 130 | variants. See bigger comment on implementation of this function |
| 131 | for details on call/return conventions. */ |
| 132 | extern Bool compute_PCMPxSTRx_wide ( /*OUT*/V128* resV, |
| 133 | /*OUT*/UInt* resOSZACP, |
| 134 | V128* argLV, V128* argRV, |
| 135 | UInt zmaskL, UInt zmaskR, |
| 136 | UInt imm8, Bool isxSTRM ); |
| 137 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 138 | #endif /* ndef __VEX_GUEST_GENERIC_X87_H */ |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 139 | |
| 140 | /*---------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 141 | /*--- end guest_generic_x87.h ---*/ |
sewardj | 52ff4cc | 2005-03-26 20:33:38 +0000 | [diff] [blame] | 142 | /*---------------------------------------------------------------*/ |