]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/WriteMsr64.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / WriteMsr64.c
1 /** @file
2 AsmWriteMsr64 function
3
4 Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Library/RegisterFilterLib.h>
10
11 /**
12 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
13 value.
14
15 Writes the 64-bit value specified by Value to the MSR specified by Index. The
16 64-bit value written to the MSR is returned. No parameter checking is
17 performed on Index or Value, and some of these may cause CPU exceptions. The
18 caller must either guarantee that Index and Value are valid, or the caller
19 must establish proper exception handlers. This function is only available on
20 IA-32 and x64.
21
22 @param Index The 32-bit MSR index to write.
23 @param Value The 64-bit value to write to the MSR.
24
25 @return Value
26
27 **/
28 UINT64
29 EFIAPI
30 AsmWriteMsr64 (
31 IN UINT32 Index,
32 IN UINT64 Value
33 )
34 {
35 BOOLEAN Flag;
36
37 Flag = FilterBeforeMsrWrite (Index, &Value);
38 if (Flag) {
39 _asm {
40 mov edx, dword ptr [Value + 4]
41 mov eax, dword ptr [Value + 0]
42 mov ecx, Index
43 wrmsr
44 }
45 }
46
47 FilterAfterMsrWrite (Index, &Value);
48
49 return Value;
50 }