2 * Copyright (c) 2008 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "arch/x86/cpuid.hh"
32 #include "base/bitfield.hh"
33 #include "cpu/thread_context.hh"
36 enum StandardCpuidFunction
{
37 VendorAndLargestStdFunc
,
42 enum ExtendedCpuidFunctions
{
43 VendorAndLargestExtFunc
,
44 FamilyModelSteppingBrandFeatures
,
54 * The following are defined by the spec but not yet implemented
56 /* // Function 9 is reserved
58 // Functions 11-24 are reserved
65 static const int vendorStringSize
= 13;
66 static const char vendorString
[vendorStringSize
] = "M5 Simulator";
67 static const int nameStringSize
= 48;
68 static const char nameString
[nameStringSize
] = "Fake M5 x86_64 CPU";
71 stringToRegister(const char *str
)
74 for (int pos
= 3; pos
>=0; pos
--) {
82 doCpuid(ThreadContext
* tc
, uint32_t function
,
83 uint32_t index
, CpuidResult
&result
)
85 uint16_t family
= bits(function
, 31, 16);
86 uint16_t funcNum
= bits(function
, 15, 0);
87 if (family
== 0x8000) {
88 // The extended functions
90 case VendorAndLargestExtFunc
:
91 assert(vendorStringSize
>= 12);
93 0x80000000 + NumExtendedCpuidFuncs
- 1,
94 stringToRegister(vendorString
),
95 stringToRegister(vendorString
+ 4),
96 stringToRegister(vendorString
+ 8));
98 case FamilyModelSteppingBrandFeatures
:
99 result
= CpuidResult(0x00020f51, 0x00000405,
100 0xe3d3fbff, 0x00000001);
106 // Zero fill anything beyond the end of the string. This
107 // should go away once the string is a vetted parameter.
108 char cleanName
[nameStringSize
];
109 memset(cleanName
, '\0', nameStringSize
);
110 strncpy(cleanName
, nameString
, nameStringSize
);
112 int offset
= (funcNum
- NameString1
) * 16;
113 assert(nameStringSize
>= offset
+ 16);
114 result
= CpuidResult(
115 stringToRegister(cleanName
+ offset
+ 0),
116 stringToRegister(cleanName
+ offset
+ 4),
117 stringToRegister(cleanName
+ offset
+ 12),
118 stringToRegister(cleanName
+ offset
+ 8));
122 result
= CpuidResult(0xff08ff08, 0xff20ff20,
123 0x40020140, 0x40020140);
125 case L2L3CacheAndL2TLB
:
126 result
= CpuidResult(0x00000000, 0x42004200,
127 0x00000000, 0x04008140);
130 result
= CpuidResult(0x80000018, 0x68747541,
131 0x69746e65, 0x444d4163);
133 case LongModeAddressSize
:
134 result
= CpuidResult(0x00003030, 0x00000000,
135 0x00000000, 0x00000000);
139 case PerformanceInfo:*/
141 warn("x86 cpuid family 0x8000: unimplemented function %u",
145 } else if (family
== 0x0000) {
146 // The standard functions
148 case VendorAndLargestStdFunc
:
149 assert(vendorStringSize
>= 12);
150 result
= CpuidResult(
151 NumStandardCpuidFuncs
- 1,
152 stringToRegister(vendorString
),
153 stringToRegister(vendorString
+ 4),
154 stringToRegister(vendorString
+ 8));
156 case FamilyModelStepping
:
157 result
= CpuidResult(0x00020f51, 0x00000805,
158 0xe7dbfbff, 0x04000209);
161 warn("x86 cpuid family 0x0000: unimplemented function %u",
166 warn("x86 cpuid: unknown family %#x", family
);
172 } // namespace X86ISA