summaryrefslogtreecommitdiff
path: root/havecpuid.c
blob: 4cdce1978bf0804ddb86637075c17903558ad12e (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
30
31
32
/*
 *  (C) 2001 Dave Jones.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 */

#include <stdio.h>
#include "x86info.h"

static int flag_is_changeable_p(unsigned long flag)
{
	unsigned long f1, f2;
	__asm__ volatile("pushf\n\t"
			"pushf\n\t"
			"pop %0\n\t"
			"mov %0,%1\n\t"
			"xor %2,%0\n\t"
			"push %0\n\t"
			"popf\n\t"
			"pushf\n\t"
			"pop %0\n\t"
			"popf\n\t"
			: "=&r" (f1), "=&r" (f2)
			: "ir" (flag));
	return ((f1^f2) & flag) != 0;
}

int HaveCPUID(void)
{
	return flag_is_changeable_p(0x200000);
}