blob: aa092c00c50fc4c7036c96b3c8df7f877a7071cc (
plain)
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
|
#define MAX_CPUS 32 /* (8*sizeof(long)) */
int apic2kernel[MAX_CPUS];
int cpu_number_start = 0, cpu_number_counter = 0;
int cpu_number(void) {
int eax = 1, ebx = 0, ecx = 0, edx = 0;
unsigned int i = 0;
int apic_id = 0;
if (!cpu_number_start) {
for (i = 0; i < MAX_CPUS; i++) {
apic2kernel[i] = -1;
}
cpu_number_start = 1;
}
asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (eax));
apic_id = (char) (ebx >> 24) & 0xff;
if (apic2kernel[apic_id] != -1) {
return apic2kernel[apic_id];
} else {
apic2kernel[apic_id] = cpu_number_counter;
cpu_number_counter++;
}
return apic2kernel[apic_id];
}
|