#ifndef I386_BITS_CPU_H
#define I386_BITS_CPU_H
#define CPU_FEATURE_P(CAP, FEATURE) \
(!!(CAP[(X86_FEATURE_##FEATURE)/32] & ((X86_FEATURE_##FEATURE) & 0x1f)))
#define NCAPINTS 4
#define X86_FEATURE_FPU (0*32+ 0)
#define X86_FEATURE_VME (0*32+ 1)
#define X86_FEATURE_DE (0*32+ 2)
#define X86_FEATURE_PSE (0*32+ 3)
#define X86_FEATURE_TSC (0*32+ 4)
#define X86_FEATURE_MSR (0*32+ 5)
#define X86_FEATURE_PAE (0*32+ 6)
#define X86_FEATURE_MCE (0*32+ 7)
#define X86_FEATURE_CX8 (0*32+ 8)
#define X86_FEATURE_APIC (0*32+ 9)
#define X86_FEATURE_SEP (0*32+11)
#define X86_FEATURE_MTRR (0*32+12)
#define X86_FEATURE_PGE (0*32+13)
#define X86_FEATURE_MCA (0*32+14)
#define X86_FEATURE_CMOV (0*32+15)
#define X86_FEATURE_PAT (0*32+16)
#define X86_FEATURE_PSE36 (0*32+17)
#define X86_FEATURE_PN (0*32+18)
#define X86_FEATURE_CLFLSH (0*32+19)
#define X86_FEATURE_DTES (0*32+21)
#define X86_FEATURE_ACPI (0*32+22)
#define X86_FEATURE_MMX (0*32+23)
#define X86_FEATURE_FXSR (0*32+24)
#define X86_FEATURE_XMM (0*32+25)
#define X86_FEATURE_XMM2 (0*32+26)
#define X86_FEATURE_SELFSNOOP (0*32+27)
#define X86_FEATURE_HT (0*32+28)
#define X86_FEATURE_ACC (0*32+29)
#define X86_FEATURE_IA64 (0*32+30)
#define X86_FEATURE_SYSCALL (1*32+11)
#define X86_FEATURE_MMXEXT (1*32+22)
#define X86_FEATURE_LM (1*32+29)
#define X86_FEATURE_3DNOWEXT (1*32+30)
#define X86_FEATURE_3DNOW (1*32+31)
#define X86_FEATURE_RECOVERY (2*32+ 0)
#define X86_FEATURE_LONGRUN (2*32+ 1)
#define X86_FEATURE_LRTI (2*32+ 3)
#define X86_FEATURE_CXMMX (3*32+ 0)
#define X86_FEATURE_K6_MTRR (3*32+ 1)
#define X86_FEATURE_CYRIX_ARR (3*32+ 2)
#define X86_FEATURE_CENTAUR_MCR (3*32+ 3)
#define MAX_X86_VENDOR_ID 16
struct cpuinfo_x86 {
uint8_t x86;
uint8_t x86_model;
uint8_t x86_mask;
int cpuid_level;
unsigned x86_capability[NCAPINTS];
char x86_vendor_id[MAX_X86_VENDOR_ID];
};
#define X86_VENDOR_INTEL 0
#define X86_VENDOR_CYRIX 1
#define X86_VENDOR_AMD 2
#define X86_VENDOR_UMC 3
#define X86_VENDOR_NEXGEN 4
#define X86_VENDOR_CENTAUR 5
#define X86_VENDOR_RISE 6
#define X86_VENDOR_TRANSMETA 7
#define X86_VENDOR_NSC 8
#define X86_VENDOR_UNKNOWN 0xff
#define X86_EFLAGS_CF 0x00000001
#define X86_EFLAGS_PF 0x00000004
#define X86_EFLAGS_AF 0x00000010
#define X86_EFLAGS_ZF 0x00000040
#define X86_EFLAGS_SF 0x00000080
#define X86_EFLAGS_TF 0x00000100
#define X86_EFLAGS_IF 0x00000200
#define X86_EFLAGS_DF 0x00000400
#define X86_EFLAGS_OF 0x00000800
#define X86_EFLAGS_IOPL 0x00003000
#define X86_EFLAGS_NT 0x00004000
#define X86_EFLAGS_RF 0x00010000
#define X86_EFLAGS_VM 0x00020000
#define X86_EFLAGS_AC 0x00040000
#define X86_EFLAGS_VIF 0x00080000
#define X86_EFLAGS_VIP 0x00100000
#define X86_EFLAGS_ID 0x00200000
static inline void cpuid(int op,
unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
{
__asm__("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (op));
}
static inline unsigned int cpuid_eax(unsigned int op)
{
unsigned int eax;
__asm__("cpuid"
: "=a" (eax)
: "0" (op)
: "bx", "cx", "dx");
return eax;
}
static inline unsigned int cpuid_ebx(unsigned int op)
{
unsigned int eax, ebx;
__asm__("cpuid"
: "=a" (eax), "=b" (ebx)
: "0" (op)
: "cx", "dx" );
return ebx;
}
static inline unsigned int cpuid_ecx(unsigned int op)
{
unsigned int eax, ecx;
__asm__("cpuid"
: "=a" (eax), "=c" (ecx)
: "0" (op)
: "bx", "dx" );
return ecx;
}
static inline unsigned int cpuid_edx(unsigned int op)
{
unsigned int eax, edx;
__asm__("cpuid"
: "=a" (eax), "=d" (edx)
: "0" (op)
: "bx", "cx");
return edx;
}
#define X86_CR4_VME 0x0001
#define X86_CR4_PVI 0x0002
#define X86_CR4_TSD 0x0004
#define X86_CR4_DE 0x0008
#define X86_CR4_PSE 0x0010
#define X86_CR4_PAE 0x0020
#define X86_CR4_MCE 0x0040
#define X86_CR4_PGE 0x0080
#define X86_CR4_PCE 0x0100
#define X86_CR4_OSFXSR 0x0200
#define X86_CR4_OSXMMEXCPT 0x0400
#define MSR_K6_EFER 0xC0000080
#define _EFER_SCE 0
#define _EFER_LME 8
#define _EFER_LMA 10
#define _EFER_NX 11
#define EFER_SCE (1<<_EFER_SCE)
#define EFER_LME (1<<EFER_LME)
#define EFER_LMA (1<<EFER_LMA)
#define EFER_NX (1<<_EFER_NX)
#define rdmsr(msr,val1,val2) \
__asm__ __volatile__("rdmsr" \
: "=a" (val1), "=d" (val2) \
: "c" (msr))
#define wrmsr(msr,val1,val2) \
__asm__ __volatile__("wrmsr" \
: \
: "c" (msr), "a" (val1), "d" (val2))
#define read_cr0() ({ \
unsigned int __dummy; \
__asm__( \
"movl %%cr0, %0\n\t" \
:"=r" (__dummy)); \
__dummy; \
})
#define write_cr0(x) \
__asm__("movl %0,%%cr0": :"r" (x));
#define read_cr3() ({ \
unsigned int __dummy; \
__asm__( \
"movl %%cr3, %0\n\t" \
:"=r" (__dummy)); \
__dummy; \
})
#define write_cr3x(x) \
__asm__("movl %0,%%cr3": :"r" (x));
#define read_cr4() ({ \
unsigned int __dummy; \
__asm__( \
"movl %%cr4, %0\n\t" \
:"=r" (__dummy)); \
__dummy; \
})
#define write_cr4x(x) \
__asm__("movl %0,%%cr4": :"r" (x));
extern struct cpuinfo_x86 cpu_info;
#ifdef CONFIG_X86_64
extern void cpu_setup(void);
#else
#define cpu_setup() do {} while(0)
#endif
#endif