RDMSR(9) (x86)

RDMSR(9) | Kernel Developer's Manual (x86) | RDMSR(9)

# NAME

msr, rdmsr, rdmsr_safe, wrmsr — functions for x86 MSRs

# SYNOPSIS

#include <x86/cpufunc.h>
uint64_t
rdmsr(u_int msr);
int
rdmsr_safe(u_int msr, uint64_t *valp);
void
wrmsr(u_int msr, uint64_t val);

# DESCRIPTION

The `RDMSR` instruction reads from a x86 model-specific register (`MSR`). Conversely, the `WRMSR` instruction is used to write to a `MSR`. In NetBSD the rdmsr(), rdmsr_safe(), and wrmsr() functions are used to access `MSRs`. The header <x86/specialreg.h> includes definitions for some of the commonly used MSRs, that is, control registers that are present in some x86 processor models but unavailable in others.

# FUNCTIONS

rdmsr(msr)
  Returns the value read from msr.
rdmsr_safe(msr, valp)
  The rdmsr_safe() function is a safer variant of rdmsr(). Upon successful completion, the function returns zero and the value read from the register msr is returned in valp. If a fault occurs while accessing msr, rdmsr_safe() returns `EFAULT`.
wrmsr(msr, val)
  The wrmsr() function writes val to the register msr.

Note that even though rdmsr_safe() provides support for reading `MSRs` in a safe manner, it is still a good practice to always verify that the given model-specific register is present by using the `CPUID` instruction, available in NetBSD via x86_cpuid().

# SEE ALSO

rdtsc(9), x86/x86_msr_xcall(9)

February 17, 2017 | NetBSD 8.3