6 #include <klibc/compiler.h>
8 static inline uint64_t rdtsc(void)
11 asm volatile("rdtsc" : "=A" (v
));
15 static inline uint32_t rdtscl(void)
18 asm volatile("rdtsc" : "=a" (v
) : : "edx");
22 static inline void cpuid_count(uint32_t op
, uint32_t cnt
,
23 uint32_t * eax
, uint32_t * ebx
,
24 uint32_t * ecx
, uint32_t * edx
)
26 asm volatile("movl %%ebx,%1 ; "
29 : "=a" (*eax
), "=SD" (*ebx
), "=c" (*ecx
), "=d" (*edx
)
33 static inline void cpuid(uint32_t op
, uint32_t * eax
, uint32_t * ebx
,
34 uint32_t * ecx
, uint32_t * edx
)
36 cpuid_count(op
, 0, eax
, ebx
, ecx
, edx
);
39 static inline __constfunc
uint32_t cpuid_eax(uint32_t level
)
43 asm volatile("pushl %%ebx ; "
52 static inline __constfunc
uint32_t cpuid_ebx(uint32_t level
)
56 asm volatile("movl %%ebx,%0 ; "
59 : "=SD" (v
), "+a" (level
)
64 static inline __constfunc
uint32_t cpuid_ecx(uint32_t level
)
68 asm volatile("pushl %%ebx ; "
71 : "=c" (v
), "+a" (level
)
76 static inline __constfunc
uint32_t cpuid_edx(uint32_t level
)
80 asm volatile("pushl %%ebx ; "
83 : "=d" (v
), "+a" (level
)
88 /* Standard macro to see if a specific flag is changeable */
89 static inline __constfunc
bool cpu_has_eflag(uint32_t flag
)
103 : "=&r" (f0
), "=&r" (f1
)
106 return !!((f0
^f1
) & flag
);
109 static inline uint64_t rdmsr(uint32_t msr
)
113 asm volatile("rdmsr" : "=A" (v
) : "c"(msr
));
117 static inline void wrmsr(uint64_t v
, uint32_t msr
)
119 asm volatile("wrmsr" : : "A" (v
), "c" (msr
));
122 static inline void cpu_relax(void)
124 asm volatile("rep ; nop");
127 static inline void hlt(void)
132 static inline void cli(void)
137 static inline void sti(void)