diff --git a/enclave/core/sgx/cpuid.c b/enclave/core/sgx/cpuid.c index 1e99252e5f..558f9b9d87 100644 --- a/enclave/core/sgx/cpuid.c +++ b/enclave/core/sgx/cpuid.c @@ -36,6 +36,12 @@ oe_result_t oe_initialize_cpuid(void) if (!(_cpuid_table[1][OE_CPUID_RCX] & OE_CPUID_AESNI_FEATURE)) oe_abort(); + // set max input value for basic and extended + _cpuid_table[oe_get_emulated_cpuid_leaf_index(0)][OE_CPUID_RAX] = + OE_CPUID_MAX_BASIC; + _cpuid_table[oe_get_emulated_cpuid_leaf_index(0x80000000)][OE_CPUID_RAX] = + OE_CPUID_MAX_EXTENDED; + result = OE_OK; done: diff --git a/include/openenclave/internal/cpuid.h b/include/openenclave/internal/cpuid.h index 496671cd15..66e7b48927 100644 --- a/include/openenclave/internal/cpuid.h +++ b/include/openenclave/internal/cpuid.h @@ -9,6 +9,8 @@ #define OE_CPUID_OPCODE 0xA20F #define OE_CPUID_LEAF_COUNT 6 /* 0,1,4,7,0x80000000,0x80000001 */ +#define OE_CPUID_MAX_BASIC 7 +#define OE_CPUID_MAX_EXTENDED 0x80000001 #define OE_CPUID_RAX 0 #define OE_CPUID_RBX 1 diff --git a/tests/VectorException/host/host.c b/tests/VectorException/host/host.c index 6952e5f957..26427c9a52 100644 --- a/tests/VectorException/host/host.c +++ b/tests/VectorException/host/host.c @@ -121,9 +121,13 @@ void test_sigill_handling( for (uint32_t j = 0; j < OE_CPUID_REG_COUNT; j++) { - if (i == 1 && j == 1) + if (leaf == 0 && j == OE_CPUID_RAX) + { + // The enclave sets this to the highest emulated leaf. + OE_TEST(OE_CPUID_MAX_BASIC == cpuid_table[i][j]); + } + else if (leaf == 1 && j == OE_CPUID_RBX) { - // Leaf 1. EBX register. // The highest 8 bits indicates the current executing processor // id. // There is no guarantee that the value is the same across @@ -135,6 +139,11 @@ void test_sigill_handling( (cpuid_info[j] & 0x00FFFFFF) == (cpuid_table[i][j] & 0x00FFFFFF)); } + else if (leaf == 0x80000000 && j == OE_CPUID_RAX) + { + // The enclave sets this to the highest emulated leaf. + OE_TEST(OE_CPUID_MAX_EXTENDED == cpuid_table[i][j]); + } else { OE_TEST(cpuid_info[j] == cpuid_table[i][j]);