|
|
01cf8b |
commit 791fe5ecf909d573bcbf353b677b9404f9da0ed4
|
|
|
01cf8b |
Author: Mark Wielaard <mark@klomp.org>
|
|
|
01cf8b |
Date: Mon May 27 22:19:27 2019 +0200
|
|
|
01cf8b |
|
|
|
01cf8b |
Expose rdrand and f16c through cpuid also if the host only has avx.
|
|
|
01cf8b |
|
|
|
01cf8b |
The amd64 CPUID dirtyhelpers are mostly static since they emulate some
|
|
|
01cf8b |
existing CPU "family". The avx2 ("i7-4910MQ") CPUID variant however
|
|
|
01cf8b |
can "dynamicly" enable rdrand and/or f16c if the host supports them.
|
|
|
01cf8b |
Do the same for the avx_and_cx16 ("i5-2300") CPUID variant.
|
|
|
01cf8b |
|
|
|
01cf8b |
https://bugs.kde.org/show_bug.cgi?id=408009
|
|
|
01cf8b |
|
|
|
01cf8b |
diff --git a/VEX/priv/guest_amd64_defs.h b/VEX/priv/guest_amd64_defs.h
|
|
|
01cf8b |
index 4f34b41..a5de527 100644
|
|
|
01cf8b |
--- a/VEX/priv/guest_amd64_defs.h
|
|
|
01cf8b |
+++ b/VEX/priv/guest_amd64_defs.h
|
|
|
01cf8b |
@@ -165,7 +165,9 @@ extern void amd64g_dirtyhelper_storeF80le ( Addr/*addr*/, ULong/*data*/ );
|
|
|
01cf8b |
extern void amd64g_dirtyhelper_CPUID_baseline ( VexGuestAMD64State* st );
|
|
|
01cf8b |
extern void amd64g_dirtyhelper_CPUID_sse3_and_cx16 ( VexGuestAMD64State* st );
|
|
|
01cf8b |
extern void amd64g_dirtyhelper_CPUID_sse42_and_cx16 ( VexGuestAMD64State* st );
|
|
|
01cf8b |
-extern void amd64g_dirtyhelper_CPUID_avx_and_cx16 ( VexGuestAMD64State* st );
|
|
|
01cf8b |
+extern void amd64g_dirtyhelper_CPUID_avx_and_cx16 ( VexGuestAMD64State* st,
|
|
|
01cf8b |
+ ULong hasF16C,
|
|
|
01cf8b |
+ ULong hasRDRAND );
|
|
|
01cf8b |
extern void amd64g_dirtyhelper_CPUID_avx2 ( VexGuestAMD64State* st,
|
|
|
01cf8b |
ULong hasF16C, ULong hasRDRAND );
|
|
|
01cf8b |
|
|
|
01cf8b |
diff --git a/VEX/priv/guest_amd64_helpers.c b/VEX/priv/guest_amd64_helpers.c
|
|
|
01cf8b |
index e4cf7e2..182bae0 100644
|
|
|
01cf8b |
--- a/VEX/priv/guest_amd64_helpers.c
|
|
|
01cf8b |
+++ b/VEX/priv/guest_amd64_helpers.c
|
|
|
01cf8b |
@@ -3141,8 +3141,11 @@ void amd64g_dirtyhelper_CPUID_sse42_and_cx16 ( VexGuestAMD64State* st )
|
|
|
01cf8b |
address sizes : 36 bits physical, 48 bits virtual
|
|
|
01cf8b |
power management:
|
|
|
01cf8b |
*/
|
|
|
01cf8b |
-void amd64g_dirtyhelper_CPUID_avx_and_cx16 ( VexGuestAMD64State* st )
|
|
|
01cf8b |
+void amd64g_dirtyhelper_CPUID_avx_and_cx16 ( VexGuestAMD64State* st,
|
|
|
01cf8b |
+ ULong hasF16C, ULong hasRDRAND )
|
|
|
01cf8b |
{
|
|
|
01cf8b |
+ vassert((hasF16C >> 1) == 0ULL);
|
|
|
01cf8b |
+ vassert((hasRDRAND >> 1) == 0ULL);
|
|
|
01cf8b |
# define SET_ABCD(_a,_b,_c,_d) \
|
|
|
01cf8b |
do { st->guest_RAX = (ULong)(_a); \
|
|
|
01cf8b |
st->guest_RBX = (ULong)(_b); \
|
|
|
01cf8b |
@@ -3157,9 +3160,14 @@ void amd64g_dirtyhelper_CPUID_avx_and_cx16 ( VexGuestAMD64State* st )
|
|
|
01cf8b |
case 0x00000000:
|
|
|
01cf8b |
SET_ABCD(0x0000000d, 0x756e6547, 0x6c65746e, 0x49656e69);
|
|
|
01cf8b |
break;
|
|
|
01cf8b |
- case 0x00000001:
|
|
|
01cf8b |
- SET_ABCD(0x000206a7, 0x00100800, 0x1f9ae3bf, 0xbfebfbff);
|
|
|
01cf8b |
+ case 0x00000001: {
|
|
|
01cf8b |
+ // As a baseline, advertise neither F16C (ecx:29) nor RDRAND (ecx:30),
|
|
|
01cf8b |
+ // but patch in support for them as directed by the caller.
|
|
|
01cf8b |
+ UInt ecx_extra
|
|
|
01cf8b |
+ = (hasF16C ? (1U << 29) : 0) | (hasRDRAND ? (1U << 30) : 0);
|
|
|
01cf8b |
+ SET_ABCD(0x000206a7, 0x00100800, (0x1f9ae3bf | ecx_extra), 0xbfebfbff);
|
|
|
01cf8b |
break;
|
|
|
01cf8b |
+ }
|
|
|
01cf8b |
case 0x00000002:
|
|
|
01cf8b |
SET_ABCD(0x76035a01, 0x00f0b0ff, 0x00000000, 0x00ca0000);
|
|
|
01cf8b |
break;
|
|
|
01cf8b |
diff --git a/VEX/priv/guest_amd64_toIR.c b/VEX/priv/guest_amd64_toIR.c
|
|
|
01cf8b |
index 56e992c..96dee38 100644
|
|
|
01cf8b |
--- a/VEX/priv/guest_amd64_toIR.c
|
|
|
01cf8b |
+++ b/VEX/priv/guest_amd64_toIR.c
|
|
|
01cf8b |
@@ -22007,7 +22007,8 @@ Long dis_ESC_0F (
|
|
|
01cf8b |
|
|
|
01cf8b |
vassert(fName); vassert(fAddr);
|
|
|
01cf8b |
IRExpr** args = NULL;
|
|
|
01cf8b |
- if (fAddr == &amd64g_dirtyhelper_CPUID_avx2) {
|
|
|
01cf8b |
+ if (fAddr == &amd64g_dirtyhelper_CPUID_avx2
|
|
|
01cf8b |
+ || fAddr == &amd64g_dirtyhelper_CPUID_avx_and_cx16) {
|
|
|
01cf8b |
Bool hasF16C = (archinfo->hwcaps & VEX_HWCAPS_AMD64_F16C) != 0;
|
|
|
01cf8b |
Bool hasRDRAND = (archinfo->hwcaps & VEX_HWCAPS_AMD64_RDRAND) != 0;
|
|
|
01cf8b |
args = mkIRExprVec_3(IRExpr_GSPTR(),
|
|
|
01cf8b |
diff --git a/coregrind/m_machine.c b/coregrind/m_machine.c
|
|
|
01cf8b |
index 3536e57..56a28d1 100644
|
|
|
01cf8b |
--- a/coregrind/m_machine.c
|
|
|
01cf8b |
+++ b/coregrind/m_machine.c
|
|
|
01cf8b |
@@ -1076,10 +1076,10 @@ Bool VG_(machine_get_hwcaps)( void )
|
|
|
01cf8b |
have_avx2 = (ebx & (1<<5)) != 0; /* True => have AVX2 */
|
|
|
01cf8b |
}
|
|
|
01cf8b |
|
|
|
01cf8b |
- /* Sanity check for RDRAND and F16C. These don't actually *need* AVX2, but
|
|
|
01cf8b |
- it's convenient to restrict them to the AVX2 case since the simulated
|
|
|
01cf8b |
- CPUID we'll offer them on has AVX2 as a base. */
|
|
|
01cf8b |
- if (!have_avx2) {
|
|
|
01cf8b |
+ /* Sanity check for RDRAND and F16C. These don't actually *need* AVX, but
|
|
|
01cf8b |
+ it's convenient to restrict them to the AVX case since the simulated
|
|
|
01cf8b |
+ CPUID we'll offer them on has AVX as a base. */
|
|
|
01cf8b |
+ if (!have_avx) {
|
|
|
01cf8b |
have_f16c = False;
|
|
|
01cf8b |
have_rdrand = False;
|
|
|
01cf8b |
}
|