2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 #include <platforms.h>
27 #include <pexpert/pexpert.h>
31 #include <i386/db_machdep.h>
32 #include <ddb/db_aout.h>
33 #include <ddb/db_access.h>
34 #include <ddb/db_sym.h>
35 #include <ddb/db_variables.h>
36 #include <ddb/db_command.h>
37 #include <ddb/db_output.h>
38 #include <ddb/db_expr.h>
41 #define min(a,b) ((a) < (b) ? (a) : (b))
42 #define quad(hi,lo) (((uint64_t)(hi)) << 32 | (lo))
44 #define bit(n) (1UL << (n))
45 #define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
46 #define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l)
49 * CPU identification routines.
51 * Note that this code assumes a processor that supports the
52 * 'cpuid' instruction.
55 static unsigned int cpuid_maxcpuid
;
57 static i386_cpu_info_t cpuid_cpu_info
;
59 uint32_t cpuid_feature
; /* XXX obsolescent for compat */
62 * We only identify Intel CPUs here. Adding support
63 * for others would be straightforward.
65 static void set_cpu_generic(i386_cpu_info_t
*);
66 static void set_cpu_intel(i386_cpu_info_t
*);
67 static void set_cpu_amd(i386_cpu_info_t
*);
68 static void set_cpu_nsc(i386_cpu_info_t
*);
69 static void set_cpu_unknown(i386_cpu_info_t
*);
73 void (* func
)(i386_cpu_info_t
*);
75 {CPUID_VID_INTEL
, set_cpu_intel
},
76 {CPUID_VID_AMD
, set_cpu_amd
},
77 {CPUID_VID_NSC
, set_cpu_nsc
},
82 cpuid_get_info(i386_cpu_info_t
*info_p
)
84 uint32_t cpuid_result
[4];
87 bzero((void *)info_p
, sizeof(i386_cpu_info_t
));
89 /* do cpuid 0 to get vendor */
90 do_cpuid(0, cpuid_result
);
91 cpuid_maxcpuid
= cpuid_result
[eax
];
92 bcopy((char *)&cpuid_result
[ebx
], &info_p
->cpuid_vendor
[0], 4); /* ug */
93 bcopy((char *)&cpuid_result
[ecx
], &info_p
->cpuid_vendor
[8], 4);
94 bcopy((char *)&cpuid_result
[edx
], &info_p
->cpuid_vendor
[4], 4);
95 info_p
->cpuid_vendor
[12] = 0;
99 if ((cpu_vendors
[i
].vendor
== 0) ||
100 (!strcmp(cpu_vendors
[i
].vendor
, info_p
->cpuid_vendor
))) {
101 cpu_vendors
[i
].func(info_p
);
108 * Cache descriptor table. Each row has the form:
109 * (descriptor_value, cache, size, linesize,
111 * Note: the CACHE_DESC macro does not expand description text in the kernel.
113 static cpuid_cache_desc_t cpuid_cache_desc_tab
[] = {
114 CACHE_DESC(CPUID_CACHE_ITLB_4K
, Lnone
, 0, 0, \
115 "Instruction TLB, 4K, pages 4-way set associative, 64 entries"),
116 CACHE_DESC(CPUID_CACHE_ITLB_4M
, Lnone
, 0, 0, \
117 "Instruction TLB, 4M, pages 4-way set associative, 2 entries"),
118 CACHE_DESC(CPUID_CACHE_DTLB_4K
, Lnone
, 0, 0, \
119 "Data TLB, 4K pages, 4-way set associative, 64 entries"),
120 CACHE_DESC(CPUID_CACHE_DTLB_4M
, Lnone
, 0, 0, \
121 "Data TLB, 4M pages, 4-way set associative, 8 entries"),
122 CACHE_DESC(CPUID_CACHE_ITLB_64
, Lnone
, 0, 0, \
123 "Instruction TLB, 4K and 2M or 4M pages, 64 entries"),
124 CACHE_DESC(CPUID_CACHE_ITLB_128
, Lnone
, 0, 0, \
125 "Instruction TLB, 4K and 2M or 4M pages, 128 entries"),
126 CACHE_DESC(CPUID_CACHE_ITLB_256
, Lnone
, 0, 0, \
127 "Instruction TLB, 4K and 2M or 4M pages, 256 entries"),
128 CACHE_DESC(CPUID_CACHE_DTLB_64
, Lnone
, 0, 0, \
129 "Data TLB, 4K and 4M pages, 64 entries"),
130 CACHE_DESC(CPUID_CACHE_DTLB_128
, Lnone
, 0, 0, \
131 "Data TLB, 4K and 4M pages, 128 entries"),
132 CACHE_DESC(CPUID_CACHE_DTLB_256
, Lnone
, 0, 0, \
133 "Data TLB, 4K and 4M pages, 256 entries"),
134 CACHE_DESC(CPUID_CACHE_ITLB_128_4
, Lnone
, 0, 0, \
135 "Instruction TLB, 4K pages, 4-way set associative, 128 entries"),
136 CACHE_DESC(CPUID_CACHE_DTLB_128_4
, Lnone
, 0, 0, \
137 "Data TLB, 4K pages, 4-way set associative, 128 entries"),
138 CACHE_DESC(CPUID_CACHE_ICACHE_8K
, L1I
, 8*1024, 32, \
139 "Instruction L1 cache, 8K, 4-way set associative, 32byte line size"),
140 CACHE_DESC(CPUID_CACHE_DCACHE_8K
, L1D
, 8*1024, 32, \
141 "Data L1 cache, 8K, 2-way set associative, 32byte line size"),
142 CACHE_DESC(CPUID_CACHE_ICACHE_16K
, L1I
, 16*1024, 32, \
143 "Instruction L1 cache, 16K, 4-way set associative, 32byte line size"),
144 CACHE_DESC(CPUID_CACHE_DCACHE_16K
, L1D
, 16*1024, 32, \
145 "Data L1 cache, 16K, 4-way set associative, 32byte line size"),
146 CACHE_DESC(CPUID_CACHE_DCACHE_8K_64
, L1D
, 8*1024, 64, \
147 "Data L1 cache, 8K, 4-way set associative, 64byte line size"),
148 CACHE_DESC(CPUID_CACHE_DCACHE_16K_64
, L1D
, 16*1024, 64, \
149 "Data L1 cache, 16K, 4-way set associative, 64byte line size"),
150 CACHE_DESC(CPUID_CACHE_DCACHE_32K_64
, L1D
, 32*1024, 64, \
151 "Data L1 cache, 32K, 4-way set associative, 64byte line size"),
152 CACHE_DESC(CPUID_CACHE_DCACHE_32K
, L1D
, 32*1024, 64, \
153 "Data L1 cache, 32K, 8-way set assocative, 64byte line size"),
154 CACHE_DESC(CPUID_CACHE_ICACHE_32K
, L1I
, 32*1024, 64, \
155 "Instruction L1 cache, 32K, 8-way set associative, 64byte line size"),
156 CACHE_DESC(CPUID_CACHE_DCACHE_16K_8
, L1D
, 16*1024, 64, \
157 "Data L1 cache, 16K, 8-way set associative, 64byte line size"),
158 CACHE_DESC(CPUID_CACHE_TRACE_12K
, L1I
, 12*1024, 64, \
159 "Trace cache, 12K-uop, 8-way set associative"),
160 CACHE_DESC(CPUID_CACHE_TRACE_16K
, L1I
, 16*1024, 64, \
161 "Trace cache, 16K-uop, 8-way set associative"),
162 CACHE_DESC(CPUID_CACHE_TRACE_32K
, L1I
, 32*1024, 64, \
163 "Trace cache, 32K-uop, 8-way set associative"),
164 CACHE_DESC(CPUID_CACHE_UCACHE_128K
, L2U
, 128*1024, 32, \
165 "Unified L2 cache, 128K, 4-way set associative, 32byte line size"),
166 CACHE_DESC(CPUID_CACHE_UCACHE_256K
, L2U
, 128*1024, 32, \
167 "Unified L2 cache, 256K, 4-way set associative, 32byte line size"),
168 CACHE_DESC(CPUID_CACHE_UCACHE_512K
, L2U
, 512*1024, 32, \
169 "Unified L2 cache, 512K, 4-way set associative, 32byte line size"),
170 CACHE_DESC(CPUID_CACHE_UCACHE_1M
, L2U
, 1*1024*1024, 32, \
171 "Unified L2 cache, 1M, 4-way set associative, 32byte line size"),
172 CACHE_DESC(CPUID_CACHE_UCACHE_2M
, L2U
, 2*1024*1024, 32, \
173 "Unified L2 cache, 2M, 4-way set associative, 32byte line size"),
174 CACHE_DESC(CPUID_CACHE_UCACHE_4M
, L2U
, 4*1024*1024, 64, \
175 "Unified L2 cache, 4M, 16-way set associative, 64byte line size"),
176 CACHE_DESC(CPUID_CACHE_UCACHE_128K_64
, L2U
, 128*1024, 64, \
177 "Unified L2 cache, 128K, 8-way set associative, 64byte line size"),
178 CACHE_DESC(CPUID_CACHE_UCACHE_256K_64
, L2U
, 256*1024, 64, \
179 "Unified L2 cache, 256K, 8-way set associative, 64byte line size"),
180 CACHE_DESC(CPUID_CACHE_UCACHE_512K_64
, L2U
, 512*1024, 64, \
181 "Unified L2 cache, 512K, 8-way set associative, 64byte line size"),
182 CACHE_DESC(CPUID_CACHE_UCACHE_1M_64
, L2U
, 1*1024*1024, 64, \
183 "Unified L2 cache, 1M, 8-way set associative, 64byte line size"),
184 CACHE_DESC(CPUID_CACHE_UCACHE_256K_32
, L2U
, 256*1024, 32, \
185 "Unified L2 cache, 256K, 8-way set associative, 32byte line size"),
186 CACHE_DESC(CPUID_CACHE_UCACHE_512K_32
, L2U
, 512*1024, 32, \
187 "Unified L2 cache, 512K, 8-way set associative, 32byte line size"),
188 CACHE_DESC(CPUID_CACHE_UCACHE_1M_32
, L2U
, 1*1024*1024, 32, \
189 "Unified L2 cache, 1M, 8-way set associative, 32byte line size"),
190 CACHE_DESC(CPUID_CACHE_UCACHE_2M_32
, L2U
, 2*1024*1024, 32, \
191 "Unified L2 cache, 2M, 8-way set associative, 32byte line size"),
192 CACHE_DESC(CPUID_CACHE_UCACHE_1M_64_4
, L2U
, 1*1024*1024, 64, \
193 "Unified L2 cache, 1M, 4-way set associative, 64byte line size"),
194 CACHE_DESC(CPUID_CACHE_UCACHE_2M_64
, L2U
, 2*1024*1024, 64, \
195 "Unified L2 cache, 2M, 8-way set associative, 64byte line size"),
196 CACHE_DESC(CPUID_CACHE_UCACHE_512K_64_2
,L2U
, 512*1024, 64, \
197 "Unified L2 cache, 512K, 2-way set associative, 64byte line size"),
198 CACHE_DESC(CPUID_CACHE_UCACHE_512K_64_4
,L2U
, 512*1024, 64, \
199 "Unified L2 cache, 512K, 4-way set associative, 64byte line size"),
200 CACHE_DESC(CPUID_CACHE_UCACHE_1M_64_8
, L2U
, 1*1024*1024, 64, \
201 "Unified L2 cache, 1M, 8-way set associative, 64byte line size"),
202 CACHE_DESC(CPUID_CACHE_UCACHE_128K_S4
, L2U
, 128*1024, 64, \
203 "Unified L2 sectored cache, 128K, 4-way set associative, 64byte line size"),
204 CACHE_DESC(CPUID_CACHE_UCACHE_128K_S2
, L2U
, 128*1024, 64, \
205 "Unified L2 sectored cache, 128K, 2-way set associative, 64byte line size"),
206 CACHE_DESC(CPUID_CACHE_UCACHE_256K_S4
, L2U
, 256*1024, 64, \
207 "Unified L2 sectored cache, 256K, 4-way set associative, 64byte line size"),
208 CACHE_DESC(CPUID_CACHE_L3CACHE_512K
, L3U
, 512*1024, 64, \
209 "Unified L3 cache, 512K, 4-way set associative, 64byte line size"),
210 CACHE_DESC(CPUID_CACHE_L3CACHE_1M
, L3U
, 1*1024*1024, 64, \
211 "Unified L3 cache, 1M, 8-way set associative, 64byte line size"),
212 CACHE_DESC(CPUID_CACHE_L3CACHE_2M
, L3U
, 2*1024*1024, 64, \
213 "Unified L3 cache, 2M, 8-way set associative, 64byte line size"),
214 CACHE_DESC(CPUID_CACHE_L3CACHE_4M
, L3U
, 4*1024*1024, 64, \
215 "Unified L3 cache, 4M, 8-way set associative, 64byte line size"),
216 CACHE_DESC(CPUID_CACHE_PREFETCH_64
, Lnone
, 0, 0, \
217 "64-Byte Prefetching"),
218 CACHE_DESC(CPUID_CACHE_PREFETCH_128
, Lnone
, 0, 0, \
219 "128-Byte Prefetching"),
220 CACHE_DESC(CPUID_CACHE_NOCACHE
, Lnone
, 0, 0, \
221 "No L2 cache or, if valid L2 cache, no L3 cache"),
222 CACHE_DESC(CPUID_CACHE_NULL
, Lnone
, 0, 0, \
226 static const char * get_intel_model_string( i386_cpu_info_t
* info_p
, cpu_type_t
* type
, cpu_subtype_t
* subtype
)
228 *type
= CPU_TYPE_X86
;
229 *subtype
= CPU_SUBTYPE_X86_ARCH1
;
231 /* check for brand id string */
232 switch(info_p
->cpuid_brand
) {
233 case CPUID_BRAND_UNSUPPORTED
:
234 /* brand ID not supported; use alternate method. */
235 switch(info_p
->cpuid_family
) {
236 case CPUID_FAMILY_486
:
238 case CPUID_FAMILY_586
:
239 return "Intel Pentium";
240 case CPUID_FAMILY_686
:
241 switch(info_p
->cpuid_model
) {
243 return "Intel Pentium Pro";
244 case CPUID_MODEL_PII
:
245 return "Intel Pentium II";
246 case CPUID_MODEL_P65
:
247 case CPUID_MODEL_P66
:
248 return "Intel Celeron";
249 case CPUID_MODEL_P67
:
250 case CPUID_MODEL_P68
:
251 case CPUID_MODEL_P6A
:
252 case CPUID_MODEL_P6B
:
253 return "Intel Pentium III";
254 case CPUID_MODEL_PM9
:
255 case CPUID_MODEL_PMD
:
256 return "Intel Pentium M";
258 return "Unknown Intel P6 Family";
260 case CPUID_FAMILY_EXTENDED
:
261 switch (info_p
->cpuid_extfamily
) {
262 case CPUID_EXTFAMILY_PENTIUM4
:
263 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
264 return "Intel Pentium 4";
266 return "Unknown Intel Extended Family";
269 return "Unknown Intel Family";
272 case CPUID_BRAND_CELERON_1
:
273 case CPUID_BRAND_CELERON_A
:
274 case CPUID_BRAND_CELERON_14
:
275 return "Intel Celeron";
276 case CPUID_BRAND_PENTIUM_III_2
:
277 case CPUID_BRAND_PENTIUM_III_4
:
278 return "Pentium III";
279 case CPUID_BRAND_PIII_XEON
:
280 if (info_p
->cpuid_signature
== 0x6B1) {
281 return "Intel Celeron";
283 return "Intel Pentium III Xeon";
285 case CPUID_BRAND_PENTIUM_III_M
:
286 return "Mobile Intel Pentium III-M";
287 case CPUID_BRAND_M_CELERON_7
:
288 case CPUID_BRAND_M_CELERON_F
:
289 case CPUID_BRAND_M_CELERON_13
:
290 case CPUID_BRAND_M_CELERON_17
:
291 return "Mobile Intel Celeron";
292 case CPUID_BRAND_PENTIUM4_8
:
293 case CPUID_BRAND_PENTIUM4_9
:
294 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
295 return "Intel Pentium 4";
296 case CPUID_BRAND_XEON
:
298 case CPUID_BRAND_XEON_MP
:
299 return "Intel Xeon MP";
300 case CPUID_BRAND_PENTIUM4_M
:
301 if (info_p
->cpuid_signature
== 0xF13) {
304 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
305 return "Mobile Intel Pentium 4";
307 case CPUID_BRAND_CELERON_M
:
308 return "Intel Celeron M";
309 case CPUID_BRAND_PENTIUM_M
:
310 return "Intel Pentium M";
311 case CPUID_BRAND_MOBILE_15
:
312 case CPUID_BRAND_MOBILE_17
:
313 return "Mobile Intel";
315 return "Unknown Intel";
318 static void set_intel_cache_info( i386_cpu_info_t
* info_p
)
320 uint32_t cpuid_result
[4];
321 uint32_t l1d_cache_linesize
= 0;
325 /* get processor cache descriptor info */
326 do_cpuid(2, cpuid_result
);
327 for (j
= 0; j
< 4; j
++) {
328 if ((cpuid_result
[j
] >> 31) == 1) /* bit31 is validity */
330 ((uint32_t *) info_p
->cache_info
)[j
] = cpuid_result
[j
];
332 /* first byte gives number of cpuid calls to get all descriptors */
333 for (i
= 1; i
< info_p
->cache_info
[0]; i
++) {
334 if (i
*16 > sizeof(info_p
->cache_info
))
336 do_cpuid(2, cpuid_result
);
337 for (j
= 0; j
< 4; j
++) {
338 if ((cpuid_result
[j
] >> 31) == 1)
340 ((uint32_t *) info_p
->cache_info
)[4*i
+j
] =
345 /* decode the descriptors looking for L1/L2/L3 size info */
346 for (i
= 1; i
< sizeof(info_p
->cache_info
); i
++) {
347 cpuid_cache_desc_t
*descp
;
348 uint8_t desc
= info_p
->cache_info
[i
];
350 if (desc
== CPUID_CACHE_NULL
)
352 for (descp
= cpuid_cache_desc_tab
;
353 descp
->value
!= CPUID_CACHE_NULL
; descp
++) {
354 if (descp
->value
!= desc
)
356 info_p
->cache_size
[descp
->type
] = descp
->size
;
357 if (descp
->type
== L2U
)
358 info_p
->cache_linesize
= descp
->linesize
;
359 if (descp
->type
== L1D
)
360 l1d_cache_linesize
= descp
->linesize
;
364 /* For P-IIIs, L2 could be 256k or 512k but we can't tell */
365 if (info_p
->cache_size
[L2U
] == 0 &&
366 info_p
->cpuid_family
== 0x6 && info_p
->cpuid_model
== 0xb) {
367 info_p
->cache_size
[L2U
] = 256*1024;
368 info_p
->cache_linesize
= 32;
370 /* If we have no L2 cache, use the L1 data cache line size */
371 if (info_p
->cache_size
[L2U
] == 0)
372 info_p
->cache_linesize
= l1d_cache_linesize
;
375 * Get cache sharing info if available.
377 do_cpuid(0, cpuid_result
);
378 if (cpuid_result
[eax
] >= 4) {
381 for (index
= 0;; index
++) {
383 * Scan making calls for cpuid with %eax = 4
384 * to get info about successive cache levels
385 * until a null type is returned.
387 cache_type_t type
= Lnone
;
389 uint32_t cache_level
;
390 uint32_t cache_sharing
;
392 reg
[eax
] = 4; /* cpuid request 4 */
393 reg
[ecx
] = index
; /* index starting at 0 */
395 //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
396 cache_type
= bitfield(reg
[eax
], 4, 0);
398 break; /* done with cache info */
399 cache_level
= bitfield(reg
[eax
], 7, 5);
400 cache_sharing
= bitfield(reg
[eax
], 25, 14);
401 info_p
->cpuid_cores_per_package
=
402 bitfield(reg
[eax
], 31, 26) + 1;
403 switch (cache_level
) {
405 type
= cache_type
== 1 ? L1D
:
406 cache_type
== 2 ? L1I
:
410 type
= cache_type
== 3 ? L2U
:
414 type
= cache_type
== 3 ? L3U
:
418 info_p
->cache_sharing
[type
] = cache_sharing
+ 1;
423 static void set_cpu_intel( i386_cpu_info_t
* info_p
)
425 set_cpu_generic(info_p
);
426 set_intel_cache_info(info_p
);
427 info_p
->cpuid_model_string
= get_intel_model_string(info_p
, &info_p
->cpuid_cpu_type
, &info_p
->cpuid_cpu_subtype
);
430 static const char * get_amd_model_string( i386_cpu_info_t
* info_p
, cpu_type_t
* type
, cpu_subtype_t
* subtype
)
432 *type
= CPU_TYPE_X86
;
433 *subtype
= CPU_SUBTYPE_X86_ARCH1
;
435 /* check for brand id string */
436 switch (info_p
->cpuid_family
)
438 case CPUID_FAMILY_486
:
439 switch (info_p
->cpuid_model
) {
440 case CPUID_MODEL_AM486_DX
:
441 case CPUID_MODEL_AM486_DX2
:
442 case CPUID_MODEL_AM486_DX2WB
:
443 case CPUID_MODEL_AM486_DX4
:
444 case CPUID_MODEL_AM486_DX4WB
:
446 case CPUID_MODEL_AM486_5X86
:
447 case CPUID_MODEL_AM486_5X86WB
:
451 case CPUID_FAMILY_586
:
452 switch (info_p
->cpuid_model
) {
453 case CPUID_MODEL_K5M0
:
454 case CPUID_MODEL_K5M1
:
455 case CPUID_MODEL_K5M2
:
456 case CPUID_MODEL_K5M3
:
458 case CPUID_MODEL_K6M6
:
459 case CPUID_MODEL_K6M7
:
461 case CPUID_MODEL_K6_2
:
463 case CPUID_MODEL_K6_III
:
467 case CPUID_FAMILY_686
:
468 switch (info_p
->cpuid_model
) {
469 case CPUID_MODEL_ATHLON_M1
:
470 case CPUID_MODEL_ATHLON_M2
:
471 case CPUID_MODEL_ATHLON_M4
:
472 case CPUID_MODEL_ATHLON_M6
:
473 case CPUID_MODEL_ATHLON_M8
:
474 case CPUID_MODEL_ATHLON_M10
:
476 case CPUID_MODEL_DURON_M3
:
477 case CPUID_MODEL_DURON_M7
:
480 return "Unknown AMD Athlon";
482 case CPUID_FAMILY_EXTENDED
:
483 switch (info_p
->cpuid_model
) {
484 case CPUID_MODEL_ATHLON64
:
485 return "AMD Athlon 64";
486 case CPUID_MODEL_OPTERON
:
487 return "AMD Opteron";
489 return "Unknown AMD-64";
492 return "Unknown AMD";
495 static void set_amd_cache_info( i386_cpu_info_t
* info_p
)
497 uint32_t cpuid_result
[4];
499 /* It would make sense to fill in info_p->cache_info with complete information
500 * on the TLBs and data cache associativity, lines, etc, either by mapping
501 * to the Intel tags (if possible), or replacing cache_info with a generic
502 * mechanism. But right now, nothing makes use of that information (that I know
506 /* L1 Cache and TLB Information */
507 do_cpuid(0x80000005, cpuid_result
);
509 /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */
512 /* EBX: TLB Information for 4-Kbyte Pages */
515 /* ECX: L1 Data Cache Information */
516 info_p
->cache_size
[L1D
] = ((cpuid_result
[ecx
] >> 24) & 0xFF) * 1024;
517 info_p
->cache_linesize
= (cpuid_result
[ecx
] & 0xFF);
519 /* EDX: L1 Instruction Cache Information */
520 info_p
->cache_size
[L1I
] = ((cpuid_result
[edx
] >> 24) & 0xFF) * 1024;
522 /* L2 Cache Information */
523 do_cpuid(0x80000006, cpuid_result
);
525 /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */
528 /* EBX: L2 TLB Information for 4-Kbyte Pages */
531 /* ECX: L2 Cache Information */
532 info_p
->cache_size
[L2U
] = ((cpuid_result
[ecx
] >> 16) & 0xFFFF) * 1024;
533 if (info_p
->cache_size
[L2U
] > 0)
534 info_p
->cache_linesize
= cpuid_result
[ecx
] & 0xFF;
537 static void set_cpu_amd( i386_cpu_info_t
* info_p
)
539 set_cpu_generic(info_p
);
540 set_amd_cache_info(info_p
);
541 info_p
->cpuid_model_string
= get_amd_model_string(info_p
, &info_p
->cpuid_cpu_type
, &info_p
->cpuid_cpu_subtype
);
544 static void set_cpu_nsc( i386_cpu_info_t
* info_p
)
546 set_cpu_generic(info_p
);
547 set_amd_cache_info(info_p
);
549 /* check for brand id string */
550 if (info_p
->cpuid_family
== CPUID_FAMILY_586
&& info_p
->cpuid_model
== CPUID_MODEL_GX1
) {
551 info_p
->cpuid_model_string
= "AMD Geode GX1";
552 } else if (info_p
->cpuid_family
== CPUID_FAMILY_586
&& info_p
->cpuid_model
== CPUID_MODEL_GX2
) {
553 info_p
->cpuid_model_string
= "AMD Geode GX";
555 info_p
->cpuid_model_string
= "Unknown National Semiconductor";
557 info_p
->cpuid_cpu_type
= CPU_TYPE_X86
;
558 info_p
->cpuid_cpu_subtype
= CPU_SUBTYPE_X86_ARCH1
;
562 set_cpu_generic(i386_cpu_info_t
*info_p
)
564 uint32_t cpuid_result
[4];
568 /* get extended cpuid results */
569 do_cpuid(0x80000000, cpuid_result
);
570 max_extid
= cpuid_result
[eax
];
572 /* check to see if we can get brand string */
573 if (max_extid
>= 0x80000004) {
575 * The brand string 48 bytes (max), guaranteed to
578 do_cpuid(0x80000002, cpuid_result
);
579 bcopy((char *)cpuid_result
, &str
[0], 16);
580 do_cpuid(0x80000003, cpuid_result
);
581 bcopy((char *)cpuid_result
, &str
[16], 16);
582 do_cpuid(0x80000004, cpuid_result
);
583 bcopy((char *)cpuid_result
, &str
[32], 16);
584 for (p
= str
; *p
!= '\0'; p
++) {
585 if (*p
!= ' ') break;
587 strncpy(info_p
->cpuid_brand_string
,
588 p
, sizeof(info_p
->cpuid_brand_string
)-1);
589 info_p
->cpuid_brand_string
[sizeof(info_p
->cpuid_brand_string
)-1] = '\0';
591 if (!strcmp(info_p
->cpuid_brand_string
, CPUID_STRING_UNKNOWN
)) {
593 * This string means we have a BIOS-programmable brand string,
594 * and the BIOS couldn't figure out what sort of CPU we have.
596 info_p
->cpuid_brand_string
[0] = '\0';
600 /* get processor signature and decode */
601 do_cpuid(1, cpuid_result
);
602 info_p
->cpuid_signature
= cpuid_result
[eax
];
603 info_p
->cpuid_stepping
= bitfield(cpuid_result
[eax
], 3, 0);
604 info_p
->cpuid_model
= bitfield(cpuid_result
[eax
], 7, 4);
605 info_p
->cpuid_family
= bitfield(cpuid_result
[eax
], 11, 8);
606 info_p
->cpuid_type
= bitfield(cpuid_result
[eax
], 13, 12);
607 info_p
->cpuid_extmodel
= bitfield(cpuid_result
[eax
], 19, 16);
608 info_p
->cpuid_extfamily
= bitfield(cpuid_result
[eax
], 27, 20);
609 info_p
->cpuid_brand
= bitfield(cpuid_result
[ebx
], 7, 0);
610 info_p
->cpuid_logical_per_package
=
611 bitfield(cpuid_result
[ebx
], 23, 16);
612 info_p
->cpuid_features
= quad(cpuid_result
[ecx
], cpuid_result
[edx
]);
614 if (max_extid
>= 0x80000001) {
615 do_cpuid(0x80000001, cpuid_result
);
616 info_p
->cpuid_extfeatures
=
617 quad(cpuid_result
[ecx
], cpuid_result
[edx
]);
624 set_cpu_unknown(__unused i386_cpu_info_t
*info_p
)
626 info_p
->cpuid_model_string
= "Unknown";
634 {CPUID_FEATURE_FPU
, "FPU",},
635 {CPUID_FEATURE_VME
, "VME",},
636 {CPUID_FEATURE_DE
, "DE",},
637 {CPUID_FEATURE_PSE
, "PSE",},
638 {CPUID_FEATURE_TSC
, "TSC",},
639 {CPUID_FEATURE_MSR
, "MSR",},
640 {CPUID_FEATURE_PAE
, "PAE",},
641 {CPUID_FEATURE_MCE
, "MCE",},
642 {CPUID_FEATURE_CX8
, "CX8",},
643 {CPUID_FEATURE_APIC
, "APIC",},
644 {CPUID_FEATURE_SEP
, "SEP",},
645 {CPUID_FEATURE_MTRR
, "MTRR",},
646 {CPUID_FEATURE_PGE
, "PGE",},
647 {CPUID_FEATURE_MCA
, "MCA",},
648 {CPUID_FEATURE_CMOV
, "CMOV",},
649 {CPUID_FEATURE_PAT
, "PAT",},
650 {CPUID_FEATURE_PSE36
, "PSE36",},
651 {CPUID_FEATURE_PSN
, "PSN",},
652 {CPUID_FEATURE_CLFSH
, "CLFSH",},
653 {CPUID_FEATURE_DS
, "DS",},
654 {CPUID_FEATURE_ACPI
, "ACPI",},
655 {CPUID_FEATURE_MMX
, "MMX",},
656 {CPUID_FEATURE_FXSR
, "FXSR",},
657 {CPUID_FEATURE_SSE
, "SSE",},
658 {CPUID_FEATURE_SSE2
, "SSE2",},
659 {CPUID_FEATURE_SS
, "SS",},
660 {CPUID_FEATURE_HTT
, "HTT",},
661 {CPUID_FEATURE_TM
, "TM",},
662 {CPUID_FEATURE_SSE3
, "SSE3"},
663 {CPUID_FEATURE_MONITOR
, "MON"},
664 {CPUID_FEATURE_DSCPL
, "DSCPL"},
665 {CPUID_FEATURE_VMX
, "VMX"},
666 {CPUID_FEATURE_SMX
, "SMX"},
667 {CPUID_FEATURE_EST
, "EST"},
668 {CPUID_FEATURE_TM2
, "TM2"},
669 {CPUID_FEATURE_MNI
, "MNI"},
670 {CPUID_FEATURE_CID
, "CID"},
671 {CPUID_FEATURE_CX16
, "CX16"},
672 {CPUID_FEATURE_xTPR
, "TPR"},
676 {CPUID_EXTFEATURE_SYSCALL
, "SYSCALL"},
677 {CPUID_EXTFEATURE_XD
, "XD"},
678 {CPUID_EXTFEATURE_EM64T
, "EM64T"},
679 {CPUID_EXTFEATURE_LAHF
, "LAHF"},
684 cpuid_get_feature_names(uint64_t features
, char *buf
, unsigned buf_len
)
690 for (i
= 0; feature_map
[i
].mask
!= 0; i
++) {
691 if ((features
& feature_map
[i
].mask
) == 0)
695 len
= min(strlen(feature_map
[i
].name
), (buf_len
-1) - (p
-buf
));
698 bcopy(feature_map
[i
].name
, p
, len
);
706 cpuid_get_extfeature_names(uint64_t extfeatures
, char *buf
, unsigned buf_len
)
712 for (i
= 0; extfeature_map
[i
].mask
!= 0; i
++) {
713 if ((extfeatures
& extfeature_map
[i
].mask
) == 0)
717 len
= min(strlen(extfeature_map
[i
].name
), (buf_len
-1)-(p
-buf
));
720 bcopy(extfeature_map
[i
].name
, p
, len
);
728 cpuid_feature_display(
733 kprintf("%s: %s\n", header
,
734 cpuid_get_feature_names(cpuid_features(),
736 if (cpuid_features() & CPUID_FEATURE_HTT
) {
737 #define s_if_plural(n) ((n > 1) ? "s" : "")
738 kprintf(" HTT: %d core%s per package;"
739 " %d logical cpu%s per package\n",
740 cpuid_cpu_info
.cpuid_cores_per_package
,
741 s_if_plural(cpuid_cpu_info
.cpuid_cores_per_package
),
742 cpuid_cpu_info
.cpuid_logical_per_package
,
743 s_if_plural(cpuid_cpu_info
.cpuid_logical_per_package
));
748 cpuid_extfeature_display(
753 kprintf("%s: %s\n", header
,
754 cpuid_get_extfeature_names(cpuid_extfeatures(),
762 if (cpuid_cpu_info
.cpuid_brand_string
[0] != '\0') {
763 kprintf("%s: %s\n", header
, cpuid_cpu_info
.cpuid_brand_string
);
770 return cpuid_cpu_info
.cpuid_family
;
776 return cpuid_cpu_info
.cpuid_cpu_type
;
780 cpuid_cpusubtype(void)
782 return cpuid_cpu_info
.cpuid_cpu_subtype
;
788 static int checked
= 0;
789 char fpu_arg
[16] = { 0 };
791 /* check for boot-time fpu limitations */
792 if (PE_parse_boot_arg("_fpu", &fpu_arg
[0])) {
793 printf("limiting fpu features to: %s\n", fpu_arg
);
794 if (!strncmp("387", fpu_arg
, sizeof "387") || !strncmp("mmx", fpu_arg
, sizeof "mmx")) {
795 printf("no sse or sse2\n");
796 cpuid_cpu_info
.cpuid_features
&= ~(CPUID_FEATURE_SSE
| CPUID_FEATURE_SSE2
| CPUID_FEATURE_FXSR
);
797 } else if (!strncmp("sse", fpu_arg
, sizeof "sse")) {
799 cpuid_cpu_info
.cpuid_features
&= ~(CPUID_FEATURE_SSE2
);
804 return cpuid_cpu_info
.cpuid_features
;
808 cpuid_extfeatures(void)
810 return cpuid_cpu_info
.cpuid_extfeatures
;
816 return &cpuid_cpu_info
;
822 cpuid_get_info(&cpuid_cpu_info
);
833 db_cpuid(__unused db_expr_t addr
,
834 __unused
int have_addr
,
835 __unused db_expr_t count
,
836 __unused
char *modif
)
842 do_cpuid(0, cpid
); /* Get the first cpuid which is the number of
844 db_printf("%08X - %08X %08X %08X %08X\n",
845 0, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);
847 mid
= cpid
[eax
]; /* Set the number */
848 for (i
= 1; i
<= mid
; i
++) { /* Dump 'em out */
849 do_cpuid(i
, cpid
); /* Get the next */
850 db_printf("%08X - %08X %08X %08X %08X\n",
851 i
, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);
855 do_cpuid(0x80000000, cpid
); /* Get the first extended cpuid which
856 * is the number of extended ids */
857 db_printf("%08X - %08X %08X %08X %08X\n",
858 0x80000000, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);
860 mid
= cpid
[eax
]; /* Set the number */
861 for (i
= 0x80000001; i
<= mid
; i
++) { /* Dump 'em out */
862 do_cpuid(i
, cpid
); /* Get the next */
863 db_printf("%08X - %08X %08X %08X %08X\n",
864 i
, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);