1 CPUID(7D) Devices CPUID(7D)
2
3
4
5 NAME
6 cpuid - CPU identification driver
7
8 SYNOPSIS
9 /dev/cpu/self/cpuid
10
11
12 DESCRIPTION
13 SPARC and x86 system
14 This device provides implementation-private information via ioctls
15 about various aspects of the implementation to Solaris libraries and
16 utilities.
17
18 x86 systems only
19 This device also provides a file-like view of the namespace and return
20 values of the x86 cpuid instruction. The cpuid instruction takes a
21 single 32-bit integer function code, and returns four 32-bit integer
22 values corresponding to the input value that describe various aspects
23 of the capabilities and configuration of the processor.
24
25 The API for the character device consists of using the seek offset to
26 set the function code value, and using a read(2) or pread(2) of 16
27 bytes to fetch the four 32-bit return values of the instruction in the
28 order %eax, %ebx, %ecx and %edx.
29
30 No data can be written to the device. Like the cpuid instruction, no
31 special privileges are required to use the device.
32
33 The device is useful to enable low-level configuration information to
34 be extracted from the CPU without having to write any assembler code to
35 invoke the cpuid instruction directly. It also allows the kernel to
36 attempt to correct any erroneous data returned by the instruction
37 (prompted by occasional errors in the information exported by various
38 processor implementations over the years).
39
40 See the processor manufacturers documentation for further information
41 about the syntax and semantics of the wide variety of information
42 available from this instruction.
43
44 Some systems can be configured to limit the cpuid opcodes which are
45 accessible. While illumos handles this condition, other software may
46 malfunction when such limits are enabled. Those settings are typically
47 manipulated in the BIOS.
48
49 EXAMPLE
50 This example allows you to determine if the current x86 processor
51 supports "long mode," which is a necessary (but not sufficient)
52 condition for running the 64-bit Solaris kernel on the processor.
53
54 /*
55
56 #include <sys/types.h>
57 #include <sys/stat.h>
58 #include <fcntl.h>
59 #include <unistd.h>
60 #include <string.h>
61 #include <errno.h>
62 #include <stdio.h>
63
64 static const char devname[] = "/dev/cpu/self/cpuid";
65
66 /*ARGSUSED*/
67 int
68 main(int argc, char *argv[])
69 {
70 struct {
71 uint32_t r_eax, r_ebx, r_ecx, r_edx;
72 } _r, *rp = &_r;
73 int d;
74 char *s;
75
76 if ((d = open(devname, O_RDONLY)) == -1) {
77 perror(devname);
78 return (1);
79 }
80
81 if (pread(d, rp, sizeof (*rp), 0) != sizeof (*rp)) {
82 perror(devname);
83 goto fail;
84 }
85
86 s = (char *)&rp->r_ebx;
87 if (strncmp(s, "Auth" "cAMD" "enti", 12) != 0 &&
88 strncmp(s, "Genu" "ntel" "ineI", 12) != 0)
89 goto fail;
90
91 if (pread(d, rp, sizeof (*rp), 0x80000001) == sizeof (*rp)) {
92 /*
93 * Read extended feature word; check bit 29
94 */
95 (void) close(d);
96 if ((rp->r_edx >> 29) & 1) {
97 (void) printf("processor supports long mode\n");
98 return (0);
99 }
100 }
101 fail:
102 (void) close(d);
103 return (1);
104 }
105
106
107 ERRORS
108 ENXIO
109 Results from attempting to read data from the device on a
110 system that does not support the CPU identification
111 interfaces
112
113
114 EINVAL
115 Results from reading from an offset larger than UINT_MAX, or
116 attempting to read with a size that is not multiple of 16
117 bytes.
118
119
120 FILES
121 /dev/cpu/self/cpuid
122 Provides access to CPU identification data.
123
124
125 ATTRIBUTES
126 See attributes(5) for descriptions of the following attributes:
127
128
129
130
131 +--------------------+-----------------+
132 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
133 +--------------------+-----------------+
134 |Interface Stability | Evolving |
135 +--------------------+-----------------+
136
137 SEE ALSO
138 psrinfo(1M), prtconf(1M), pread(2), read(2), attributes(5)
139
140
141
142 April 9, 2016 CPUID(7D)