From bc29dd7f73bb21c91b19d48ff9291099ffb134f9 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Thu, 5 Nov 2020 13:03:36 +0900 Subject: [PATCH] kernel/arch: Clean up cpu_get_capabilities() implementation Reverse the order of the dwords returned so that the most important features are in the lower dword and add macros that can be used to test for feature support on the executing processor. --- kernel/arch/cpu32.S | 23 ++++++++++++----------- kernel/include/arch.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/kernel/arch/cpu32.S b/kernel/arch/cpu32.S index e98f45f..63eb5a3 100644 --- a/kernel/arch/cpu32.S +++ b/kernel/arch/cpu32.S @@ -35,26 +35,27 @@ boot_id: .global cpu_get_id cpu_get_id: - movl $APIC_ID_ADDR, %esi - movl (%esi), %eax - shrl $24, %eax - ret + movl $APIC_ID_ADDR, %esi + movl (%esi), %eax + shrl $24, %eax + ret .global cpu_get_capabilities cpu_get_capabilities: pushl %ebx - movl $1, %eax - cpuid - movl %ecx, %eax + movl $1, %eax + cpuid + movl %edx, %eax + movl %ecx, %edx popl %ebx - ret + ret .global cpu_timestamp cpu_timestamp: - lfence - rdtsc - ret + lfence + rdtsc + ret .global cpu_set_pstate diff --git a/kernel/include/arch.h b/kernel/include/arch.h index 9f828a7..a13ffc1 100644 --- a/kernel/include/arch.h +++ b/kernel/include/arch.h @@ -183,6 +183,39 @@ struct region { typedef struct pagedir pg_dir_t; +#define CPU_CAPABILITY_FPU (1 << 0) +#define CPU_CAPABILITY_VME (1 << 1) +#define CPU_CAPABILITY_DE (1 << 2) +#define CPU_CAPABILITY_PSE (1 << 3) +#define CPU_CAPABILITY_TSC (1 << 4) +#define CPU_CAPABILITY_MSR (1 << 5) +#define CPU_CAPABILITY_PAE (1 << 6) +#define CPU_CAPABILITY_MCE (1 << 7) +#define CPU_CAPABILITY_CX8 (1 << 8) +#define CPU_CAPABILITY_APIC (1 << 9) + +#define CPU_CAPABILITY_SEP (1 << 11) +#define CPU_CAPABILITY_MTRR (1 << 12) +#define CPU_CAPABILITY_PGE (1 << 13) +#define CPU_CAPABILITY_MCA (1 << 14) +#define CPU_CAPABILITY_CMOV (1 << 15) +#define CPU_CAPABILITY_PAT (1 << 16) +#define CPU_CAPABILITY_PSE36 (1 << 17) +#define CPU_CAPABILITY_PSN (1 << 18) +#define CPU_CAPABILITY_CLFSH (1 << 19) + +#define CPU_CAPABILITY_DS (1 << 21) +#define CPU_CAPABILITY_ACPI (1 << 22) +#define CPU_CAPABILITY_MMX (1 << 23) +#define CPU_CAPABILITY_FXSR (1 << 24) +#define CPU_CAPABILITY_SSE (1 << 25) +#define CPU_CAPABILITY_SSE2 (1 << 26) +#define CPU_CAPABILITY_SS (1 << 27) +#define CPU_CAPABILITY_HTT (1 << 28) +#define CPU_CAPABILITY_TM (1 << 29) + +#define CPU_CAPABILITY_PBE (1 << 31) + int cpu_get_id(void); u64_t cpu_get_capabilities(void); u64_t cpu_timestamp(void); -- 2.47.3