From babc6f3e064d1e90f4ce3cd4d5becde31433a25e Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 17 Jul 2026 18:06:03 -0300 Subject: [PATCH] cpu: cpu_cache_line_size --- kernel-src/arch/x86-64/cpu.c | 15 +++++++++++++++ kernel-src/include/x86-64/arch/cpu.h | 1 + 2 files changed, 16 insertions(+) diff --git a/kernel-src/arch/x86-64/cpu.c b/kernel-src/arch/x86-64/cpu.c index 814aabb5..d8f84f07 100644 --- a/kernel-src/arch/x86-64/cpu.c +++ b/kernel-src/arch/x86-64/cpu.c @@ -18,6 +18,21 @@ static bool has_smap; static bool has_smap_detected; static bool has_smep; +static size_t cache_line_size; + +size_t cpu_cache_line_size(void) { + size_t size = cache_line_size; + if (size) + return size; + + uint32_t eax, ebx, ecx, edx; + __assert(__get_cpuid(1, &eax, &ebx, &ecx, &edx)); + size = ((ebx >> 8) & 0xff) * 8; + __assert(size); + + cache_line_size = size; + return size; +} void arch_syscall_entry(); static void illisr(isr_t *self, context_t *ctx) { diff --git a/kernel-src/include/x86-64/arch/cpu.h b/kernel-src/include/x86-64/arch/cpu.h index e02162b5..d24d77b3 100644 --- a/kernel-src/include/x86-64/arch/cpu.h +++ b/kernel-src/include/x86-64/arch/cpu.h @@ -114,6 +114,7 @@ static inline uint16_t be_to_cpu_w(uint16_t w) { } cpu_t *get_bsp(void); +size_t cpu_cache_line_size(void); void arch_cpu_user_access_begin(void); void arch_cpu_user_access_end(void); bool arch_cpu_smep_enabled(void);