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_infop
= NULL
;
58 static i386_cpu_info_t cpuid_cpu_info
;
60 uint32_t cpuid_feature
; /* XXX obsolescent for compat */
63 * We only identify Intel CPUs here. Adding support
64 * for others would be straightforward.
66 static void set_cpu_generic(i386_cpu_info_t
*);
67 static void set_cpu_intel(i386_cpu_info_t
*);
68 static void set_cpu_amd(i386_cpu_info_t
*);
69 static void set_cpu_nsc(i386_cpu_info_t
*);
70 static void set_cpu_unknown(i386_cpu_info_t
*);
74 void (* func
)(i386_cpu_info_t
*);
76 {CPUID_VID_INTEL
, set_cpu_intel
},
77 {CPUID_VID_AMD
, set_cpu_amd
},
78 {CPUID_VID_NSC
, set_cpu_nsc
},
83 cpuid_get_info(i386_cpu_info_t
*info_p
)
85 uint32_t cpuid_result
[4];
88 bzero((void *)info_p
, sizeof(i386_cpu_info_t
));
90 /* do cpuid 0 to get vendor */
91 do_cpuid(0, cpuid_result
);
92 cpuid_maxcpuid
= cpuid_result
[eax
];
93 bcopy((char *)&cpuid_result
[ebx
], &info_p
->cpuid_vendor
[0], 4); /* ug */
94 bcopy((char *)&cpuid_result
[ecx
], &info_p
->cpuid_vendor
[8], 4);
95 bcopy((char *)&cpuid_result
[edx
], &info_p
->cpuid_vendor
[4], 4);
96 info_p
->cpuid_vendor
[12] = 0;
100 if ((cpu_vendors
[i
].vendor
== 0) ||
101 (!strcmp(cpu_vendors
[i
].vendor
, info_p
->cpuid_vendor
))) {
102 cpu_vendors
[i
].func(info_p
);
109 * Cache descriptor table. Each row has the form:
110 * (descriptor_value, cache, size, linesize,
112 * Note: the CACHE_DESC macro does not expand description text in the kernel.
114 static cpuid_cache_desc_t cpuid_cache_desc_tab
[] = {
115 CACHE_DESC(CPUID_CACHE_ITLB_4K
, Lnone
, 0, 0, \
116 "Instruction TLB, 4K, pages 4-way set associative, 64 entries"),
117 CACHE_DESC(CPUID_CACHE_ITLB_4M
, Lnone
, 0, 0, \
118 "Instruction TLB, 4M, pages 4-way set associative, 2 entries"),
119 CACHE_DESC(CPUID_CACHE_DTLB_4K
, Lnone
, 0, 0, \
120 "Data TLB, 4K pages, 4-way set associative, 64 entries"),
121 CACHE_DESC(CPUID_CACHE_DTLB_4M
, Lnone
, 0, 0, \
122 "Data TLB, 4M pages, 4-way set associative, 8 entries"),
123 CACHE_DESC(CPUID_CACHE_ITLB_64
, Lnone
, 0, 0, \
124 "Instruction TLB, 4K and 2M or 4M pages, 64 entries"),
125 CACHE_DESC(CPUID_CACHE_ITLB_128
, Lnone
, 0, 0, \
126 "Instruction TLB, 4K and 2M or 4M pages, 128 entries"),
127 CACHE_DESC(CPUID_CACHE_ITLB_256
, Lnone
, 0, 0, \
128 "Instruction TLB, 4K and 2M or 4M pages, 256 entries"),
129 CACHE_DESC(CPUID_CACHE_DTLB_64
, Lnone
, 0, 0, \
130 "Data TLB, 4K and 4M pages, 64 entries"),
131 CACHE_DESC(CPUID_CACHE_DTLB_128
, Lnone
, 0, 0, \
132 "Data TLB, 4K and 4M pages, 128 entries"),
133 CACHE_DESC(CPUID_CACHE_DTLB_256
, Lnone
, 0, 0, \
134 "Data TLB, 4K and 4M pages, 256 entries"),
135 CACHE_DESC(CPUID_CACHE_ITLB_4K_128_4
, Lnone
, 0, 0, \
136 "Instruction TLB, 4K pages, 4-way set associative, 128 entries"),
137 CACHE_DESC(CPUID_CACHE_DTLB_4K_128_4
, Lnone
, 0, 0, \
138 "Data TLB, 4K pages, 4-way set associative, 128 entries"),
139 CACHE_DESC(CPUID_CACHE_ICACHE_8K
, L1I
, 8*1024, 32, \
140 "Instruction L1 cache, 8K, 4-way set associative, 32byte line size"),
141 CACHE_DESC(CPUID_CACHE_DCACHE_8K
, L1D
, 8*1024, 32, \
142 "Data L1 cache, 8K, 2-way set associative, 32byte line size"),
143 CACHE_DESC(CPUID_CACHE_ICACHE_16K
, L1I
, 16*1024, 32, \
144 "Instruction L1 cache, 16K, 4-way set associative, 32byte line size"),
145 CACHE_DESC(CPUID_CACHE_DCACHE_16K
, L1D
, 16*1024, 32, \
146 "Data L1 cache, 16K, 4-way set associative, 32byte line size"),
147 CACHE_DESC(CPUID_CACHE_DCACHE_8K_4_64
, L1D
, 8*1024, 64, \
148 "Data L1 cache, 8K, 4-way set associative, 64byte line size"),
149 CACHE_DESC(CPUID_CACHE_DCACHE_16K_4_64
, L1D
, 16*1024, 64, \
150 "Data L1 cache, 16K, 4-way set associative, 64byte line size"),
151 CACHE_DESC(CPUID_CACHE_DCACHE_32K_4_64
, L1D
, 32*1024, 64, \
152 "Data L1 cache, 32K, 4-way set associative, 64byte line size"),
153 CACHE_DESC(CPUID_CACHE_DCACHE_32K
, L1D
, 32*1024, 64, \
154 "Data L1 cache, 32K, 8-way set assocative, 64byte line size"),
155 CACHE_DESC(CPUID_CACHE_ICACHE_32K
, L1I
, 32*1024, 64, \
156 "Instruction L1 cache, 32K, 8-way set associative, 64byte line size"),
157 CACHE_DESC(CPUID_CACHE_DCACHE_16K_8_64
, L1D
, 16*1024, 64, \
158 "Data L1 cache, 16K, 8-way set associative, 64byte line size"),
159 CACHE_DESC(CPUID_CACHE_TRACE_12K_8
, L1I
, 12*1024, 64, \
160 "Trace cache, 12K-uop, 8-way set associative"),
161 CACHE_DESC(CPUID_CACHE_TRACE_16K_8
, L1I
, 16*1024, 64, \
162 "Trace cache, 16K-uop, 8-way set associative"),
163 CACHE_DESC(CPUID_CACHE_TRACE_32K_8
, L1I
, 32*1024, 64, \
164 "Trace cache, 32K-uop, 8-way set associative"),
165 CACHE_DESC(CPUID_CACHE_L2_128K
, L2U
, 128*1024, 32, \
166 "Unified L2 cache, 128K, 4-way set associative, 32byte line size"),
167 CACHE_DESC(CPUID_CACHE_L2_256K
, L2U
, 128*1024, 32, \
168 "Unified L2 cache, 256K, 4-way set associative, 32byte line size"),
169 CACHE_DESC(CPUID_CACHE_L2_512K
, L2U
, 512*1024, 32, \
170 "Unified L2 cache, 512K, 4-way set associative, 32byte line size"),
171 CACHE_DESC(CPUID_CACHE_L2_1M_4
, L2U
, 1*1024*1024, 32, \
172 "Unified L2 cache, 1M, 4-way set associative, 32byte line size"),
173 CACHE_DESC(CPUID_CACHE_L2_2M_4
, L2U
, 2*1024*1024, 32, \
174 "Unified L2 cache, 2M, 4-way set associative, 32byte line size"),
175 CACHE_DESC(CPUID_CACHE_L2_4M_16_64
, L2U
, 4*1024*1024, 64, \
176 "Unified L2 cache, 4M, 16-way set associative, 64byte line size"),
177 CACHE_DESC(CPUID_CACHE_L2_128K_8_64_2
, L2U
, 128*1024, 64, \
178 "Unified L2 cache, 128K, 8-way set associative, 64byte line size"),
179 CACHE_DESC(CPUID_CACHE_L2_256K_8_64_2
, L2U
, 256*1024, 64, \
180 "Unified L2 cache, 256K, 8-way set associative, 64byte line size"),
181 CACHE_DESC(CPUID_CACHE_L2_512K_8_64_2
, L2U
, 512*1024, 64, \
182 "Unified L2 cache, 512K, 8-way set associative, 64byte line size"),
183 CACHE_DESC(CPUID_CACHE_L2_1M_8_64_2
, L2U
, 1*1024*1024, 64, \
184 "Unified L2 cache, 1M, 8-way set associative, 64byte line size"),
185 CACHE_DESC(CPUID_CACHE_L2_256K_8_32
, L2U
, 256*1024, 32, \
186 "Unified L2 cache, 256K, 8-way set associative, 32byte line size"),
187 CACHE_DESC(CPUID_CACHE_L2_512K_8_32
, L2U
, 512*1024, 32, \
188 "Unified L2 cache, 512K, 8-way set associative, 32byte line size"),
189 CACHE_DESC(CPUID_CACHE_L2_1M_8_32
, L2U
, 1*1024*1024, 32, \
190 "Unified L2 cache, 1M, 8-way set associative, 32byte line size"),
191 CACHE_DESC(CPUID_CACHE_L2_2M_8_32
, L2U
, 2*1024*1024, 32, \
192 "Unified L2 cache, 2M, 8-way set associative, 32byte line size"),
193 CACHE_DESC(CPUID_CACHE_L2_1M_4_64
, L2U
, 1*1024*1024, 64, \
194 "Unified L2 cache, 1M, 4-way set associative, 64byte line size"),
195 CACHE_DESC(CPUID_CACHE_L2_2M_8_64
, L2U
, 2*1024*1024, 64, \
196 "Unified L2 cache, 2M, 8-way set associative, 64byte line size"),
197 CACHE_DESC(CPUID_CACHE_L2_512K_2_64
,L2U
, 512*1024, 64, \
198 "Unified L2 cache, 512K, 2-way set associative, 64byte line size"),
199 CACHE_DESC(CPUID_CACHE_L2_512K_4_64
,L2U
, 512*1024, 64, \
200 "Unified L2 cache, 512K, 4-way set associative, 64byte line size"),
201 CACHE_DESC(CPUID_CACHE_L2_1M_8_64
, L2U
, 1*1024*1024, 64, \
202 "Unified L2 cache, 1M, 8-way set associative, 64byte line size"),
203 CACHE_DESC(CPUID_CACHE_L2_128K_S4
, L2U
, 128*1024, 64, \
204 "Unified L2 sectored cache, 128K, 4-way set associative, 64byte line size"),
205 CACHE_DESC(CPUID_CACHE_L2_128K_S2
, L2U
, 128*1024, 64, \
206 "Unified L2 sectored cache, 128K, 2-way set associative, 64byte line size"),
207 CACHE_DESC(CPUID_CACHE_L2_256K_S4
, L2U
, 256*1024, 64, \
208 "Unified L2 sectored cache, 256K, 4-way set associative, 64byte line size"),
209 CACHE_DESC(CPUID_CACHE_L3_512K
, L3U
, 512*1024, 64, \
210 "Unified L3 cache, 512K, 4-way set associative, 64byte line size"),
211 CACHE_DESC(CPUID_CACHE_L3_1M
, L3U
, 1*1024*1024, 64, \
212 "Unified L3 cache, 1M, 8-way set associative, 64byte line size"),
213 CACHE_DESC(CPUID_CACHE_L3_2M
, L3U
, 2*1024*1024, 64, \
214 "Unified L3 cache, 2M, 8-way set associative, 64byte line size"),
215 CACHE_DESC(CPUID_CACHE_L3_4M
, L3U
, 4*1024*1024, 64, \
216 "Unified L3 cache, 4M, 8-way set associative, 64byte line size"),
217 CACHE_DESC(CPUID_CACHE_PREFETCH_64
, Lnone
, 0, 0, \
218 "64-Byte Prefetching"),
219 CACHE_DESC(CPUID_CACHE_PREFETCH_128
, Lnone
, 0, 0, \
220 "128-Byte Prefetching"),
221 CACHE_DESC(CPUID_CACHE_NOCACHE
, Lnone
, 0, 0, \
222 "No L2 cache or, if valid L2 cache, no L3 cache"),
223 CACHE_DESC(CPUID_CACHE_NULL
, Lnone
, 0, 0, \
227 static const char * get_intel_model_string( i386_cpu_info_t
* info_p
, cpu_type_t
* type
, cpu_subtype_t
* subtype
)
229 *type
= CPU_TYPE_X86
;
230 *subtype
= CPU_SUBTYPE_X86_ARCH1
;
232 /* check for brand id string */
233 switch(info_p
->cpuid_brand
) {
234 case CPUID_BRAND_UNSUPPORTED
:
235 /* brand ID not supported; use alternate method. */
236 switch(info_p
->cpuid_family
) {
237 case CPUID_FAMILY_486
:
239 case CPUID_FAMILY_586
:
240 return "Intel Pentium";
241 case CPUID_FAMILY_686
:
242 switch(info_p
->cpuid_model
) {
244 return "Intel Pentium Pro";
245 case CPUID_MODEL_PII
:
246 return "Intel Pentium II";
247 case CPUID_MODEL_P65
:
248 case CPUID_MODEL_P66
:
249 return "Intel Celeron";
250 case CPUID_MODEL_P67
:
251 case CPUID_MODEL_P68
:
252 case CPUID_MODEL_P6A
:
253 case CPUID_MODEL_P6B
:
254 return "Intel Pentium III";
255 case CPUID_MODEL_PM9
:
256 case CPUID_MODEL_PMD
:
257 return "Intel Pentium M";
259 return "Unknown Intel P6 Family";
261 case CPUID_FAMILY_EXTENDED
:
262 switch (info_p
->cpuid_extfamily
) {
263 case CPUID_EXTFAMILY_PENTIUM4
:
264 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
265 return "Intel Pentium 4";
267 return "Unknown Intel Extended Family";
270 return "Unknown Intel Family";
273 case CPUID_BRAND_CELERON_1
:
274 case CPUID_BRAND_CELERON_A
:
275 case CPUID_BRAND_CELERON_14
:
276 return "Intel Celeron";
277 case CPUID_BRAND_PENTIUM_III_2
:
278 case CPUID_BRAND_PENTIUM_III_4
:
279 return "Pentium III";
280 case CPUID_BRAND_PIII_XEON
:
281 if (info_p
->cpuid_signature
== 0x6B1) {
282 return "Intel Celeron";
284 return "Intel Pentium III Xeon";
286 case CPUID_BRAND_PENTIUM_III_M
:
287 return "Mobile Intel Pentium III-M";
288 case CPUID_BRAND_M_CELERON_7
:
289 case CPUID_BRAND_M_CELERON_F
:
290 case CPUID_BRAND_M_CELERON_13
:
291 case CPUID_BRAND_M_CELERON_17
:
292 return "Mobile Intel Celeron";
293 case CPUID_BRAND_PENTIUM4_8
:
294 case CPUID_BRAND_PENTIUM4_9
:
295 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
296 return "Intel Pentium 4";
297 case CPUID_BRAND_XEON
:
299 case CPUID_BRAND_XEON_MP
:
300 return "Intel Xeon MP";
301 case CPUID_BRAND_PENTIUM4_M
:
302 if (info_p
->cpuid_signature
== 0xF13) {
305 *subtype
= CPU_SUBTYPE_PENTIUM_4
;
306 return "Mobile Intel Pentium 4";
308 case CPUID_BRAND_CELERON_M
:
309 return "Intel Celeron M";
310 case CPUID_BRAND_PENTIUM_M
:
311 return "Intel Pentium M";
312 case CPUID_BRAND_MOBILE_15
:
313 case CPUID_BRAND_MOBILE_17
:
314 return "Mobile Intel";
316 return "Unknown Intel";
319 static void set_intel_cache_info( i386_cpu_info_t
* info_p
)
321 uint32_t cpuid_result
[4];
322 uint32_t l1d_cache_linesize
= 0;
326 /* get processor cache descriptor info */
327 do_cpuid(2, cpuid_result
);
328 for (j
= 0; j
< 4; j
++) {
329 if ((cpuid_result
[j
] >> 31) == 1) /* bit31 is validity */
331 ((uint32_t *) info_p
->cache_info
)[j
] = cpuid_result
[j
];
333 /* first byte gives number of cpuid calls to get all descriptors */
334 for (i
= 1; i
< info_p
->cache_info
[0]; i
++) {
335 if (i
*16 > sizeof(info_p
->cache_info
))
337 do_cpuid(2, cpuid_result
);
338 for (j
= 0; j
< 4; j
++) {
339 if ((cpuid_result
[j
] >> 31) == 1)
341 ((uint32_t *) info_p
->cache_info
)[4*i
+j
] =
346 /* decode the descriptors looking for L1/L2/L3 size info */
347 for (i
= 1; i
< sizeof(info_p
->cache_info
); i
++) {
348 cpuid_cache_desc_t
*descp
;
349 uint8_t desc
= info_p
->cache_info
[i
];
351 if (desc
== CPUID_CACHE_NULL
)
353 for (descp
= cpuid_cache_desc_tab
;
354 descp
->value
!= CPUID_CACHE_NULL
; descp
++) {
355 if (descp
->value
!= desc
)
357 info_p
->cache_size
[descp
->type
] = descp
->size
;
358 if (descp
->type
== L2U
)
359 info_p
->cache_linesize
= descp
->linesize
;
360 if (descp
->type
== L1D
)
361 l1d_cache_linesize
= descp
->linesize
;
365 /* For P-IIIs, L2 could be 256k or 512k but we can't tell */
366 if (info_p
->cache_size
[L2U
] == 0 &&
367 info_p
->cpuid_family
== 0x6 && info_p
->cpuid_model
== 0xb) {
368 info_p
->cache_size
[L2U
] = 256*1024;
369 info_p
->cache_linesize
= 32;
371 /* If we have no L2 cache, use the L1 data cache line size */
372 if (info_p
->cache_size
[L2U
] == 0)
373 info_p
->cache_linesize
= l1d_cache_linesize
;
376 * Get cache sharing info if available.
378 do_cpuid(0, cpuid_result
);
379 if (cpuid_result
[eax
] >= 4) {
382 for (index
= 0;; index
++) {
384 * Scan making calls for cpuid with %eax = 4
385 * to get info about successive cache levels
386 * until a null type is returned.
388 cache_type_t type
= Lnone
;
390 uint32_t cache_level
;
391 uint32_t cache_sharing
;
393 reg
[eax
] = 4; /* cpuid request 4 */
394 reg
[ecx
] = index
; /* index starting at 0 */
396 //kprintf("cpuid(4) index=%d eax=%p\n", index, reg[eax]);
397 cache_type
= bitfield(reg
[eax
], 4, 0);
399 break; /* done with cache info */
400 cache_level
= bitfield(reg
[eax
], 7, 5);
401 cache_sharing
= bitfield(reg
[eax
], 25, 14);
402 info_p
->cpuid_cores_per_package
=
403 bitfield(reg
[eax
], 31, 26) + 1;
404 switch (cache_level
) {
406 type
= cache_type
== 1 ? L1D
:
407 cache_type
== 2 ? L1I
:
411 type
= cache_type
== 3 ? L2U
:
415 type
= cache_type
== 3 ? L3U
:
419 info_p
->cache_sharing
[type
] = cache_sharing
+ 1;
424 static void set_cpu_intel( i386_cpu_info_t
* info_p
)
426 set_cpu_generic(info_p
);
427 set_intel_cache_info(info_p
);
428 info_p
->cpuid_model_string
= get_intel_model_string(info_p
, &info_p
->cpuid_cpu_type
, &info_p
->cpuid_cpu_subtype
);
431 static const char * get_amd_model_string( i386_cpu_info_t
* info_p
, cpu_type_t
* type
, cpu_subtype_t
* subtype
)
433 *type
= CPU_TYPE_X86
;
434 *subtype
= CPU_SUBTYPE_X86_ARCH1
;
436 /* check for brand id string */
437 switch (info_p
->cpuid_family
)
439 case CPUID_FAMILY_486
:
440 switch (info_p
->cpuid_model
) {
441 case CPUID_MODEL_AM486_DX
:
442 case CPUID_MODEL_AM486_DX2
:
443 case CPUID_MODEL_AM486_DX2WB
:
444 case CPUID_MODEL_AM486_DX4
:
445 case CPUID_MODEL_AM486_DX4WB
:
447 case CPUID_MODEL_AM486_5X86
:
448 case CPUID_MODEL_AM486_5X86WB
:
452 case CPUID_FAMILY_586
:
453 switch (info_p
->cpuid_model
) {
454 case CPUID_MODEL_K5M0
:
455 case CPUID_MODEL_K5M1
:
456 case CPUID_MODEL_K5M2
:
457 case CPUID_MODEL_K5M3
:
459 case CPUID_MODEL_K6M6
:
460 case CPUID_MODEL_K6M7
:
462 case CPUID_MODEL_K6_2
:
464 case CPUID_MODEL_K6_III
:
468 case CPUID_FAMILY_686
:
469 switch (info_p
->cpuid_model
) {
470 case CPUID_MODEL_ATHLON_M1
:
471 case CPUID_MODEL_ATHLON_M2
:
472 case CPUID_MODEL_ATHLON_M4
:
473 case CPUID_MODEL_ATHLON_M6
:
474 case CPUID_MODEL_ATHLON_M8
:
475 case CPUID_MODEL_ATHLON_M10
:
477 case CPUID_MODEL_DURON_M3
:
478 case CPUID_MODEL_DURON_M7
:
481 return "Unknown AMD Athlon";
483 case CPUID_FAMILY_EXTENDED
:
484 switch (info_p
->cpuid_model
) {
485 case CPUID_MODEL_ATHLON64
:
486 return "AMD Athlon 64";
487 case CPUID_MODEL_OPTERON
:
488 return "AMD Opteron";
490 return "Unknown AMD-64";
493 return "Unknown AMD";
496 static void set_amd_cache_info( i386_cpu_info_t
* info_p
)
498 uint32_t cpuid_result
[4];
500 /* It would make sense to fill in info_p->cache_info with complete information
501 * on the TLBs and data cache associativity, lines, etc, either by mapping
502 * to the Intel tags (if possible), or replacing cache_info with a generic
503 * mechanism. But right now, nothing makes use of that information (that I know
507 /* L1 Cache and TLB Information */
508 do_cpuid(0x80000005, cpuid_result
);
510 /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */
513 /* EBX: TLB Information for 4-Kbyte Pages */
516 /* ECX: L1 Data Cache Information */
517 info_p
->cache_size
[L1D
] = ((cpuid_result
[ecx
] >> 24) & 0xFF) * 1024;
518 info_p
->cache_linesize
= (cpuid_result
[ecx
] & 0xFF);
520 /* EDX: L1 Instruction Cache Information */
521 info_p
->cache_size
[L1I
] = ((cpuid_result
[edx
] >> 24) & 0xFF) * 1024;
523 /* L2 Cache Information */
524 do_cpuid(0x80000006, cpuid_result
);
526 /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */
529 /* EBX: L2 TLB Information for 4-Kbyte Pages */
532 /* ECX: L2 Cache Information */
533 info_p
->cache_size
[L2U
] = ((cpuid_result
[ecx
] >> 16) & 0xFFFF) * 1024;
534 if (info_p
->cache_size
[L2U
] > 0)
535 info_p
->cache_linesize
= cpuid_result
[ecx
] & 0xFF;
538 static void set_cpu_amd( i386_cpu_info_t
* info_p
)
540 set_cpu_generic(info_p
);
541 set_amd_cache_info(info_p
);
542 info_p
->cpuid_model_string
= get_amd_model_string(info_p
, &info_p
->cpuid_cpu_type
, &info_p
->cpuid_cpu_subtype
);
545 static void set_cpu_nsc( i386_cpu_info_t
* info_p
)
547 set_cpu_generic(info_p
);
548 set_amd_cache_info(info_p
);
550 /* check for brand id string */
551 if (info_p
->cpuid_family
== CPUID_FAMILY_586
&& info_p
->cpuid_model
== CPUID_MODEL_GX1
) {
552 info_p
->cpuid_model_string
= "AMD Geode GX1";
553 } else if (info_p
->cpuid_family
== CPUID_FAMILY_586
&& info_p
->cpuid_model
== CPUID_MODEL_GX2
) {
554 info_p
->cpuid_model_string
= "AMD Geode GX";
556 info_p
->cpuid_model_string
= "Unknown National Semiconductor";
558 info_p
->cpuid_cpu_type
= CPU_TYPE_X86
;
559 info_p
->cpuid_cpu_subtype
= CPU_SUBTYPE_X86_ARCH1
;
563 set_cpu_generic(i386_cpu_info_t
*info_p
)
565 uint32_t cpuid_result
[4];
569 /* get extended cpuid results */
570 do_cpuid(0x80000000, cpuid_result
);
571 max_extid
= cpuid_result
[eax
];
573 /* check to see if we can get brand string */
574 if (max_extid
>= 0x80000004) {
576 * The brand string 48 bytes (max), guaranteed to
579 do_cpuid(0x80000002, cpuid_result
);
580 bcopy((char *)cpuid_result
, &str
[0], 16);
581 do_cpuid(0x80000003, cpuid_result
);
582 bcopy((char *)cpuid_result
, &str
[16], 16);
583 do_cpuid(0x80000004, cpuid_result
);
584 bcopy((char *)cpuid_result
, &str
[32], 16);
585 for (p
= str
; *p
!= '\0'; p
++) {
586 if (*p
!= ' ') break;
588 strncpy(info_p
->cpuid_brand_string
,
589 p
, sizeof(info_p
->cpuid_brand_string
)-1);
590 info_p
->cpuid_brand_string
[sizeof(info_p
->cpuid_brand_string
)-1] = '\0';
592 if (!strcmp(info_p
->cpuid_brand_string
, CPUID_STRING_UNKNOWN
)) {
594 * This string means we have a BIOS-programmable brand string,
595 * and the BIOS couldn't figure out what sort of CPU we have.
597 info_p
->cpuid_brand_string
[0] = '\0';
601 /* get processor signature and decode */
602 do_cpuid(1, cpuid_result
);
603 info_p
->cpuid_signature
= cpuid_result
[eax
];
604 info_p
->cpuid_stepping
= bitfield(cpuid_result
[eax
], 3, 0);
605 info_p
->cpuid_model
= bitfield(cpuid_result
[eax
], 7, 4);
606 info_p
->cpuid_family
= bitfield(cpuid_result
[eax
], 11, 8);
607 info_p
->cpuid_type
= bitfield(cpuid_result
[eax
], 13, 12);
608 info_p
->cpuid_extmodel
= bitfield(cpuid_result
[eax
], 19, 16);
609 info_p
->cpuid_extfamily
= bitfield(cpuid_result
[eax
], 27, 20);
610 info_p
->cpuid_brand
= bitfield(cpuid_result
[ebx
], 7, 0);
611 info_p
->cpuid_logical_per_package
=
612 bitfield(cpuid_result
[ebx
], 23, 16);
613 info_p
->cpuid_features
= quad(cpuid_result
[ecx
], cpuid_result
[edx
]);
615 if (max_extid
>= 0x80000001) {
616 do_cpuid(0x80000001, cpuid_result
);
617 info_p
->cpuid_extfeatures
=
618 quad(cpuid_result
[ecx
], cpuid_result
[edx
]);
625 set_cpu_unknown(__unused i386_cpu_info_t
*info_p
)
627 info_p
->cpuid_model_string
= "Unknown";
635 {CPUID_FEATURE_FPU
, "FPU",},
636 {CPUID_FEATURE_VME
, "VME",},
637 {CPUID_FEATURE_DE
, "DE",},
638 {CPUID_FEATURE_PSE
, "PSE",},
639 {CPUID_FEATURE_TSC
, "TSC",},
640 {CPUID_FEATURE_MSR
, "MSR",},
641 {CPUID_FEATURE_PAE
, "PAE",},
642 {CPUID_FEATURE_MCE
, "MCE",},
643 {CPUID_FEATURE_CX8
, "CX8",},
644 {CPUID_FEATURE_APIC
, "APIC",},
645 {CPUID_FEATURE_SEP
, "SEP",},
646 {CPUID_FEATURE_MTRR
, "MTRR",},
647 {CPUID_FEATURE_PGE
, "PGE",},
648 {CPUID_FEATURE_MCA
, "MCA",},
649 {CPUID_FEATURE_CMOV
, "CMOV",},
650 {CPUID_FEATURE_PAT
, "PAT",},
651 {CPUID_FEATURE_PSE36
, "PSE36",},
652 {CPUID_FEATURE_PSN
, "PSN",},
653 {CPUID_FEATURE_CLFSH
, "CLFSH",},
654 {CPUID_FEATURE_DS
, "DS",},
655 {CPUID_FEATURE_ACPI
, "ACPI",},
656 {CPUID_FEATURE_MMX
, "MMX",},
657 {CPUID_FEATURE_FXSR
, "FXSR",},
658 {CPUID_FEATURE_SSE
, "SSE",},
659 {CPUID_FEATURE_SSE2
, "SSE2",},
660 {CPUID_FEATURE_SS
, "SS",},
661 {CPUID_FEATURE_HTT
, "HTT",},
662 {CPUID_FEATURE_TM
, "TM",},
663 {CPUID_FEATURE_SSE3
, "SSE3"},
664 {CPUID_FEATURE_MONITOR
, "MON"},
665 {CPUID_FEATURE_DSCPL
, "DSCPL"},
666 {CPUID_FEATURE_VMX
, "VMX"},
667 {CPUID_FEATURE_SMX
, "SMX"},
668 {CPUID_FEATURE_EST
, "EST"},
669 {CPUID_FEATURE_TM2
, "TM2"},
670 {CPUID_FEATURE_MNI
, "MNI"},
671 {CPUID_FEATURE_CID
, "CID"},
672 {CPUID_FEATURE_CX16
, "CX16"},
673 {CPUID_FEATURE_xTPR
, "TPR"},
674 {CPUID_FEATURE_PDCM
, "PDCM"},
675 {CPUID_FEATURE_DCA
, "DCA"},
676 {CPUID_FEATURE_SSE4_1
, "SSE4.1"},
677 {CPUID_FEATURE_SSE4_2
, "SSE4.2"},
678 {CPUID_FEATURE_POPCNT
, "POPCNT"},
682 {CPUID_EXTFEATURE_SYSCALL
, "SYSCALL"},
683 {CPUID_EXTFEATURE_XD
, "XD"},
684 {CPUID_EXTFEATURE_EM64T
, "EM64T"},
685 {CPUID_EXTFEATURE_LAHF
, "LAHF"},
692 /* Set-up the cpuid_indo stucture lazily */
693 if (cpuid_cpu_infop
== NULL
) {
694 cpuid_get_info(&cpuid_cpu_info
);
695 cpuid_cpu_infop
= &cpuid_cpu_info
;
697 return cpuid_cpu_infop
;
701 cpuid_get_feature_names(uint64_t features
, char *buf
, unsigned buf_len
)
707 for (i
= 0; feature_map
[i
].mask
!= 0; i
++) {
708 if ((features
& feature_map
[i
].mask
) == 0)
712 len
= min(strlen(feature_map
[i
].name
), (buf_len
-1) - (p
-buf
));
715 bcopy(feature_map
[i
].name
, p
, len
);
723 cpuid_get_extfeature_names(uint64_t extfeatures
, char *buf
, unsigned buf_len
)
729 for (i
= 0; extfeature_map
[i
].mask
!= 0; i
++) {
730 if ((extfeatures
& extfeature_map
[i
].mask
) == 0)
734 len
= min(strlen(extfeature_map
[i
].name
), (buf_len
-1)-(p
-buf
));
737 bcopy(extfeature_map
[i
].name
, p
, len
);
745 cpuid_feature_display(
750 kprintf("%s: %s\n", header
,
751 cpuid_get_feature_names(cpuid_features(),
753 if (cpuid_features() & CPUID_FEATURE_HTT
) {
754 #define s_if_plural(n) ((n > 1) ? "s" : "")
755 kprintf(" HTT: %d core%s per package;"
756 " %d logical cpu%s per package\n",
757 cpuid_cpu_info
.cpuid_cores_per_package
,
758 s_if_plural(cpuid_cpu_info
.cpuid_cores_per_package
),
759 cpuid_cpu_info
.cpuid_logical_per_package
,
760 s_if_plural(cpuid_cpu_info
.cpuid_logical_per_package
));
765 cpuid_extfeature_display(
770 kprintf("%s: %s\n", header
,
771 cpuid_get_extfeature_names(cpuid_extfeatures(),
779 if (cpuid_info()->cpuid_brand_string
[0] != '\0') {
780 kprintf("%s: %s\n", header
, cpuid_cpu_info
.cpuid_brand_string
);
787 return cpuid_info()->cpuid_family
;
793 return cpuid_info()->cpuid_cpu_type
;
797 cpuid_cpusubtype(void)
799 return cpuid_info()->cpuid_cpu_subtype
;
805 static int checked
= 0;
806 char fpu_arg
[16] = { 0 };
810 /* check for boot-time fpu limitations */
811 if (PE_parse_boot_arg("_fpu", &fpu_arg
[0])) {
812 printf("limiting fpu features to: %s\n", fpu_arg
);
813 if (!strncmp("387", fpu_arg
, sizeof "387") || !strncmp("mmx", fpu_arg
, sizeof "mmx")) {
814 printf("no sse or sse2\n");
815 cpuid_cpu_info
.cpuid_features
&= ~(CPUID_FEATURE_SSE
| CPUID_FEATURE_SSE2
| CPUID_FEATURE_FXSR
);
816 } else if (!strncmp("sse", fpu_arg
, sizeof "sse")) {
818 cpuid_cpu_info
.cpuid_features
&= ~(CPUID_FEATURE_SSE2
);
823 return cpuid_cpu_info
.cpuid_features
;
827 cpuid_extfeatures(void)
829 return cpuid_info()->cpuid_extfeatures
;
835 cpuid_get_info(&cpuid_cpu_info
);
846 db_cpuid(__unused db_expr_t addr
,
847 __unused
int have_addr
,
848 __unused db_expr_t count
,
849 __unused
char *modif
)
855 do_cpuid(0, cpid
); /* Get the first cpuid which is the number of
857 db_printf("%08X - %08X %08X %08X %08X\n",
858 0, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);
860 mid
= cpid
[eax
]; /* Set the number */
861 for (i
= 1; 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
]);
868 do_cpuid(0x80000000, cpid
); /* Get the first extended cpuid which
869 * is the number of extended ids */
870 db_printf("%08X - %08X %08X %08X %08X\n",
871 0x80000000, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);
873 mid
= cpid
[eax
]; /* Set the number */
874 for (i
= 0x80000001; i
<= mid
; i
++) { /* Dump 'em out */
875 do_cpuid(i
, cpid
); /* Get the next */
876 db_printf("%08X - %08X %08X %08X %08X\n",
877 i
, cpid
[eax
], cpid
[ebx
], cpid
[ecx
], cpid
[edx
]);