1 2 /*---------------------------------------------------------------*/ 3 /*--- begin guest_generic_x87.h ---*/ 4 /*---------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2012 OpenWorks LLP 11 info (at) open-works.net 12 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. 17 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 26 02110-1301, USA. 27 28 The GNU General Public License is contained in the file COPYING. 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. 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 44 #ifndef __VEX_GUEST_GENERIC_X87_H 45 #define __VEX_GUEST_GENERIC_X87_H 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 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 92 #define FP_ENV_LSTOP 9 93 #define FP_ENV_OPOFF 10 /* and 11 */ 94 #define FP_ENV_OPSEL 12 95 #define FP_REG(ii) (10*(7-(ii))) 96 97 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 116 /* Do the computations for x86/amd64 FXTRACT. Called directly from 117 generated code. CLEAN HELPER. */ 118 extern ULong x86amd64g_calculate_FXTRACT ( ULong arg, HWord getExp ); 119 120 /* Compute result and new OSZACP flags for all 8-bit PCMP{E,I}STR{I,M} 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 ); 128 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 138 #endif /* ndef __VEX_GUEST_GENERIC_X87_H */ 139 140 /*---------------------------------------------------------------*/ 141 /*--- end guest_generic_x87.h ---*/ 142 /*---------------------------------------------------------------*/ 143