2003-04-16 11:03:45 +08:00
|
|
|
#ifndef CPUID_H
|
|
|
|
#define CPUID_H
|
|
|
|
|
|
|
|
extern inline void
|
|
|
|
cpuid (unsigned *a, unsigned *b, unsigned *c, unsigned *d, unsigned in)
|
|
|
|
{
|
|
|
|
asm ("cpuid"
|
|
|
|
: "=a" (*a),
|
2004-05-29 03:50:07 +08:00
|
|
|
"=b" (*b),
|
|
|
|
"=c" (*c),
|
|
|
|
"=d" (*d)
|
2003-04-16 11:03:45 +08:00
|
|
|
: "a" (in));
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
2003-04-16 11:03:45 +08:00
|
|
|
extern inline bool
|
2013-04-23 17:44:36 +08:00
|
|
|
can_set_flag (register unsigned long flag)
|
2003-04-16 11:03:45 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
register unsigned long r1, r2;
|
|
|
|
asm("pushfq\n"
|
|
|
|
"popq %0\n"
|
|
|
|
"movq %0, %1\n"
|
|
|
|
"xorq %2, %0\n"
|
|
|
|
"pushq %0\n"
|
|
|
|
"popfq\n"
|
|
|
|
"pushfq\n"
|
|
|
|
"popq %0\n"
|
|
|
|
"pushq %1\n"
|
|
|
|
"popfq\n"
|
|
|
|
: "=&r" (r1), "=&r" (r2)
|
|
|
|
: "ir" (flag)
|
|
|
|
);
|
|
|
|
return ((r1 ^ r2) & flag) != 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
extern inline bool
|
|
|
|
can_set_flag (register unsigned flag)
|
|
|
|
{
|
|
|
|
register unsigned r1, r2;
|
2003-04-16 11:03:45 +08:00
|
|
|
asm("pushfl\n"
|
|
|
|
"popl %0\n"
|
|
|
|
"movl %0, %1\n"
|
|
|
|
"xorl %2, %0\n"
|
|
|
|
"pushl %0\n"
|
|
|
|
"popfl\n"
|
|
|
|
"pushfl\n"
|
|
|
|
"popl %0\n"
|
|
|
|
"pushl %1\n"
|
|
|
|
"popfl\n"
|
|
|
|
: "=&r" (r1), "=&r" (r2)
|
|
|
|
: "ir" (flag)
|
|
|
|
);
|
|
|
|
return ((r1 ^ r2) & flag) != 0;
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2003-04-16 11:03:45 +08:00
|
|
|
|
|
|
|
#endif // !CPUID_H
|