]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/x86/x86/identcpu.c
MFC r271197:
[FreeBSD/stable/10.git] / sys / x86 / x86 / identcpu.c
1 /*-
2  * Copyright (c) 1992 Terrence R. Lambert.
3  * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
4  * Copyright (c) 1997 KATO Takenori.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      from: Id: machdep.c,v 1.193 1996/06/18 01:22:04 bde Exp
39  */
40
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
43
44 #include "opt_cpu.h"
45
46 #include <sys/param.h>
47 #include <sys/bus.h>
48 #include <sys/cpu.h>
49 #include <sys/eventhandler.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/sysctl.h>
53 #include <sys/power.h>
54
55 #include <machine/asmacros.h>
56 #include <machine/clock.h>
57 #include <machine/cputypes.h>
58 #include <machine/frame.h>
59 #include <machine/intr_machdep.h>
60 #include <machine/md_var.h>
61 #include <machine/segments.h>
62 #include <machine/specialreg.h>
63
64 #include <amd64/vmm/intel/vmx_controls.h>
65 #include <x86/isa/icu.h>
66
67 #ifdef __i386__
68 #define IDENTBLUE_CYRIX486      0
69 #define IDENTBLUE_IBMCPU        1
70 #define IDENTBLUE_CYRIXM2       2
71
72 static void identifycyrix(void);
73 static void print_transmeta_info(void);
74 #endif
75 static u_int find_cpu_vendor_id(void);
76 static void print_AMD_info(void);
77 static void print_INTEL_info(void);
78 static void print_INTEL_TLB(u_int data);
79 static void print_via_padlock_info(void);
80 static void print_vmx_info(void);
81
82 int     cpu_class;
83 char machine[] = MACHINE;
84
85 #ifdef __amd64__
86 #ifdef SCTL_MASK32
87 extern int adaptive_machine_arch;
88 #endif
89
90 static int
91 sysctl_hw_machine(SYSCTL_HANDLER_ARGS)
92 {
93 #ifdef SCTL_MASK32
94         static const char machine32[] = "i386";
95 #endif
96         int error;
97
98 #ifdef SCTL_MASK32
99         if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
100                 error = SYSCTL_OUT(req, machine32, sizeof(machine32));
101         else
102 #endif
103                 error = SYSCTL_OUT(req, machine, sizeof(machine));
104         return (error);
105
106 }
107 SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD,
108     NULL, 0, sysctl_hw_machine, "A", "Machine class");
109 #else
110 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
111     machine, 0, "Machine class");
112 #endif
113
114 static char cpu_model[128];
115 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
116     cpu_model, 0, "Machine model");
117
118 static int hw_clockrate;
119 SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
120     &hw_clockrate, 0, "CPU instruction clock rate");
121
122 static eventhandler_tag tsc_post_tag;
123
124 static char cpu_brand[48];
125
126 #ifdef __i386__
127 #define MAX_BRAND_INDEX 8
128
129 static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = {
130         NULL,                   /* No brand */
131         "Intel Celeron",
132         "Intel Pentium III",
133         "Intel Pentium III Xeon",
134         NULL,
135         NULL,
136         NULL,
137         NULL,
138         "Intel Pentium 4"
139 };
140 #endif
141
142 static struct {
143         char    *cpu_name;
144         int     cpu_class;
145 } cpus[] = {
146 #ifdef __i386__
147         { "Intel 80286",        CPUCLASS_286 },         /* CPU_286   */
148         { "i386SX",             CPUCLASS_386 },         /* CPU_386SX */
149         { "i386DX",             CPUCLASS_386 },         /* CPU_386   */
150         { "i486SX",             CPUCLASS_486 },         /* CPU_486SX */
151         { "i486DX",             CPUCLASS_486 },         /* CPU_486   */
152         { "Pentium",            CPUCLASS_586 },         /* CPU_586   */
153         { "Cyrix 486",          CPUCLASS_486 },         /* CPU_486DLC */
154         { "Pentium Pro",        CPUCLASS_686 },         /* CPU_686 */
155         { "Cyrix 5x86",         CPUCLASS_486 },         /* CPU_M1SC */
156         { "Cyrix 6x86",         CPUCLASS_486 },         /* CPU_M1 */
157         { "Blue Lightning",     CPUCLASS_486 },         /* CPU_BLUE */
158         { "Cyrix 6x86MX",       CPUCLASS_686 },         /* CPU_M2 */
159         { "NexGen 586",         CPUCLASS_386 },         /* CPU_NX586 (XXX) */
160         { "Cyrix 486S/DX",      CPUCLASS_486 },         /* CPU_CY486DX */
161         { "Pentium II",         CPUCLASS_686 },         /* CPU_PII */
162         { "Pentium III",        CPUCLASS_686 },         /* CPU_PIII */
163         { "Pentium 4",          CPUCLASS_686 },         /* CPU_P4 */
164 #else
165         { "Clawhammer",         CPUCLASS_K8 },          /* CPU_CLAWHAMMER */
166         { "Sledgehammer",       CPUCLASS_K8 },          /* CPU_SLEDGEHAMMER */
167 #endif
168 };
169
170 static struct {
171         char    *vendor;
172         u_int   vendor_id;
173 } cpu_vendors[] = {
174         { INTEL_VENDOR_ID,      CPU_VENDOR_INTEL },     /* GenuineIntel */
175         { AMD_VENDOR_ID,        CPU_VENDOR_AMD },       /* AuthenticAMD */
176         { CENTAUR_VENDOR_ID,    CPU_VENDOR_CENTAUR },   /* CentaurHauls */
177 #ifdef __i386__
178         { NSC_VENDOR_ID,        CPU_VENDOR_NSC },       /* Geode by NSC */
179         { CYRIX_VENDOR_ID,      CPU_VENDOR_CYRIX },     /* CyrixInstead */
180         { TRANSMETA_VENDOR_ID,  CPU_VENDOR_TRANSMETA }, /* GenuineTMx86 */
181         { SIS_VENDOR_ID,        CPU_VENDOR_SIS },       /* SiS SiS SiS  */
182         { UMC_VENDOR_ID,        CPU_VENDOR_UMC },       /* UMC UMC UMC  */
183         { NEXGEN_VENDOR_ID,     CPU_VENDOR_NEXGEN },    /* NexGenDriven */
184         { RISE_VENDOR_ID,       CPU_VENDOR_RISE },      /* RiseRiseRise */
185 #if 0
186         /* XXX CPUID 8000_0000h and 8086_0000h, not 0000_0000h */
187         { "TransmetaCPU",       CPU_VENDOR_TRANSMETA },
188 #endif
189 #endif
190 };
191
192 void
193 printcpuinfo(void)
194 {
195         u_int regs[4], i;
196         char *brand;
197
198         cpu_class = cpus[cpu].cpu_class;
199         printf("CPU: ");
200         strncpy(cpu_model, cpus[cpu].cpu_name, sizeof (cpu_model));
201
202         /* Check for extended CPUID information and a processor name. */
203         if (cpu_exthigh >= 0x80000004) {
204                 brand = cpu_brand;
205                 for (i = 0x80000002; i < 0x80000005; i++) {
206                         do_cpuid(i, regs);
207                         memcpy(brand, regs, sizeof(regs));
208                         brand += sizeof(regs);
209                 }
210         }
211
212         switch (cpu_vendor_id) {
213         case CPU_VENDOR_INTEL:
214 #ifdef __i386__
215                 if ((cpu_id & 0xf00) > 0x300) {
216                         u_int brand_index;
217
218                         cpu_model[0] = '\0';
219
220                         switch (cpu_id & 0x3000) {
221                         case 0x1000:
222                                 strcpy(cpu_model, "Overdrive ");
223                                 break;
224                         case 0x2000:
225                                 strcpy(cpu_model, "Dual ");
226                                 break;
227                         }
228
229                         switch (cpu_id & 0xf00) {
230                         case 0x400:
231                                 strcat(cpu_model, "i486 ");
232                                 /* Check the particular flavor of 486 */
233                                 switch (cpu_id & 0xf0) {
234                                 case 0x00:
235                                 case 0x10:
236                                         strcat(cpu_model, "DX");
237                                         break;
238                                 case 0x20:
239                                         strcat(cpu_model, "SX");
240                                         break;
241                                 case 0x30:
242                                         strcat(cpu_model, "DX2");
243                                         break;
244                                 case 0x40:
245                                         strcat(cpu_model, "SL");
246                                         break;
247                                 case 0x50:
248                                         strcat(cpu_model, "SX2");
249                                         break;
250                                 case 0x70:
251                                         strcat(cpu_model,
252                                             "DX2 Write-Back Enhanced");
253                                         break;
254                                 case 0x80:
255                                         strcat(cpu_model, "DX4");
256                                         break;
257                                 }
258                                 break;
259                         case 0x500:
260                                 /* Check the particular flavor of 586 */
261                                 strcat(cpu_model, "Pentium");
262                                 switch (cpu_id & 0xf0) {
263                                 case 0x00:
264                                         strcat(cpu_model, " A-step");
265                                         break;
266                                 case 0x10:
267                                         strcat(cpu_model, "/P5");
268                                         break;
269                                 case 0x20:
270                                         strcat(cpu_model, "/P54C");
271                                         break;
272                                 case 0x30:
273                                         strcat(cpu_model, "/P24T");
274                                         break;
275                                 case 0x40:
276                                         strcat(cpu_model, "/P55C");
277                                         break;
278                                 case 0x70:
279                                         strcat(cpu_model, "/P54C");
280                                         break;
281                                 case 0x80:
282                                         strcat(cpu_model, "/P55C (quarter-micron)");
283                                         break;
284                                 default:
285                                         /* nothing */
286                                         break;
287                                 }
288 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
289                                 /*
290                                  * XXX - If/when Intel fixes the bug, this
291                                  * should also check the version of the
292                                  * CPU, not just that it's a Pentium.
293                                  */
294                                 has_f00f_bug = 1;
295 #endif
296                                 break;
297                         case 0x600:
298                                 /* Check the particular flavor of 686 */
299                                 switch (cpu_id & 0xf0) {
300                                 case 0x00:
301                                         strcat(cpu_model, "Pentium Pro A-step");
302                                         break;
303                                 case 0x10:
304                                         strcat(cpu_model, "Pentium Pro");
305                                         break;
306                                 case 0x30:
307                                 case 0x50:
308                                 case 0x60:
309                                         strcat(cpu_model,
310                                 "Pentium II/Pentium II Xeon/Celeron");
311                                         cpu = CPU_PII;
312                                         break;
313                                 case 0x70:
314                                 case 0x80:
315                                 case 0xa0:
316                                 case 0xb0:
317                                         strcat(cpu_model,
318                                         "Pentium III/Pentium III Xeon/Celeron");
319                                         cpu = CPU_PIII;
320                                         break;
321                                 default:
322                                         strcat(cpu_model, "Unknown 80686");
323                                         break;
324                                 }
325                                 break;
326                         case 0xf00:
327                                 strcat(cpu_model, "Pentium 4");
328                                 cpu = CPU_P4;
329                                 break;
330                         default:
331                                 strcat(cpu_model, "unknown");
332                                 break;
333                         }
334
335                         /*
336                          * If we didn't get a brand name from the extended
337                          * CPUID, try to look it up in the brand table.
338                          */
339                         if (cpu_high > 0 && *cpu_brand == '\0') {
340                                 brand_index = cpu_procinfo & CPUID_BRAND_INDEX;
341                                 if (brand_index <= MAX_BRAND_INDEX &&
342                                     cpu_brandtable[brand_index] != NULL)
343                                         strcpy(cpu_brand,
344                                             cpu_brandtable[brand_index]);
345                         }
346                 }
347 #else
348                 /* Please make up your mind folks! */
349                 strcat(cpu_model, "EM64T");
350 #endif
351                 break;
352         case CPU_VENDOR_AMD:
353                 /*
354                  * Values taken from AMD Processor Recognition
355                  * http://www.amd.com/K6/k6docs/pdf/20734g.pdf
356                  * (also describes ``Features'' encodings.
357                  */
358                 strcpy(cpu_model, "AMD ");
359 #ifdef __i386__
360                 switch (cpu_id & 0xFF0) {
361                 case 0x410:
362                         strcat(cpu_model, "Standard Am486DX");
363                         break;
364                 case 0x430:
365                         strcat(cpu_model, "Enhanced Am486DX2 Write-Through");
366                         break;
367                 case 0x470:
368                         strcat(cpu_model, "Enhanced Am486DX2 Write-Back");
369                         break;
370                 case 0x480:
371                         strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Through");
372                         break;
373                 case 0x490:
374                         strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Back");
375                         break;
376                 case 0x4E0:
377                         strcat(cpu_model, "Am5x86 Write-Through");
378                         break;
379                 case 0x4F0:
380                         strcat(cpu_model, "Am5x86 Write-Back");
381                         break;
382                 case 0x500:
383                         strcat(cpu_model, "K5 model 0");
384                         break;
385                 case 0x510:
386                         strcat(cpu_model, "K5 model 1");
387                         break;
388                 case 0x520:
389                         strcat(cpu_model, "K5 PR166 (model 2)");
390                         break;
391                 case 0x530:
392                         strcat(cpu_model, "K5 PR200 (model 3)");
393                         break;
394                 case 0x560:
395                         strcat(cpu_model, "K6");
396                         break;
397                 case 0x570:
398                         strcat(cpu_model, "K6 266 (model 1)");
399                         break;
400                 case 0x580:
401                         strcat(cpu_model, "K6-2");
402                         break;
403                 case 0x590:
404                         strcat(cpu_model, "K6-III");
405                         break;
406                 case 0x5a0:
407                         strcat(cpu_model, "Geode LX");
408                         break;
409                 default:
410                         strcat(cpu_model, "Unknown");
411                         break;
412                 }
413 #else
414                 if ((cpu_id & 0xf00) == 0xf00)
415                         strcat(cpu_model, "AMD64 Processor");
416                 else
417                         strcat(cpu_model, "Unknown");
418 #endif
419                 break;
420 #ifdef __i386__
421         case CPU_VENDOR_CYRIX:
422                 strcpy(cpu_model, "Cyrix ");
423                 switch (cpu_id & 0xff0) {
424                 case 0x440:
425                         strcat(cpu_model, "MediaGX");
426                         break;
427                 case 0x520:
428                         strcat(cpu_model, "6x86");
429                         break;
430                 case 0x540:
431                         cpu_class = CPUCLASS_586;
432                         strcat(cpu_model, "GXm");
433                         break;
434                 case 0x600:
435                         strcat(cpu_model, "6x86MX");
436                         break;
437                 default:
438                         /*
439                          * Even though CPU supports the cpuid
440                          * instruction, it can be disabled.
441                          * Therefore, this routine supports all Cyrix
442                          * CPUs.
443                          */
444                         switch (cyrix_did & 0xf0) {
445                         case 0x00:
446                                 switch (cyrix_did & 0x0f) {
447                                 case 0x00:
448                                         strcat(cpu_model, "486SLC");
449                                         break;
450                                 case 0x01:
451                                         strcat(cpu_model, "486DLC");
452                                         break;
453                                 case 0x02:
454                                         strcat(cpu_model, "486SLC2");
455                                         break;
456                                 case 0x03:
457                                         strcat(cpu_model, "486DLC2");
458                                         break;
459                                 case 0x04:
460                                         strcat(cpu_model, "486SRx");
461                                         break;
462                                 case 0x05:
463                                         strcat(cpu_model, "486DRx");
464                                         break;
465                                 case 0x06:
466                                         strcat(cpu_model, "486SRx2");
467                                         break;
468                                 case 0x07:
469                                         strcat(cpu_model, "486DRx2");
470                                         break;
471                                 case 0x08:
472                                         strcat(cpu_model, "486SRu");
473                                         break;
474                                 case 0x09:
475                                         strcat(cpu_model, "486DRu");
476                                         break;
477                                 case 0x0a:
478                                         strcat(cpu_model, "486SRu2");
479                                         break;
480                                 case 0x0b:
481                                         strcat(cpu_model, "486DRu2");
482                                         break;
483                                 default:
484                                         strcat(cpu_model, "Unknown");
485                                         break;
486                                 }
487                                 break;
488                         case 0x10:
489                                 switch (cyrix_did & 0x0f) {
490                                 case 0x00:
491                                         strcat(cpu_model, "486S");
492                                         break;
493                                 case 0x01:
494                                         strcat(cpu_model, "486S2");
495                                         break;
496                                 case 0x02:
497                                         strcat(cpu_model, "486Se");
498                                         break;
499                                 case 0x03:
500                                         strcat(cpu_model, "486S2e");
501                                         break;
502                                 case 0x0a:
503                                         strcat(cpu_model, "486DX");
504                                         break;
505                                 case 0x0b:
506                                         strcat(cpu_model, "486DX2");
507                                         break;
508                                 case 0x0f:
509                                         strcat(cpu_model, "486DX4");
510                                         break;
511                                 default:
512                                         strcat(cpu_model, "Unknown");
513                                         break;
514                                 }
515                                 break;
516                         case 0x20:
517                                 if ((cyrix_did & 0x0f) < 8)
518                                         strcat(cpu_model, "6x86");      /* Where did you get it? */
519                                 else
520                                         strcat(cpu_model, "5x86");
521                                 break;
522                         case 0x30:
523                                 strcat(cpu_model, "6x86");
524                                 break;
525                         case 0x40:
526                                 if ((cyrix_did & 0xf000) == 0x3000) {
527                                         cpu_class = CPUCLASS_586;
528                                         strcat(cpu_model, "GXm");
529                                 } else
530                                         strcat(cpu_model, "MediaGX");
531                                 break;
532                         case 0x50:
533                                 strcat(cpu_model, "6x86MX");
534                                 break;
535                         case 0xf0:
536                                 switch (cyrix_did & 0x0f) {
537                                 case 0x0d:
538                                         strcat(cpu_model, "Overdrive CPU");
539                                         break;
540                                 case 0x0e:
541                                         strcpy(cpu_model, "Texas Instruments 486SXL");
542                                         break;
543                                 case 0x0f:
544                                         strcat(cpu_model, "486SLC/DLC");
545                                         break;
546                                 default:
547                                         strcat(cpu_model, "Unknown");
548                                         break;
549                                 }
550                                 break;
551                         default:
552                                 strcat(cpu_model, "Unknown");
553                                 break;
554                         }
555                         break;
556                 }
557                 break;
558         case CPU_VENDOR_RISE:
559                 strcpy(cpu_model, "Rise ");
560                 switch (cpu_id & 0xff0) {
561                 case 0x500:     /* 6401 and 6441 (Kirin) */
562                 case 0x520:     /* 6510 (Lynx) */
563                         strcat(cpu_model, "mP6");
564                         break;
565                 default:
566                         strcat(cpu_model, "Unknown");
567                 }
568                 break;
569 #endif
570         case CPU_VENDOR_CENTAUR:
571 #ifdef __i386__
572                 switch (cpu_id & 0xff0) {
573                 case 0x540:
574                         strcpy(cpu_model, "IDT WinChip C6");
575                         break;
576                 case 0x580:
577                         strcpy(cpu_model, "IDT WinChip 2");
578                         break;
579                 case 0x590:
580                         strcpy(cpu_model, "IDT WinChip 3");
581                         break;
582                 case 0x660:
583                         strcpy(cpu_model, "VIA C3 Samuel");
584                         break;
585                 case 0x670:
586                         if (cpu_id & 0x8)
587                                 strcpy(cpu_model, "VIA C3 Ezra");
588                         else
589                                 strcpy(cpu_model, "VIA C3 Samuel 2");
590                         break;
591                 case 0x680:
592                         strcpy(cpu_model, "VIA C3 Ezra-T");
593                         break;
594                 case 0x690:
595                         strcpy(cpu_model, "VIA C3 Nehemiah");
596                         break;
597                 case 0x6a0:
598                 case 0x6d0:
599                         strcpy(cpu_model, "VIA C7 Esther");
600                         break;
601                 case 0x6f0:
602                         strcpy(cpu_model, "VIA Nano");
603                         break;
604                 default:
605                         strcpy(cpu_model, "VIA/IDT Unknown");
606                 }
607 #else
608                 strcpy(cpu_model, "VIA ");
609                 if ((cpu_id & 0xff0) == 0x6f0)
610                         strcat(cpu_model, "Nano Processor");
611                 else
612                         strcat(cpu_model, "Unknown");
613 #endif
614                 break;
615 #ifdef __i386__
616         case CPU_VENDOR_IBM:
617                 strcpy(cpu_model, "Blue Lightning CPU");
618                 break;
619         case CPU_VENDOR_NSC:
620                 switch (cpu_id & 0xff0) {
621                 case 0x540:
622                         strcpy(cpu_model, "Geode SC1100");
623                         cpu = CPU_GEODE1100;
624                         break;
625                 default:
626                         strcpy(cpu_model, "Geode/NSC unknown");
627                         break;
628                 }
629                 break;
630 #endif
631         default:
632                 strcat(cpu_model, "Unknown");
633                 break;
634         }
635
636         /*
637          * Replace cpu_model with cpu_brand minus leading spaces if
638          * we have one.
639          */
640         brand = cpu_brand;
641         while (*brand == ' ')
642                 ++brand;
643         if (*brand != '\0')
644                 strcpy(cpu_model, brand);
645
646         printf("%s (", cpu_model);
647         if (tsc_freq != 0) {
648                 hw_clockrate = (tsc_freq + 5000) / 1000000;
649                 printf("%jd.%02d-MHz ",
650                     (intmax_t)(tsc_freq + 4999) / 1000000,
651                     (u_int)((tsc_freq + 4999) / 10000) % 100);
652         }
653         switch(cpu_class) {
654 #ifdef __i386__
655         case CPUCLASS_286:
656                 printf("286");
657                 break;
658         case CPUCLASS_386:
659                 printf("386");
660                 break;
661 #if defined(I486_CPU)
662         case CPUCLASS_486:
663                 printf("486");
664                 break;
665 #endif
666 #if defined(I586_CPU)
667         case CPUCLASS_586:
668                 printf("586");
669                 break;
670 #endif
671 #if defined(I686_CPU)
672         case CPUCLASS_686:
673                 printf("686");
674                 break;
675 #endif
676 #else
677         case CPUCLASS_K8:
678                 printf("K8");
679                 break;
680 #endif
681         default:
682                 printf("Unknown");      /* will panic below... */
683         }
684         printf("-class CPU)\n");
685         if (*cpu_vendor)
686                 printf("  Origin=\"%s\"", cpu_vendor);
687         if (cpu_id)
688                 printf("  Id=0x%x", cpu_id);
689
690         if (cpu_vendor_id == CPU_VENDOR_INTEL ||
691             cpu_vendor_id == CPU_VENDOR_AMD ||
692             cpu_vendor_id == CPU_VENDOR_CENTAUR ||
693 #ifdef __i386__
694             cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
695             cpu_vendor_id == CPU_VENDOR_RISE ||
696             cpu_vendor_id == CPU_VENDOR_NSC ||
697             (cpu_vendor_id == CPU_VENDOR_CYRIX && ((cpu_id & 0xf00) > 0x500)) ||
698 #endif
699             0) {
700                 printf("  Family=0x%x", CPUID_TO_FAMILY(cpu_id));
701                 printf("  Model=0x%x", CPUID_TO_MODEL(cpu_id));
702                 printf("  Stepping=%u", cpu_id & CPUID_STEPPING);
703 #ifdef __i386__
704                 if (cpu_vendor_id == CPU_VENDOR_CYRIX)
705                         printf("\n  DIR=0x%04x", cyrix_did);
706 #endif
707
708                 /*
709                  * AMD CPUID Specification
710                  * http://support.amd.com/us/Embedded_TechDocs/25481.pdf
711                  *
712                  * Intel Processor Identification and CPUID Instruction
713                  * http://www.intel.com/assets/pdf/appnote/241618.pdf
714                  */
715                 if (cpu_high > 0) {
716
717                         /*
718                          * Here we should probably set up flags indicating
719                          * whether or not various features are available.
720                          * The interesting ones are probably VME, PSE, PAE,
721                          * and PGE.  The code already assumes without bothering
722                          * to check that all CPUs >= Pentium have a TSC and
723                          * MSRs.
724                          */
725                         printf("\n  Features=0x%b", cpu_feature,
726                         "\020"
727                         "\001FPU"       /* Integral FPU */
728                         "\002VME"       /* Extended VM86 mode support */
729                         "\003DE"        /* Debugging Extensions (CR4.DE) */
730                         "\004PSE"       /* 4MByte page tables */
731                         "\005TSC"       /* Timestamp counter */
732                         "\006MSR"       /* Machine specific registers */
733                         "\007PAE"       /* Physical address extension */
734                         "\010MCE"       /* Machine Check support */
735                         "\011CX8"       /* CMPEXCH8 instruction */
736                         "\012APIC"      /* SMP local APIC */
737                         "\013oldMTRR"   /* Previous implementation of MTRR */
738                         "\014SEP"       /* Fast System Call */
739                         "\015MTRR"      /* Memory Type Range Registers */
740                         "\016PGE"       /* PG_G (global bit) support */
741                         "\017MCA"       /* Machine Check Architecture */
742                         "\020CMOV"      /* CMOV instruction */
743                         "\021PAT"       /* Page attributes table */
744                         "\022PSE36"     /* 36 bit address space support */
745                         "\023PN"        /* Processor Serial number */
746                         "\024CLFLUSH"   /* Has the CLFLUSH instruction */
747                         "\025<b20>"
748                         "\026DTS"       /* Debug Trace Store */
749                         "\027ACPI"      /* ACPI support */
750                         "\030MMX"       /* MMX instructions */
751                         "\031FXSR"      /* FXSAVE/FXRSTOR */
752                         "\032SSE"       /* Streaming SIMD Extensions */
753                         "\033SSE2"      /* Streaming SIMD Extensions #2 */
754                         "\034SS"        /* Self snoop */
755                         "\035HTT"       /* Hyperthreading (see EBX bit 16-23) */
756                         "\036TM"        /* Thermal Monitor clock slowdown */
757                         "\037IA64"      /* CPU can execute IA64 instructions */
758                         "\040PBE"       /* Pending Break Enable */
759                         );
760
761                         if (cpu_feature2 != 0) {
762                                 printf("\n  Features2=0x%b", cpu_feature2,
763                                 "\020"
764                                 "\001SSE3"      /* SSE3 */
765                                 "\002PCLMULQDQ" /* Carry-Less Mul Quadword */
766                                 "\003DTES64"    /* 64-bit Debug Trace */
767                                 "\004MON"       /* MONITOR/MWAIT Instructions */
768                                 "\005DS_CPL"    /* CPL Qualified Debug Store */
769                                 "\006VMX"       /* Virtual Machine Extensions */
770                                 "\007SMX"       /* Safer Mode Extensions */
771                                 "\010EST"       /* Enhanced SpeedStep */
772                                 "\011TM2"       /* Thermal Monitor 2 */
773                                 "\012SSSE3"     /* SSSE3 */
774                                 "\013CNXT-ID"   /* L1 context ID available */
775                                 "\014<b11>"
776                                 "\015FMA"       /* Fused Multiply Add */
777                                 "\016CX16"      /* CMPXCHG16B Instruction */
778                                 "\017xTPR"      /* Send Task Priority Messages*/
779                                 "\020PDCM"      /* Perf/Debug Capability MSR */
780                                 "\021<b16>"
781                                 "\022PCID"      /* Process-context Identifiers*/
782                                 "\023DCA"       /* Direct Cache Access */
783                                 "\024SSE4.1"    /* SSE 4.1 */
784                                 "\025SSE4.2"    /* SSE 4.2 */
785                                 "\026x2APIC"    /* xAPIC Extensions */
786                                 "\027MOVBE"     /* MOVBE Instruction */
787                                 "\030POPCNT"    /* POPCNT Instruction */
788                                 "\031TSCDLT"    /* TSC-Deadline Timer */
789                                 "\032AESNI"     /* AES Crypto */
790                                 "\033XSAVE"     /* XSAVE/XRSTOR States */
791                                 "\034OSXSAVE"   /* OS-Enabled State Management*/
792                                 "\035AVX"       /* Advanced Vector Extensions */
793                                 "\036F16C"      /* Half-precision conversions */
794                                 "\037RDRAND"    /* RDRAND Instruction */
795                                 "\040HV"        /* Hypervisor */
796                                 );
797                         }
798
799                         if (amd_feature != 0) {
800                                 printf("\n  AMD Features=0x%b", amd_feature,
801                                 "\020"          /* in hex */
802                                 "\001<s0>"      /* Same */
803                                 "\002<s1>"      /* Same */
804                                 "\003<s2>"      /* Same */
805                                 "\004<s3>"      /* Same */
806                                 "\005<s4>"      /* Same */
807                                 "\006<s5>"      /* Same */
808                                 "\007<s6>"      /* Same */
809                                 "\010<s7>"      /* Same */
810                                 "\011<s8>"      /* Same */
811                                 "\012<s9>"      /* Same */
812                                 "\013<b10>"     /* Undefined */
813                                 "\014SYSCALL"   /* Have SYSCALL/SYSRET */
814                                 "\015<s12>"     /* Same */
815                                 "\016<s13>"     /* Same */
816                                 "\017<s14>"     /* Same */
817                                 "\020<s15>"     /* Same */
818                                 "\021<s16>"     /* Same */
819                                 "\022<s17>"     /* Same */
820                                 "\023<b18>"     /* Reserved, unknown */
821                                 "\024MP"        /* Multiprocessor Capable */
822                                 "\025NX"        /* Has EFER.NXE, NX */
823                                 "\026<b21>"     /* Undefined */
824                                 "\027MMX+"      /* AMD MMX Extensions */
825                                 "\030<s23>"     /* Same */
826                                 "\031<s24>"     /* Same */
827                                 "\032FFXSR"     /* Fast FXSAVE/FXRSTOR */
828                                 "\033Page1GB"   /* 1-GB large page support */
829                                 "\034RDTSCP"    /* RDTSCP */
830                                 "\035<b28>"     /* Undefined */
831                                 "\036LM"        /* 64 bit long mode */
832                                 "\0373DNow!+"   /* AMD 3DNow! Extensions */
833                                 "\0403DNow!"    /* AMD 3DNow! */
834                                 );
835                         }
836
837                         if (amd_feature2 != 0) {
838                                 printf("\n  AMD Features2=0x%b", amd_feature2,
839                                 "\020"
840                                 "\001LAHF"      /* LAHF/SAHF in long mode */
841                                 "\002CMP"       /* CMP legacy */
842                                 "\003SVM"       /* Secure Virtual Mode */
843                                 "\004ExtAPIC"   /* Extended APIC register */
844                                 "\005CR8"       /* CR8 in legacy mode */
845                                 "\006ABM"       /* LZCNT instruction */
846                                 "\007SSE4A"     /* SSE4A */
847                                 "\010MAS"       /* Misaligned SSE mode */
848                                 "\011Prefetch"  /* 3DNow! Prefetch/PrefetchW */
849                                 "\012OSVW"      /* OS visible workaround */
850                                 "\013IBS"       /* Instruction based sampling */
851                                 "\014XOP"       /* XOP extended instructions */
852                                 "\015SKINIT"    /* SKINIT/STGI */
853                                 "\016WDT"       /* Watchdog timer */
854                                 "\017<b14>"
855                                 "\020LWP"       /* Lightweight Profiling */
856                                 "\021FMA4"      /* 4-operand FMA instructions */
857                                 "\022TCE"       /* Translation Cache Extension */
858                                 "\023<b18>"
859                                 "\024NodeId"    /* NodeId MSR support */
860                                 "\025<b20>"
861                                 "\026TBM"       /* Trailing Bit Manipulation */
862                                 "\027Topology"  /* Topology Extensions */
863                                 "\030PCXC"      /* Core perf count */
864                                 "\031PNXC"      /* NB perf count */
865                                 "\032<b25>"
866                                 "\033DBE"       /* Data Breakpoint extension */
867                                 "\034PTSC"      /* Performance TSC */
868                                 "\035PL2I"      /* L2I perf count */
869                                 "\036<b29>"
870                                 "\037<b30>"
871                                 "\040<b31>"
872                                 );
873                         }
874
875                         if (cpu_stdext_feature != 0) {
876                                 printf("\n  Structured Extended Features=0x%b",
877                                     cpu_stdext_feature,
878                                        "\020"
879                                        /* RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */
880                                        "\001FSGSBASE"
881                                        "\002TSCADJ"
882                                        /* Bit Manipulation Instructions */
883                                        "\004BMI1"
884                                        /* Hardware Lock Elision */
885                                        "\005HLE"
886                                        /* Advanced Vector Instructions 2 */
887                                        "\006AVX2"
888                                        /* Supervisor Mode Execution Prot. */
889                                        "\010SMEP"
890                                        /* Bit Manipulation Instructions */
891                                        "\011BMI2"
892                                        "\012ERMS"
893                                        /* Invalidate Processor Context ID */
894                                        "\013INVPCID"
895                                        /* Restricted Transactional Memory */
896                                        "\014RTM"
897                                        /* Intel Memory Protection Extensions */
898                                        "\017MPX"
899                                        /* AVX512 Foundation */
900                                        "\021AVX512F"
901                                        /* Enhanced NRBG */
902                                        "\023RDSEED"
903                                        /* ADCX + ADOX */
904                                        "\024ADX"
905                                        /* Supervisor Mode Access Prevention */
906                                        "\025SMAP"
907                                        "\030CLFLUSHOPT"
908                                        "\032PROCTRACE"
909                                        "\033AVX512PF"
910                                        "\034AVX512ER"
911                                        "\035AVX512CD"
912                                        "\036SHA"
913                                        );
914                         }
915
916                         if ((cpu_feature2 & CPUID2_XSAVE) != 0) {
917                                 cpuid_count(0xd, 0x1, regs);
918                                 if (regs[0] != 0) {
919                                         printf("\n  XSAVE Features=0x%b",
920                                             regs[0],
921                                             "\020"
922                                             "\001XSAVEOPT"
923                                             "\002XSAVEC"
924                                             "\003XINUSE"
925                                             "\004XSAVES");
926                                 }
927                         }
928
929                         if (via_feature_rng != 0 || via_feature_xcrypt != 0)
930                                 print_via_padlock_info();
931
932                         if (cpu_feature2 & CPUID2_VMX)
933                                 print_vmx_info();
934
935                         if ((cpu_feature & CPUID_HTT) &&
936                             cpu_vendor_id == CPU_VENDOR_AMD)
937                                 cpu_feature &= ~CPUID_HTT;
938
939                         /*
940                          * If this CPU supports P-state invariant TSC then
941                          * mention the capability.
942                          */
943                         if (tsc_is_invariant) {
944                                 printf("\n  TSC: P-state invariant");
945                                 if (tsc_perf_stat)
946                                         printf(", performance statistics");
947                         }
948
949                 }
950 #ifdef __i386__
951         } else if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
952                 printf("  DIR=0x%04x", cyrix_did);
953                 printf("  Stepping=%u", (cyrix_did & 0xf000) >> 12);
954                 printf("  Revision=%u", (cyrix_did & 0x0f00) >> 8);
955 #ifndef CYRIX_CACHE_REALLY_WORKS
956                 if (cpu == CPU_M1 && (cyrix_did & 0xff00) < 0x1700)
957                         printf("\n  CPU cache: write-through mode");
958 #endif
959 #endif
960         }
961
962         /* Avoid ugly blank lines: only print newline when we have to. */
963         if (*cpu_vendor || cpu_id)
964                 printf("\n");
965
966         if (!bootverbose)
967                 return;
968
969         if (cpu_vendor_id == CPU_VENDOR_AMD)
970                 print_AMD_info();
971         else if (cpu_vendor_id == CPU_VENDOR_INTEL)
972                 print_INTEL_info();
973 #ifdef __i386__
974         else if (cpu_vendor_id == CPU_VENDOR_TRANSMETA)
975                 print_transmeta_info();
976 #endif
977 }
978
979 void
980 panicifcpuunsupported(void)
981 {
982
983 #ifdef __i386__
984 #if !defined(lint)
985 #if !defined(I486_CPU) && !defined(I586_CPU) && !defined(I686_CPU)
986 #error This kernel is not configured for one of the supported CPUs
987 #endif
988 #else /* lint */
989 #endif /* lint */
990 #else /* __amd64__ */
991 #ifndef HAMMER
992 #error "You need to specify a cpu type"
993 #endif
994 #endif
995         /*
996          * Now that we have told the user what they have,
997          * let them know if that machine type isn't configured.
998          */
999         switch (cpu_class) {
1000 #ifdef __i386__
1001         case CPUCLASS_286:      /* a 286 should not make it this far, anyway */
1002         case CPUCLASS_386:
1003 #if !defined(I486_CPU)
1004         case CPUCLASS_486:
1005 #endif
1006 #if !defined(I586_CPU)
1007         case CPUCLASS_586:
1008 #endif
1009 #if !defined(I686_CPU)
1010         case CPUCLASS_686:
1011 #endif
1012 #else /* __amd64__ */
1013         case CPUCLASS_X86:
1014 #ifndef HAMMER
1015         case CPUCLASS_K8:
1016 #endif
1017 #endif
1018                 panic("CPU class not configured");
1019         default:
1020                 break;
1021         }
1022 }
1023
1024 #ifdef __i386__
1025 static  volatile u_int trap_by_rdmsr;
1026
1027 /*
1028  * Special exception 6 handler.
1029  * The rdmsr instruction generates invalid opcodes fault on 486-class
1030  * Cyrix CPU.  Stacked eip register points the rdmsr instruction in the
1031  * function identblue() when this handler is called.  Stacked eip should
1032  * be advanced.
1033  */
1034 inthand_t       bluetrap6;
1035 #ifdef __GNUCLIKE_ASM
1036 __asm
1037 ("                                                                      \n\
1038         .text                                                           \n\
1039         .p2align 2,0x90                                                 \n\
1040         .type   " __XSTRING(CNAME(bluetrap6)) ",@function               \n\
1041 " __XSTRING(CNAME(bluetrap6)) ":                                        \n\
1042         ss                                                              \n\
1043         movl    $0xa8c1d," __XSTRING(CNAME(trap_by_rdmsr)) "            \n\
1044         addl    $2, (%esp)      /* rdmsr is a 2-byte instruction */     \n\
1045         iret                                                            \n\
1046 ");
1047 #endif
1048
1049 /*
1050  * Special exception 13 handler.
1051  * Accessing non-existent MSR generates general protection fault.
1052  */
1053 inthand_t       bluetrap13;
1054 #ifdef __GNUCLIKE_ASM
1055 __asm
1056 ("                                                                      \n\
1057         .text                                                           \n\
1058         .p2align 2,0x90                                                 \n\
1059         .type   " __XSTRING(CNAME(bluetrap13)) ",@function              \n\
1060 " __XSTRING(CNAME(bluetrap13)) ":                                       \n\
1061         ss                                                              \n\
1062         movl    $0xa89c4," __XSTRING(CNAME(trap_by_rdmsr)) "            \n\
1063         popl    %eax            /* discard error code */                \n\
1064         addl    $2, (%esp)      /* rdmsr is a 2-byte instruction */     \n\
1065         iret                                                            \n\
1066 ");
1067 #endif
1068
1069 /*
1070  * Distinguish IBM Blue Lightning CPU from Cyrix CPUs that does not
1071  * support cpuid instruction.  This function should be called after
1072  * loading interrupt descriptor table register.
1073  *
1074  * I don't like this method that handles fault, but I couldn't get
1075  * information for any other methods.  Does blue giant know?
1076  */
1077 static int
1078 identblue(void)
1079 {
1080
1081         trap_by_rdmsr = 0;
1082
1083         /*
1084          * Cyrix 486-class CPU does not support rdmsr instruction.
1085          * The rdmsr instruction generates invalid opcode fault, and exception
1086          * will be trapped by bluetrap6() on Cyrix 486-class CPU.  The
1087          * bluetrap6() set the magic number to trap_by_rdmsr.
1088          */
1089         setidt(IDT_UD, bluetrap6, SDT_SYS386TGT, SEL_KPL,
1090             GSEL(GCODE_SEL, SEL_KPL));
1091
1092         /*
1093          * Certain BIOS disables cpuid instruction of Cyrix 6x86MX CPU.
1094          * In this case, rdmsr generates general protection fault, and
1095          * exception will be trapped by bluetrap13().
1096          */
1097         setidt(IDT_GP, bluetrap13, SDT_SYS386TGT, SEL_KPL,
1098             GSEL(GCODE_SEL, SEL_KPL));
1099
1100         rdmsr(0x1002);          /* Cyrix CPU generates fault. */
1101
1102         if (trap_by_rdmsr == 0xa8c1d)
1103                 return IDENTBLUE_CYRIX486;
1104         else if (trap_by_rdmsr == 0xa89c4)
1105                 return IDENTBLUE_CYRIXM2;
1106         return IDENTBLUE_IBMCPU;
1107 }
1108
1109
1110 /*
1111  * identifycyrix() set lower 16 bits of cyrix_did as follows:
1112  *
1113  *  F E D C B A 9 8 7 6 5 4 3 2 1 0
1114  * +-------+-------+---------------+
1115  * |  SID  |  RID  |   Device ID   |
1116  * |    (DIR 1)    |    (DIR 0)    |
1117  * +-------+-------+---------------+
1118  */
1119 static void
1120 identifycyrix(void)
1121 {
1122         register_t saveintr;
1123         int     ccr2_test = 0, dir_test = 0;
1124         u_char  ccr2, ccr3;
1125
1126         saveintr = intr_disable();
1127
1128         ccr2 = read_cyrix_reg(CCR2);
1129         write_cyrix_reg(CCR2, ccr2 ^ CCR2_LOCK_NW);
1130         read_cyrix_reg(CCR2);
1131         if (read_cyrix_reg(CCR2) != ccr2)
1132                 ccr2_test = 1;
1133         write_cyrix_reg(CCR2, ccr2);
1134
1135         ccr3 = read_cyrix_reg(CCR3);
1136         write_cyrix_reg(CCR3, ccr3 ^ CCR3_MAPEN3);
1137         read_cyrix_reg(CCR3);
1138         if (read_cyrix_reg(CCR3) != ccr3)
1139                 dir_test = 1;                                   /* CPU supports DIRs. */
1140         write_cyrix_reg(CCR3, ccr3);
1141
1142         if (dir_test) {
1143                 /* Device ID registers are available. */
1144                 cyrix_did = read_cyrix_reg(DIR1) << 8;
1145                 cyrix_did += read_cyrix_reg(DIR0);
1146         } else if (ccr2_test)
1147                 cyrix_did = 0x0010;             /* 486S A-step */
1148         else
1149                 cyrix_did = 0x00ff;             /* Old 486SLC/DLC and TI486SXLC/SXL */
1150
1151         intr_restore(saveintr);
1152 }
1153 #endif
1154
1155 /* Update TSC freq with the value indicated by the caller. */
1156 static void
1157 tsc_freq_changed(void *arg __unused, const struct cf_level *level, int status)
1158 {
1159
1160         /* If there was an error during the transition, don't do anything. */
1161         if (status != 0)
1162                 return;
1163
1164         /* Total setting for this level gives the new frequency in MHz. */
1165         hw_clockrate = level->total_set.freq;
1166 }
1167
1168 static void
1169 hook_tsc_freq(void *arg __unused)
1170 {
1171
1172         if (tsc_is_invariant)
1173                 return;
1174
1175         tsc_post_tag = EVENTHANDLER_REGISTER(cpufreq_post_change,
1176             tsc_freq_changed, NULL, EVENTHANDLER_PRI_ANY);
1177 }
1178
1179 SYSINIT(hook_tsc_freq, SI_SUB_CONFIGURE, SI_ORDER_ANY, hook_tsc_freq, NULL);
1180
1181 /*
1182  * Final stage of CPU identification.
1183  */
1184 #ifdef __i386__
1185 void
1186 finishidentcpu(void)
1187 #else
1188 void
1189 identify_cpu(void)
1190 #endif
1191 {
1192         u_int regs[4], cpu_stdext_disable;
1193 #ifdef __i386__
1194         u_char ccr3;
1195 #endif
1196
1197 #ifdef __amd64__
1198         do_cpuid(0, regs);
1199         cpu_high = regs[0];
1200         ((u_int *)&cpu_vendor)[0] = regs[1];
1201         ((u_int *)&cpu_vendor)[1] = regs[3];
1202         ((u_int *)&cpu_vendor)[2] = regs[2];
1203         cpu_vendor[12] = '\0';
1204
1205         do_cpuid(1, regs);
1206         cpu_id = regs[0];
1207         cpu_procinfo = regs[1];
1208         cpu_feature = regs[3];
1209         cpu_feature2 = regs[2];
1210 #endif
1211
1212         cpu_vendor_id = find_cpu_vendor_id();
1213
1214         /*
1215          * Clear "Limit CPUID Maxval" bit and get the largest standard CPUID
1216          * function number again if it is set from BIOS.  It is necessary
1217          * for probing correct CPU topology later.
1218          * XXX This is only done on the BSP package.
1219          */
1220         if (cpu_vendor_id == CPU_VENDOR_INTEL && cpu_high > 0 && cpu_high < 4 &&
1221             ((CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x3) ||
1222             (CPUID_TO_FAMILY(cpu_id) == 0x6 && CPUID_TO_MODEL(cpu_id) >= 0xe))) {
1223                 uint64_t msr;
1224                 msr = rdmsr(MSR_IA32_MISC_ENABLE);
1225                 if ((msr & 0x400000ULL) != 0) {
1226                         wrmsr(MSR_IA32_MISC_ENABLE, msr & ~0x400000ULL);
1227                         do_cpuid(0, regs);
1228                         cpu_high = regs[0];
1229                 }
1230         }
1231
1232         if (cpu_high >= 5 && (cpu_feature2 & CPUID2_MON) != 0) {
1233                 do_cpuid(5, regs);
1234                 cpu_mon_mwait_flags = regs[2];
1235                 cpu_mon_min_size = regs[0] &  CPUID5_MON_MIN_SIZE;
1236                 cpu_mon_max_size = regs[1] &  CPUID5_MON_MAX_SIZE;
1237         }
1238
1239         if (cpu_high >= 7) {
1240                 cpuid_count(7, 0, regs);
1241                 cpu_stdext_feature = regs[1];
1242
1243                 /*
1244                  * Some hypervisors fail to filter out unsupported
1245                  * extended features.  For now, disable the
1246                  * extensions, activation of which requires setting a
1247                  * bit in CR4, and which VM monitors do not support.
1248                  */
1249                 if (cpu_feature2 & CPUID2_HV) {
1250                         cpu_stdext_disable = CPUID_STDEXT_FSGSBASE |
1251                             CPUID_STDEXT_SMEP;
1252                 } else
1253                         cpu_stdext_disable = 0;
1254                 TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable);
1255                 cpu_stdext_feature &= ~cpu_stdext_disable;
1256         }
1257
1258 #ifdef __i386__
1259         if (cpu_high > 0 &&
1260             (cpu_vendor_id == CPU_VENDOR_INTEL ||
1261              cpu_vendor_id == CPU_VENDOR_AMD ||
1262              cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
1263              cpu_vendor_id == CPU_VENDOR_CENTAUR ||
1264              cpu_vendor_id == CPU_VENDOR_NSC)) {
1265                 do_cpuid(0x80000000, regs);
1266                 if (regs[0] >= 0x80000000)
1267                         cpu_exthigh = regs[0];
1268         }
1269 #else
1270         if (cpu_vendor_id == CPU_VENDOR_INTEL ||
1271             cpu_vendor_id == CPU_VENDOR_AMD ||
1272             cpu_vendor_id == CPU_VENDOR_CENTAUR) {
1273                 do_cpuid(0x80000000, regs);
1274                 cpu_exthigh = regs[0];
1275         }
1276 #endif
1277         if (cpu_exthigh >= 0x80000001) {
1278                 do_cpuid(0x80000001, regs);
1279                 amd_feature = regs[3] & ~(cpu_feature & 0x0183f3ff);
1280                 amd_feature2 = regs[2];
1281         }
1282         if (cpu_exthigh >= 0x80000007) {
1283                 do_cpuid(0x80000007, regs);
1284                 amd_pminfo = regs[3];
1285         }
1286         if (cpu_exthigh >= 0x80000008) {
1287                 do_cpuid(0x80000008, regs);
1288                 cpu_procinfo2 = regs[2];
1289         }
1290
1291 #ifdef __i386__
1292         if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1293                 if (cpu == CPU_486) {
1294                         /*
1295                          * These conditions are equivalent to:
1296                          *     - CPU does not support cpuid instruction.
1297                          *     - Cyrix/IBM CPU is detected.
1298                          */
1299                         if (identblue() == IDENTBLUE_IBMCPU) {
1300                                 strcpy(cpu_vendor, "IBM");
1301                                 cpu_vendor_id = CPU_VENDOR_IBM;
1302                                 cpu = CPU_BLUE;
1303                                 return;
1304                         }
1305                 }
1306                 switch (cpu_id & 0xf00) {
1307                 case 0x600:
1308                         /*
1309                          * Cyrix's datasheet does not describe DIRs.
1310                          * Therefor, I assume it does not have them
1311                          * and use the result of the cpuid instruction.
1312                          * XXX they seem to have it for now at least. -Peter
1313                          */
1314                         identifycyrix();
1315                         cpu = CPU_M2;
1316                         break;
1317                 default:
1318                         identifycyrix();
1319                         /*
1320                          * This routine contains a trick.
1321                          * Don't check (cpu_id & 0x00f0) == 0x50 to detect M2, now.
1322                          */
1323                         switch (cyrix_did & 0x00f0) {
1324                         case 0x00:
1325                         case 0xf0:
1326                                 cpu = CPU_486DLC;
1327                                 break;
1328                         case 0x10:
1329                                 cpu = CPU_CY486DX;
1330                                 break;
1331                         case 0x20:
1332                                 if ((cyrix_did & 0x000f) < 8)
1333                                         cpu = CPU_M1;
1334                                 else
1335                                         cpu = CPU_M1SC;
1336                                 break;
1337                         case 0x30:
1338                                 cpu = CPU_M1;
1339                                 break;
1340                         case 0x40:
1341                                 /* MediaGX CPU */
1342                                 cpu = CPU_M1SC;
1343                                 break;
1344                         default:
1345                                 /* M2 and later CPUs are treated as M2. */
1346                                 cpu = CPU_M2;
1347
1348                                 /*
1349                                  * enable cpuid instruction.
1350                                  */
1351                                 ccr3 = read_cyrix_reg(CCR3);
1352                                 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1353                                 write_cyrix_reg(CCR4, read_cyrix_reg(CCR4) | CCR4_CPUID);
1354                                 write_cyrix_reg(CCR3, ccr3);
1355
1356                                 do_cpuid(0, regs);
1357                                 cpu_high = regs[0];     /* eax */
1358                                 do_cpuid(1, regs);
1359                                 cpu_id = regs[0];       /* eax */
1360                                 cpu_feature = regs[3];  /* edx */
1361                                 break;
1362                         }
1363                 }
1364         } else if (cpu == CPU_486 && *cpu_vendor == '\0') {
1365                 /*
1366                  * There are BlueLightning CPUs that do not change
1367                  * undefined flags by dividing 5 by 2.  In this case,
1368                  * the CPU identification routine in locore.s leaves
1369                  * cpu_vendor null string and puts CPU_486 into the
1370                  * cpu.
1371                  */
1372                 if (identblue() == IDENTBLUE_IBMCPU) {
1373                         strcpy(cpu_vendor, "IBM");
1374                         cpu_vendor_id = CPU_VENDOR_IBM;
1375                         cpu = CPU_BLUE;
1376                         return;
1377                 }
1378         }
1379 #else
1380         /* XXX */
1381         cpu = CPU_CLAWHAMMER;
1382 #endif
1383 }
1384
1385 static u_int
1386 find_cpu_vendor_id(void)
1387 {
1388         int     i;
1389
1390         for (i = 0; i < sizeof(cpu_vendors) / sizeof(cpu_vendors[0]); i++)
1391                 if (strcmp(cpu_vendor, cpu_vendors[i].vendor) == 0)
1392                         return (cpu_vendors[i].vendor_id);
1393         return (0);
1394 }
1395
1396 static void
1397 print_AMD_assoc(int i)
1398 {
1399         if (i == 255)
1400                 printf(", fully associative\n");
1401         else
1402                 printf(", %d-way associative\n", i);
1403 }
1404
1405 static void
1406 print_AMD_l2_assoc(int i)
1407 {
1408         switch (i & 0x0f) {
1409         case 0: printf(", disabled/not present\n"); break;
1410         case 1: printf(", direct mapped\n"); break;
1411         case 2: printf(", 2-way associative\n"); break;
1412         case 4: printf(", 4-way associative\n"); break;
1413         case 6: printf(", 8-way associative\n"); break;
1414         case 8: printf(", 16-way associative\n"); break;
1415         case 15: printf(", fully associative\n"); break;
1416         default: printf(", reserved configuration\n"); break;
1417         }
1418 }
1419
1420 static void
1421 print_AMD_info(void)
1422 {
1423 #ifdef __i386__
1424         uint64_t amd_whcr;
1425 #endif
1426         u_int regs[4];
1427
1428         if (cpu_exthigh >= 0x80000005) {
1429                 do_cpuid(0x80000005, regs);
1430                 printf("L1 2MB data TLB: %d entries", (regs[0] >> 16) & 0xff);
1431                 print_AMD_assoc(regs[0] >> 24);
1432
1433                 printf("L1 2MB instruction TLB: %d entries", regs[0] & 0xff);
1434                 print_AMD_assoc((regs[0] >> 8) & 0xff);
1435
1436                 printf("L1 4KB data TLB: %d entries", (regs[1] >> 16) & 0xff);
1437                 print_AMD_assoc(regs[1] >> 24);
1438
1439                 printf("L1 4KB instruction TLB: %d entries", regs[1] & 0xff);
1440                 print_AMD_assoc((regs[1] >> 8) & 0xff);
1441
1442                 printf("L1 data cache: %d kbytes", regs[2] >> 24);
1443                 printf(", %d bytes/line", regs[2] & 0xff);
1444                 printf(", %d lines/tag", (regs[2] >> 8) & 0xff);
1445                 print_AMD_assoc((regs[2] >> 16) & 0xff);
1446
1447                 printf("L1 instruction cache: %d kbytes", regs[3] >> 24);
1448                 printf(", %d bytes/line", regs[3] & 0xff);
1449                 printf(", %d lines/tag", (regs[3] >> 8) & 0xff);
1450                 print_AMD_assoc((regs[3] >> 16) & 0xff);
1451         }
1452
1453         if (cpu_exthigh >= 0x80000006) {
1454                 do_cpuid(0x80000006, regs);
1455                 if ((regs[0] >> 16) != 0) {
1456                         printf("L2 2MB data TLB: %d entries",
1457                             (regs[0] >> 16) & 0xfff);
1458                         print_AMD_l2_assoc(regs[0] >> 28);
1459                         printf("L2 2MB instruction TLB: %d entries",
1460                             regs[0] & 0xfff);
1461                         print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
1462                 } else {
1463                         printf("L2 2MB unified TLB: %d entries",
1464                             regs[0] & 0xfff);
1465                         print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
1466                 }
1467                 if ((regs[1] >> 16) != 0) {
1468                         printf("L2 4KB data TLB: %d entries",
1469                             (regs[1] >> 16) & 0xfff);
1470                         print_AMD_l2_assoc(regs[1] >> 28);
1471
1472                         printf("L2 4KB instruction TLB: %d entries",
1473                             (regs[1] >> 16) & 0xfff);
1474                         print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
1475                 } else {
1476                         printf("L2 4KB unified TLB: %d entries",
1477                             (regs[1] >> 16) & 0xfff);
1478                         print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
1479                 }
1480                 printf("L2 unified cache: %d kbytes", regs[2] >> 16);
1481                 printf(", %d bytes/line", regs[2] & 0xff);
1482                 printf(", %d lines/tag", (regs[2] >> 8) & 0x0f);
1483                 print_AMD_l2_assoc((regs[2] >> 12) & 0x0f);
1484         }
1485
1486 #ifdef __i386__
1487         if (((cpu_id & 0xf00) == 0x500)
1488             && (((cpu_id & 0x0f0) > 0x80)
1489                 || (((cpu_id & 0x0f0) == 0x80)
1490                     && (cpu_id & 0x00f) > 0x07))) {
1491                 /* K6-2(new core [Stepping 8-F]), K6-III or later */
1492                 amd_whcr = rdmsr(0xc0000082);
1493                 if (!(amd_whcr & (0x3ff << 22))) {
1494                         printf("Write Allocate Disable\n");
1495                 } else {
1496                         printf("Write Allocate Enable Limit: %dM bytes\n",
1497                             (u_int32_t)((amd_whcr & (0x3ff << 22)) >> 22) * 4);
1498                         printf("Write Allocate 15-16M bytes: %s\n",
1499                             (amd_whcr & (1 << 16)) ? "Enable" : "Disable");
1500                 }
1501         } else if (((cpu_id & 0xf00) == 0x500)
1502                    && ((cpu_id & 0x0f0) > 0x50)) {
1503                 /* K6, K6-2(old core) */
1504                 amd_whcr = rdmsr(0xc0000082);
1505                 if (!(amd_whcr & (0x7f << 1))) {
1506                         printf("Write Allocate Disable\n");
1507                 } else {
1508                         printf("Write Allocate Enable Limit: %dM bytes\n",
1509                             (u_int32_t)((amd_whcr & (0x7f << 1)) >> 1) * 4);
1510                         printf("Write Allocate 15-16M bytes: %s\n",
1511                             (amd_whcr & 0x0001) ? "Enable" : "Disable");
1512                         printf("Hardware Write Allocate Control: %s\n",
1513                             (amd_whcr & 0x0100) ? "Enable" : "Disable");
1514                 }
1515         }
1516 #endif
1517         /*
1518          * Opteron Rev E shows a bug as in very rare occasions a read memory
1519          * barrier is not performed as expected if it is followed by a
1520          * non-atomic read-modify-write instruction.
1521          * As long as that bug pops up very rarely (intensive machine usage
1522          * on other operating systems generally generates one unexplainable
1523          * crash any 2 months) and as long as a model specific fix would be
1524          * impratical at this stage, print out a warning string if the broken
1525          * model and family are identified.
1526          */
1527         if (CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x20 &&
1528             CPUID_TO_MODEL(cpu_id) <= 0x3f)
1529                 printf("WARNING: This architecture revision has known SMP "
1530                     "hardware bugs which may cause random instability\n");
1531 }
1532
1533 static void
1534 print_INTEL_info(void)
1535 {
1536         u_int regs[4];
1537         u_int rounds, regnum;
1538         u_int nwaycode, nway;
1539
1540         if (cpu_high >= 2) {
1541                 rounds = 0;
1542                 do {
1543                         do_cpuid(0x2, regs);
1544                         if (rounds == 0 && (rounds = (regs[0] & 0xff)) == 0)
1545                                 break;  /* we have a buggy CPU */
1546
1547                         for (regnum = 0; regnum <= 3; ++regnum) {
1548                                 if (regs[regnum] & (1<<31))
1549                                         continue;
1550                                 if (regnum != 0)
1551                                         print_INTEL_TLB(regs[regnum] & 0xff);
1552                                 print_INTEL_TLB((regs[regnum] >> 8) & 0xff);
1553                                 print_INTEL_TLB((regs[regnum] >> 16) & 0xff);
1554                                 print_INTEL_TLB((regs[regnum] >> 24) & 0xff);
1555                         }
1556                 } while (--rounds > 0);
1557         }
1558
1559         if (cpu_exthigh >= 0x80000006) {
1560                 do_cpuid(0x80000006, regs);
1561                 nwaycode = (regs[2] >> 12) & 0x0f;
1562                 if (nwaycode >= 0x02 && nwaycode <= 0x08)
1563                         nway = 1 << (nwaycode / 2);
1564                 else
1565                         nway = 0;
1566                 printf("L2 cache: %u kbytes, %u-way associative, %u bytes/line\n",
1567                     (regs[2] >> 16) & 0xffff, nway, regs[2] & 0xff);
1568         }
1569 }
1570
1571 static void
1572 print_INTEL_TLB(u_int data)
1573 {
1574         switch (data) {
1575         case 0x0:
1576         case 0x40:
1577         default:
1578                 break;
1579         case 0x1:
1580                 printf("Instruction TLB: 4 KB pages, 4-way set associative, 32 entries\n");
1581                 break;
1582         case 0x2:
1583                 printf("Instruction TLB: 4 MB pages, fully associative, 2 entries\n");
1584                 break;
1585         case 0x3:
1586                 printf("Data TLB: 4 KB pages, 4-way set associative, 64 entries\n");
1587                 break;
1588         case 0x4:
1589                 printf("Data TLB: 4 MB Pages, 4-way set associative, 8 entries\n");
1590                 break;
1591         case 0x6:
1592                 printf("1st-level instruction cache: 8 KB, 4-way set associative, 32 byte line size\n");
1593                 break;
1594         case 0x8:
1595                 printf("1st-level instruction cache: 16 KB, 4-way set associative, 32 byte line size\n");
1596                 break;
1597         case 0xa:
1598                 printf("1st-level data cache: 8 KB, 2-way set associative, 32 byte line size\n");
1599                 break;
1600         case 0xc:
1601                 printf("1st-level data cache: 16 KB, 4-way set associative, 32 byte line size\n");
1602                 break;
1603         case 0x22:
1604                 printf("3rd-level cache: 512 KB, 4-way set associative, sectored cache, 64 byte line size\n");
1605                 break;
1606         case 0x23:
1607                 printf("3rd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
1608                 break;
1609         case 0x25:
1610                 printf("3rd-level cache: 2 MB, 8-way set associative, sectored cache, 64 byte line size\n");
1611                 break;
1612         case 0x29:
1613                 printf("3rd-level cache: 4 MB, 8-way set associative, sectored cache, 64 byte line size\n");
1614                 break;
1615         case 0x2c:
1616                 printf("1st-level data cache: 32 KB, 8-way set associative, 64 byte line size\n");
1617                 break;
1618         case 0x30:
1619                 printf("1st-level instruction cache: 32 KB, 8-way set associative, 64 byte line size\n");
1620                 break;
1621         case 0x39:
1622                 printf("2nd-level cache: 128 KB, 4-way set associative, sectored cache, 64 byte line size\n");
1623                 break;
1624         case 0x3b:
1625                 printf("2nd-level cache: 128 KB, 2-way set associative, sectored cache, 64 byte line size\n");
1626                 break;
1627         case 0x3c:
1628                 printf("2nd-level cache: 256 KB, 4-way set associative, sectored cache, 64 byte line size\n");
1629                 break;
1630         case 0x41:
1631                 printf("2nd-level cache: 128 KB, 4-way set associative, 32 byte line size\n");
1632                 break;
1633         case 0x42:
1634                 printf("2nd-level cache: 256 KB, 4-way set associative, 32 byte line size\n");
1635                 break;
1636         case 0x43:
1637                 printf("2nd-level cache: 512 KB, 4-way set associative, 32 byte line size\n");
1638                 break;
1639         case 0x44:
1640                 printf("2nd-level cache: 1 MB, 4-way set associative, 32 byte line size\n");
1641                 break;
1642         case 0x45:
1643                 printf("2nd-level cache: 2 MB, 4-way set associative, 32 byte line size\n");
1644                 break;
1645         case 0x46:
1646                 printf("3rd-level cache: 4 MB, 4-way set associative, 64 byte line size\n");
1647                 break;
1648         case 0x47:
1649                 printf("3rd-level cache: 8 MB, 8-way set associative, 64 byte line size\n");
1650                 break;
1651         case 0x50:
1652                 printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 64 entries\n");
1653                 break;
1654         case 0x51:
1655                 printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 128 entries\n");
1656                 break;
1657         case 0x52:
1658                 printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 256 entries\n");
1659                 break;
1660         case 0x5b:
1661                 printf("Data TLB: 4 KB or 4 MB pages, fully associative, 64 entries\n");
1662                 break;
1663         case 0x5c:
1664                 printf("Data TLB: 4 KB or 4 MB pages, fully associative, 128 entries\n");
1665                 break;
1666         case 0x5d:
1667                 printf("Data TLB: 4 KB or 4 MB pages, fully associative, 256 entries\n");
1668                 break;
1669         case 0x60:
1670                 printf("1st-level data cache: 16 KB, 8-way set associative, sectored cache, 64 byte line size\n");
1671                 break;
1672         case 0x66:
1673                 printf("1st-level data cache: 8 KB, 4-way set associative, sectored cache, 64 byte line size\n");
1674                 break;
1675         case 0x67:
1676                 printf("1st-level data cache: 16 KB, 4-way set associative, sectored cache, 64 byte line size\n");
1677                 break;
1678         case 0x68:
1679                 printf("1st-level data cache: 32 KB, 4 way set associative, sectored cache, 64 byte line size\n");
1680                 break;
1681         case 0x70:
1682                 printf("Trace cache: 12K-uops, 8-way set associative\n");
1683                 break;
1684         case 0x71:
1685                 printf("Trace cache: 16K-uops, 8-way set associative\n");
1686                 break;
1687         case 0x72:
1688                 printf("Trace cache: 32K-uops, 8-way set associative\n");
1689                 break;
1690         case 0x78:
1691                 printf("2nd-level cache: 1 MB, 4-way set associative, 64-byte line size\n");
1692                 break;
1693         case 0x79:
1694                 printf("2nd-level cache: 128 KB, 8-way set associative, sectored cache, 64 byte line size\n");
1695                 break;
1696         case 0x7a:
1697                 printf("2nd-level cache: 256 KB, 8-way set associative, sectored cache, 64 byte line size\n");
1698                 break;
1699         case 0x7b:
1700                 printf("2nd-level cache: 512 KB, 8-way set associative, sectored cache, 64 byte line size\n");
1701                 break;
1702         case 0x7c:
1703                 printf("2nd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
1704                 break;
1705         case 0x7d:
1706                 printf("2nd-level cache: 2-MB, 8-way set associative, 64-byte line size\n");
1707                 break;
1708         case 0x7f:
1709                 printf("2nd-level cache: 512-KB, 2-way set associative, 64-byte line size\n");
1710                 break;
1711         case 0x82:
1712                 printf("2nd-level cache: 256 KB, 8-way set associative, 32 byte line size\n");
1713                 break;
1714         case 0x83:
1715                 printf("2nd-level cache: 512 KB, 8-way set associative, 32 byte line size\n");
1716                 break;
1717         case 0x84:
1718                 printf("2nd-level cache: 1 MB, 8-way set associative, 32 byte line size\n");
1719                 break;
1720         case 0x85:
1721                 printf("2nd-level cache: 2 MB, 8-way set associative, 32 byte line size\n");
1722                 break;
1723         case 0x86:
1724                 printf("2nd-level cache: 512 KB, 4-way set associative, 64 byte line size\n");
1725                 break;
1726         case 0x87:
1727                 printf("2nd-level cache: 1 MB, 8-way set associative, 64 byte line size\n");
1728                 break;
1729         case 0xb0:
1730                 printf("Instruction TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
1731                 break;
1732         case 0xb3:
1733                 printf("Data TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
1734                 break;
1735         }
1736 }
1737
1738 #ifdef __i386__
1739 static void
1740 print_transmeta_info(void)
1741 {
1742         u_int regs[4], nreg = 0;
1743
1744         do_cpuid(0x80860000, regs);
1745         nreg = regs[0];
1746         if (nreg >= 0x80860001) {
1747                 do_cpuid(0x80860001, regs);
1748                 printf("  Processor revision %u.%u.%u.%u\n",
1749                        (regs[1] >> 24) & 0xff,
1750                        (regs[1] >> 16) & 0xff,
1751                        (regs[1] >> 8) & 0xff,
1752                        regs[1] & 0xff);
1753         }
1754         if (nreg >= 0x80860002) {
1755                 do_cpuid(0x80860002, regs);
1756                 printf("  Code Morphing Software revision %u.%u.%u-%u-%u\n",
1757                        (regs[1] >> 24) & 0xff,
1758                        (regs[1] >> 16) & 0xff,
1759                        (regs[1] >> 8) & 0xff,
1760                        regs[1] & 0xff,
1761                        regs[2]);
1762         }
1763         if (nreg >= 0x80860006) {
1764                 char info[65];
1765                 do_cpuid(0x80860003, (u_int*) &info[0]);
1766                 do_cpuid(0x80860004, (u_int*) &info[16]);
1767                 do_cpuid(0x80860005, (u_int*) &info[32]);
1768                 do_cpuid(0x80860006, (u_int*) &info[48]);
1769                 info[64] = 0;
1770                 printf("  %s\n", info);
1771         }
1772 }
1773 #endif
1774
1775 static void
1776 print_via_padlock_info(void)
1777 {
1778         u_int regs[4];
1779
1780         do_cpuid(0xc0000001, regs);
1781         printf("\n  VIA Padlock Features=0x%b", regs[3],
1782         "\020"
1783         "\003RNG"               /* RNG */
1784         "\007AES"               /* ACE */
1785         "\011AES-CTR"           /* ACE2 */
1786         "\013SHA1,SHA256"       /* PHE */
1787         "\015RSA"               /* PMM */
1788         );
1789 }
1790
1791 static uint32_t
1792 vmx_settable(uint64_t basic, int msr, int true_msr)
1793 {
1794         uint64_t val;
1795
1796         if (basic & (1ULL << 55))
1797                 val = rdmsr(true_msr);
1798         else
1799                 val = rdmsr(msr);
1800
1801         /* Just report the controls that can be set to 1. */
1802         return (val >> 32);
1803 }
1804
1805 static void
1806 print_vmx_info(void)
1807 {
1808         uint64_t basic, msr;
1809         uint32_t entry, exit, mask, pin, proc, proc2;
1810         int comma;
1811
1812         printf("\n  VT-x: ");
1813         msr = rdmsr(MSR_IA32_FEATURE_CONTROL);
1814         if (!(msr & IA32_FEATURE_CONTROL_VMX_EN))
1815                 printf("(disabled in BIOS) ");
1816         basic = rdmsr(MSR_VMX_BASIC);
1817         pin = vmx_settable(basic, MSR_VMX_PINBASED_CTLS,
1818             MSR_VMX_TRUE_PINBASED_CTLS);
1819         proc = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS,
1820             MSR_VMX_TRUE_PROCBASED_CTLS);
1821         if (proc & PROCBASED_SECONDARY_CONTROLS)
1822                 proc2 = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS2,
1823                     MSR_VMX_PROCBASED_CTLS2);
1824         else
1825                 proc2 = 0;
1826         exit = vmx_settable(basic, MSR_VMX_EXIT_CTLS, MSR_VMX_TRUE_EXIT_CTLS);
1827         entry = vmx_settable(basic, MSR_VMX_ENTRY_CTLS, MSR_VMX_TRUE_ENTRY_CTLS);
1828
1829         if (!bootverbose) {
1830                 comma = 0;
1831                 if (exit & VM_EXIT_SAVE_PAT && exit & VM_EXIT_LOAD_PAT &&
1832                     entry & VM_ENTRY_LOAD_PAT) {
1833                         printf("%sPAT", comma ? "," : "");
1834                         comma = 1;
1835                 }
1836                 if (proc & PROCBASED_HLT_EXITING) {
1837                         printf("%sHLT", comma ? "," : "");
1838                         comma = 1;
1839                 }
1840                 if (proc & PROCBASED_MTF) {
1841                         printf("%sMTF", comma ? "," : "");
1842                         comma = 1;
1843                 }
1844                 if (proc & PROCBASED_PAUSE_EXITING) {
1845                         printf("%sPAUSE", comma ? "," : "");
1846                         comma = 1;
1847                 }
1848                 if (proc2 & PROCBASED2_ENABLE_EPT) {
1849                         printf("%sEPT", comma ? "," : "");
1850                         comma = 1;
1851                 }
1852                 if (proc2 & PROCBASED2_UNRESTRICTED_GUEST) {
1853                         printf("%sUG", comma ? "," : "");
1854                         comma = 1;
1855                 }
1856                 if (proc2 & PROCBASED2_ENABLE_VPID) {
1857                         printf("%sVPID", comma ? "," : "");
1858                         comma = 1;
1859                 }
1860                 if (proc & PROCBASED_USE_TPR_SHADOW &&
1861                     proc2 & PROCBASED2_VIRTUALIZE_APIC_ACCESSES &&
1862                     proc2 & PROCBASED2_VIRTUALIZE_X2APIC_MODE &&
1863                     proc2 & PROCBASED2_APIC_REGISTER_VIRTUALIZATION &&
1864                     proc2 & PROCBASED2_VIRTUAL_INTERRUPT_DELIVERY) {
1865                         printf("%sVID", comma ? "," : "");
1866                         comma = 1;
1867                         if (pin & PINBASED_POSTED_INTERRUPT)
1868                                 printf(",PostIntr");
1869                 }
1870                 return;
1871         }
1872
1873         mask = basic >> 32;
1874         printf("Basic Features=0x%b", mask,
1875         "\020"
1876         "\02132PA"              /* 32-bit physical addresses */
1877         "\022SMM"               /* SMM dual-monitor */
1878         "\027INS/OUTS"          /* VM-exit info for INS and OUTS */
1879         "\030TRUE"              /* TRUE_CTLS MSRs */
1880         );
1881         printf("\n        Pin-Based Controls=0x%b", pin,
1882         "\020"
1883         "\001ExtINT"            /* External-interrupt exiting */
1884         "\004NMI"               /* NMI exiting */
1885         "\006VNMI"              /* Virtual NMIs */
1886         "\007PreTmr"            /* Activate VMX-preemption timer */
1887         "\010PostIntr"          /* Process posted interrupts */
1888         );
1889         printf("\n        Primary Processor Controls=0x%b", proc,
1890         "\020"
1891         "\003INTWIN"            /* Interrupt-window exiting */
1892         "\004TSCOff"            /* Use TSC offsetting */
1893         "\010HLT"               /* HLT exiting */
1894         "\012INVLPG"            /* INVLPG exiting */
1895         "\013MWAIT"             /* MWAIT exiting */
1896         "\014RDPMC"             /* RDPMC exiting */
1897         "\015RDTSC"             /* RDTSC exiting */
1898         "\020CR3-LD"            /* CR3-load exiting */
1899         "\021CR3-ST"            /* CR3-store exiting */
1900         "\024CR8-LD"            /* CR8-load exiting */
1901         "\025CR8-ST"            /* CR8-store exiting */
1902         "\026TPR"               /* Use TPR shadow */
1903         "\027NMIWIN"            /* NMI-window exiting */
1904         "\030MOV-DR"            /* MOV-DR exiting */
1905         "\031IO"                /* Unconditional I/O exiting */
1906         "\032IOmap"             /* Use I/O bitmaps */
1907         "\034MTF"               /* Monitor trap flag */
1908         "\035MSRmap"            /* Use MSR bitmaps */
1909         "\036MONITOR"           /* MONITOR exiting */
1910         "\037PAUSE"             /* PAUSE exiting */
1911         );
1912         if (proc & PROCBASED_SECONDARY_CONTROLS)
1913                 printf("\n        Secondary Processor Controls=0x%b", proc2,
1914                 "\020"
1915                 "\001APIC"              /* Virtualize APIC accesses */
1916                 "\002EPT"               /* Enable EPT */
1917                 "\003DT"                /* Descriptor-table exiting */
1918                 "\004RDTSCP"            /* Enable RDTSCP */
1919                 "\005x2APIC"            /* Virtualize x2APIC mode */
1920                 "\006VPID"              /* Enable VPID */
1921                 "\007WBINVD"            /* WBINVD exiting */
1922                 "\010UG"                /* Unrestricted guest */
1923                 "\011APIC-reg"          /* APIC-register virtualization */
1924                 "\012VID"               /* Virtual-interrupt delivery */
1925                 "\013PAUSE-loop"        /* PAUSE-loop exiting */
1926                 "\014RDRAND"            /* RDRAND exiting */
1927                 "\015INVPCID"           /* Enable INVPCID */
1928                 "\016VMFUNC"            /* Enable VM functions */
1929                 "\017VMCS"              /* VMCS shadowing */
1930                 "\020EPT#VE"            /* EPT-violation #VE */
1931                 "\021XSAVES"            /* Enable XSAVES/XRSTORS */
1932                 );
1933         printf("\n        Exit Controls=0x%b", mask,
1934         "\020"
1935         "\003DR"                /* Save debug controls */
1936                                 /* Ignore Host address-space size */
1937         "\015PERF"              /* Load MSR_PERF_GLOBAL_CTRL */
1938         "\020AckInt"            /* Acknowledge interrupt on exit */
1939         "\023PAT-SV"            /* Save MSR_PAT */
1940         "\024PAT-LD"            /* Load MSR_PAT */
1941         "\025EFER-SV"           /* Save MSR_EFER */
1942         "\026EFER-LD"           /* Load MSR_EFER */
1943         "\027PTMR-SV"           /* Save VMX-preemption timer value */
1944         );
1945         printf("\n        Entry Controls=0x%b", mask,
1946         "\020"
1947         "\003DR"                /* Save debug controls */
1948                                 /* Ignore IA-32e mode guest */
1949                                 /* Ignore Entry to SMM */
1950                                 /* Ignore Deactivate dual-monitor treatment */
1951         "\016PERF"              /* Load MSR_PERF_GLOBAL_CTRL */
1952         "\017PAT"               /* Load MSR_PAT */
1953         "\020EFER"              /* Load MSR_EFER */
1954         );
1955         if (proc & PROCBASED_SECONDARY_CONTROLS &&
1956             (proc2 & (PROCBASED2_ENABLE_EPT | PROCBASED2_ENABLE_VPID)) != 0) {
1957                 msr = rdmsr(MSR_VMX_EPT_VPID_CAP);
1958                 mask = msr;
1959                 printf("\n        EPT Features=0x%b", mask,
1960                 "\020"
1961                 "\001XO"                /* Execute-only translations */
1962                 "\007PW4"               /* Page-walk length of 4 */
1963                 "\011UC"                /* EPT paging-structure mem can be UC */
1964                 "\017WB"                /* EPT paging-structure mem can be WB */
1965                 "\0212M"                /* EPT PDE can map a 2-Mbyte page */
1966                 "\0221G"                /* EPT PDPTE can map a 1-Gbyte page */
1967                 "\025INVEPT"            /* INVEPT is supported */
1968                 "\026AD"                /* Accessed and dirty flags for EPT */
1969                 "\032single"            /* INVEPT single-context type */
1970                 "\033all"               /* INVEPT all-context type */
1971                 );
1972                 mask = msr >> 32;
1973                 printf("\n        VPID Features=0x%b", mask,
1974                 "\020"
1975                 "\001INVVPID"           /* INVVPID is supported */
1976                 "\011individual"        /* INVVPID individual-address type */
1977                 "\012single"            /* INVVPID single-context type */
1978                 "\013all"               /* INVVPID all-context type */
1979                  /* INVVPID single-context-retaining-globals type */
1980                 "\014single-globals"
1981                 );
1982         }
1983 }