2011-08-08 22:20:29 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id$
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2017-10-15 22:17:07 +03:00
|
|
|
// Copyright (c) 2011-2017 Stanislav Shwartsman
|
2011-08-08 22:20:29 +04:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2021-01-30 22:40:18 +03:00
|
|
|
#include "gui/siminterface.h"
|
2011-08-08 22:20:29 +04:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "param_names.h"
|
|
|
|
#include "generic_cpuid.h"
|
|
|
|
|
|
|
|
#define LOG_THIS cpu->
|
|
|
|
|
2013-05-07 00:33:27 +04:00
|
|
|
#undef BX_CPUID_SUPPORT_ISA_EXTENSION
|
|
|
|
|
|
|
|
#define BX_CPUID_SUPPORT_ISA_EXTENSION(feature) \
|
2014-08-31 22:39:18 +04:00
|
|
|
(this->is_cpu_extension_supported(feature))
|
2013-05-07 00:33:27 +04:00
|
|
|
|
2012-01-07 21:06:03 +04:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2012-01-07 21:06:03 +04:00
|
|
|
bx_generic_cpuid_t::bx_generic_cpuid_t(BX_CPU_C *cpu): bx_cpuid_t(cpu)
|
|
|
|
{
|
2011-08-08 22:20:29 +04:00
|
|
|
init_cpu_extensions_bitmask();
|
2014-08-31 22:39:18 +04:00
|
|
|
|
2012-06-04 18:27:34 +04:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
init_vmx_extensions_bitmask();
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
init_svm_extensions_bitmask();
|
|
|
|
#endif
|
2011-12-29 01:54:51 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL <= 5
|
|
|
|
// 486 and Pentium processors
|
|
|
|
max_std_leaf = 1;
|
|
|
|
#else
|
|
|
|
// for Pentium Pro, Pentium II, Pentium 4 processors
|
|
|
|
max_std_leaf = 2;
|
|
|
|
|
|
|
|
// do not report CPUID functions above 0x3 if cpuid_limit_winnt is set
|
|
|
|
// to workaround WinNT issue.
|
2021-01-02 19:28:51 +03:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MONITOR_MWAIT))
|
|
|
|
max_std_leaf = 0x5;
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_X2APIC))
|
|
|
|
max_std_leaf = 0xB;
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_XSAVE))
|
|
|
|
max_std_leaf = 0xD;
|
2011-12-29 01:54:51 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL <= 5
|
2021-01-02 19:28:51 +03:00
|
|
|
max_ext_leaf = 0x0;
|
2011-12-29 01:54:51 +04:00
|
|
|
#else
|
|
|
|
max_ext_leaf = 0x80000008;
|
|
|
|
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SVM))
|
|
|
|
max_ext_leaf = 0x8000000A;
|
|
|
|
#endif
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_generic_cpuid_t::get_cpuid_leaf(Bit32u function, Bit32u subfunction, cpuid_function_t *leaf) const
|
|
|
|
{
|
2015-02-12 00:31:17 +03:00
|
|
|
static const char *brand_string = (const char *)SIM->get_param_string(BXPN_BRAND_STRING)->getptr();
|
2014-03-16 00:19:30 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool cpuid_limit_winnt = SIM->get_param_bool(BXPN_CPUID_LIMIT_WINNT)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (cpuid_limit_winnt)
|
|
|
|
if (function > 2 && function < 0x80000000) function = 2;
|
|
|
|
|
2011-12-29 01:54:51 +04:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
if (function >= 0x80000000 && function > max_ext_leaf)
|
2011-12-29 01:59:39 +04:00
|
|
|
function = max_std_leaf;
|
2011-12-29 01:54:51 +04:00
|
|
|
#endif
|
|
|
|
if (function < 0x80000000 && function > max_std_leaf)
|
|
|
|
function = max_std_leaf;
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
switch(function) {
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
case 0x80000000:
|
|
|
|
get_ext_cpuid_leaf_0(leaf);
|
|
|
|
return;
|
|
|
|
case 0x80000001:
|
|
|
|
get_ext_cpuid_leaf_1(leaf);
|
|
|
|
return;
|
|
|
|
case 0x80000002:
|
|
|
|
case 0x80000003:
|
|
|
|
case 0x80000004:
|
2014-03-16 00:19:30 +04:00
|
|
|
get_ext_cpuid_brand_string_leaf(brand_string, function, leaf);
|
2011-08-08 22:20:29 +04:00
|
|
|
return;
|
|
|
|
case 0x80000005:
|
|
|
|
get_ext_cpuid_leaf_5(leaf);
|
|
|
|
return;
|
|
|
|
case 0x80000006:
|
|
|
|
get_ext_cpuid_leaf_6(leaf);
|
|
|
|
return;
|
|
|
|
case 0x80000007:
|
|
|
|
get_ext_cpuid_leaf_7(leaf);
|
|
|
|
return;
|
|
|
|
case 0x80000008:
|
|
|
|
get_ext_cpuid_leaf_8(leaf);
|
|
|
|
return;
|
2011-12-29 01:54:51 +04:00
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
case 0x8000000A:
|
|
|
|
get_ext_cpuid_leaf_A(leaf);
|
|
|
|
return;
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
case 0x00000000:
|
|
|
|
get_std_cpuid_leaf_0(leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000001:
|
|
|
|
get_std_cpuid_leaf_1(leaf);
|
|
|
|
return;
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
case 0x00000002:
|
|
|
|
get_std_cpuid_leaf_2(leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000003:
|
2012-05-11 10:51:04 +04:00
|
|
|
get_reserved_leaf(leaf);
|
2011-08-08 22:20:29 +04:00
|
|
|
return;
|
|
|
|
case 0x00000004:
|
|
|
|
get_std_cpuid_leaf_4(subfunction, leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000005:
|
|
|
|
get_std_cpuid_leaf_5(leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000006:
|
|
|
|
get_std_cpuid_leaf_6(leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000007:
|
|
|
|
get_std_cpuid_leaf_7(subfunction, leaf);
|
|
|
|
return;
|
|
|
|
case 0x00000008:
|
|
|
|
case 0x00000009:
|
2012-05-11 10:51:04 +04:00
|
|
|
get_reserved_leaf(leaf);
|
2011-08-08 22:20:29 +04:00
|
|
|
return;
|
|
|
|
case 0x0000000A:
|
|
|
|
get_std_cpuid_leaf_A(leaf);
|
|
|
|
return;
|
|
|
|
case 0x0000000B:
|
|
|
|
get_std_cpuid_extended_topology_leaf(subfunction, leaf);
|
|
|
|
return;
|
|
|
|
case 0x0000000C:
|
|
|
|
get_reserved_leaf(leaf);
|
|
|
|
return;
|
|
|
|
case 0x0000000D:
|
|
|
|
default:
|
|
|
|
get_std_cpuid_xsave_leaf(subfunction, leaf);
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x00000000 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_0(cpuid_function_t *leaf) const
|
|
|
|
{
|
2015-02-12 00:31:17 +03:00
|
|
|
static const Bit8u *vendor_string = (const Bit8u *)SIM->get_param_string(BXPN_VENDOR_STRING)->getptr();
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// EAX: highest std function understood by CPUID
|
|
|
|
// EBX: vendor ID string
|
|
|
|
// EDX: vendor ID string
|
|
|
|
// ECX: vendor ID string
|
2021-01-02 19:28:51 +03:00
|
|
|
get_leaf_0(max_std_leaf, (const char *) vendor_string, leaf);
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x00000001 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_1(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// EAX: CPU Version Information
|
|
|
|
// [3:0] Stepping ID
|
|
|
|
// [7:4] Model: starts at 1
|
|
|
|
// [11:8] Family: 4=486, 5=Pentium, 6=PPro, ...
|
|
|
|
// [13:12] Type: 0=OEM, 1=overdrive, 2=dual cpu, 3=reserved
|
|
|
|
// [19:16] Extended Model
|
|
|
|
// [27:20] Extended Family
|
|
|
|
leaf->eax = get_cpu_version_information();
|
|
|
|
|
|
|
|
// EBX:
|
|
|
|
// [7:0] Brand ID
|
|
|
|
// [15:8] CLFLUSH cache line size (value*8 = cache line size in bytes)
|
|
|
|
// [23:16] Number of logical processors in one physical processor
|
|
|
|
// [31:24] Local Apic ID
|
|
|
|
leaf->ebx = 0;
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_CLFLUSH)) {
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->ebx |= (CACHE_LINE_SIZE / 8) << 8;
|
|
|
|
}
|
|
|
|
unsigned n_logical_processors = ncores*nthreads;
|
|
|
|
leaf->ebx |= (n_logical_processors << 16);
|
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
leaf->ebx |= ((cpu->get_apic_id() & 0xff) << 24);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ECX: Extended Feature Flags
|
2011-08-16 20:49:04 +04:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->ecx = get_extended_cpuid_features();
|
2011-08-16 20:49:04 +04:00
|
|
|
#else
|
|
|
|
leaf->ecx = 0;
|
|
|
|
#endif
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// EDX: Standard Feature Flags
|
|
|
|
leaf->edx = get_std_cpuid_features();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
|
|
|
|
// leaf 0x00000002 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_2(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// CPUID function 0x00000002 - Cache and TLB Descriptors
|
|
|
|
#if BX_CPU_VENDOR_INTEL
|
|
|
|
leaf->eax = 0x00410601; // for Pentium Pro compatibility
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
#else
|
|
|
|
leaf->eax = 0; // ignore for AMD
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-11 10:51:04 +04:00
|
|
|
// leaf 0x00000003 - Processor Serial Number (not supported) //
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// leaf 0x00000004 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_4(Bit32u subfunction, cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// CPUID function 0x00000004 - Deterministic Cache Parameters
|
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x00000005 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_5(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// CPUID function 0x00000005 - MONITOR/MWAIT Leaf
|
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MONITOR_MWAIT))
|
2011-08-08 22:20:29 +04:00
|
|
|
{
|
|
|
|
// EAX - Smallest monitor-line size in bytes
|
|
|
|
// EBX - Largest monitor-line size in bytes
|
|
|
|
// ECX -
|
|
|
|
// [31:2] - reserved
|
|
|
|
// [1:1] - exit MWAIT even with EFLAGS.IF = 0
|
|
|
|
// [0:0] - MONITOR/MWAIT extensions are supported
|
|
|
|
// EDX -
|
|
|
|
// [03-00] - number of C0 sub C-states supported using MWAIT
|
|
|
|
// [07-04] - number of C1 sub C-states supported using MWAIT
|
|
|
|
// [11-08] - number of C2 sub C-states supported using MWAIT
|
|
|
|
// [15-12] - number of C3 sub C-states supported using MWAIT
|
|
|
|
// [19-16] - number of C4 sub C-states supported using MWAIT
|
|
|
|
// [31-20] - reserved (MBZ)
|
|
|
|
leaf->eax = CACHE_LINE_SIZE;
|
|
|
|
leaf->ebx = CACHE_LINE_SIZE;
|
|
|
|
leaf->ecx = 3;
|
|
|
|
leaf->edx = 0x00000020;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x00000006 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_6(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// CPUID function 0x00000006 - Thermal and Power Management Leaf
|
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x00000007 //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_7(Bit32u subfunction, cpuid_function_t *leaf) const
|
|
|
|
{
|
2021-02-16 21:57:49 +03:00
|
|
|
switch(subfunction) {
|
|
|
|
case 0:
|
|
|
|
leaf->eax = 0; /* report max sub-leaf that supported in leaf 7 */
|
|
|
|
leaf->ebx = get_std_cpuid_leaf_7_ebx(BX_CPU_VENDOR_INTEL ? BX_CPUID_EXT3_ENCHANCED_REP_STRINGS : 0);
|
|
|
|
leaf->ecx = get_std_cpuid_leaf_7_ecx();
|
|
|
|
leaf->edx = 0;
|
|
|
|
default:
|
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
2012-05-11 10:51:04 +04:00
|
|
|
// leaf 0x00000008 reserved //
|
|
|
|
// leaf 0x00000009 direct cache access not supported //
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// leaf 0x0000000A //
|
|
|
|
void bx_generic_cpuid_t::get_std_cpuid_leaf_A(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// CPUID function 0x0000000A - Architectural Performance Monitoring Leaf
|
2014-10-15 12:04:38 +04:00
|
|
|
|
|
|
|
// EAX:
|
|
|
|
// [7:0] Version ID of architectural performance monitoring
|
|
|
|
// [15:8] Number of general-purpose performance monitoring counters per logical processor
|
|
|
|
// [23:16] Bit width of general-purpose, performance monitoring counter
|
|
|
|
// [31:24] Length of EBX bit vector to enumerate architectural performance
|
|
|
|
// monitoring events.
|
|
|
|
|
|
|
|
// EBX:
|
|
|
|
// [0] Core cycle event not available if 1
|
|
|
|
// [1] Instruction retired event not available if 1
|
|
|
|
// [2] Reference cycles event not available if 1
|
|
|
|
// [3] Last-level cache reference event not available if 1
|
|
|
|
// [4] Last-level cache misses event not available if 1
|
|
|
|
// [5] Branch instruction retired event not available if 1
|
|
|
|
// [6] Branch mispredict retired event not available if 1
|
|
|
|
// [31:7] reserved
|
|
|
|
|
|
|
|
// ECX: reserved
|
|
|
|
|
|
|
|
// EDX:
|
|
|
|
// [4:0] Number of fixed performance counters (if Version ID > 1)
|
|
|
|
// [12:5] Bit width of fixed-function performance counters (if Version ID > 1)
|
|
|
|
// [31:13] reserved
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
2014-10-15 23:04:28 +04:00
|
|
|
|
|
|
|
BX_INFO(("WARNING: Architectural Performance Monitoring is not implemented"));
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x0000000C - reserved //
|
|
|
|
|
2015-09-21 16:16:17 +03:00
|
|
|
// leaf 0x0000000D - XSAVE //
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// leaf 0x80000000 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_0(cpuid_function_t *leaf) const
|
|
|
|
{
|
2015-02-12 00:31:17 +03:00
|
|
|
static const Bit8u *vendor_string = (const Bit8u *)SIM->get_param_string(BXPN_VENDOR_STRING)->getptr();
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
// EAX: highest extended function understood by CPUID
|
|
|
|
// EBX: vendor ID string
|
|
|
|
// EDX: vendor ID string
|
|
|
|
// ECX: vendor ID string
|
2015-02-12 00:31:17 +03:00
|
|
|
get_leaf_0(max_ext_leaf, BX_CPU_VENDOR_INTEL ? NULL : (const char *) vendor_string, leaf);
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x80000001 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_1(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// EAX: CPU Version Information
|
|
|
|
leaf->eax = BX_CPU_VENDOR_INTEL ? 0 : get_cpu_version_information();
|
|
|
|
|
|
|
|
// EBX: Brand ID
|
|
|
|
leaf->ebx = 0;
|
|
|
|
|
|
|
|
// ECX:
|
|
|
|
leaf->ecx = get_ext2_cpuid_features();
|
|
|
|
|
|
|
|
// EDX:
|
|
|
|
// Many of the bits in EDX are the same as FN 0x00000001 [*] for AMD
|
|
|
|
// [*] [0:0] FPU on chip
|
|
|
|
// [*] [1:1] VME: Virtual-8086 Mode enhancements
|
|
|
|
// [*] [2:2] DE: Debug Extensions (I/O breakpoints)
|
|
|
|
// [*] [3:3] PSE: Page Size Extensions
|
|
|
|
// [*] [4:4] TSC: Time Stamp Counter
|
|
|
|
// [*] [5:5] MSR: RDMSR and WRMSR support
|
|
|
|
// [*] [6:6] PAE: Physical Address Extensions
|
|
|
|
// [*] [7:7] MCE: Machine Check Exception
|
|
|
|
// [*] [8:8] CXS: CMPXCHG8B instruction
|
|
|
|
// [*] [9:9] APIC: APIC on Chip
|
|
|
|
// [10:10] Reserved
|
|
|
|
// [11:11] SYSCALL/SYSRET support
|
|
|
|
// [*] [12:12] MTRR: Memory Type Range Reg
|
|
|
|
// [*] [13:13] PGE/PTE Global Bit
|
|
|
|
// [*] [14:14] MCA: Machine Check Architecture
|
|
|
|
// [*] [15:15] CMOV: Cond Mov/Cmp Instructions
|
|
|
|
// [*] [16:16] PAT: Page Attribute Table
|
|
|
|
// [*] [17:17] PSE-36: Physical Address Extensions
|
|
|
|
// [18:19] Reserved
|
|
|
|
// [20:20] No-Execute page protection
|
|
|
|
// [21:21] Reserved
|
|
|
|
// [22:22] AMD MMX Extensions
|
|
|
|
// [*] [23:23] MMX Technology
|
|
|
|
// [*] [24:24] FXSR: FXSAVE/FXRSTOR (also indicates CR4.OSFXSR is available)
|
|
|
|
// [25:25] Fast FXSAVE/FXRSTOR mode support
|
|
|
|
// [26:26] 1G paging support
|
|
|
|
// [27:27] Support RDTSCP Instruction
|
|
|
|
// [28:28] Reserved
|
|
|
|
// [29:29] Long Mode
|
|
|
|
// [30:30] AMD 3DNow! Extensions
|
|
|
|
// [31:31] AMD 3DNow! Instructions
|
|
|
|
leaf->edx = get_std2_cpuid_features();
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x80000002 //
|
|
|
|
// leaf 0x80000003 //
|
|
|
|
// leaf 0x80000004 //
|
|
|
|
|
|
|
|
// leaf 0x80000005 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_5(cpuid_function_t *leaf) const
|
|
|
|
{
|
2019-12-09 21:16:29 +03:00
|
|
|
// CPUID function 0x80000005 - L1 Cache and TLB Identifiers
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->eax = 0x01ff01ff;
|
|
|
|
leaf->ebx = 0x01ff01ff;
|
|
|
|
leaf->ecx = 0x40020140;
|
|
|
|
leaf->edx = 0x40020140;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x80000006 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_6(cpuid_function_t *leaf) const
|
|
|
|
{
|
2019-12-09 21:16:29 +03:00
|
|
|
// CPUID function 0x80000006 - L2 Cache and TLB Identifiers
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0x42004200;
|
|
|
|
leaf->ecx = 0x02008140;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x80000007 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_7(cpuid_function_t *leaf) const
|
|
|
|
{
|
2019-12-09 21:16:29 +03:00
|
|
|
// CPUID function 0x80000007 - Advanced Power Management
|
2011-08-08 22:20:29 +04:00
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0;
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaf 0x80000008 //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_8(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
// virtual & phys address size in low 2 bytes.
|
|
|
|
leaf->eax = BX_PHY_ADDRESS_WIDTH | (BX_LIN_ADDRESS_WIDTH << 8);
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0; // Reserved, undefined
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-29 01:54:51 +04:00
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
|
|
|
|
// leaf 0x8000000A //
|
|
|
|
void bx_generic_cpuid_t::get_ext_cpuid_leaf_A(cpuid_function_t *leaf) const
|
|
|
|
{
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SVM))
|
|
|
|
{
|
|
|
|
leaf->eax = BX_SVM_REVISION;
|
|
|
|
leaf->ebx = 0x40; /* number of ASIDs */
|
|
|
|
leaf->ecx = 0;
|
|
|
|
|
2012-02-14 03:29:01 +04:00
|
|
|
// * [0:0] NP - Nested paging support
|
2011-12-29 01:54:51 +04:00
|
|
|
// [1:1] LBR virtualization
|
|
|
|
// [2:2] SVM Lock
|
2012-02-14 03:29:01 +04:00
|
|
|
// * [3:3] NRIPS - Next RIP save on VMEXIT
|
2011-12-29 01:54:51 +04:00
|
|
|
// [4:4] TscRate - MSR based TSC ratio control
|
|
|
|
// [5:5] VMCB Clean bits support
|
|
|
|
// [6:6] Flush by ASID support
|
|
|
|
// [7:7] Decode assists support
|
|
|
|
// [9:8] Reserved
|
|
|
|
// [10:10] Pause filter support
|
|
|
|
// [11:11] Reserved
|
|
|
|
// [12:12] Pause filter threshold support
|
|
|
|
// [31:13] Reserved
|
2012-02-14 03:29:01 +04:00
|
|
|
|
|
|
|
leaf->edx = BX_CPUID_SVM_NESTED_PAGING | BX_CPUID_SVM_NRIP_SAVE;
|
2011-12-29 01:54:51 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
leaf->eax = 0;
|
|
|
|
leaf->ebx = 0;
|
|
|
|
leaf->ecx = 0; // Reserved, undefined
|
|
|
|
leaf->edx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
void bx_generic_cpuid_t::init_cpu_extensions_bitmask(void)
|
2011-08-08 22:20:29 +04:00
|
|
|
{
|
|
|
|
#if BX_SUPPORT_FPU
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_X87);
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 4
|
2013-04-17 23:46:11 +04:00
|
|
|
static unsigned cpu_level = SIM->get_param_num(BXPN_CPUID_LEVEL)->get();
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_486);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 5
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool mmx_enabled = SIM->get_param_bool(BXPN_CPUID_MMX)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2013-04-17 23:46:11 +04:00
|
|
|
if (cpu_level >= 5) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_PENTIUM);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2013-04-17 23:46:11 +04:00
|
|
|
if (mmx_enabled)
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_MMX);
|
2013-04-17 23:46:11 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_3DNOW
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_3DNOW);
|
2013-04-17 23:46:11 +04:00
|
|
|
if (! mmx_enabled) {
|
|
|
|
BX_PANIC(("PANIC: 3DNOW emulation requires MMX support !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
2014-08-31 22:39:18 +04:00
|
|
|
|
|
|
|
enable_cpu_extension(BX_ISA_VME);
|
|
|
|
enable_cpu_extension(BX_ISA_DEBUG_EXTENSIONS);
|
|
|
|
enable_cpu_extension(BX_ISA_PSE);
|
|
|
|
|
|
|
|
#if BX_PHY_ADDRESS_LONG
|
|
|
|
enable_cpu_extension(BX_ISA_PSE36);
|
|
|
|
#endif
|
2013-04-17 23:46:11 +04:00
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
static unsigned apic_enabled = SIM->get_param_enum(BXPN_CPUID_APIC)->get();
|
|
|
|
|
|
|
|
if (cpu_level < 6) {
|
|
|
|
if (apic_enabled != BX_CPUID_SUPPORT_LEGACY_APIC && apic_enabled != BX_CPUID_SUPPORT_XAPIC)
|
|
|
|
BX_PANIC(("PANIC: APIC extensions emulation require P6 CPU level support !"));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (apic_enabled) {
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
case BX_CPUID_SUPPORT_X2APIC:
|
|
|
|
enable_cpu_extension(BX_ISA_XAPIC);
|
|
|
|
enable_cpu_extension(BX_ISA_X2APIC);
|
|
|
|
break;
|
|
|
|
case BX_CPUID_SUPPORT_XAPIC_EXT:
|
|
|
|
enable_cpu_extension(BX_ISA_XAPIC);
|
|
|
|
enable_cpu_extension(BX_ISA_XAPIC_EXT);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case BX_CPUID_SUPPORT_XAPIC:
|
|
|
|
enable_cpu_extension(BX_ISA_XAPIC);
|
|
|
|
break;
|
|
|
|
case BX_CPUID_SUPPORT_LEGACY_APIC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BX_PANIC(("unknown APIC option %d", apic_enabled));
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2014-08-31 22:39:18 +04:00
|
|
|
if (cpu_level >= 6) {
|
|
|
|
enable_cpu_extension(BX_ISA_P6);
|
|
|
|
enable_cpu_extension(BX_ISA_PAE);
|
|
|
|
enable_cpu_extension(BX_ISA_PGE);
|
|
|
|
enable_cpu_extension(BX_ISA_MTRR);
|
|
|
|
enable_cpu_extension(BX_ISA_PAT);
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool mwait_enabled = SIM->get_param_bool(BXPN_CPUID_MWAIT)->get();
|
2013-04-17 23:46:11 +04:00
|
|
|
if (mwait_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_MONITOR_MWAIT);
|
2013-04-17 23:46:11 +04:00
|
|
|
if (cpu_level < 6)
|
|
|
|
BX_PANIC(("PANIC: MONITOR/MWAIT emulation requires P6 CPU level support !"));
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
static unsigned simd_enabled = SIM->get_param_enum(BXPN_CPUID_SIMD)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
// determine SSE in runtime
|
2013-09-16 23:50:36 +04:00
|
|
|
switch (simd_enabled) {
|
2014-09-26 16:14:53 +04:00
|
|
|
#if BX_SUPPORT_EVEX
|
|
|
|
case BX_CPUID_SUPPORT_AVX512:
|
|
|
|
enable_cpu_extension(BX_ISA_AVX512);
|
|
|
|
enable_cpu_extension(BX_ISA_AVX512_VL);
|
|
|
|
enable_cpu_extension(BX_ISA_AVX512_BW);
|
|
|
|
enable_cpu_extension(BX_ISA_AVX512_DQ);
|
|
|
|
enable_cpu_extension(BX_ISA_AVX512_CD);
|
|
|
|
#endif
|
2013-09-16 23:50:36 +04:00
|
|
|
#if BX_SUPPORT_AVX
|
|
|
|
case BX_CPUID_SUPPORT_AVX2:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_AVX2);
|
2013-09-16 23:50:36 +04:00
|
|
|
case BX_CPUID_SUPPORT_AVX:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_AVX);
|
2013-09-16 23:50:36 +04:00
|
|
|
#endif
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSE4_2:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE4_2);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSE4_1:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE4_1);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSSE3:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSSE3);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSE3:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE3);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSE2:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE2);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_SSE:
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE);
|
2011-08-08 22:20:29 +04:00
|
|
|
case BX_CPUID_SUPPORT_NOSSE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled) {
|
2013-04-17 23:46:11 +04:00
|
|
|
if (mmx_enabled == 0 || cpu_level < 6 || BX_CPU_LEVEL < 6) {
|
2011-09-25 21:36:20 +04:00
|
|
|
BX_PANIC(("PANIC: SSE support requires P6 emulation with MMX enabled !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
2012-02-14 03:29:01 +04:00
|
|
|
// enable CLFLUSH only when SSE2 or higher is enabled
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled >= BX_CPUID_SUPPORT_SSE2)
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_CLFLUSH);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2012-02-14 03:29:01 +04:00
|
|
|
// enable POPCNT if SSE4.2 is enabled
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled >= BX_CPUID_SUPPORT_SSE4_2)
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_POPCNT);
|
2012-02-14 03:29:01 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool sse4a_enabled = SIM->get_param_bool(BXPN_CPUID_SSE4A)->get();
|
2011-09-18 20:18:22 +04:00
|
|
|
if (sse4a_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SSE4A);
|
2011-09-18 20:18:22 +04:00
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
if (! simd_enabled) {
|
2011-09-25 21:36:20 +04:00
|
|
|
BX_PANIC(("PANIC: SSE4A require SSE to be enabled !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-09-18 20:18:22 +04:00
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool misaligned_sse_enabled = SIM->get_param_bool(BXPN_CPUID_MISALIGNED_SSE)->get();
|
2014-08-31 22:39:18 +04:00
|
|
|
if (misaligned_sse_enabled) {
|
|
|
|
enable_cpu_extension(BX_ISA_MISALIGNED_SSE);
|
|
|
|
if (cpu_level < 6)
|
|
|
|
BX_PANIC(("PANIC: Misaligned SSE emulation requires P6 CPU level support !"));
|
|
|
|
|
|
|
|
if (! simd_enabled) {
|
|
|
|
BX_PANIC(("PANIC: Misaligned SSE require simd extensions to be enabled !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool sep_enabled = SIM->get_param_bool(BXPN_CPUID_SEP)->get();
|
2013-04-17 23:46:11 +04:00
|
|
|
if (sep_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SYSENTER_SYSEXIT);
|
|
|
|
if (cpu_level < 6) {
|
2013-04-17 23:46:11 +04:00
|
|
|
BX_PANIC(("PANIC: SYSENTER/SYSEXIT emulation requires P6 CPU level support !"));
|
2014-08-31 22:39:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-04-17 23:46:11 +04:00
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool xsave_enabled = SIM->get_param_bool(BXPN_CPUID_XSAVE)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (xsave_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_XSAVE);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
if (! simd_enabled) {
|
2011-08-08 22:20:29 +04:00
|
|
|
BX_PANIC(("PANIC: XSAVE emulation requires SSE support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool xsaveopt_enabled = SIM->get_param_bool(BXPN_CPUID_XSAVEOPT)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (xsaveopt_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_XSAVEOPT);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
if (! xsave_enabled) {
|
|
|
|
BX_PANIC(("PANIC: XSAVEOPT emulation requires XSAVE !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool aes_enabled = SIM->get_param_bool(BXPN_CPUID_AES)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (aes_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_AES_PCLMULQDQ);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
// AES required 3-byte opcode (SSS3E support or more)
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
2011-09-25 21:36:20 +04:00
|
|
|
BX_PANIC(("PANIC: AES support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool sha_enabled = SIM->get_param_bool(BXPN_CPUID_SHA)->get();
|
2013-07-24 22:44:22 +04:00
|
|
|
if (sha_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SHA);
|
2013-07-24 22:44:22 +04:00
|
|
|
|
|
|
|
// SHA required 3-byte opcode (SSS3E support or more)
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
2013-07-24 22:44:22 +04:00
|
|
|
BX_PANIC(("PANIC: SHA support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool movbe_enabled = SIM->get_param_bool(BXPN_CPUID_MOVBE)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (movbe_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_MOVBE);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
// MOVBE required 3-byte opcode (SSS3E support or more)
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
2011-08-08 22:20:29 +04:00
|
|
|
BX_PANIC(("PANIC: MOVBE support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool adx_enabled = SIM->get_param_bool(BXPN_CPUID_ADX)->get();
|
2012-07-12 18:51:54 +04:00
|
|
|
if (adx_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_ADX);
|
2012-07-12 18:51:54 +04:00
|
|
|
|
|
|
|
// ADX required 3-byte opcode (SSS3E support or more)
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
2012-07-12 18:51:54 +04:00
|
|
|
BX_PANIC(("PANIC: ADX support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool x86_64_enabled = SIM->get_param_bool(BXPN_CPUID_X86_64)->get();
|
2011-09-25 21:36:20 +04:00
|
|
|
if (x86_64_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
if (cpu_level < 6) {
|
2013-04-17 23:46:11 +04:00
|
|
|
BX_PANIC(("PANIC: x86-64 emulation requires P6 CPU level support !"));
|
2014-08-31 22:39:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_cpu_extension(BX_ISA_LONG_MODE);
|
|
|
|
enable_cpu_extension(BX_ISA_FFXSR);
|
|
|
|
enable_cpu_extension(BX_ISA_NX);
|
2013-04-17 23:46:11 +04:00
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_CMPXCHG16B);
|
|
|
|
enable_cpu_extension(BX_ISA_RDTSCP);
|
|
|
|
enable_cpu_extension(BX_ISA_LM_LAHF_SAHF);
|
2011-09-25 21:36:20 +04:00
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_SSE2) {
|
2011-09-25 21:36:20 +04:00
|
|
|
BX_PANIC(("PANIC: x86-64 emulation requires SSE2 support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! sep_enabled) {
|
|
|
|
BX_PANIC(("PANIC: x86-64 emulation requires SYSENTER/SYSEXIT support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool fsgsbase_enabled = SIM->get_param_bool(BXPN_CPUID_FSGSBASE)->get();
|
2011-09-25 21:36:20 +04:00
|
|
|
if (fsgsbase_enabled)
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_FSGSBASE);
|
2011-09-25 21:36:20 +04:00
|
|
|
|
|
|
|
static unsigned apic_enabled = SIM->get_param_enum(BXPN_CPUID_APIC)->get();
|
|
|
|
if (apic_enabled < BX_CPUID_SUPPORT_XAPIC) {
|
|
|
|
BX_PANIC(("PANIC: x86-64 emulation requires XAPIC support !"));
|
|
|
|
return;
|
|
|
|
}
|
2014-08-31 22:39:18 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool pcid_enabled = SIM->get_param_bool(BXPN_CPUID_PCID)->get();
|
2014-08-31 22:39:18 +04:00
|
|
|
if (pcid_enabled)
|
|
|
|
enable_cpu_extension(BX_ISA_PCID);
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool xlarge_pages = SIM->get_param_bool(BXPN_CPUID_1G_PAGES)->get();
|
2014-08-31 22:39:18 +04:00
|
|
|
if (xlarge_pages)
|
|
|
|
enable_cpu_extension(BX_ISA_1G_PAGES);
|
2011-09-25 21:36:20 +04:00
|
|
|
}
|
2011-09-26 22:47:47 +04:00
|
|
|
else {
|
2017-04-11 21:35:17 +03:00
|
|
|
static unsigned vmx_enabled = SIM->get_param_num(BXPN_CPUID_VMX)->get();
|
|
|
|
if (vmx_enabled >= 2) {
|
2013-04-17 23:46:11 +04:00
|
|
|
BX_PANIC(("PANIC: VMX=2 emulation requires x86-64 support !"));
|
2011-09-26 22:47:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 21:36:20 +04:00
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
#if BX_SUPPORT_AVX
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled >= BX_CPUID_SUPPORT_AVX) {
|
2011-08-08 22:20:29 +04:00
|
|
|
if (! xsave_enabled) {
|
|
|
|
BX_PANIC(("PANIC: AVX emulation requires XSAVE support !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-09-25 21:36:20 +04:00
|
|
|
|
|
|
|
if (! x86_64_enabled) {
|
2011-08-27 17:47:16 +04:00
|
|
|
BX_PANIC(("PANIC: AVX emulation requires x86-64 support !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool avx_f16c_enabled = SIM->get_param_bool(BXPN_CPUID_AVX_F16CVT)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
if (avx_f16c_enabled) {
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX) {
|
2011-08-08 22:20:29 +04:00
|
|
|
BX_PANIC(("PANIC: Float16 convert emulation requires AVX support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_AVX_F16C);
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool avx_fma_enabled = SIM->get_param_bool(BXPN_CPUID_AVX_FMA)->get();
|
2011-09-30 02:20:56 +04:00
|
|
|
if (avx_fma_enabled) {
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX2) {
|
2011-09-30 02:20:56 +04:00
|
|
|
BX_PANIC(("PANIC: FMA emulation requires AVX2 support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_AVX_FMA);
|
2011-09-30 02:20:56 +04:00
|
|
|
}
|
|
|
|
|
2011-08-27 17:47:16 +04:00
|
|
|
static unsigned bmi_enabled = SIM->get_param_num(BXPN_CPUID_BMI)->get();
|
|
|
|
if (bmi_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_BMI1);
|
|
|
|
enable_cpu_extension(BX_ISA_LZCNT);
|
2011-08-27 17:47:16 +04:00
|
|
|
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX) {
|
2011-08-27 17:47:16 +04:00
|
|
|
BX_PANIC(("PANIC: Bit Manipulation Instructions (BMI) emulation requires AVX support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bmi_enabled >= 2)
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_BMI2);
|
2011-08-27 17:47:16 +04:00
|
|
|
}
|
2011-10-07 18:09:35 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool fma4_enabled = SIM->get_param_bool(BXPN_CPUID_FMA4)->get();
|
2011-10-07 18:09:35 +04:00
|
|
|
if (fma4_enabled) {
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX) {
|
2011-10-07 18:09:35 +04:00
|
|
|
BX_PANIC(("PANIC: FMA4 emulation requires AVX support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_FMA4);
|
2011-10-07 18:09:35 +04:00
|
|
|
}
|
2011-10-20 00:54:04 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool xop_enabled = SIM->get_param_bool(BXPN_CPUID_XOP)->get();
|
2011-10-20 00:54:04 +04:00
|
|
|
if (xop_enabled) {
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX) {
|
2011-10-20 00:54:04 +04:00
|
|
|
BX_PANIC(("PANIC: XOP emulation requires AVX support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_XOP);
|
2011-10-20 00:54:04 +04:00
|
|
|
}
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool tbm_enabled = SIM->get_param_bool(BXPN_CPUID_TBM)->get();
|
2011-10-20 00:54:04 +04:00
|
|
|
if (tbm_enabled) {
|
2013-09-16 23:50:36 +04:00
|
|
|
if (simd_enabled < BX_CPUID_SUPPORT_AVX || ! xop_enabled) {
|
2011-10-20 00:54:04 +04:00
|
|
|
BX_PANIC(("PANIC: TBM emulation requires AVX and XOP support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_TBM);
|
2011-10-20 00:54:04 +04:00
|
|
|
}
|
2011-09-25 21:36:20 +04:00
|
|
|
#endif // BX_SUPPORT_AVX
|
|
|
|
|
|
|
|
#endif // BX_SUPPORT_X86_64
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_VMX
|
2011-12-21 13:11:51 +04:00
|
|
|
static unsigned vmx_enabled = SIM->get_param_num(BXPN_CPUID_VMX)->get();
|
|
|
|
if (vmx_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_VMX);
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2011-12-21 13:11:51 +04:00
|
|
|
if (! sep_enabled) {
|
|
|
|
BX_PANIC(("PANIC: VMX emulation requires SYSENTER/SYSEXIT support !"));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-25 23:35:29 +04:00
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
static unsigned svm_enabled = SIM->get_param_num(BXPN_CPUID_SVM)->get();
|
|
|
|
if (svm_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SVM);
|
|
|
|
|
|
|
|
// auto-enable together with SVM
|
|
|
|
enable_cpu_extension(BX_ISA_ALT_MOV_CR8);
|
|
|
|
enable_cpu_extension(BX_ISA_XAPIC_EXT);
|
2011-12-25 23:35:29 +04:00
|
|
|
|
|
|
|
if (! x86_64_enabled) {
|
|
|
|
BX_PANIC(("PANIC: SVM emulation requires x86-64 support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_SUPPORT_VMX && BX_SUPPORT_SVM
|
|
|
|
if (vmx_enabled && svm_enabled) {
|
|
|
|
BX_PANIC(("PANIC: VMX and SVM emulation cannot be enabled together in same configuration !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool smep_enabled = SIM->get_param_bool(BXPN_CPUID_SMEP)->get();
|
2013-04-18 00:24:12 +04:00
|
|
|
if (smep_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SMEP);
|
2013-04-18 00:24:12 +04:00
|
|
|
if (cpu_level < 6)
|
|
|
|
BX_PANIC(("PANIC: SMEP emulation requires P6 CPU level support !"));
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool smap_enabled = SIM->get_param_bool(BXPN_CPUID_SMAP)->get();
|
2013-04-18 00:24:12 +04:00
|
|
|
if (smap_enabled) {
|
2014-08-31 22:39:18 +04:00
|
|
|
enable_cpu_extension(BX_ISA_SMAP);
|
2013-04-18 00:24:12 +04:00
|
|
|
if (cpu_level < 6)
|
|
|
|
BX_PANIC(("PANIC: SMAP emulation requires P6 CPU level support !"));
|
2013-04-17 23:46:11 +04:00
|
|
|
}
|
2012-09-10 19:22:26 +04:00
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif // CPU_LEVEL >= 6
|
|
|
|
|
|
|
|
#endif // CPU_LEVEL >= 5
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
#endif // CPU_LEVEL >= 4
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
2011-09-26 16:31:40 +04:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
void bx_generic_cpuid_t::init_vmx_extensions_bitmask(void)
|
|
|
|
{
|
2011-12-21 13:11:51 +04:00
|
|
|
Bit32u features_bitmask = 0;
|
2011-09-26 16:31:40 +04:00
|
|
|
|
2011-12-21 13:11:51 +04:00
|
|
|
static unsigned vmx_enabled = SIM->get_param_num(BXPN_CPUID_VMX)->get();
|
|
|
|
if (vmx_enabled) {
|
|
|
|
features_bitmask |= BX_VMX_VIRTUAL_NMI;
|
2011-09-26 16:31:40 +04:00
|
|
|
|
2014-11-02 17:14:36 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool x86_64_enabled = SIM->get_param_bool(BXPN_CPUID_X86_64)->get();
|
2011-12-21 13:11:51 +04:00
|
|
|
if (x86_64_enabled) {
|
|
|
|
features_bitmask |= BX_VMX_TPR_SHADOW |
|
|
|
|
BX_VMX_APIC_VIRTUALIZATION |
|
|
|
|
BX_VMX_WBINVD_VMEXIT;
|
2011-09-26 23:36:20 +04:00
|
|
|
|
2011-09-26 16:31:40 +04:00
|
|
|
#if BX_SUPPORT_VMX >= 2
|
2011-12-21 13:11:51 +04:00
|
|
|
if (vmx_enabled >= 2) {
|
|
|
|
features_bitmask |= BX_VMX_PREEMPTION_TIMER |
|
|
|
|
BX_VMX_PAT |
|
|
|
|
BX_VMX_EFER |
|
|
|
|
BX_VMX_EPT |
|
|
|
|
BX_VMX_VPID |
|
|
|
|
BX_VMX_UNRESTRICTED_GUEST |
|
|
|
|
BX_VMX_DESCRIPTOR_TABLE_EXIT |
|
|
|
|
BX_VMX_X2APIC_VIRTUALIZATION |
|
2013-05-20 22:18:52 +04:00
|
|
|
BX_VMX_PAUSE_LOOP_EXITING |
|
|
|
|
BX_VMX_EPT_ACCESS_DIRTY |
|
|
|
|
BX_VMX_VINTR_DELIVERY |
|
|
|
|
BX_VMX_VMCS_SHADOWING |
|
|
|
|
BX_VMX_EPTP_SWITCHING | BX_VMX_EPT_EXCEPTION;
|
2011-12-21 13:11:51 +04:00
|
|
|
|
|
|
|
features_bitmask |= BX_VMX_SAVE_DEBUGCTL_DISABLE |
|
|
|
|
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
|
|
|
|
BX_VMX_PERF_GLOBAL_CTRL;
|
|
|
|
}
|
2011-09-26 16:31:40 +04:00
|
|
|
#endif
|
2011-12-21 13:11:51 +04:00
|
|
|
}
|
2014-11-02 17:14:36 +03:00
|
|
|
#endif
|
2011-09-26 16:31:40 +04:00
|
|
|
}
|
2014-11-02 17:14:36 +03:00
|
|
|
|
2011-09-26 16:31:40 +04:00
|
|
|
this->vmx_extensions_bitmask = features_bitmask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-25 23:35:29 +04:00
|
|
|
#if BX_SUPPORT_SVM
|
|
|
|
void bx_generic_cpuid_t::init_svm_extensions_bitmask(void)
|
|
|
|
{
|
|
|
|
Bit32u features_bitmask = 0;
|
|
|
|
|
2021-01-30 11:35:35 +03:00
|
|
|
static bool svm_enabled = SIM->get_param_bool(BXPN_CPUID_SVM)->get();
|
2011-12-25 23:35:29 +04:00
|
|
|
if (svm_enabled) {
|
2012-02-20 00:15:23 +04:00
|
|
|
features_bitmask = BX_CPUID_SVM_NESTED_PAGING |
|
|
|
|
BX_CPUID_SVM_NRIP_SAVE;
|
2011-12-25 23:35:29 +04:00
|
|
|
}
|
2012-02-20 00:15:23 +04:00
|
|
|
|
2011-12-25 23:35:29 +04:00
|
|
|
this->svm_extensions_bitmask = features_bitmask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
/*
|
|
|
|
* Get CPU version information:
|
|
|
|
*
|
|
|
|
* [3:0] Stepping ID
|
|
|
|
* [7:4] Model: starts at 1
|
|
|
|
* [11:8] Family: 4=486, 5=Pentium, 6=PPro, ...
|
|
|
|
* [13:12] Type: 0=OEM, 1=overdrive, 2=dual cpu, 3=reserved
|
|
|
|
* [19:16] Extended Model
|
|
|
|
* [27:29] Extended Family
|
|
|
|
*/
|
|
|
|
|
|
|
|
Bit32u bx_generic_cpuid_t::get_cpu_version_information(void) const
|
|
|
|
{
|
2013-04-17 23:46:11 +04:00
|
|
|
static Bit32u level = SIM->get_param_num(BXPN_CPUID_LEVEL)->get();
|
2011-08-08 22:20:29 +04:00
|
|
|
static Bit32u stepping = SIM->get_param_num(BXPN_CPUID_STEPPING)->get();
|
|
|
|
static Bit32u model = SIM->get_param_num(BXPN_CPUID_MODEL)->get();
|
|
|
|
static Bit32u family = SIM->get_param_num(BXPN_CPUID_FAMILY)->get();
|
|
|
|
|
2013-04-17 23:46:11 +04:00
|
|
|
if (family < 6 && family != level)
|
|
|
|
BX_PANIC(("PANIC: CPUID family %x not matching configured cpu level %d", family, level));
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
return ((family & 0xfff0) << 16) |
|
|
|
|
((model & 0xf0) << 12) |
|
|
|
|
((family & 0x0f) << 8) |
|
|
|
|
((model & 0x0f) << 4) | stepping;
|
|
|
|
}
|
|
|
|
|
2011-08-16 20:49:04 +04:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
/* Get CPU extended feature flags. */
|
|
|
|
Bit32u bx_generic_cpuid_t::get_extended_cpuid_features(void) const
|
|
|
|
{
|
|
|
|
// [0:0] SSE3: SSE3 Instructions
|
|
|
|
// [1:1] PCLMULQDQ Instruction support
|
|
|
|
// [2:2] DTES64: 64-bit DS area
|
|
|
|
// [3:3] MONITOR/MWAIT support
|
|
|
|
// [4:4] DS-CPL: CPL qualified debug store
|
|
|
|
// [5:5] VMX: Virtual Machine Technology
|
|
|
|
// [6:6] SMX: Secure Virtual Machine Technology
|
|
|
|
// [7:7] EST: Enhanced Intel SpeedStep Technology
|
|
|
|
// [8:8] TM2: Thermal Monitor 2
|
|
|
|
// [9:9] SSSE3: SSSE3 Instructions
|
|
|
|
// [10:10] CNXT-ID: L1 context ID
|
|
|
|
// [11:11] reserved
|
|
|
|
// [12:12] FMA Instructions support
|
|
|
|
// [13:13] CMPXCHG16B: CMPXCHG16B instruction support
|
|
|
|
// [14:14] xTPR update control
|
|
|
|
// [15:15] PDCM - Perfon and Debug Capability MSR
|
|
|
|
// [16:16] reserved
|
|
|
|
// [17:17] PCID: Process Context Identifiers
|
|
|
|
// [18:18] DCA - Direct Cache Access
|
|
|
|
// [19:19] SSE4.1 Instructions
|
|
|
|
// [20:20] SSE4.2 Instructions
|
|
|
|
// [21:21] X2APIC
|
|
|
|
// [22:22] MOVBE instruction
|
|
|
|
// [23:23] POPCNT instruction
|
|
|
|
// [24:24] TSC Deadline
|
|
|
|
// [25:25] AES Instructions
|
|
|
|
// [26:26] XSAVE extensions support
|
|
|
|
// [27:27] OSXSAVE support
|
|
|
|
// [28:28] AVX extensions support
|
|
|
|
// [29:29] AVX F16C - Float16 conversion support
|
|
|
|
// [30:30] RDRAND instruction
|
|
|
|
// [31:31] reserved
|
|
|
|
|
|
|
|
Bit32u features = 0;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE3))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_SSE3;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_AES_PCLMULQDQ))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_PCLMULQDQ;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MONITOR_MWAIT))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_MONITOR_MWAIT;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_VMX))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_VMX;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSSE3))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_SSSE3;
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LONG_MODE))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_CMPXCHG16B;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PCID))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_PCID;
|
|
|
|
#endif
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE4_1))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_SSE4_1;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE4_2))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_SSE4_2;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_X2APIC))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_X2APIC;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MOVBE))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_MOVBE;
|
|
|
|
|
2012-02-14 03:29:01 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_POPCNT))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_POPCNT;
|
|
|
|
|
|
|
|
// support for AES
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_AES_PCLMULQDQ))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_AES;
|
|
|
|
|
|
|
|
// support XSAVE extensions
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_XSAVE)) {
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_XSAVE;
|
|
|
|
if (cpu->cr4.get_OSXSAVE())
|
|
|
|
features |= BX_CPUID_EXT_OSXSAVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_AVX
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_AVX))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_AVX;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_AVX_F16C))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_EXT_AVX_F16C;
|
2011-09-30 02:20:56 +04:00
|
|
|
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_AVX_FMA))
|
|
|
|
features |= BX_CPUID_EXT_FMA;
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
2011-08-16 20:49:04 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
/* Get CPU feature flags. Returned by CPUID functions 1 and 80000001. */
|
|
|
|
Bit32u bx_generic_cpuid_t::get_std_cpuid_features(void) const
|
|
|
|
{
|
|
|
|
// [0:0] FPU on chip
|
|
|
|
// [1:1] VME: Virtual-8086 Mode enhancements
|
|
|
|
// [2:2] DE: Debug Extensions (I/O breakpoints)
|
|
|
|
// [3:3] PSE: Page Size Extensions
|
|
|
|
// [4:4] TSC: Time Stamp Counter
|
|
|
|
// [5:5] MSR: RDMSR and WRMSR support
|
|
|
|
// [6:6] PAE: Physical Address Extensions
|
|
|
|
// [7:7] MCE: Machine Check Exception
|
|
|
|
// [8:8] CXS: CMPXCHG8B instruction
|
|
|
|
// [9:9] APIC: APIC on Chip
|
|
|
|
// [10:10] Reserved
|
|
|
|
// [11:11] SYSENTER/SYSEXIT support
|
|
|
|
// [12:12] MTRR: Memory Type Range Reg
|
|
|
|
// [13:13] PGE/PTE Global Bit
|
|
|
|
// [14:14] MCA: Machine Check Architecture
|
|
|
|
// [15:15] CMOV: Cond Mov/Cmp Instructions
|
|
|
|
// [16:16] PAT: Page Attribute Table
|
|
|
|
// [17:17] PSE-36: Physical Address Extensions
|
|
|
|
// [18:18] PSN: Processor Serial Number
|
|
|
|
// [19:19] CLFLUSH: CLFLUSH Instruction support
|
|
|
|
// [20:20] Reserved
|
|
|
|
// [21:21] DS: Debug Store
|
|
|
|
// [22:22] ACPI: Thermal Monitor and Software Controlled Clock Facilities
|
|
|
|
// [23:23] MMX Technology
|
|
|
|
// [24:24] FXSR: FXSAVE/FXRSTOR (also indicates CR4.OSFXSR is available)
|
|
|
|
// [25:25] SSE: SSE Extensions
|
|
|
|
// [26:26] SSE2: SSE2 Extensions
|
|
|
|
// [27:27] Self Snoop
|
|
|
|
// [28:28] Hyper Threading Technology
|
|
|
|
// [29:29] TM: Thermal Monitor
|
|
|
|
// [30:30] Reserved
|
|
|
|
// [31:31] PBE: Pending Break Enable
|
|
|
|
|
|
|
|
Bit32u features = 0;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_X87))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_X87;
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 5
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PENTIUM)) {
|
2011-08-08 22:20:29 +04:00
|
|
|
// Pentium only features
|
2011-08-18 01:13:06 +04:00
|
|
|
features |= BX_CPUID_STD_TSC;
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_MSR;
|
|
|
|
// support Machine Check
|
|
|
|
features |= BX_CPUID_STD_MCE | BX_CPUID_STD_MCA;
|
|
|
|
features |= BX_CPUID_STD_CMPXCHG8B;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_VME))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_VME;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_DEBUG_EXTENSIONS))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_DEBUG_EXTENSIONS;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PSE))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_PSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
// if MSR_APICBASE APIC Global Enable bit has been cleared,
|
|
|
|
// the CPUID feature flag for the APIC is set to 0.
|
|
|
|
if (cpu->msr.apicbase & 0x800)
|
|
|
|
features |= BX_CPUID_STD_APIC; // APIC on chip
|
|
|
|
#endif
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SYSENTER_SYSEXIT))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_SYSENTER_SYSEXIT;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_CLFLUSH))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_CLFLUSH;
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 5
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MMX))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_MMX;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_P6)) {
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_CMOV;
|
|
|
|
features |= BX_CPUID_STD_ACPI;
|
|
|
|
}
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MTRR))
|
2011-08-11 22:06:09 +04:00
|
|
|
features |= BX_CPUID_STD_MTRR;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PAT))
|
2011-08-11 22:06:09 +04:00
|
|
|
features |= BX_CPUID_STD_PAT;
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PAE))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_PAE;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PGE))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_GLOBAL_PAGES;
|
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_PSE36))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_PSE36;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE))
|
2011-08-11 22:06:09 +04:00
|
|
|
features |= BX_CPUID_STD_FXSAVE_FXRSTOR | BX_CPUID_STD_SSE;
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE2))
|
2011-08-08 22:20:29 +04:00
|
|
|
features |= BX_CPUID_STD_SSE2;
|
|
|
|
|
|
|
|
if (BX_CPU_VENDOR_INTEL)
|
|
|
|
features |= BX_CPUID_STD_SELF_SNOOP;
|
|
|
|
#endif
|
|
|
|
|
2020-01-11 09:18:13 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2012-01-07 21:06:03 +04:00
|
|
|
features |= BX_CPUID_STD_HT;
|
2020-01-11 09:18:13 +03:00
|
|
|
#endif
|
2011-08-08 22:20:29 +04:00
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
|
|
|
|
/* Get CPU feature flags. Returned by CPUID function 80000001 in EDX register */
|
|
|
|
Bit32u bx_generic_cpuid_t::get_std2_cpuid_features(void) const
|
|
|
|
{
|
|
|
|
// Many of the bits in EDX are the same as EAX [*] for AMD
|
|
|
|
// [*] [0:0] FPU on chip
|
|
|
|
// [*] [1:1] VME: Virtual-8086 Mode enhancements
|
|
|
|
// [*] [2:2] DE: Debug Extensions (I/O breakpoints)
|
|
|
|
// [*] [3:3] PSE: Page Size Extensions
|
|
|
|
// [*] [4:4] TSC: Time Stamp Counter
|
|
|
|
// [*] [5:5] MSR: RDMSR and WRMSR support
|
|
|
|
// [*] [6:6] PAE: Physical Address Extensions
|
|
|
|
// [*] [7:7] MCE: Machine Check Exception
|
|
|
|
// [*] [8:8] CXS: CMPXCHG8B instruction
|
|
|
|
// [*] [9:9] APIC: APIC on Chip
|
|
|
|
// [10:10] Reserved
|
|
|
|
// [11:11] SYSCALL/SYSRET support
|
|
|
|
// [*] [12:12] MTRR: Memory Type Range Reg
|
|
|
|
// [*] [13:13] PGE/PTE Global Bit
|
|
|
|
// [*] [14:14] MCA: Machine Check Architecture
|
|
|
|
// [*] [15:15] CMOV: Cond Mov/Cmp Instructions
|
|
|
|
// [*] [16:16] PAT: Page Attribute Table
|
|
|
|
// [*] [17:17] PSE-36: Physical Address Extensions
|
|
|
|
// [18:19] Reserved
|
|
|
|
// [20:20] No-Execute page protection
|
|
|
|
// [21:21] Reserved
|
|
|
|
// [22:22] AMD MMX Extensions
|
|
|
|
// [*] [23:23] MMX Technology
|
|
|
|
// [*] [24:24] FXSR: FXSAVE/FXRSTOR (also indicates CR4.OSFXSR is available)
|
|
|
|
// [25:25] Fast FXSAVE/FXRSTOR mode support
|
|
|
|
// [26:26] 1G paging support
|
|
|
|
// [27:27] Support RDTSCP Instruction
|
|
|
|
// [28:28] Reserved
|
|
|
|
// [29:29] Long Mode
|
|
|
|
// [30:30] AMD 3DNow! Extensions
|
|
|
|
// [31:31] AMD 3DNow! Instructions
|
|
|
|
Bit32u features = BX_CPU_VENDOR_INTEL ? 0 : get_std_cpuid_features();
|
|
|
|
features &= 0x0183F3FF;
|
|
|
|
#if BX_SUPPORT_3DNOW
|
|
|
|
// only AMD is interesting in AMD MMX extensions
|
|
|
|
features |= BX_CPUID_STD2_AMD_MMX_EXT | BX_CPUID_STD2_3DNOW_EXT | BX_CPUID_STD2_3DNOW;
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_X86_64
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LONG_MODE)) {
|
2011-09-25 21:36:20 +04:00
|
|
|
features |= BX_CPUID_STD2_LONG_MODE;
|
|
|
|
|
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_RDTSCP))
|
|
|
|
features |= BX_CPUID_STD2_RDTSCP;
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_NX))
|
2011-09-25 21:36:20 +04:00
|
|
|
features |= BX_CPUID_STD2_NX;
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_FFXSR))
|
2011-09-25 21:36:20 +04:00
|
|
|
features |= BX_CPUID_STD2_FFXSR;
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_1G_PAGES))
|
2011-09-25 21:36:20 +04:00
|
|
|
features |= BX_CPUID_STD2_1G_PAGES;
|
|
|
|
|
|
|
|
if (cpu->long64_mode())
|
|
|
|
features |= BX_CPUID_STD2_SYSCALL_SYSRET;
|
|
|
|
}
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get CPU feature flags. Returned by CPUID function 80000001 in ECX register */
|
|
|
|
Bit32u bx_generic_cpuid_t::get_ext2_cpuid_features(void) const
|
|
|
|
{
|
|
|
|
// ECX:
|
|
|
|
// [0:0] LAHF/SAHF instructions support in 64-bit mode
|
|
|
|
// [1:1] CMP_Legacy: Core multi-processing legacy mode (AMD)
|
|
|
|
// [2:2] SVM: Secure Virtual Machine (AMD)
|
|
|
|
// [3:3] Extended APIC Space
|
|
|
|
// [4:4] AltMovCR8: LOCK MOV CR0 means MOV CR8
|
|
|
|
// [5:5] LZCNT: LZCNT instruction support
|
|
|
|
// [6:6] SSE4A: SSE4A Instructions support (deprecated?)
|
|
|
|
// [7:7] Misaligned SSE support
|
|
|
|
// [8:8] PREFETCHW: PREFETCHW instruction support
|
|
|
|
// [9:9] OSVW: OS visible workarounds (AMD)
|
|
|
|
// [10:10] IBS: Instruction based sampling
|
|
|
|
// [11:11] XOP: Extended Operations Support and XOP Prefix
|
|
|
|
// [12:12] SKINIT support
|
|
|
|
// [13:13] WDT: Watchdog timer support
|
|
|
|
// [14:14] reserved
|
|
|
|
// [15:15] LWP: Light weight profiling
|
|
|
|
// [16:16] FMA4: Four-operand FMA instructions support
|
|
|
|
// [18:17] reserved
|
|
|
|
// [19:19] NodeId: Indicates support for NodeId MSR (0xc001100c)
|
|
|
|
// [20:20] reserved
|
2011-09-18 22:17:34 +04:00
|
|
|
// [21:21] TBM: trailing bit manipulation instructions support
|
2011-08-08 22:20:29 +04:00
|
|
|
// [22:22] Topology extensions support
|
|
|
|
// [31:23] reserved
|
|
|
|
|
|
|
|
Bit32u features = 0;
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LONG_MODE))
|
2011-09-25 21:36:20 +04:00
|
|
|
features |= BX_CPUID_EXT2_LAHF_SAHF | BX_CPUID_EXT2_PREFETCHW;
|
2011-08-08 22:20:29 +04:00
|
|
|
#endif
|
2011-10-20 00:54:04 +04:00
|
|
|
|
2014-08-31 22:39:18 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_MISALIGNED_SSE))
|
2012-12-20 23:43:11 +04:00
|
|
|
features |= BX_CPUID_EXT2_MISALIGNED_SSE;
|
2011-08-08 22:20:29 +04:00
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LZCNT))
|
2011-09-18 22:17:34 +04:00
|
|
|
features |= BX_CPUID_EXT2_LZCNT;
|
|
|
|
|
2011-09-25 21:36:20 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SSE4A))
|
2011-09-18 22:17:34 +04:00
|
|
|
features |= BX_CPUID_EXT2_SSE4A;
|
|
|
|
|
2011-10-20 00:54:04 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_XOP))
|
|
|
|
features |= BX_CPUID_EXT2_XOP;
|
|
|
|
|
2011-10-07 18:09:35 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_FMA4))
|
|
|
|
features |= BX_CPUID_EXT2_FMA4;
|
|
|
|
|
2011-10-20 00:54:04 +04:00
|
|
|
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_TBM))
|
|
|
|
features |= BX_CPUID_EXT2_TBM;
|
|
|
|
|
2011-08-08 22:20:29 +04:00
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void bx_generic_cpuid_t::dump_cpuid(void) const
|
|
|
|
{
|
2015-02-12 00:31:17 +03:00
|
|
|
bx_cpuid_t::dump_cpuid(max_std_leaf, (max_ext_leaf > 0x80000000) ? (max_ext_leaf-0x80000000) : 0);
|
2011-08-08 22:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bx_cpuid_t *create_bx_generic_cpuid(BX_CPU_C *cpu) { return new bx_generic_cpuid_t(cpu); }
|
|
|
|
|
|
|
|
#endif
|