1 /////////////////////////////////////////////////////////////////////////
2 // $Id: p3_katmai.cc 13153 2017-03-26 20:12:14Z sshwarts $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 //   Copyright (c) 2011-2017 Stanislav Shwartsman
6 //          Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7 //
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Lesser General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Lesser General Public License for more details.
17 //
18 //  You should have received a copy of the GNU Lesser General Public
19 //  License along with this library; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
21 //
22 /////////////////////////////////////////////////////////////////////////
23 
24 #include "bochs.h"
25 #include "cpu.h"
26 #include "p3_katmai.h"
27 
28 #if BX_CPU_LEVEL >= 6
29 
30 #define LOG_THIS cpu->
31 
p3_katmai_t(BX_CPU_C * cpu)32 p3_katmai_t::p3_katmai_t(BX_CPU_C *cpu): bx_cpuid_t(cpu)
33 {
34   enable_cpu_extension(BX_ISA_X87);
35   enable_cpu_extension(BX_ISA_486);
36   enable_cpu_extension(BX_ISA_PENTIUM);
37   enable_cpu_extension(BX_ISA_MMX);
38   enable_cpu_extension(BX_ISA_P6);
39   enable_cpu_extension(BX_ISA_SYSENTER_SYSEXIT);
40   enable_cpu_extension(BX_ISA_SSE);
41   enable_cpu_extension(BX_ISA_DEBUG_EXTENSIONS);
42   enable_cpu_extension(BX_ISA_VME);
43   enable_cpu_extension(BX_ISA_PSE);
44   enable_cpu_extension(BX_ISA_PAE);
45   enable_cpu_extension(BX_ISA_PGE);
46 #if BX_PHY_ADDRESS_LONG
47   enable_cpu_extension(BX_ISA_PSE36);
48 #endif
49   enable_cpu_extension(BX_ISA_MTRR);
50   enable_cpu_extension(BX_ISA_PAT);
51 }
52 
get_cpuid_leaf(Bit32u function,Bit32u subfunction,cpuid_function_t * leaf) const53 void p3_katmai_t::get_cpuid_leaf(Bit32u function, Bit32u subfunction, cpuid_function_t *leaf) const
54 {
55   switch(function) {
56   case 0x00000000:
57     get_std_cpuid_leaf_0(leaf);
58     return;
59   case 0x00000001:
60     get_std_cpuid_leaf_1(leaf);
61     return;
62   case 0x00000002:
63     get_std_cpuid_leaf_2(leaf);
64     return;
65   case 0x00000003:
66   default:
67     get_std_cpuid_leaf_3(leaf);
68     return;
69   }
70 }
71 
72 // leaf 0x00000000 //
get_std_cpuid_leaf_0(cpuid_function_t * leaf) const73 void p3_katmai_t::get_std_cpuid_leaf_0(cpuid_function_t *leaf) const
74 {
75   get_leaf_0(0x3, "GenuineIntel", leaf);
76 }
77 
78 // leaf 0x00000001 //
get_std_cpuid_leaf_1(cpuid_function_t * leaf) const79 void p3_katmai_t::get_std_cpuid_leaf_1(cpuid_function_t *leaf) const
80 {
81   // EAX:       CPU Version Information
82   //   [3:0]   Stepping ID
83   //   [7:4]   Model: starts at 1
84   //   [11:8]  Family: 4=486, 5=Pentium, 6=PPro, ...
85   //   [13:12] Type: 0=OEM, 1=overdrive, 2=dual cpu, 3=reserved
86   //   [19:16] Extended Model
87   //   [27:20] Extended Family
88   leaf->eax = 0x00000673;
89 
90   leaf->ebx = 0;
91   leaf->ecx = 0;
92 
93   // EDX: Standard Feature Flags
94   // * [0:0]   FPU on chip
95   // * [1:1]   VME: Virtual-8086 Mode enhancements
96   // * [2:2]   DE: Debug Extensions (I/O breakpoints)
97   // * [3:3]   PSE: Page Size Extensions
98   // * [4:4]   TSC: Time Stamp Counter
99   // * [5:5]   MSR: RDMSR and WRMSR support
100   // * [6:6]   PAE: Physical Address Extensions
101   // * [7:7]   MCE: Machine Check Exception
102   // * [8:8]   CXS: CMPXCHG8B instruction
103   //   [9:9]   APIC: APIC on Chip
104   //   [10:10] Reserved
105   // * [11:11] SYSENTER/SYSEXIT support
106   // * [12:12] MTRR: Memory Type Range Reg
107   // * [13:13] PGE/PTE Global Bit
108   // * [14:14] MCA: Machine Check Architecture
109   // * [15:15] CMOV: Cond Mov/Cmp Instructions
110   // * [16:16] PAT: Page Attribute Table
111   // * [17:17] PSE-36: Physical Address Extensions
112   // * [18:18] PSN: Processor Serial Number
113   //   [19:19] CLFLUSH: CLFLUSH Instruction support
114   //   [20:20] Reserved
115   //   [21:21] DS: Debug Store
116   //   [22:22] ACPI: Thermal Monitor and Software Controlled Clock Facilities
117   // * [23:23] MMX Technology
118   // * [24:24] FXSR: FXSAVE/FXRSTOR (also indicates CR4.OSFXSR is available)
119   // * [25:25] SSE: SSE Extensions
120   //   [26:26] SSE2: SSE2 Extensions
121   //   [27:27] Self Snoop
122   //   [28:28] Hyper Threading Technology
123   //   [29:29] TM: Thermal Monitor
124   //   [30:30] Reserved
125   //   [31:31] PBE: Pending Break Enable
126   leaf->edx = BX_CPUID_STD_X87 |
127               BX_CPUID_STD_VME |
128               BX_CPUID_STD_DEBUG_EXTENSIONS |
129               BX_CPUID_STD_PSE |
130               BX_CPUID_STD_TSC |
131               BX_CPUID_STD_MSR |
132               BX_CPUID_STD_PAE |
133               BX_CPUID_STD_MCE |
134               BX_CPUID_STD_CMPXCHG8B |
135               BX_CPUID_STD_SYSENTER_SYSEXIT |
136               BX_CPUID_STD_MTRR |
137               BX_CPUID_STD_GLOBAL_PAGES |
138               BX_CPUID_STD_MCA |
139               BX_CPUID_STD_CMOV |
140               BX_CPUID_STD_PAT |
141 #if BX_PHY_ADDRESS_LONG
142               BX_CPUID_STD_PSE36 |
143 #endif
144               BX_CPUID_STD_MMX |
145               BX_CPUID_STD_FXSAVE_FXRSTOR |
146               BX_CPUID_STD_SSE;
147 #if BX_SUPPORT_APIC
148   // if MSR_APICBASE APIC Global Enable bit has been cleared,
149   // the CPUID feature flag for the APIC is set to 0.
150   if (cpu->msr.apicbase & 0x800)
151     leaf->edx |= BX_CPUID_STD_APIC; // APIC on chip
152 #endif
153 }
154 
155 // leaf 0x00000002 //
get_std_cpuid_leaf_2(cpuid_function_t * leaf) const156 void p3_katmai_t::get_std_cpuid_leaf_2(cpuid_function_t *leaf) const
157 {
158   // CPUID function 0x00000002 - Cache and TLB Descriptors
159   leaf->eax = 0x03020101;
160   leaf->ebx = 0x00000000;
161   leaf->ecx = 0x00000000;
162   leaf->edx = 0x0C040843;
163 }
164 
165 // leaf 0x00000003 //
get_std_cpuid_leaf_3(cpuid_function_t * leaf) const166 void p3_katmai_t::get_std_cpuid_leaf_3(cpuid_function_t *leaf) const
167 {
168   // CPUID function 0x00000003 - Processor Serial Number
169   leaf->eax = 0;
170   leaf->ebx = 0;
171   leaf->ecx = 0;
172   leaf->edx = 0;
173 }
174 
dump_cpuid(void) const175 void p3_katmai_t::dump_cpuid(void) const
176 {
177   bx_cpuid_t::dump_cpuid(0x3, 0);
178 }
179 
create_p3_katmai_cpuid(BX_CPU_C * cpu)180 bx_cpuid_t *create_p3_katmai_cpuid(BX_CPU_C *cpu) { return new p3_katmai_t(cpu); }
181 
182 #endif
183