Module Name: src Committed By: maxv Date: Sat Sep 7 18:33:16 UTC 2019
Modified Files: src/sys/arch/amd64/amd64: cpufunc.S src/sys/arch/i386/i386: cpufunc.S src/sys/arch/x86/include: cpufunc.h Log Message: Convert rdmsr_locked and wrmsr_locked to inlines. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sys/arch/amd64/amd64/cpufunc.S cvs rdiff -u -r1.34 -r1.35 src/sys/arch/i386/i386/cpufunc.S cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/include/cpufunc.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/cpufunc.S diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.43 src/sys/arch/amd64/amd64/cpufunc.S:1.44 --- src/sys/arch/amd64/amd64/cpufunc.S:1.43 Fri Jul 5 17:08:55 2019 +++ src/sys/arch/amd64/amd64/cpufunc.S Sat Sep 7 18:33:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.S,v 1.43 2019/07/05 17:08:55 maxv Exp $ */ +/* $NetBSD: cpufunc.S,v 1.44 2019/09/07 18:33:16 maxv Exp $ */ /* * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. @@ -167,26 +167,6 @@ END(x86_write_flags) STRONG_ALIAS(x86_write_psl,x86_write_flags) #endif /* XENPV */ -ENTRY(rdmsr_locked) - movq %rdi, %rcx - xorq %rax, %rax - movl $OPTERON_MSR_PASSCODE, %edi - rdmsr - shlq $32, %rdx - orq %rdx, %rax - ret -END(rdmsr_locked) - -ENTRY(wrmsr_locked) - movq %rdi, %rcx - movq %rsi, %rax - movq %rsi, %rdx - shrq $32, %rdx - movl $OPTERON_MSR_PASSCODE, %edi - wrmsr - ret -END(wrmsr_locked) - /* * Support for reading MSRs in the safe manner (returns EFAULT on fault) */ Index: src/sys/arch/i386/i386/cpufunc.S diff -u src/sys/arch/i386/i386/cpufunc.S:1.34 src/sys/arch/i386/i386/cpufunc.S:1.35 --- src/sys/arch/i386/i386/cpufunc.S:1.34 Fri Jul 5 17:08:55 2019 +++ src/sys/arch/i386/i386/cpufunc.S Sat Sep 7 18:33:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.S,v 1.34 2019/07/05 17:08:55 maxv Exp $ */ +/* $NetBSD: cpufunc.S,v 1.35 2019/09/07 18:33:16 maxv Exp $ */ /*- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include <sys/errno.h> #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.34 2019/07/05 17:08:55 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.35 2019/09/07 18:33:16 maxv Exp $"); #include "opt_xen.h" @@ -91,26 +91,6 @@ STRONG_ALIAS(x86_write_psl,x86_write_fla STRONG_ALIAS(x86_read_psl,x86_read_flags) #endif /* XENPV */ -ENTRY(rdmsr_locked) - movl 4(%esp), %ecx - pushl %edi - movl $OPTERON_MSR_PASSCODE, %edi - rdmsr - popl %edi - ret -END(rdmsr_locked) - -ENTRY(wrmsr_locked) - movl 4(%esp), %ecx - movl 8(%esp), %eax - movl 12(%esp), %edx - pushl %edi - movl $OPTERON_MSR_PASSCODE, %edi - wrmsr - popl %edi - ret -END(wrmsr_locked) - /* * Support for reading MSRs in the safe manner (returns EFAULT on fault) */ Index: src/sys/arch/x86/include/cpufunc.h diff -u src/sys/arch/x86/include/cpufunc.h:1.35 src/sys/arch/x86/include/cpufunc.h:1.36 --- src/sys/arch/x86/include/cpufunc.h:1.35 Sat Sep 7 11:09:03 2019 +++ src/sys/arch/x86/include/cpufunc.h Sat Sep 7 18:33:16 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.h,v 1.35 2019/09/07 11:09:03 maxv Exp $ */ +/* $NetBSD: cpufunc.h,v 1.36 2019/09/07 18:33:16 maxv Exp $ */ /* * Copyright (c) 1998, 2007, 2019 The NetBSD Foundation, Inc. @@ -419,8 +419,21 @@ rdmsr(u_int msr) return (low | ((uint64_t)high << 32)); } -uint64_t rdmsr_locked(u_int); -int rdmsr_safe(u_int, uint64_t *); +static inline uint64_t +rdmsr_locked(u_int msr) +{ + uint32_t low, high, pass = OPTERON_MSR_PASSCODE; + + __asm volatile ( + "rdmsr" + : "=a" (low), "=d" (high) + : "c" (msr), "D" (pass) + ); + + return (low | ((uint64_t)high << 32)); +} + +int rdmsr_safe(u_int, uint64_t *); static inline void wrmsr(u_int msr, uint64_t val) @@ -437,7 +450,20 @@ wrmsr(u_int msr, uint64_t val) ); } -void wrmsr_locked(u_int, uint64_t); +static inline void +wrmsr_locked(u_int msr, uint64_t val) +{ + uint32_t low, high, pass = OPTERON_MSR_PASSCODE; + + low = val; + high = val >> 32; + __asm volatile ( + "wrmsr" + : + : "a" (low), "d" (high), "c" (msr), "D" (pass) + : "memory" + ); +} #endif /* _KERNEL */