From 50bf5cc0bca1b0cb9dbaf461a41b80725baabba1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 11 Mar 2024 12:51:40 -0400 Subject: kernel/amd64: Add control register r/w helpers Signed-off-by: Ian Moffett --- sys/include/arch/amd64/cpu.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'sys/include') diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h index e2ed851..1968569 100644 --- a/sys/include/arch/amd64/cpu.h +++ b/sys/include/arch/amd64/cpu.h @@ -110,6 +110,34 @@ amd64_read_gs_base(void) return rdmsr(IA32_KERNEL_GS_BASE); } +static inline uint64_t +amd64_read_cr0(void) +{ + uint64_t cr0; + __ASMV("mov %%cr0, %0" : "=r" (cr0) :: "memory"); + return cr0; +} + +static inline void +amd64_write_cr0(uint64_t val) +{ + __ASMV("mov %0, %%cr0" :: "r" (val) : "memory"); +} + +static inline uint64_t +amd64_read_cr4(void) +{ + uint64_t cr4; + __ASMV("mov %%cr4, %0" : "=r" (cr4) :: "memory"); + return cr4; +} + +static inline void +amd64_write_cr4(uint64_t val) +{ + __ASMV("mov %0, %%cr4" :: "r" (val) : "memory"); +} + struct cpu_info *amd64_this_cpu(void); #endif /* !_AMD64_CPU_H_ */ -- cgit v1.2.3