blob: fa7229cb1aee636760dc3e0795247aea95ec34d4 [file] [log] [blame]
sewardj52ff4cc2005-03-26 20:33:38 +00001
2/*---------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin guest_generic_x87.h ---*/
sewardj52ff4cc2005-03-26 20:33:38 +00004/*---------------------------------------------------------------*/
5
6/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardj52ff4cc2005-03-26 20:33:38 +00009
sewardje6c53e02011-10-23 07:33:43 +000010 Copyright (C) 2004-2011 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
sewardj52ff4cc2005-03-26 20:33:38 +000012
sewardj752f9062010-05-03 21:38:49 +000013 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.
sewardj52ff4cc2005-03-26 20:33:38 +000017
sewardj752f9062010-05-03 21:38:49 +000018 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
sewardj7bd6ffe2005-08-03 16:07:36 +000026 02110-1301, USA.
27
sewardj752f9062010-05-03 21:38:49 +000028 The GNU General Public License is contained in the file COPYING.
sewardj52ff4cc2005-03-26 20:33:38 +000029
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.
sewardj52ff4cc2005-03-26 20:33:38 +000034*/
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
sewardjcef7d3e2009-07-02 12:21:59 +000044#ifndef __VEX_GUEST_GENERIC_X87_H
45#define __VEX_GUEST_GENERIC_X87_H
sewardj52ff4cc2005-03-26 20:33:38 +000046
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*/
59extern
60void 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*/
74extern
75void convert_f80le_to_f64le ( /*IN*/UChar* f80, /*OUT*/UChar* f64 );
76
77
sewardj4017a3b2005-06-13 12:17:27 +000078/* Layout of the real x87 state. */
79typedef
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
sewardj9ae42a72012-02-16 14:18:56 +000092#define FP_ENV_LSTOP 9
sewardj4017a3b2005-06-13 12:17:27 +000093#define FP_ENV_OPOFF 10 /* and 11 */
94#define FP_ENV_OPSEL 12
95#define FP_REG(ii) (10*(7-(ii)))
96
97
sewardj9ae42a72012-02-16 14:18:56 +000098/* Layout of the 16-bit FNSAVE x87 state. */
99typedef
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
sewardj0b2d3fe2010-08-06 07:59:38 +0000116/* Do the computations for x86/amd64 FXTRACT. Called directly from
117 generated code. CLEAN HELPER. */
sewardj879cee02006-03-07 01:15:50 +0000118extern ULong x86amd64g_calculate_FXTRACT ( ULong arg, HWord getExp );
119
sewardj3c3d6d62012-02-16 15:21:08 +0000120/* Compute result and new OSZACP flags for all 8-bit PCMP{E,I}STR{I,M}
sewardjacfbd7d2010-08-17 22:52:08 +0000121 variants. See bigger comment on implementation of this function
122 for details on call/return conventions. */
123extern 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 );
sewardj4017a3b2005-06-13 12:17:27 +0000128
sewardj3c3d6d62012-02-16 15:21:08 +0000129/* 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. */
132extern 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
sewardjcef7d3e2009-07-02 12:21:59 +0000138#endif /* ndef __VEX_GUEST_GENERIC_X87_H */
sewardj52ff4cc2005-03-26 20:33:38 +0000139
140/*---------------------------------------------------------------*/
sewardjcef7d3e2009-07-02 12:21:59 +0000141/*--- end guest_generic_x87.h ---*/
sewardj52ff4cc2005-03-26 20:33:38 +0000142/*---------------------------------------------------------------*/