2003-04-16 05:03:45 +02: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-28 21:50:07 +02:00
|
|
|
"=b" (*b),
|
|
|
|
"=c" (*c),
|
|
|
|
"=d" (*d)
|
2003-04-16 05:03:45 +02:00
|
|
|
: "a" (in));
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
2003-04-16 05:03:45 +02:00
|
|
|
extern inline bool
|
2013-04-23 11:44:36 +02:00
|
|
|
can_set_flag (register unsigned long flag)
|
2003-04-16 05:03:45 +02:00
|
|
|
{
|
2013-04-23 11:44:36 +02: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 05:03:45 +02: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 11:44:36 +02:00
|
|
|
#endif
|
2003-04-16 05:03:45 +02:00
|
|
|
|
|
|
|
#endif // !CPUID_H
|