xref: /netbsd-src/share/man/man9/man9.x86/rdmsr.9 (revision 53476e53610d3d93009a823cbc21cc511ce170f6)
1.\" $NetBSD: rdmsr.9,v 1.4 2017/02/17 22:31:08 christos Exp $
2.\"
3.\" Copyright (c) 2011 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd February 17, 2017
31.Dt RDMSR 9 x86
32.Os
33.Sh NAME
34.Nm msr ,
35.Nm rdmsr ,
36.Nm rdmsr_safe ,
37.Nm wrmsr
38.Nd functions for x86 MSRs
39.Sh SYNOPSIS
40.In x86/cpufunc.h
41.Ft uint64_t
42.Fn rdmsr "u_int msr"
43.\" .Ft uint64_t
44.\" .Fn rdmsr_locked "u_int msr"
45.Ft int
46.Fn rdmsr_safe "u_int msr" "uint64_t *valp"
47.Ft void
48.Fn wrmsr "u_int msr" "uint64_t val"
49.\" .Ft void
50.\" .Fn wrmsr_locked "u_int msr" "u_int" "uint64_t val"
51.Sh DESCRIPTION
52The
53.Dv RDMSR
54instruction reads from a x86 model-specific register
55.Pq Dv MSR .
56Conversely, the
57.Dv WRMSR
58instruction is used to write to a
59.Dv MSR .
60In
61.Nx
62the
63.Fn rdmsr ,
64.Fn rdmsr_safe ,
65and
66.Fn wrmsr
67functions are used to access
68.Dv MSRs .
69The header
70.In x86/specialreg.h
71includes definitions for some of the commonly used MSRs,
72that is, control registers that are present
73in some x86 processor models but unavailable in others.
74.Sh FUNCTIONS
75.Bl -tag -width abcd
76.It Fn rdmsr "msr"
77Returns the value read from
78.Fa msr .
79.\" .It Fn rdmsr_locked "msr"
80.It Fn rdmsr_safe "msr" "valp"
81The
82.Fn rdmsr_safe
83function is a safer variant of
84.Fn rdmsr .
85Upon successful completion,
86the function returns zero and the value read from the register
87.Fa msr
88is returned in
89.Fa valp .
90If a fault occurs while accessing
91.Fa msr ,
92.Fn rdmsr_safe
93returns
94.Dv EFAULT .
95.It Fn wrmsr "msr" "val"
96The
97.Fn wrmsr
98function writes
99.Fa val
100to the register
101.Fa msr .
102.\" .It Fn wrmsr_locked "msr" "xxx" "val"
103.El
104.Pp
105Note that even though
106.Fn rdmsr_safe
107provides support for reading
108.Dv MSRs
109in a safe manner, it is still a good practice
110to always verify that the given model-specific register
111is present by using the
112.Dv CPUID
113instruction, available in
114.Nx
115via
116.Fn x86_cpuid .
117.Sh SEE ALSO
118.Xr rdtsc 9 ,
119.Xr x86/x86_msr_xcall 9
120