This source file includes following definitions.
- cpuid
- cpuprobe
- dump_cpuinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <machine/psl.h>
20 #include <machine/specialreg.h>
21
22 #include "libsa.h"
23
24 int amd64_supported;
25 static int cpu_family, cpu_model, cpu_stepping;
26 static int psl_check;
27 static u_int32_t feature_ecx, feature_edx, feature_amd;
28 static char cpu_brandstr[48];
29 static char cpu_vendor[13];
30
31
32
33
34
35 u_int32_t
36 cpuid(u_int32_t eax, u_int32_t *regs)
37 {
38 __asm __volatile(
39 "cpuid\n\t"
40 "movl %%eax, 0(%2)\n\t"
41 "movl %%ebx, 4(%2)\n\t"
42 "movl %%ecx, 8(%2)\n\t"
43 "movl %%edx, 12(%2)\n\t"
44 : "=a" (eax)
45 : "0" (eax), "S" (regs)
46 : "bx", "cx", "dx");
47
48 return eax;
49 }
50
51 void
52 cpuprobe(void)
53 {
54 u_int32_t cpuid_max, extended_max;
55 u_int32_t regs[4];
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 __asm __volatile(
75 "pushfl\n\t"
76 "popl %2\n\t"
77 "xorl %2, %0\n\t"
78 "pushl %0\n\t"
79 "popfl\n\t"
80 "pushfl\n\t"
81 "popl %0\n\t"
82 "xorl %2, %0\n\t"
83 : "=r" (psl_check)
84 : "0" (PSL_ID), "r" (0)
85 : "cc");
86
87 if (psl_check == PSL_ID) {
88 cpuid_max = cpuid(0, regs);
89
90 bcopy(®s[1], cpu_vendor, sizeof(regs[1]));
91 bcopy(®s[3], cpu_vendor + 4, sizeof(regs[3]));
92 bcopy(®s[2], cpu_vendor + 8, sizeof(regs[2]));
93 cpu_vendor[sizeof(cpu_vendor) - 1] = '\0';
94
95 if (cpuid_max >= 1) {
96 u_int32_t id;
97
98 id = cpuid(1, regs);
99 cpu_stepping = id & 0x000000f;
100 cpu_model = (id >> 4) & 0x0000000f;
101 cpu_family = (id >> 8) & 0x0000000f;
102
103 feature_ecx = regs[2];
104 feature_edx = regs[3];
105 }
106
107 extended_max = cpuid(0x80000000, regs);
108
109 if (extended_max >= 0x80000001) {
110 cpuid(0x80000001, regs);
111 feature_amd = regs[3];
112 if (feature_amd & CPUID_LONG)
113 amd64_supported = 1;
114 }
115
116 cpu_brandstr[0] = '\0';
117 if (extended_max >= 0x80000004) {
118 u_int32_t brand_ints[12];
119
120 cpuid(0x80000002, brand_ints);
121 cpuid(0x80000003, brand_ints + 4);
122 cpuid(0x80000004, brand_ints + 8);
123
124 bcopy(brand_ints, cpu_brandstr,
125 sizeof(cpu_brandstr) - 1);
126
127 cpu_brandstr[sizeof(cpu_brandstr) - 1] = '\0';
128 }
129 }
130
131 printf("%s", amd64_supported ? " amd64" : " i386");
132 }
133
134 void
135 dump_cpuinfo(void)
136 {
137 printf("\"%s\", family %d, model %d, step %d\n",
138 cpu_vendor, cpu_family, cpu_model, cpu_stepping);
139
140 if (*cpu_brandstr)
141 printf("%s\n", cpu_brandstr);
142
143 printf("features: ecx 0x%x, edx 0x%x, amd 0x%x\n",
144 feature_ecx, feature_edx, feature_amd);
145
146 printf("psl_check: 0x%x\n", psl_check);
147 }