File: | home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmmMsrHandler.c |
Warning: | line 106, column 3 Value stored to 'SmmCpuState' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /** @file |
2 | SMM MSR handler |
3 | |
4 | Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> |
5 | This program and the accompanying materials |
6 | are licensed and made available under the terms and conditions of the BSD License |
7 | which accompanies this distribution. The full text of the license may be found at |
8 | http://opensource.org/licenses/bsd-license.php. |
9 | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. |
12 | |
13 | **/ |
14 | |
15 | // most of this code was borrowed from the Intel driver |
16 | // howver, the only MSR of interest is the EFER MSR since that is needed to configure |
17 | // the guest VM for 64 bit |
18 | |
19 | // may merge this code back into to Intel reference with VM/PE mods |
20 | |
21 | #include "StmRuntime.h" |
22 | #include "PeStm.h" |
23 | |
24 | /** |
25 | |
26 | This function is RDMSR handler for VM/PE. |
27 | |
28 | @param Index CPU index |
29 | |
30 | **/ |
31 | VOIDvoid |
32 | PeReadMsrHandler ( |
33 | IN UINT32 CpuIndex |
34 | ) |
35 | { |
36 | UINT64 Data64; |
37 | UINT32 MsrIndex; |
38 | X86_REGISTER *Reg; |
39 | UINT32 VmType = mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType; |
40 | |
41 | UINT32 Index = 0; // PE/VM only has index as 0 |
42 | |
43 | Reg = &mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Register; |
44 | MsrIndex = ReadUnaligned32 ((UINT32 *)&Reg->Rcx); |
45 | |
46 | DEBUG ((EFI_D_INFO, "%ld PeReadMsrHandler - 0x%llx\n", CpuIndex, MsrIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeReadMsrHandler - 0x%llx\n" , CpuIndex, MsrIndex); } } while (((BOOLEAN)(0==1))); |
47 | |
48 | switch (MsrIndex) { |
49 | case IA32_EFER_MSR_INDEX0xC0000080: |
50 | Data64 = mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer; |
51 | break; |
52 | #if 0 |
53 | case IA32_SYSENTER_CS_MSR_INDEX0x174: |
54 | Data64 = (UINT64)VmRead32 (VMCS_32_GUEST_IA32_SYSENTER_CS_INDEX0x482A); |
55 | break; |
56 | case IA32_SYSENTER_ESP_MSR_INDEX0x175: |
57 | Data64 = (UINT64)VmReadN (VMCS_N_GUEST_IA32_SYSENTER_ESP_INDEX0x6824); |
58 | break; |
59 | case IA32_SYSENTER_EIP_MSR_INDEX0x176: |
60 | Data64 = (UINT64)VmReadN (VMCS_N_GUEST_IA32_SYSENTER_EIP_INDEX0x6826); |
61 | break; |
62 | |
63 | case IA32_FS_BASE_MSR_INDEX0xC0000100: |
64 | Data64 = (UINT64)VmReadN (VMCS_N_GUEST_FS_BASE_INDEX0x680E); |
65 | break; |
66 | case IA32_GS_BASE_MSR_INDEX0xC0000101: |
67 | Data64 = (UINT64)VmReadN (VMCS_N_GUEST_GS_BASE_INDEX0x6810); |
68 | break; |
69 | #endif |
70 | default: |
71 | // since we do not allow the VM/PE to generally read MSRs |
72 | // we return 0 for a read. |
73 | |
74 | Data64 = 0; |
75 | |
76 | } |
77 | |
78 | Reg->Rax = (UINTN)(UINT32)Data64; // HIGH bits are cleared |
79 | Reg->Rdx = (UINTN)(UINT32)RShiftU64 (Data64, 32); // HIGH bits are cleared |
80 | |
81 | VmWriteN (VMCS_N_GUEST_RIP_INDEX0x681E, VmReadN(VMCS_N_GUEST_RIP_INDEX0x681E) + VmRead32(VMCS_32_RO_VMEXIT_INSTRUCTION_LENGTH_INDEX0x440C)); |
82 | return ; |
83 | } |
84 | |
85 | /** |
86 | |
87 | This function is WRMSR handler for SMM. |
88 | |
89 | @param Index CPU index |
90 | |
91 | **/ |
92 | VOIDvoid |
93 | PeWriteMsrHandler ( |
94 | IN UINT32 CpuIndex |
95 | ) |
96 | { |
97 | UINT64 Data64; |
98 | UINT32 MsrIndex; |
99 | VM_ENTRY_CONTROLS VmEntryControls; |
100 | X86_REGISTER *Reg; |
101 | STM_SMM_CPU_STATE *SmmCpuState; |
102 | UINT32 VmType = mHostContextCommon.HostContextPerCpu[CpuIndex].GuestVmType; |
103 | |
104 | UINT32 Index = 0; // PE VM only Index = 0 |
105 | |
106 | SmmCpuState = mGuestContextCommonSmi.GuestContextPerCpu[Index].SmmCpuState; |
Value stored to 'SmmCpuState' is never read | |
107 | |
108 | Reg = &mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Register; |
109 | MsrIndex = ReadUnaligned32 ((UINT32 *)&Reg->Rcx); |
110 | |
111 | Data64 = LShiftU64 ((UINT64)ReadUnaligned32 ((UINT32 *)&Reg->Rdx), 32) | (UINT64)ReadUnaligned32 ((UINT32 *)&Reg->Rax); |
112 | DEBUG ((EFI_D_INFO, "%ld PeWriteMsrHandler - 0x%llx 0x%llx\n", CpuIndex, MsrIndex, Data64))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeWriteMsrHandler - 0x%llx 0x%llx\n" , CpuIndex, MsrIndex, Data64); } } while (((BOOLEAN)(0==1))); |
113 | |
114 | switch (MsrIndex) { |
115 | case IA32_EFER_MSR_INDEX0xC0000080: |
116 | #if 0 |
117 | AcquireSpinLock (&mHostContextCommon.DebugLock); |
118 | if ((Data64 & IA32_EFER_MSR_SCE1u) != 0) { |
119 | DEBUG ((EFI_D_INFO, "%ld WriteMsrHandler - SCE\n", CpuIndex,))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld WriteMsrHandler - SCE\n" , CpuIndex,); } } while (((BOOLEAN)(0==1))); |
120 | } |
121 | if ((Data64 & IA32_EFER_MSR_XDE(1u << 11)) != 0) { |
122 | DEBUG ((EFI_D_INFO, "%ld WriteMsrHandler - XDE\n", CpuIndex,))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld WriteMsrHandler - XDE\n" , CpuIndex,); } } while (((BOOLEAN)(0==1))); |
123 | } |
124 | ReleaseSpinLock (&mHostContextCommon.DebugLock); |
125 | #endif |
126 | mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer = Data64; |
127 | // |
128 | // Check IA32e mode switch |
129 | // |
130 | VmEntryControls.Uint32 = VmRead32 (VMCS_32_CONTROL_VMENTRY_CONTROLS_INDEX0x4012); |
131 | if ((Data64 & IA32_EFER_MSR_MLE(1u << 8)) != 0) { |
132 | mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer |= IA32_EFER_MSR_MLE(1u << 8); |
133 | } else { |
134 | mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer &= ~IA32_EFER_MSR_MLE(1u << 8); |
135 | } |
136 | if (((mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer & IA32_EFER_MSR_MLE(1u << 8)) != 0) && |
137 | ((mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Cr0 & CR0_PG(1u << 31)) != 0)) { |
138 | mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer |= IA32_EFER_MSR_MLA(1u << 10); |
139 | VmEntryControls.Bits.Ia32eGuest = 1; |
140 | } else { |
141 | mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer &= ~IA32_EFER_MSR_MLA(1u << 10); |
142 | VmEntryControls.Bits.Ia32eGuest = 0; |
143 | } |
144 | VmWrite32 (VMCS_32_CONTROL_VMENTRY_CONTROLS_INDEX0x4012, VmEntryControls.Uint32); |
145 | VmWrite64 (VMCS_64_GUEST_IA32_EFER_INDEX0x2806, mGuestContextCommonSmm[VmType].GuestContextPerCpu[Index].Efer); |
146 | |
147 | break; |
148 | #if 0 |
149 | case IA32_SYSENTER_CS_MSR_INDEX0x174: |
150 | VmWrite32 (VMCS_32_GUEST_IA32_SYSENTER_CS_INDEX0x482A, (UINT32)Data64); |
151 | break; |
152 | case IA32_SYSENTER_ESP_MSR_INDEX0x175: |
153 | VmWriteN (VMCS_N_GUEST_IA32_SYSENTER_ESP_INDEX0x6824, (UINTN)Data64); |
154 | break; |
155 | case IA32_SYSENTER_EIP_MSR_INDEX0x176: |
156 | VmWriteN (VMCS_N_GUEST_IA32_SYSENTER_EIP_INDEX0x6826, (UINTN)Data64); |
157 | break; |
158 | |
159 | case IA32_FS_BASE_MSR_INDEX0xC0000100: |
160 | VmWriteN (VMCS_N_GUEST_FS_BASE_INDEX0x680E, (UINTN)Data64); |
161 | // AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use FS |
162 | break; |
163 | case IA32_GS_BASE_MSR_INDEX0xC0000101: |
164 | VmWriteN (VMCS_N_GUEST_GS_BASE_INDEX0x6810, (UINTN)Data64); |
165 | // AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use GS |
166 | break; |
167 | case IA32_KERNAL_GS_BASE_MSR_INDEX0xC0000102: |
168 | AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use this |
169 | break; |
170 | case IA32_STAR_MSR_INDEX0xC0000081: |
171 | AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use this |
172 | break; |
173 | case IA32_LSTAR_MSR_INDEX0xC0000082: |
174 | AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use this |
175 | break; |
176 | case IA32_FMASK_MSR_INDEX0xC0000084: |
177 | AsmWriteMsr64 (MsrIndex, Data64); // VMM does not use this |
178 | break; |
179 | #endif |
180 | |
181 | default: |
182 | DEBUG ((EFI_D_ERROR, "%ldWriteMsrHandler - VM/PE has no access to this MSR - ignoring\n", CpuIndex))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ldWriteMsrHandler - VM/PE has no access to this MSR - ignoring\n" , CpuIndex); } } while (((BOOLEAN)(0==1))); |
183 | break; |
184 | } |
185 | |
186 | VmWriteN (VMCS_N_GUEST_RIP_INDEX0x681E, VmReadN(VMCS_N_GUEST_RIP_INDEX0x681E) + VmRead32(VMCS_32_RO_VMEXIT_INSTRUCTION_LENGTH_INDEX0x440C)); |
187 | return ; |
188 | } |