2003-09-26 20:07:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2010-02-28 17:52:17 +03:00
|
|
|
// $Id: cpuid.cc,v 1.95 2010-02-28 14:52:16 sshwarts Exp $
|
2005-03-19 23:44:01 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2003-09-26 20:07:38 +04:00
|
|
|
//
|
2009-10-15 00:45:29 +04:00
|
|
|
// Copyright (c) 2007-2009 Stanislav Shwartsman
|
2007-10-16 02:07:52 +04:00
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
2003-09-26 20:07:38 +04:00
|
|
|
//
|
|
|
|
// 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
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
|
2005-03-19 23:44:01 +03:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
2003-09-26 20:07:38 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
|
|
|
|
2010-02-26 17:18:19 +03:00
|
|
|
#include "param_names.h"
|
|
|
|
|
2003-09-26 20:07:38 +04:00
|
|
|
#if BX_SUPPORT_X86_64==0
|
|
|
|
// Make life easier for merging code.
|
|
|
|
#define RAX EAX
|
|
|
|
#define RBX EBX
|
|
|
|
#define RCX ECX
|
|
|
|
#define RDX EDX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get CPU version information. */
|
2008-03-23 00:29:41 +03:00
|
|
|
Bit32u BX_CPU_C::get_cpu_version_information(void)
|
2003-09-26 20:07:38 +04:00
|
|
|
{
|
|
|
|
Bit32u family = 0, model = 0, stepping = 0;
|
|
|
|
Bit32u extended_model = 0;
|
|
|
|
Bit32u extended_family = 0;
|
|
|
|
|
2006-06-10 01:14:25 +04:00
|
|
|
#if BX_CPU_LEVEL > 3
|
|
|
|
|
2003-09-26 20:07:38 +04:00
|
|
|
/* ****** */
|
|
|
|
/* i486 */
|
|
|
|
/* ****** */
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL == 4
|
2006-06-10 01:14:25 +04:00
|
|
|
family = 4;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_FPU
|
2006-06-10 01:17:26 +04:00
|
|
|
model = 1; // 486dx
|
2006-06-10 01:14:25 +04:00
|
|
|
stepping = 3;
|
2003-09-26 20:07:38 +04:00
|
|
|
#else
|
2006-06-10 01:17:26 +04:00
|
|
|
model = 2; // 486sx
|
2006-06-10 01:14:25 +04:00
|
|
|
stepping = 3;
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* **************** */
|
|
|
|
/* i586 (Pentium) */
|
|
|
|
/* **************** */
|
|
|
|
|
|
|
|
#elif BX_CPU_LEVEL == 5
|
2006-06-10 01:14:25 +04:00
|
|
|
family = 5;
|
2005-02-14 00:20:48 +03:00
|
|
|
#if BX_SUPPORT_MMX
|
2006-06-10 01:17:26 +04:00
|
|
|
model = 4; // Pentium MMX
|
2005-02-14 00:20:48 +03:00
|
|
|
#else
|
2006-06-10 01:17:26 +04:00
|
|
|
model = 1; // Pentium 60/66
|
2005-02-14 00:20:48 +03:00
|
|
|
#endif
|
2006-06-10 01:17:26 +04:00
|
|
|
stepping = 3;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
/* ****** */
|
|
|
|
/* i686 */
|
|
|
|
/* ****** */
|
|
|
|
|
|
|
|
#elif BX_CPU_LEVEL == 6
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
unsigned sse_enabled = SIM->get_param_enum(BXPN_CPUID_SSE)->get();
|
|
|
|
|
|
|
|
if (sse_enabled >= 2) {
|
|
|
|
|
2003-09-26 20:07:38 +04:00
|
|
|
/*
|
|
|
|
The model, family, and processor type for the first
|
|
|
|
processor in the Intel Pentium 4 family is as follows:
|
|
|
|
* Model-0000B
|
|
|
|
* Family-1111B
|
|
|
|
* Processor Type-00B (OEM)
|
2005-02-20 23:02:54 +03:00
|
|
|
* Stepping-0B
|
2003-09-26 20:07:38 +04:00
|
|
|
*/
|
2010-02-26 01:04:31 +03:00
|
|
|
model = 0;
|
|
|
|
family = 0xf;
|
|
|
|
stepping = 0;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2010-02-26 01:04:31 +03:00
|
|
|
model = 2; // Hammer returns what?
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
}
|
|
|
|
else { // Pentium Pro/Pentium II/Pentium III processor
|
|
|
|
family = 6;
|
|
|
|
model = 8;
|
|
|
|
stepping = 3;
|
|
|
|
}
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
#else
|
2006-06-10 01:17:26 +04:00
|
|
|
BX_PANIC(("CPUID family ID not implemented for CPU LEVEL > 6"));
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
2006-06-10 01:14:25 +04:00
|
|
|
#endif // BX_CPU_LEVEL > 3
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
return (extended_family << 20) |
|
|
|
|
(extended_model << 16) |
|
|
|
|
(family << 8) |
|
2003-09-26 20:07:38 +04:00
|
|
|
(model<<4) | stepping;
|
2008-02-03 00:46:54 +03:00
|
|
|
}
|
2003-09-26 20:07:38 +04:00
|
|
|
|
|
|
|
/* Get CPU extended feature flags. */
|
2008-03-23 00:29:41 +03:00
|
|
|
Bit32u BX_CPU_C::get_extended_cpuid_features(void)
|
2003-09-26 20:07:38 +04:00
|
|
|
{
|
2007-04-19 20:12:21 +04:00
|
|
|
// [0:0] SSE3: SSE3 Instructions
|
2008-04-04 16:23:19 +04:00
|
|
|
// [1:1] PCLMULQDQ Instruction support
|
|
|
|
// [2:2] reserved
|
2007-04-19 20:12:21 +04:00
|
|
|
// [3:3] MONITOR/MWAIT support
|
|
|
|
// [4:4] DS-CPL: CPL qualified debug store
|
|
|
|
// [5:5] VMX: Virtual Machine Technology
|
2008-04-04 16:23:19 +04:00
|
|
|
// [6:6] SMX: Secure Virtual Machine Technology
|
2007-04-19 20:12:21 +04:00
|
|
|
// [7:7] EST: Enhanced Intel SpeedStep Technology
|
|
|
|
// [8:8] TM2: Thermal Monitor 2
|
|
|
|
// [9:9] SSE3E: SSE3E Instructions (Intel Core Duo 2 new instructions)
|
|
|
|
// [10:10] CNXT-ID: L1 context ID
|
2008-04-04 16:23:19 +04:00
|
|
|
// [11:11] reserved
|
|
|
|
// [12:12] FMA Instructions support
|
2007-04-19 20:12:21 +04:00
|
|
|
// [13:13] CMPXCHG16B: CMPXCHG16B instruction support
|
|
|
|
// [14:14] xTPR update control
|
2008-04-04 16:23:19 +04:00
|
|
|
// [17:15] reserved
|
|
|
|
// [18:18] DCA - Direct Cache Access
|
|
|
|
// [19:19] SSE4.1 Instructions
|
|
|
|
// [20:20] SSE4.2 Instructions
|
2009-02-21 01:00:42 +03:00
|
|
|
// [21:21] X2APIC
|
2008-08-11 22:53:24 +04:00
|
|
|
// [22:22] MOVBE instruction
|
2008-02-13 19:45:21 +03:00
|
|
|
// [23:23] POPCNT instruction
|
2008-04-04 16:23:19 +04:00
|
|
|
// [24:24] reserved
|
|
|
|
// [25:25] AES Instructions
|
2008-02-13 19:45:21 +03:00
|
|
|
// [26:26] XSAVE extensions support
|
|
|
|
// [27:27] OSXSAVE support
|
2008-04-04 16:23:19 +04:00
|
|
|
// [28:28] AVX extensions support
|
|
|
|
// [31:29] reserved
|
2007-04-19 20:12:21 +04:00
|
|
|
|
2005-05-20 00:25:16 +04:00
|
|
|
Bit32u features = 0;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
// support SSE3
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE3)
|
|
|
|
features |= (1<<0);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_PCLMULQDQ)
|
|
|
|
features |= (1<<1);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_MONITOR_MWAIT)
|
|
|
|
features |= (1<<3);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_VMX)
|
|
|
|
features |= (1<<5);
|
|
|
|
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSSE3)
|
|
|
|
features |= (1<<9);
|
2005-05-20 00:25:16 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2010-02-26 01:04:31 +03:00
|
|
|
// support CMPXCHG16B
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_X86_64)
|
|
|
|
features |= (1<<13);
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
2007-04-19 20:12:21 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE4_1)
|
|
|
|
features |= (1<<19);
|
2007-10-02 01:08:26 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE4_2)
|
|
|
|
features |= (1<<20);
|
2007-09-19 23:38:10 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_MOVBE)
|
|
|
|
features |= (1<<22);
|
2008-08-11 22:53:24 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
// enable POPCNT if SSE4_2 is enabled
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE4_2)
|
|
|
|
features |= (1<<23);
|
2008-02-13 19:45:21 +03:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_AES)
|
|
|
|
features |= (1<<25);
|
2008-05-31 00:35:08 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
// support XSAVE extensions
|
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_XSAVE)
|
|
|
|
features |= (1<<26) | (1<<27);
|
2008-02-03 00:46:54 +03:00
|
|
|
|
2003-09-26 20:07:38 +04:00
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get CPU feature flags. Returned by CPUID functions 1 and 80000001. */
|
2008-03-23 00:29:41 +03:00
|
|
|
Bit32u BX_CPU_C::get_std_cpuid_features(void)
|
2003-09-26 20:07:38 +04:00
|
|
|
{
|
2009-05-19 19:46:07 +04:00
|
|
|
// [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] 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] Reserved
|
|
|
|
// [28:28] Hyper Threading Technology
|
|
|
|
// [29:29] TM: Thermal Monitor
|
|
|
|
// [30:30] Reserved
|
|
|
|
// [31:31] PBE: Pending Break Enable
|
|
|
|
|
2005-05-20 00:25:16 +04:00
|
|
|
Bit32u features = 0;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_X87)
|
|
|
|
features |= (1<<0);
|
|
|
|
|
2009-08-10 19:44:50 +04:00
|
|
|
#if BX_CPU_LEVEL >= 5
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_PENTIUM) {
|
|
|
|
// Pentium only features
|
2010-02-27 01:53:43 +03:00
|
|
|
features |= (1<<1); // support VME
|
2010-02-26 01:04:31 +03:00
|
|
|
features |= (1<<3); // support PSE
|
|
|
|
features |= (1<<4); // support Time Stamp Counter
|
|
|
|
features |= (1<<5); // support RDMSR/WRMSR
|
|
|
|
features |= (1<<7) | (1<<14); // support Machine Check
|
|
|
|
features |= (1<<8); // support CMPXCHG8B instruction
|
|
|
|
}
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
2009-05-19 19:46:07 +04:00
|
|
|
features |= (1<<2); // support Debug Extensions
|
|
|
|
|
2009-05-19 22:54:05 +04:00
|
|
|
#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 (BX_CPU_THIS_PTR msr.apicbase & 0x800)
|
|
|
|
features |= (1<<9); // APIC on chip
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SYSENTER_SYSEXIT)
|
|
|
|
features |= (1<<11);
|
2003-12-31 20:35:43 +03:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_CLFLUSH)
|
|
|
|
features |= (1<<19);
|
2007-01-29 00:27:31 +03:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_MMX)
|
|
|
|
features |= (1<<23);
|
2009-05-19 22:54:05 +04:00
|
|
|
|
2003-12-31 20:35:43 +03:00
|
|
|
#if BX_CPU_LEVEL >= 6
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_P6) {
|
|
|
|
features |= (1<<15); // Implement CMOV instructions
|
|
|
|
features |= (1<<24); // Implement FSAVE/FXRSTOR instructions
|
|
|
|
features |= (1<<6); // support PAE
|
|
|
|
features |= (1<<12); // support MTRRs
|
|
|
|
features |= (1<<13); // support Global pages
|
|
|
|
features |= (1<<16); // support PAT
|
|
|
|
features |= (1<<17); // support PSE-36
|
|
|
|
}
|
2003-09-26 20:07:38 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE)
|
|
|
|
features |= (1<<25);
|
2007-09-20 21:33:35 +04:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_THIS_PTR cpuid_features_bitmask & BX_CPU_SSE2)
|
|
|
|
features |= (1<<26);
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
2006-02-11 18:28:43 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
|
|
|
// Intel(R) HyperThreading Technology
|
2008-02-03 00:46:54 +03:00
|
|
|
if (SIM->get_param_num(BXPN_CPU_NTHREADS)->get() > 1)
|
2006-02-11 18:28:43 +03:00
|
|
|
features |= (1<<28);
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1) BX_CPU_C::CPUID(bxInstruction_c *i)
|
2003-09-26 20:07:38 +04:00
|
|
|
{
|
2008-02-14 01:51:31 +03:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2008-02-14 01:42:41 +03:00
|
|
|
Bit32u function = EAX;
|
|
|
|
Bit32u subfunction = ECX;
|
2003-09-26 20:07:38 +04:00
|
|
|
|
2009-01-31 13:43:24 +03:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
if (BX_CPU_THIS_PTR in_vmx_guest) {
|
|
|
|
BX_ERROR(("VMEXIT: CPUID in VMX non-root operation"));
|
|
|
|
VMexit(i, VMX_VMEXIT_CPUID, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
if(function < 0x80000000) {
|
|
|
|
if(function < MAX_STD_CPUID_FUNCTION) {
|
|
|
|
RAX = BX_CPU_THIS_PTR cpuid_std_function[function].eax;
|
|
|
|
RBX = BX_CPU_THIS_PTR cpuid_std_function[function].ebx;
|
|
|
|
RCX = BX_CPU_THIS_PTR cpuid_std_function[function].ecx;
|
|
|
|
RDX = BX_CPU_THIS_PTR cpuid_std_function[function].edx;
|
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
if (function == 1) {
|
|
|
|
// if MSR_APICBASE APIC Global Enable bit has been cleared,
|
|
|
|
// the CPUID feature flag for the APIC is set to 0.
|
|
|
|
if ((BX_CPU_THIS_PTR msr.apicbase & 0x800) == 0)
|
|
|
|
RDX &= ~(1<<9); // APIC on chip
|
|
|
|
}
|
2008-02-14 01:25:24 +03:00
|
|
|
#endif
|
|
|
|
if (function == 0xD && subfunction > 0) {
|
|
|
|
RAX = 0;
|
|
|
|
RBX = 0;
|
|
|
|
RCX = 0;
|
|
|
|
RDX = 0;
|
|
|
|
}
|
2007-10-12 23:30:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
function -= 0x80000000;
|
|
|
|
if(function < MAX_EXT_CPUID_FUNCTION) {
|
|
|
|
RAX = BX_CPU_THIS_PTR cpuid_ext_function[function].eax;
|
|
|
|
RBX = BX_CPU_THIS_PTR cpuid_ext_function[function].ebx;
|
|
|
|
RCX = BX_CPU_THIS_PTR cpuid_ext_function[function].ecx;
|
|
|
|
RDX = BX_CPU_THIS_PTR cpuid_ext_function[function].edx;
|
|
|
|
#if BX_SUPPORT_APIC
|
2008-05-09 22:09:04 +04:00
|
|
|
if (function == 1) {
|
2007-10-12 23:30:51 +04:00
|
|
|
// if MSR_APICBASE APIC Global Enable bit has been cleared,
|
|
|
|
// the CPUID feature flag for the APIC is set to 0.
|
|
|
|
if ((BX_CPU_THIS_PTR msr.apicbase & 0x800) == 0)
|
|
|
|
RDX &= ~(1<<9); // APIC on chip
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unknown CPUID function
|
|
|
|
RAX = 0;
|
|
|
|
RBX = 0;
|
|
|
|
RCX = 0;
|
|
|
|
RDX = 0;
|
|
|
|
#else
|
|
|
|
BX_INFO(("CPUID: not available on < 486"));
|
2008-07-13 19:35:10 +04:00
|
|
|
exception(BX_UD_EXCEPTION, 0, 0);
|
2006-02-11 18:28:43 +03:00
|
|
|
#endif
|
2007-10-12 23:30:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPU_C::set_cpuid_defaults(void)
|
|
|
|
{
|
2008-08-19 20:43:07 +04:00
|
|
|
Bit8u *vendor_string = (Bit8u *)SIM->get_param_string(BXPN_VENDOR_STRING)->getptr();
|
|
|
|
Bit8u *brand_string = (Bit8u *)SIM->get_param_string(BXPN_BRAND_STRING)->getptr();
|
2008-09-23 01:38:15 +04:00
|
|
|
bool cpuid_limit_winnt = SIM->get_param_bool(BXPN_CPUID_LIMIT_WINNT)->get();
|
2008-08-19 20:43:07 +04:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid_function_t *cpuid;
|
|
|
|
int i;
|
|
|
|
|
2007-11-16 23:33:21 +03:00
|
|
|
for (i=0;i<MAX_STD_CPUID_FUNCTION;i++) {
|
2007-10-12 23:30:51 +04:00
|
|
|
BX_CPU_THIS_PTR cpuid_std_function[i].eax = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_std_function[i].ebx = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_std_function[i].ecx = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_std_function[i].edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0;i<MAX_EXT_CPUID_FUNCTION;i++) {
|
|
|
|
BX_CPU_THIS_PTR cpuid_ext_function[i].eax = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_ext_function[i].ebx = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_ext_function[i].ecx = 0;
|
|
|
|
BX_CPU_THIS_PTR cpuid_ext_function[i].edx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x00000000
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[0]);
|
|
|
|
|
|
|
|
// EAX: highest input value understood by CPUID
|
|
|
|
// EBX: vendor ID string
|
|
|
|
// EDX: vendor ID string
|
|
|
|
// ECX: vendor ID string
|
2006-02-11 18:28:43 +03:00
|
|
|
|
2003-10-05 16:14:02 +04:00
|
|
|
#if BX_CPU_LEVEL <= 5
|
2007-10-12 23:30:51 +04:00
|
|
|
// 486 and Pentium processors
|
|
|
|
cpuid->eax = 1;
|
2008-02-03 00:46:54 +03:00
|
|
|
#else
|
2007-10-12 23:30:51 +04:00
|
|
|
// for Pentium Pro, Pentium II, Pentium 4 processors
|
2008-02-14 01:25:24 +03:00
|
|
|
cpuid->eax = 2;
|
2008-09-23 01:38:15 +04:00
|
|
|
// do not report CPUID functions above 0x3 if cpuid_limit_winnt is set
|
|
|
|
// to workaround WinNT issue.
|
|
|
|
if (! cpuid_limit_winnt) {
|
|
|
|
if (BX_SUPPORT_MONITOR_MWAIT)
|
|
|
|
cpuid->eax = 0x5;
|
2010-02-27 01:53:43 +03:00
|
|
|
if (BX_CPU_SUPPORT_FEATURE(BX_CPU_XSAVE))
|
2008-09-23 01:38:15 +04:00
|
|
|
cpuid->eax = 0xD;
|
|
|
|
}
|
2003-09-26 20:07:38 +04:00
|
|
|
#endif
|
2007-10-12 23:30:51 +04:00
|
|
|
|
2008-08-19 20:43:07 +04:00
|
|
|
// CPUID vendor string (e.g. GenuineIntel, AuthenticAMD, CentaurHauls, ...)
|
|
|
|
memcpy(&(cpuid->ebx), vendor_string , 4);
|
|
|
|
memcpy(&(cpuid->edx), vendor_string + 4, 4);
|
|
|
|
memcpy(&(cpuid->ecx), vendor_string + 8, 4);
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x00000001
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[1]);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// [31:14] Reserved
|
|
|
|
cpuid->eax = get_cpu_version_information();
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
// EBX:
|
2007-10-12 23:30:51 +04:00
|
|
|
// [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
|
|
|
|
|
|
|
|
cpuid->ebx = 0;
|
2007-01-29 00:27:31 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
2009-02-21 01:00:42 +03:00
|
|
|
cpuid->ebx |= ((BX_CPU_THIS_PTR lapic.get_id() & 0xff) << 24);
|
2007-01-29 00:27:31 +03:00
|
|
|
#endif
|
2010-02-26 01:04:31 +03:00
|
|
|
if (BX_CPU_SUPPORT_FEATURE(BX_CPU_CLFLUSH)) {
|
|
|
|
cpuid->ebx |= (CACHE_LINE_SIZE / 8) << 8;
|
|
|
|
}
|
2006-02-11 18:28:43 +03:00
|
|
|
#if BX_SUPPORT_SMP
|
2007-10-12 23:30:51 +04:00
|
|
|
unsigned n_logical_processors = SIM->get_param_num(BXPN_CPU_NCORES)->get()*SIM->get_param_num(BXPN_CPU_NTHREADS)->get();
|
|
|
|
if (n_logical_processors > 1)
|
|
|
|
cpuid->ebx |= (n_logical_processors << 16);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ECX: Extended Feature Flags
|
|
|
|
// [0:0] SSE3: SSE3 Instructions
|
2008-04-04 16:23:19 +04:00
|
|
|
// [1:1] PCLMULQDQ Instruction support
|
|
|
|
// [2:2] reserved
|
2007-10-12 23:30:51 +04:00
|
|
|
// [3:3] MONITOR/MWAIT support
|
|
|
|
// [4:4] DS-CPL: CPL qualified debug store
|
|
|
|
// [5:5] VMX: Virtual Machine Technology
|
2008-04-04 16:23:19 +04:00
|
|
|
// [6:6] SMX: Secure Virtual Machine Technology
|
2007-10-12 23:30:51 +04:00
|
|
|
// [7:7] EST: Enhanced Intel SpeedStep Technology
|
|
|
|
// [8:8] TM2: Thermal Monitor 2
|
|
|
|
// [9:9] SSE3E: SSE3E Instructions (Intel Core Duo 2 new instructions)
|
|
|
|
// [10:10] CNXT-ID: L1 context ID
|
2008-04-04 16:23:19 +04:00
|
|
|
// [11:11] reserved
|
|
|
|
// [12:12] FMA Instructions support
|
2007-10-12 23:30:51 +04:00
|
|
|
// [13:13] CMPXCHG16B: CMPXCHG16B instruction support
|
|
|
|
// [14:14] xTPR update control
|
2008-04-04 16:23:19 +04:00
|
|
|
// [17:15] reserved
|
|
|
|
// [18:18] DCA - Direct Cache Access
|
|
|
|
// [19:19] SSE4.1 Instructions
|
|
|
|
// [20:20] SSE4.2 Instructions
|
2009-02-21 01:00:42 +03:00
|
|
|
// [21:21] X2APIC
|
|
|
|
// [22:22] MOVBE instruction
|
2008-04-04 16:23:19 +04:00
|
|
|
// [23:23] POPCNT instruction
|
|
|
|
// [24:24] reserved
|
|
|
|
// [25:25] AES Instructions
|
|
|
|
// [26:26] XSAVE extensions support
|
|
|
|
// [27:27] OSXSAVE support
|
|
|
|
// [28:28] AVX extensions support
|
|
|
|
// [31:29] reserved
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid->ecx = get_extended_cpuid_features();
|
|
|
|
|
|
|
|
// EDX: Feature Flags
|
|
|
|
// [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
|
2007-12-15 20:42:24 +03:00
|
|
|
// [17:17] PSE-36: Physical Address Extensions
|
2007-10-12 23:30:51 +04:00
|
|
|
// [18:18] 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] Reserved
|
|
|
|
// [28:28] Hyper Threading Technology
|
|
|
|
// [29:29] TM: Thermal Monitor
|
|
|
|
// [30:30] Reserved
|
|
|
|
// [31:31] PBE: Pending Break Enable
|
|
|
|
cpuid->edx = get_std_cpuid_features();
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
// ------------------------------------------------------
|
2007-10-13 01:45:41 +04:00
|
|
|
// CPUID function 0x00000002 - Cache and TLB Descriptors
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[2]);
|
|
|
|
|
2007-10-13 01:45:41 +04:00
|
|
|
#if BX_CPU_VENDOR_INTEL
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid->eax = 0x00410601; // for Pentium Pro compatibility
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0;
|
|
|
|
cpuid->edx = 0;
|
2007-10-13 01:45:41 +04:00
|
|
|
#else
|
|
|
|
cpuid->eax = 0; // ignore for AMD
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
#endif
|
2007-01-29 20:56:03 +03:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
// ------------------------------------------------------
|
2007-10-13 01:45:41 +04:00
|
|
|
// CPUID function 0x00000003 - Processor Serial Number
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[3]);
|
|
|
|
|
|
|
|
cpuid->eax = 0;
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
|
2008-09-23 01:38:15 +04:00
|
|
|
// do not report CPUID functions above 0x3 if cpuid_limit_winnt is set
|
|
|
|
// to workaround WinNT issue.
|
2008-09-23 01:41:22 +04:00
|
|
|
if (cpuid_limit_winnt) return;
|
2008-09-23 01:38:15 +04:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
// ------------------------------------------------------
|
2007-10-13 01:45:41 +04:00
|
|
|
// CPUID function 0x00000004 - Deterministic Cache Parameters
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[4]);
|
|
|
|
|
|
|
|
cpuid->eax = 0;
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
|
2007-10-13 01:45:41 +04:00
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
2007-10-12 23:30:51 +04:00
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x00000005
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[5]);
|
|
|
|
|
|
|
|
// 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 - Reserved
|
|
|
|
cpuid->eax = CACHE_LINE_SIZE;
|
|
|
|
cpuid->ebx = CACHE_LINE_SIZE;
|
|
|
|
cpuid->ecx = 3;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-02-14 01:25:24 +03:00
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x0000000D
|
2010-02-27 01:53:43 +03:00
|
|
|
if (BX_CPU_SUPPORT_FEATURE(BX_CPU_XSAVE))
|
|
|
|
{
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[0xD]);
|
|
|
|
|
|
|
|
// EAX - XCR0 lower 32 bits
|
|
|
|
// EBX - Maximum size (in bytes) required by enabled features
|
|
|
|
// ECX - Maximum size (in bytes) required by CPU supported features
|
|
|
|
// EDX - XCR0 upper 32 bits
|
|
|
|
cpuid->eax = BX_CPU_THIS_PTR xcr0.get32();
|
|
|
|
cpuid->ebx = 512+64;
|
|
|
|
cpuid->ecx = 512+64;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
}
|
2008-02-14 01:25:24 +03:00
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
// do not report Pentium 4 extended functions if not needed
|
2010-02-27 01:53:43 +03:00
|
|
|
if (! BX_CPU_SUPPORT_FEATURE(BX_CPU_SSE2))
|
2010-02-26 01:04:31 +03:00
|
|
|
return;
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000000
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[0]);
|
|
|
|
|
|
|
|
// EAX: highest input value understood by CPUID
|
|
|
|
// EBX: vendor ID string
|
|
|
|
// EDX: vendor ID string
|
|
|
|
// ECX: vendor ID string
|
|
|
|
cpuid->eax = BX_SUPPORT_X86_64 ? 0x80000008 : 0x80000004;
|
|
|
|
#if BX_CPU_VENDOR_INTEL
|
2007-10-13 01:45:41 +04:00
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->edx = 0; // Reserved for Intel
|
|
|
|
cpuid->ecx = 0;
|
2007-10-12 23:30:51 +04:00
|
|
|
#else
|
2008-08-19 20:43:07 +04:00
|
|
|
memcpy(&(cpuid->ebx), vendor_string , 4);
|
|
|
|
memcpy(&(cpuid->edx), vendor_string + 4, 4);
|
|
|
|
memcpy(&(cpuid->ecx), vendor_string + 8, 4);
|
2007-10-12 01:29:01 +04:00
|
|
|
#endif
|
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000001
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[1]);
|
|
|
|
|
|
|
|
// EAX: CPU Version Information
|
2007-10-13 01:45:41 +04:00
|
|
|
cpuid->eax = BX_CPU_VENDOR_INTEL ? 0 : get_cpu_version_information();
|
2007-10-12 23:30:51 +04:00
|
|
|
|
2007-10-13 01:45:41 +04:00
|
|
|
// EBX: Brand ID
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid->ebx = 0;
|
|
|
|
|
|
|
|
// ECX:
|
|
|
|
// [0:0] LAHF/SAHF available in 64-bit mode
|
|
|
|
// [1:1] AMD CmpLegacy
|
|
|
|
// [2:2] AMD Secure Virtual Machine Technology
|
|
|
|
// [3:3] Extended APIC Space
|
2008-02-03 00:46:54 +03:00
|
|
|
// [4:4] Alternative CR8 (treat lock mov cr0 as mov cr8)
|
2007-10-12 23:30:51 +04:00
|
|
|
// [5:5] LZCNT support
|
|
|
|
// [6:6] SSE4A support
|
|
|
|
// [7:7] Misaligned SSE support
|
|
|
|
// [8:8] 3DNow! prefetch support
|
|
|
|
// [9:9] OS visible workarounds
|
2007-12-15 20:42:24 +03:00
|
|
|
// [10:10] Reserved
|
|
|
|
// [11:11] SSE5A
|
|
|
|
// [12:31] Reserved
|
2007-10-13 01:45:41 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid->ecx = 1 | (1<<8);
|
2007-10-13 01:45:41 +04:00
|
|
|
#endif
|
2007-07-15 23:03:39 +04:00
|
|
|
#if BX_SUPPORT_MISALIGNED_SSE
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid->ecx |= (1<<7);
|
|
|
|
#endif
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
// EDX:
|
2007-10-13 01:45:41 +04:00
|
|
|
// Many of the bits in EDX are the same as EAX [*] for AMD
|
2007-10-12 23:30:51 +04:00
|
|
|
// [*] [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
|
2007-12-15 20:42:24 +03:00
|
|
|
// [*] [17:17] PSE-36: Physical Address Extensions
|
2007-10-12 23:30:51 +04:00
|
|
|
// [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
|
2007-10-13 01:45:41 +04:00
|
|
|
// [26:26] 1G paging support
|
2007-10-12 23:30:51 +04:00
|
|
|
// [27:27] Support RDTSCP Instruction
|
|
|
|
// [28:28] Reserved
|
|
|
|
// [29:29] Long Mode
|
|
|
|
// [30:30] AMD 3DNow! Extensions
|
|
|
|
// [31:31] AMD 3DNow! Instructions
|
2007-10-13 01:45:41 +04:00
|
|
|
unsigned features = BX_CPU_VENDOR_INTEL ? 0 : get_std_cpuid_features();
|
|
|
|
features &= 0x0183F3FF;
|
|
|
|
#if BX_SUPPORT_3DNOW
|
2007-11-25 23:52:40 +03:00
|
|
|
features |= (1 << 22) | (1 << 30) | (1 << 31); // only AMD is interesting in AMD MMX extensions
|
2007-10-13 01:45:41 +04:00
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
features |= (1 << 29) | (1 << 27) | (1 << 25) | (1 << 20) | (1 << 11);
|
2008-12-12 00:00:01 +03:00
|
|
|
#if BX_SUPPORT_1G_PAGES
|
2009-05-19 22:54:05 +04:00
|
|
|
features |= (1 << 26);
|
2008-12-12 00:00:01 +03:00
|
|
|
#endif
|
2007-10-12 23:30:51 +04:00
|
|
|
#endif
|
2007-10-13 01:45:41 +04:00
|
|
|
cpuid->edx = features;
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// Processor Brand String, use the value that is returned
|
2008-02-03 00:46:54 +03:00
|
|
|
// by the first processor in the Pentium 4 family
|
2008-08-19 20:43:07 +04:00
|
|
|
// (according to Intel manual or the AMD manual)
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000002
|
|
|
|
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[2]);
|
2008-08-19 20:43:07 +04:00
|
|
|
memcpy(&(cpuid->eax), brand_string , 4);
|
|
|
|
memcpy(&(cpuid->ebx), brand_string + 4, 4);
|
|
|
|
memcpy(&(cpuid->ecx), brand_string + 8, 4);
|
|
|
|
memcpy(&(cpuid->edx), brand_string + 12, 4);
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// CPUID function 0x80000003
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[3]);
|
2008-08-19 20:43:07 +04:00
|
|
|
memcpy(&(cpuid->eax), brand_string + 16, 4);
|
|
|
|
memcpy(&(cpuid->ebx), brand_string + 20, 4);
|
|
|
|
memcpy(&(cpuid->ecx), brand_string + 24, 4);
|
|
|
|
memcpy(&(cpuid->edx), brand_string + 28, 4);
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// CPUID function 0x80000004
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[4]);
|
2008-08-19 20:43:07 +04:00
|
|
|
memcpy(&(cpuid->eax), brand_string + 32, 4);
|
|
|
|
memcpy(&(cpuid->ebx), brand_string + 36, 4);
|
|
|
|
memcpy(&(cpuid->ecx), brand_string + 40, 4);
|
|
|
|
memcpy(&(cpuid->edx), brand_string + 44, 4);
|
2005-02-15 00:17:20 +03:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000005
|
2010-01-24 23:21:47 +03:00
|
|
|
|
|
|
|
#if BX_CPU_VENDOR_INTEL == 0
|
2007-10-12 23:30:51 +04:00
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[5]);
|
|
|
|
|
|
|
|
/* cache info (L1 cache) */
|
|
|
|
cpuid->eax = 0x01ff01ff;
|
|
|
|
cpuid->ebx = 0x01ff01ff;
|
|
|
|
cpuid->ecx = 0x40020140;
|
|
|
|
cpuid->edx = 0x40020140;
|
2010-01-24 23:21:47 +03:00
|
|
|
#endif
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000006
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[6]);
|
|
|
|
|
|
|
|
/* cache info (L2 cache) */
|
|
|
|
cpuid->eax = 0;
|
|
|
|
cpuid->ebx = 0x42004200;
|
|
|
|
cpuid->ecx = 0x02008140;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x00000007
|
2008-05-09 22:09:04 +04:00
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[7]);
|
2007-10-12 23:30:51 +04:00
|
|
|
|
|
|
|
cpuid->eax = 0;
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0;
|
|
|
|
cpuid->edx = 0;
|
|
|
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
// CPUID function 0x80000008
|
|
|
|
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[8]);
|
|
|
|
|
|
|
|
// virtual & phys address size in low 2 bytes.
|
|
|
|
cpuid->eax = BX_PHY_ADDRESS_WIDTH | (BX_LIN_ADDRESS_WIDTH << 8);
|
|
|
|
cpuid->ebx = 0;
|
|
|
|
cpuid->ecx = 0; // Reserved, undefined
|
|
|
|
cpuid->edx = 0;
|
2007-01-29 20:56:03 +03:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
#endif // BX_SUPPORT_X86_64
|
2003-09-26 20:07:38 +04:00
|
|
|
|
2007-10-12 23:30:51 +04:00
|
|
|
#endif // BX_CPU_LEVEL >= 6
|
2003-09-26 20:07:38 +04:00
|
|
|
}
|
2010-02-26 01:04:31 +03:00
|
|
|
|
|
|
|
void BX_CPU_C::init_cpu_features_bitmask(void)
|
|
|
|
{
|
|
|
|
Bit32u features_bitmask = 0;
|
|
|
|
|
2010-02-26 14:44:50 +03:00
|
|
|
bx_bool sep_enabled = SIM->get_param_bool(BXPN_CPUID_SEP)->get();
|
2010-02-26 01:04:31 +03:00
|
|
|
bx_bool aes_enabled = SIM->get_param_bool(BXPN_CPUID_AES)->get();
|
|
|
|
bx_bool movbe_enabled = SIM->get_param_bool(BXPN_CPUID_MOVBE)->get();
|
2010-02-27 01:53:43 +03:00
|
|
|
bx_bool xsave_enabled = SIM->get_param_bool(BXPN_CPUID_XSAVE)->get();
|
2010-02-28 17:52:17 +03:00
|
|
|
bx_bool xapic_enabled = SIM->get_param_bool(BXPN_CPUID_XAPIC)->get();
|
2010-02-26 01:04:31 +03:00
|
|
|
unsigned sse_enabled = SIM->get_param_enum(BXPN_CPUID_SSE)->get();
|
|
|
|
|
|
|
|
// sanity checks
|
|
|
|
if (aes_enabled) {
|
|
|
|
// AES required 3-byte opcode (SSS3E support or more)
|
|
|
|
if (sse_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
|
|
|
BX_PANIC(("PANIC: AES support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movbe_enabled) {
|
|
|
|
// MOVBE required 3-byte opcode (SSS3E support or more)
|
|
|
|
if (sse_enabled < BX_CPUID_SUPPORT_SSSE3) {
|
|
|
|
BX_PANIC(("PANIC: MOVBE support requires SSSE3 or higher !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-28 17:52:17 +03:00
|
|
|
if (xapic_enabled) {
|
|
|
|
if (! BX_SUPPORT_APIC) {
|
|
|
|
BX_PANIC(("PANIC: XAPIC enabled when APIC is not compiled in !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
if (sse_enabled) {
|
|
|
|
if (BX_SUPPORT_MMX == 0 || BX_CPU_LEVEL < 6) {
|
|
|
|
BX_PANIC(("PANIC: SSE support requires P6 emulation with MMX enabled !"));
|
|
|
|
return;
|
|
|
|
}
|
2010-02-26 01:34:56 +03:00
|
|
|
|
|
|
|
if (sse_enabled >= BX_CPUID_SUPPORT_SSE2) {
|
2010-02-28 17:52:17 +03:00
|
|
|
if (! xapic_enabled) {
|
|
|
|
BX_PANIC(("PANIC: SSE2 is enabled and without XAPIC !"));
|
2010-02-26 01:34:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-02-26 01:04:31 +03:00
|
|
|
}
|
|
|
|
else {
|
2010-02-27 01:53:43 +03:00
|
|
|
if (xsave_enabled) {
|
2010-02-26 01:04:31 +03:00
|
|
|
BX_PANIC(("PANIC: XSAVE emulation requires SSE support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2010-02-26 01:44:46 +03:00
|
|
|
if (sse_enabled < BX_CPUID_SUPPORT_SSE2) {
|
2010-02-26 01:04:31 +03:00
|
|
|
BX_PANIC(("PANIC: x86-64 emulation requires SSE2 support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-26 14:44:50 +03:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
if (! sep_enabled) {
|
|
|
|
BX_PANIC(("PANIC: VMX emulation requires SYSENTER/SYSEXIT support !"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
#if BX_SUPPORT_FPU
|
|
|
|
features_bitmask |= BX_CPU_X87;
|
|
|
|
#endif
|
|
|
|
#if BX_CPU_LEVEL >= 4
|
|
|
|
features_bitmask |= BX_CPU_486;
|
|
|
|
#endif
|
|
|
|
#if BX_CPU_LEVEL >= 5
|
|
|
|
features_bitmask |= BX_CPU_PENTIUM;
|
|
|
|
#endif
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
features_bitmask |= BX_CPU_P6;
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_MMX
|
|
|
|
features_bitmask |= BX_CPU_MMX;
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_3DNOW
|
|
|
|
features_bitmask |= BX_CPU_3DNOW;
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
|
|
|
features_bitmask |= BX_CPU_MONITOR_MWAIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 6
|
|
|
|
// enabled CLFLUSH only when SSE2 or higher is enabled
|
|
|
|
if (sse_enabled >= BX_CPUID_SUPPORT_SSE2)
|
|
|
|
features_bitmask |= BX_CPU_CLFLUSH;
|
|
|
|
|
|
|
|
// determine SSE in runtime
|
|
|
|
switch (sse_enabled) {
|
|
|
|
case BX_CPUID_SUPPORT_SSE4_2:
|
|
|
|
features_bitmask |= BX_CPU_SSE4_2;
|
|
|
|
case BX_CPUID_SUPPORT_SSE4_1:
|
|
|
|
features_bitmask |= BX_CPU_SSE4_1;
|
|
|
|
case BX_CPUID_SUPPORT_SSSE3:
|
|
|
|
features_bitmask |= BX_CPU_SSSE3;
|
|
|
|
case BX_CPUID_SUPPORT_SSE3:
|
|
|
|
features_bitmask |= BX_CPU_SSE3;
|
|
|
|
case BX_CPUID_SUPPORT_SSE2:
|
|
|
|
features_bitmask |= BX_CPU_SSE2;
|
|
|
|
case BX_CPUID_SUPPORT_SSE:
|
|
|
|
features_bitmask |= BX_CPU_SSE;
|
|
|
|
case BX_CPUID_SUPPORT_NOSSE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
2010-02-26 14:44:50 +03:00
|
|
|
if (sep_enabled)
|
|
|
|
features_bitmask |= BX_CPU_SYSENTER_SYSEXIT;
|
|
|
|
|
2010-02-27 01:53:43 +03:00
|
|
|
if (xsave_enabled)
|
|
|
|
features_bitmask |= BX_CPU_XSAVE;
|
2010-02-26 01:04:31 +03:00
|
|
|
|
2010-02-27 01:53:43 +03:00
|
|
|
if (aes_enabled)
|
|
|
|
features_bitmask |= BX_CPU_AES | BX_CPU_PCLMULQDQ;
|
2010-02-26 01:04:31 +03:00
|
|
|
|
|
|
|
if (movbe_enabled)
|
|
|
|
features_bitmask |= BX_CPU_MOVBE;
|
|
|
|
#endif
|
|
|
|
|
2010-02-27 01:53:43 +03:00
|
|
|
#if BX_SUPPORT_VMX
|
|
|
|
features_bitmask |= BX_CPU_VMX;
|
|
|
|
#endif
|
|
|
|
|
2010-02-26 01:04:31 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
features_bitmask |= BX_CPU_X86_64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BX_CPU_THIS_PTR cpuid_features_bitmask = features_bitmask;
|
|
|
|
}
|