-
Notifications
You must be signed in to change notification settings - Fork 20
/
cpuid-solaris.c
82 lines (72 loc) · 1.77 KB
/
cpuid-solaris.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Licensed under the terms of the GNU GPL License version 2.
*
* Solaris routines for retrieving cpuid registers.
* Originally submitted by John Levon <[email protected]>
*/
#ifdef __sun__
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <x86info.h>
void bind_cpu(int cpunr)
{
//FIXME
}
void cpuid(unsigned int CPU_number, unsigned long long idx,
unsigned int *eax,
unsigned int *ebx,
unsigned int *ecx,
unsigned int *edx)
{
static int nodriver = 0;
char cpuname[20];
unsigned char buffer[CPUID_CHUNK_SIZE];
unsigned int *ptr = (unsigned int *)buffer;
int fh;
if (eax != NULL) {
*eax = (unsigned int) idx;
if (*eax == 4)
*ecx = idx >> 32;
}
if (nodriver == 1) {
if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx))
printf("%s", NATIVE_CPUID_FAILED_MSG);
return;
}
memset(cpuname, 0, sizeof(cpuname));
/* Solaris doesn't (yet) have per-CPU interface */
(void)snprintf(cpuname, sizeof(cpuname), "/dev/cpu/self/cpuid");
fh = open(cpuname, O_RDONLY);
if (fh != -1) {
if (lseek64(fh, (off64_t)idx, SEEK_CUR) < 0) {
printf("cpuid seek error: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (read(fh, &buffer[0], CPUID_CHUNK_SIZE) == -1) {
perror(cpuname);
exit(EXIT_FAILURE);
}
if (eax!=0) *eax = *ptr;
if (ebx!=0) *ebx = *(++ptr);
if (ecx!=0) *ecx = *(++ptr);
if (edx!=0) *edx = *(++ptr);
if (close(fh) == -1) {
perror("close");
exit(EXIT_FAILURE);
}
} else {
/* Something went wrong, just do UP and hope for the best. */
nodriver = 1;
if (native_cpuid(CPU_number, idx, eax,ebx,ecx,edx))
printf("%s", NATIVE_CPUID_FAILED_MSG);
return;
}
}
#endif /* __sun__ */