Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit 859197f

Browse files
committed
cpuid: Expand support for CPUID.07H
Adjust the implementation for CPUID.07H, including caching host and guest values. * Add X86_FEATURE_ERMS definition for CPUID.(EAX=07H,ECX=0):EBX.ERMS[bit 9], which is the currently supported feature in CPUID.(EAX=07H, ECX=0) * CPUID.(EAX=07H, ECX=1) is not supported so far Signed-off-by: Wenchao Wang <wenchao.wang@intel.com>
1 parent 32ccd30 commit 859197f

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

core/cpuid.c

+24-27
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "ia32.h"
3636

3737
#define CPUID_CACHE_SIZE 6
38-
#define CPUID_FEATURE_SET_SIZE 2
38+
#define CPUID_FEATURE_SET_SIZE 3
3939
#define MAX_BASIC_CPUID 0x16
4040
#define MAX_EXTENDED_CPUID 0x80000008
4141

@@ -95,7 +95,6 @@ static hax_cpuid_entry * find_cpuid_entry(hax_cpuid_entry *features,
9595
uint32_t index);
9696
static void dump_features(hax_cpuid_entry *features, uint32_t size);
9797

98-
static void get_guest_cache(cpuid_args_t *args, hax_cpuid_entry *entry);
9998
static void adjust_0000_0001(cpuid_args_t *args);
10099
static void adjust_8000_0001(cpuid_args_t *args);
101100
static void execute_0000_0000(cpuid_args_t *args);
@@ -132,6 +131,7 @@ static const cpuid_manager_t kCpuidManager[] = {
132131
{0x00000001, 0, execute_0000_0001}, // Version Information and Features
133132
{0x00000002, 0, execute_0000_0002}, // Cache and TLB Information
134133
{0x00000007, 0, execute_0000_0007}, // Structured Extended Feature Flags
134+
{0x00000007, 1, execute_0000_0007}, // Structured Extended Feature Flags
135135
{0x0000000a, 0, execute_0000_000a}, // Architectural Performance Monitoring
136136
{0x00000015, 0, NULL}, // Time Stamp Counter and Nominal
137137
// Core Crystal Clock Information
@@ -173,6 +173,7 @@ static const cpuid_controller_t kCpuidController[] = {
173173
{0x00000001, 0, set_leaf_0000_0001},
174174
{0x00000002, 0, NULL},
175175
{0x00000007, 0, NULL},
176+
{0x00000007, 1, NULL},
176177
{0x0000000a, 0, NULL},
177178
{0x00000015, 0, set_leaf_0000_0015},
178179
{0x00000016, 0, set_leaf_0000_0016},
@@ -270,6 +271,12 @@ void cpuid_init_supported_features(void)
270271
.edx = cache.data[1]
271272
};
272273
host_supported[1] = (hax_cpuid_entry){
274+
.function = 0x07,
275+
.index = 0,
276+
.ebx = cache.data[3],
277+
.ecx = cache.data[2]
278+
};
279+
host_supported[2] = (hax_cpuid_entry){
273280
.function = 0x80000001,
274281
.ecx = cache.data[4],
275282
.edx = cache.data[5]
@@ -320,6 +327,12 @@ void cpuid_init_supported_features(void)
320327
FEATURE(HTT)
321328
};
322329
hax_supported[1] = (hax_cpuid_entry){
330+
.function = 0x07,
331+
.index = 0,
332+
.ebx =
333+
FEATURE(ERMS)
334+
};
335+
hax_supported[2] = (hax_cpuid_entry){
323336
.function = 0x80000001,
324337
.edx =
325338
FEATURE(NX) |
@@ -667,22 +680,6 @@ static void dump_features(hax_cpuid_entry *features, uint32_t size)
667680
}
668681
}
669682

670-
static void get_guest_cache(cpuid_args_t *args, hax_cpuid_entry *entry)
671-
{
672-
if (args == NULL)
673-
return;
674-
675-
if (entry == NULL) {
676-
args->eax = args->ebx = args->ecx = args->edx = 0;
677-
return;
678-
}
679-
680-
args->eax = entry->eax;
681-
args->ebx = entry->ebx;
682-
args->ecx = entry->ecx;
683-
args->edx = entry->edx;
684-
}
685-
686683
static void adjust_0000_0001(cpuid_args_t *args)
687684
{
688685
#define VIRT_FAMILY 0x06
@@ -764,7 +761,7 @@ static void adjust_8000_0001(cpuid_args_t *args)
764761
if (args == NULL)
765762
return;
766763

767-
hax_supported = &cache.hax_supported[1];
764+
hax_supported = &cache.hax_supported[2];
768765

769766
args->eax = args->ebx = 0;
770767
// Report only the features specified but turn off any features this
@@ -810,18 +807,18 @@ static void execute_0000_0007(cpuid_args_t *args)
810807
return;
811808

812809
switch (args->ecx) {
813-
case 0: { // Sub-leaf 0
814-
// The maximum input value for supported leaf 7 sub-leaves
815-
// Bit 09: Supports Enhanced REP MOVSB/STOSB if 1
816-
// TODO: Add sub-leaf in the CPUID manager so that the feature bits
817-
// can be specified in cache.hax_supported[] during CPUID
818-
// initialization.
819-
args->ebx = cache.data[3] & 0x00000200;
810+
case 0: { // Structured Extended Feature Flags Enumeration Leaf
811+
hax_cpuid_entry *host_supported, *hax_supported;
812+
813+
host_supported = &cache.host_supported[1];
814+
hax_supported = &cache.hax_supported[1];
815+
816+
args->ebx = host_supported->ebx & hax_supported->ebx;
820817
args->eax = args->ecx = args->edx = 0;
821818
break;
822819
}
823820
case 1: { // Structured Extended Feature Enumeration Sub-leaf
824-
get_guest_cache(args, NULL);
821+
args->eax = args->ebx = args->ecx = args->edx = 0;
825822
break;
826823
}
827824
default: {

core/include/cpuid.h

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ enum {
203203
X86_FEATURE_AVX2 = FEAT(5), /* 0x00000020 Advanced Vector Extensions 2 */
204204
X86_FEATURE_SMEP = FEAT(7), /* 0x00000080 Supervisor-Mode Execution Prevention */
205205
X86_FEATURE_BMI2 = FEAT(8), /* 0x00000100 Bit Manipulation Instruction Set 2 */
206+
X86_FEATURE_ERMS = FEAT(9), /* 0x00000200 Enhanced REP MOVSB/STOSB */
206207
X86_FEATURE_INVPCID = FEAT(10), /* 0x00000400 INVPCID instruction */
207208
X86_FEATURE_RTM = FEAT(11), /* 0x00000800 Transactional Synchronization Extensions */
208209
X86_FEATURE_RDT_M = FEAT(12), /* 0x00001000 Resource Director Technology Monitoring */

0 commit comments

Comments
 (0)