File: cpu_info_by_asm.c

package info (click to toggle)
opus 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,860 kB
  • sloc: ansic: 592,652; sh: 4,541; asm: 723; makefile: 457; perl: 264; python: 77
file content (31 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
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
#include <stdio.h>
int main() {
    unsigned int CPUInfo0;
    unsigned int CPUInfo1;
    unsigned int CPUInfo2;
    unsigned int CPUInfo3;
    unsigned int InfoType;
#if defined(__i386__) && defined(__PIC__)
/* %ebx is PIC register in 32-bit, so mustn't clobber it. */
    __asm__ __volatile__ (
        "xchg %%ebx, %1\n"
        "cpuid\n"
        "xchg %%ebx, %1\n":
        "=a" (CPUInfo0),
        "=r" (CPUInfo1),
        "=c" (CPUInfo2),
        "=d" (CPUInfo3) :
        "0" (InfoType), "2" (0)
    );
#else
    __asm__ __volatile__ (
        "cpuid":
        "=a" (CPUInfo0),
        "=b" (CPUInfo1),
        "=c" (CPUInfo2),
        "=d" (CPUInfo3) :
        "0" (InfoType), "2" (0)
    );
#endif
    return 0;
}