From 801a0ee83d5d3997732345a9bb2a268d9f19accb Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Wed, 19 Feb 2025 18:37:12 +0300 Subject: [PATCH] kernel: Change x86_*_msr to be an inline function on 32-bit platform Change-Id: Ida5ff96cda06ca4463f15b636f1275977f3ec0ac Reviewed-on: https://review.haiku-os.org/c/haiku/+/9015 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- headers/private/kernel/arch/x86/64/cpu.h | 16 ---------------- headers/private/kernel/arch/x86/arch_cpu.h | 3 --- headers/private/kernel/arch/x86/arch_cpuasm.h | 14 ++++++++++++++ src/system/kernel/arch/x86/32/arch.S | 16 ---------------- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/headers/private/kernel/arch/x86/64/cpu.h b/headers/private/kernel/arch/x86/64/cpu.h index d69ebcae39..33358c60f8 100644 --- a/headers/private/kernel/arch/x86/64/cpu.h +++ b/headers/private/kernel/arch/x86/64/cpu.h @@ -13,22 +13,6 @@ extern uint16 gFPUControlDefault; extern uint32 gFPUMXCSRDefault; -static inline uint64_t -x86_read_msr(uint32_t msr) -{ - uint64_t high, low; - asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); - return (high << 32) | low; -} - - -static inline void -x86_write_msr(uint32_t msr, uint64_t value) -{ - asm volatile("wrmsr" : : "a" (value) , "d" (value >> 32), "c" (msr)); -} - - static inline void x86_context_switch(arch_thread* oldState, arch_thread* newState) { diff --git a/headers/private/kernel/arch/x86/arch_cpu.h b/headers/private/kernel/arch/x86/arch_cpu.h index 4d53112981..9c6c3ae424 100644 --- a/headers/private/kernel/arch/x86/arch_cpu.h +++ b/headers/private/kernel/arch/x86/arch_cpu.h @@ -697,9 +697,6 @@ void x86_page_fault_exception(iframe* iframe); void x86_swap_pgdir(addr_t newPageDir); -uint64 x86_read_msr(uint32 registerNumber); -void x86_write_msr(uint32 registerNumber, uint64 value); - void x86_context_switch(struct arch_thread* oldState, struct arch_thread* newState); diff --git a/headers/private/kernel/arch/x86/arch_cpuasm.h b/headers/private/kernel/arch/x86/arch_cpuasm.h index 7b5579f4da..e2dd6f7919 100644 --- a/headers/private/kernel/arch/x86/arch_cpuasm.h +++ b/headers/private/kernel/arch/x86/arch_cpuasm.h @@ -13,6 +13,20 @@ #define nop() __asm__ ("nop"::) +static inline uint64_t +x86_read_msr(uint32_t msr) +{ + uint32_t high, low; + asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); + return (((uint64_t) high) << 32) | low; +} + +static inline void +x86_write_msr(uint32_t msr, uint64_t value) +{ + asm volatile("wrmsr" : : "a" ((uint32_t)value) , "d" ((uint32_t)(value >> 32)), "c" (msr)); +} + #define x86_read_cr0() ({ \ size_t _v; \ __asm__("mov %%cr0,%0" : "=r" (_v)); \ diff --git a/src/system/kernel/arch/x86/32/arch.S b/src/system/kernel/arch/x86/32/arch.S index d796fa6e91..fb6393f617 100644 --- a/src/system/kernel/arch/x86/32/arch.S +++ b/src/system/kernel/arch/x86/32/arch.S @@ -77,22 +77,6 @@ FUNCTION(x86_get_stack_frame): ret FUNCTION_END(x86_get_stack_frame) -/* uint64 x86_read_msr(uint32 register); */ -FUNCTION(x86_read_msr): - movl 4(%esp), %ecx - rdmsr - ret -FUNCTION_END(x86_read_msr) - -/* void x86_write_msr(uint32 register, uint64 value); */ -FUNCTION(x86_write_msr): - movl 4(%esp), %ecx - movl 8(%esp), %eax - movl 12(%esp), %edx - wrmsr - ret -FUNCTION_END(x86_write_msr) - /* void x86_context_switch(struct arch_thread* oldState, struct arch_thread* newState); */ FUNCTION(x86_context_switch):