kernel/x86_64: inline x86_{read, write}_msr()

This patch makes it possible to inline rdmsr and wrmsr instruction. The
performance impact shouldn't be significant since they are used relatively
rarely and wrmsr is usually a serializing instruction, but there is no reason
not to do so.
This commit is contained in:
Pawel Dziepak 2014-05-06 21:41:49 +02:00
parent 88e8e24c84
commit 76636769bd
3 changed files with 20 additions and 24 deletions

View File

@ -9,6 +9,22 @@
#include <arch_thread_types.h>
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)
{

View File

@ -461,8 +461,6 @@ void x86_fxrstor(const void* fpuState);
void x86_noop_swap(void* oldFpuState, const void* newFpuState);
void x86_fxsave_swap(void* oldFpuState, const void* newFpuState);
addr_t x86_get_stack_frame();
uint64 x86_read_msr(uint32 registerNumber);
void x86_write_msr(uint32 registerNumber, uint64 value);
uint32 x86_count_mtrrs(void);
void x86_set_mtrr(uint32 index, uint64 base, uint64 length, uint8 type);
status_t x86_get_mtrr(uint32 index, uint64* _base, uint64* _length,
@ -481,6 +479,10 @@ void x86_hardware_interrupt(iframe* frame);
void x86_page_fault_exception(iframe* iframe);
#ifndef __x86_64__
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);

View File

@ -55,28 +55,6 @@ FUNCTION(x86_get_stack_frame):
FUNCTION_END(x86_get_stack_frame)
/* uint64 x86_read_msr(uint32 register); */
FUNCTION(x86_read_msr):
mov %edi, %ecx
rdmsr
shl $32, %rdx
mov %eax, %eax
or %rdx, %rax
ret
FUNCTION_END(x86_read_msr)
/* void x86_write_msr(uint32 register, uint64 value); */
FUNCTION(x86_write_msr):
mov %rsi, %rdx
mov %esi, %eax
mov %edi, %ecx
shr $32, %rdx
wrmsr
ret
FUNCTION_END(x86_write_msr)
/* void x86_64_thread_entry(); */
FUNCTION(x86_64_thread_entry):
xorq %rbp, %rbp