diff --git a/hermit/arch/x86/include/asm/processor.h b/hermit/arch/x86/include/asm/processor.h index b347402d5..5b21f28c8 100644 --- a/hermit/arch/x86/include/asm/processor.h +++ b/hermit/arch/x86/include/asm/processor.h @@ -56,6 +56,7 @@ extern "C" { #define CPU_FEATURE_PGE (1 << 13) #define CPU_FEATURE_PAT (1 << 16) #define CPU_FEATURE_PSE36 (1 << 17) +#define CPU_FEATURE_CLFLUSH (1 << 19) #define CPU_FEATURE_MMX (1 << 23) #define CPU_FEATURE_FXSR (1 << 24) #define CPU_FEATURE_SSE (1 << 25) @@ -310,6 +311,10 @@ inline static uint32_t has_fxsr(void) { return (cpu_info.feature1 & CPU_FEATURE_FXSR); } +inline static uint32_t has_clflush(void) { + return (cpu_info.feature1 & CPU_FEATURE_CLFLUSH); +} + inline static uint32_t has_sse(void) { return (cpu_info.feature1 & CPU_FEATURE_SSE); } @@ -681,6 +686,21 @@ inline static void invalid_cache(void) { asm volatile ("invd"); } +static inline void monitor(const void *eax, unsigned long ecx, unsigned long edx) +{ + asm volatile("monitor" :: "a" (eax), "c" (ecx), "d"(edx)); +} + +static inline void mwait(unsigned long eax, unsigned long ecx) +{ + asm volatile("mwait" :: "a" (eax), "c" (ecx)); +} + +static inline void clflush(volatile void *addr) +{ + asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); +} + #if 0 // the old way to serialize the store and load operations static inline void mb(void) { asm volatile ("lock; addl $0,0(%%esp)" ::: "memory", "cc"); } diff --git a/hermit/arch/x86/kernel/processor.c b/hermit/arch/x86/kernel/processor.c index 772e27f75..050bc9841 100644 --- a/hermit/arch/x86/kernel/processor.c +++ b/hermit/arch/x86/kernel/processor.c @@ -552,7 +552,7 @@ int cpu_detection(void) { a = b = c = d = 0; cpuid(1, &a, &b, &cpu_info.feature2, &cpu_info.feature1); - kprintf("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + kprintf("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", has_sse() ? "SSE " : "", has_sse2() ? "SSE2 " : "", has_sse3() ? "SSE3 " : "", @@ -571,6 +571,7 @@ int cpu_detection(void) { has_rdtscp() ? "RDTSCP " : "", has_fsgsbase() ? "FSGSBASE " : "", has_mwait() ? "MWAIT " : "", + has_clflush() ? "CLFLUSH " : "", has_bmi1() ? "BMI1 " : "", has_bmi2() ? "BMI2 " : "", has_dca() ? "DCA " : "",