]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/X86Msr.c
Make use of MdePkg's FreePool library function to replace gBS->FreePool.
[mirror_edk2.git] / MdePkg / Library / BaseLib / X86Msr.c
CommitLineData
e1f414b6 1/** @file\r
2 IA-32/x64 MSR functions.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
e1f414b6 13**/\r
14\r
1efcc4ae 15\r
47fc17d8 16#include "BaseLibInternals.h"\r
f734a10a 17\r
e1f414b6 18\r
19/**\r
20 Returns the lower 32-bits of a Machine Specific Register(MSR).\r
21\r
22 Reads and returns the lower 32-bits of the MSR specified by Index.\r
23 No parameter checking is performed on Index, and some Index values may cause\r
24 CPU exceptions. The caller must either guarantee that Index is valid, or the\r
25 caller must set up exception handlers to catch the exceptions. This function\r
030cd1a2 26 is only available on IA-32 and x64.\r
e1f414b6 27\r
28 @param Index The 32-bit MSR index to read.\r
29\r
30 @return The lower 32 bits of the MSR identified by Index.\r
31\r
32**/\r
33UINT32\r
34EFIAPI\r
35AsmReadMsr32 (\r
36 IN UINT32 Index\r
37 )\r
38{\r
39 return (UINT32)AsmReadMsr64 (Index);\r
40}\r
41\r
42/**\r
43 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).\r
44\r
45 Writes the 32-bit value specified by Value to the MSR specified by Index. The\r
46 upper 32-bits of the MSR write are set to zero. The 32-bit value written to\r
47 the MSR is returned. No parameter checking is performed on Index or Value,\r
48 and some of these may cause CPU exceptions. The caller must either guarantee\r
49 that Index and Value are valid, or the caller must establish proper exception\r
030cd1a2 50 handlers. This function is only available on IA-32 and x64.\r
e1f414b6 51\r
52 @param Index The 32-bit MSR index to write.\r
53 @param Value The 32-bit value to write to the MSR.\r
54\r
55 @return Value\r
56\r
57**/\r
58UINT32\r
59EFIAPI\r
60AsmWriteMsr32 (\r
61 IN UINT32 Index,\r
62 IN UINT32 Value\r
63 )\r
64{\r
65 return (UINT32)AsmWriteMsr64 (Index, Value);\r
66}\r
67\r
68/**\r
62991af2 69 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and\r
e1f414b6 70 writes the result back to the 64-bit MSR.\r
71\r
62991af2 72 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
e1f414b6 73 between the lower 32-bits of the read result and the value specified by\r
74 OrData, and writes the result to the 64-bit MSR specified by Index. The lower\r
75 32-bits of the value written to the MSR is returned. No parameter checking is\r
76 performed on Index or OrData, and some of these may cause CPU exceptions. The\r
77 caller must either guarantee that Index and OrData are valid, or the caller\r
78 must establish proper exception handlers. This function is only available on\r
030cd1a2 79 IA-32 and x64.\r
e1f414b6 80\r
81 @param Index The 32-bit MSR index to write.\r
82 @param OrData The value to OR with the read value from the MSR.\r
83\r
84 @return The lower 32-bit value written to the MSR.\r
85\r
86**/\r
87UINT32\r
88EFIAPI\r
89AsmMsrOr32 (\r
90 IN UINT32 Index,\r
91 IN UINT32 OrData\r
92 )\r
93{\r
94 return (UINT32)AsmMsrOr64 (Index, OrData);\r
95}\r
96\r
97/**\r
98 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes\r
99 the result back to the 64-bit MSR.\r
100\r
101 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
102 lower 32-bits of the read result and the value specified by AndData, and\r
103 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of\r
104 the value written to the MSR is returned. No parameter checking is performed\r
105 on Index or AndData, and some of these may cause CPU exceptions. The caller\r
106 must either guarantee that Index and AndData are valid, or the caller must\r
107 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 108 and x64.\r
e1f414b6 109\r
110 @param Index The 32-bit MSR index to write.\r
111 @param AndData The value to AND with the read value from the MSR.\r
112\r
113 @return The lower 32-bit value written to the MSR.\r
114\r
115**/\r
116UINT32\r
117EFIAPI\r
118AsmMsrAnd32 (\r
119 IN UINT32 Index,\r
120 IN UINT32 AndData\r
121 )\r
122{\r
123 return (UINT32)AsmMsrAnd64 (Index, AndData);\r
124}\r
125\r
126/**\r
62991af2 127 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR\r
e1f414b6 128 on the lower 32-bits, and writes the result back to the 64-bit MSR.\r
129\r
130 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
131 lower 32-bits of the read result and the value specified by AndData\r
62991af2 132 preserving the upper 32-bits, performs a bitwise OR between the\r
e1f414b6 133 result of the AND operation and the value specified by OrData, and writes the\r
134 result to the 64-bit MSR specified by Address. The lower 32-bits of the value\r
135 written to the MSR is returned. No parameter checking is performed on Index,\r
136 AndData, or OrData, and some of these may cause CPU exceptions. The caller\r
137 must either guarantee that Index, AndData, and OrData are valid, or the\r
138 caller must establish proper exception handlers. This function is only\r
030cd1a2 139 available on IA-32 and x64.\r
e1f414b6 140\r
141 @param Index The 32-bit MSR index to write.\r
142 @param AndData The value to AND with the read value from the MSR.\r
143 @param OrData The value to OR with the result of the AND operation.\r
144\r
145 @return The lower 32-bit value written to the MSR.\r
146\r
147**/\r
148UINT32\r
149EFIAPI\r
150AsmMsrAndThenOr32 (\r
151 IN UINT32 Index,\r
152 IN UINT32 AndData,\r
153 IN UINT32 OrData\r
154 )\r
155{\r
156 return (UINT32)AsmMsrAndThenOr64 (Index, AndData, OrData);\r
157}\r
158\r
159/**\r
160 Reads a bit field of an MSR.\r
161\r
162 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is\r
163 specified by the StartBit and the EndBit. The value of the bit field is\r
164 returned. The caller must either guarantee that Index is valid, or the caller\r
165 must set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 166 available on IA-32 and x64.\r
e1f414b6 167\r
168 If StartBit is greater than 31, then ASSERT().\r
169 If EndBit is greater than 31, then ASSERT().\r
170 If EndBit is less than StartBit, then ASSERT().\r
171\r
172 @param Index The 32-bit MSR index to read.\r
173 @param StartBit The ordinal of the least significant bit in the bit field.\r
174 Range 0..31.\r
175 @param EndBit The ordinal of the most significant bit in the bit field.\r
176 Range 0..31.\r
177\r
178 @return The bit field read from the MSR.\r
179\r
180**/\r
181UINT32\r
182EFIAPI\r
183AsmMsrBitFieldRead32 (\r
184 IN UINT32 Index,\r
185 IN UINTN StartBit,\r
186 IN UINTN EndBit\r
187 )\r
188{\r
189 return BitFieldRead32 (AsmReadMsr32 (Index), StartBit, EndBit);\r
190}\r
191\r
192/**\r
193 Writes a bit field to an MSR.\r
194\r
195 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r
196 field is specified by the StartBit and the EndBit. All other bits in the\r
197 destination MSR are preserved. The lower 32-bits of the MSR written is\r
62991af2 198 returned. The caller must either guarantee that Index and the data written \r
199 is valid, or the caller must set up exception handlers to catch the exceptions. \r
200 This function is only available on IA-32 and x64.\r
e1f414b6 201\r
202 If StartBit is greater than 31, then ASSERT().\r
203 If EndBit is greater than 31, then ASSERT().\r
204 If EndBit is less than StartBit, then ASSERT().\r
205\r
206 @param Index The 32-bit MSR index to write.\r
207 @param StartBit The ordinal of the least significant bit in the bit field.\r
208 Range 0..31.\r
209 @param EndBit The ordinal of the most significant bit in the bit field.\r
210 Range 0..31.\r
211 @param Value New value of the bit field.\r
212\r
213 @return The lower 32-bit of the value written to the MSR.\r
214\r
215**/\r
216UINT32\r
217EFIAPI\r
218AsmMsrBitFieldWrite32 (\r
219 IN UINT32 Index,\r
220 IN UINTN StartBit,\r
221 IN UINTN EndBit,\r
222 IN UINT32 Value\r
223 )\r
224{\r
225 ASSERT (EndBit < sizeof (Value) * 8);\r
226 ASSERT (StartBit <= EndBit);\r
227 return (UINT32)AsmMsrBitFieldWrite64 (Index, StartBit, EndBit, Value);\r
228}\r
229\r
230/**\r
231 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the\r
232 result back to the bit field in the 64-bit MSR.\r
233\r
62991af2 234 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
e1f414b6 235 between the read result and the value specified by OrData, and writes the\r
236 result to the 64-bit MSR specified by Index. The lower 32-bits of the value\r
237 written to the MSR are returned. Extra left bits in OrData are stripped. The\r
238 caller must either guarantee that Index and the data written is valid, or\r
239 the caller must set up exception handlers to catch the exceptions. This\r
030cd1a2 240 function is only available on IA-32 and x64.\r
e1f414b6 241\r
242 If StartBit is greater than 31, then ASSERT().\r
243 If EndBit is greater than 31, then ASSERT().\r
244 If EndBit is less than StartBit, then ASSERT().\r
245\r
246 @param Index The 32-bit MSR index to write.\r
247 @param StartBit The ordinal of the least significant bit in the bit field.\r
248 Range 0..31.\r
249 @param EndBit The ordinal of the most significant bit in the bit field.\r
250 Range 0..31.\r
251 @param OrData The value to OR with the read value from the MSR.\r
252\r
253 @return The lower 32-bit of the value written to the MSR.\r
254\r
255**/\r
256UINT32\r
257EFIAPI\r
258AsmMsrBitFieldOr32 (\r
259 IN UINT32 Index,\r
260 IN UINTN StartBit,\r
261 IN UINTN EndBit,\r
262 IN UINT32 OrData\r
263 )\r
264{\r
265 ASSERT (EndBit < sizeof (OrData) * 8);\r
266 ASSERT (StartBit <= EndBit);\r
267 return (UINT32)AsmMsrBitFieldOr64 (Index, StartBit, EndBit, OrData);\r
268}\r
269\r
270/**\r
271 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
272 result back to the bit field in the 64-bit MSR.\r
273\r
274 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
275 read result and the value specified by AndData, and writes the result to the\r
276 64-bit MSR specified by Index. The lower 32-bits of the value written to the\r
277 MSR are returned. Extra left bits in AndData are stripped. The caller must\r
278 either guarantee that Index and the data written is valid, or the caller must\r
279 set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 280 available on IA-32 and x64.\r
e1f414b6 281\r
282 If StartBit is greater than 31, then ASSERT().\r
283 If EndBit is greater than 31, then ASSERT().\r
284 If EndBit is less than StartBit, then ASSERT().\r
285\r
286 @param Index The 32-bit MSR index to write.\r
287 @param StartBit The ordinal of the least significant bit in the bit field.\r
288 Range 0..31.\r
289 @param EndBit The ordinal of the most significant bit in the bit field.\r
290 Range 0..31.\r
291 @param AndData The value to AND with the read value from the MSR.\r
292\r
293 @return The lower 32-bit of the value written to the MSR.\r
294\r
295**/\r
296UINT32\r
297EFIAPI\r
298AsmMsrBitFieldAnd32 (\r
299 IN UINT32 Index,\r
300 IN UINTN StartBit,\r
301 IN UINTN EndBit,\r
302 IN UINT32 AndData\r
303 )\r
304{\r
305 ASSERT (EndBit < sizeof (AndData) * 8);\r
306 ASSERT (StartBit <= EndBit);\r
307 return (UINT32)AsmMsrBitFieldAnd64 (Index, StartBit, EndBit, AndData);\r
308}\r
309\r
310/**\r
311 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 312 bitwise OR, and writes the result back to the bit field in the\r
e1f414b6 313 64-bit MSR.\r
314\r
315 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a\r
62991af2 316 bitwise OR between the read result and the value specified by\r
e1f414b6 317 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
318 lower 32-bits of the value written to the MSR are returned. Extra left bits\r
319 in both AndData and OrData are stripped. The caller must either guarantee\r
320 that Index and the data written is valid, or the caller must set up exception\r
321 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 322 and x64.\r
e1f414b6 323\r
324 If StartBit is greater than 31, then ASSERT().\r
325 If EndBit is greater than 31, then ASSERT().\r
326 If EndBit is less than StartBit, then ASSERT().\r
327\r
328 @param Index The 32-bit MSR index to write.\r
329 @param StartBit The ordinal of the least significant bit in the bit field.\r
330 Range 0..31.\r
331 @param EndBit The ordinal of the most significant bit in the bit field.\r
332 Range 0..31.\r
333 @param AndData The value to AND with the read value from the MSR.\r
334 @param OrData The value to OR with the result of the AND operation.\r
335\r
336 @return The lower 32-bit of the value written to the MSR.\r
337\r
338**/\r
339UINT32\r
340EFIAPI\r
341AsmMsrBitFieldAndThenOr32 (\r
342 IN UINT32 Index,\r
343 IN UINTN StartBit,\r
344 IN UINTN EndBit,\r
345 IN UINT32 AndData,\r
346 IN UINT32 OrData\r
347 )\r
348{\r
349 ASSERT (EndBit < sizeof (AndData) * 8);\r
350 ASSERT (StartBit <= EndBit);\r
351 return (UINT32)AsmMsrBitFieldAndThenOr64 (\r
352 Index,\r
353 StartBit,\r
354 EndBit,\r
355 AndData,\r
356 OrData\r
357 );\r
358}\r
359\r
360/**\r
62991af2 361 Reads a 64-bit MSR, performs a bitwise OR, and writes the result\r
e1f414b6 362 back to the 64-bit MSR.\r
363\r
62991af2 364 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
e1f414b6 365 between the read result and the value specified by OrData, and writes the\r
366 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
367 returned. No parameter checking is performed on Index or OrData, and some of\r
368 these may cause CPU exceptions. The caller must either guarantee that Index\r
369 and OrData are valid, or the caller must establish proper exception handlers.\r
030cd1a2 370 This function is only available on IA-32 and x64.\r
e1f414b6 371\r
372 @param Index The 32-bit MSR index to write.\r
373 @param OrData The value to OR with the read value from the MSR.\r
374\r
375 @return The value written back to the MSR.\r
376\r
377**/\r
378UINT64\r
379EFIAPI\r
380AsmMsrOr64 (\r
381 IN UINT32 Index,\r
382 IN UINT64 OrData\r
383 )\r
384{\r
385 return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) | OrData);\r
386}\r
387\r
388/**\r
389 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the\r
390 64-bit MSR.\r
391\r
392 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
393 read result and the value specified by OrData, and writes the result to the\r
394 64-bit MSR specified by Index. The value written to the MSR is returned. No\r
395 parameter checking is performed on Index or OrData, and some of these may\r
396 cause CPU exceptions. The caller must either guarantee that Index and OrData\r
397 are valid, or the caller must establish proper exception handlers. This\r
030cd1a2 398 function is only available on IA-32 and x64.\r
e1f414b6 399\r
400 @param Index The 32-bit MSR index to write.\r
401 @param AndData The value to AND with the read value from the MSR.\r
402\r
403 @return The value written back to the MSR.\r
404\r
405**/\r
406UINT64\r
407EFIAPI\r
408AsmMsrAnd64 (\r
409 IN UINT32 Index,\r
410 IN UINT64 AndData\r
411 )\r
412{\r
413 return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) & AndData);\r
414}\r
415\r
416/**\r
62991af2 417 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise \r
e1f414b6 418 OR, and writes the result back to the 64-bit MSR.\r
419\r
420 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
62991af2 421 result and the value specified by AndData, performs a bitwise OR\r
e1f414b6 422 between the result of the AND operation and the value specified by OrData,\r
423 and writes the result to the 64-bit MSR specified by Index. The value written\r
424 to the MSR is returned. No parameter checking is performed on Index, AndData,\r
425 or OrData, and some of these may cause CPU exceptions. The caller must either\r
426 guarantee that Index, AndData, and OrData are valid, or the caller must\r
427 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 428 and x64.\r
e1f414b6 429\r
430 @param Index The 32-bit MSR index to write.\r
431 @param AndData The value to AND with the read value from the MSR.\r
432 @param OrData The value to OR with the result of the AND operation.\r
433\r
434 @return The value written back to the MSR.\r
435\r
436**/\r
437UINT64\r
438EFIAPI\r
439AsmMsrAndThenOr64 (\r
440 IN UINT32 Index,\r
441 IN UINT64 AndData,\r
442 IN UINT64 OrData\r
443 )\r
444{\r
445 return AsmWriteMsr64 (Index, (AsmReadMsr64 (Index) & AndData) | OrData);\r
446}\r
447\r
448/**\r
449 Reads a bit field of an MSR.\r
450\r
451 Reads the bit field in the 64-bit MSR. The bit field is specified by the\r
452 StartBit and the EndBit. The value of the bit field is returned. The caller\r
453 must either guarantee that Index is valid, or the caller must set up\r
454 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 455 on IA-32 and x64.\r
e1f414b6 456\r
457 If StartBit is greater than 63, then ASSERT().\r
458 If EndBit is greater than 63, then ASSERT().\r
459 If EndBit is less than StartBit, then ASSERT().\r
460\r
461 @param Index The 32-bit MSR index to read.\r
462 @param StartBit The ordinal of the least significant bit in the bit field.\r
463 Range 0..63.\r
464 @param EndBit The ordinal of the most significant bit in the bit field.\r
465 Range 0..63.\r
466\r
467 @return The value written back to the MSR.\r
468\r
469**/\r
470UINT64\r
471EFIAPI\r
472AsmMsrBitFieldRead64 (\r
473 IN UINT32 Index,\r
474 IN UINTN StartBit,\r
475 IN UINTN EndBit\r
476 )\r
477{\r
478 return BitFieldRead64 (AsmReadMsr64 (Index), StartBit, EndBit);\r
479}\r
480\r
481/**\r
482 Writes a bit field to an MSR.\r
483\r
484 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
485 the StartBit and the EndBit. All other bits in the destination MSR are\r
62991af2 486 preserved. The MSR written is returned. The caller must either guarantee \r
487 that Index and the data written is valid, or the caller must set up exception \r
488 handlers to catch the exceptions. This function is only available on IA-32 and x64.\r
e1f414b6 489\r
490 If StartBit is greater than 63, then ASSERT().\r
491 If EndBit is greater than 63, then ASSERT().\r
492 If EndBit is less than StartBit, then ASSERT().\r
493\r
494 @param Index The 32-bit MSR index to write.\r
495 @param StartBit The ordinal of the least significant bit in the bit field.\r
496 Range 0..63.\r
497 @param EndBit The ordinal of the most significant bit in the bit field.\r
498 Range 0..63.\r
499 @param Value New value of the bit field.\r
500\r
501 @return The value written back to the MSR.\r
502\r
503**/\r
504UINT64\r
505EFIAPI\r
506AsmMsrBitFieldWrite64 (\r
507 IN UINT32 Index,\r
508 IN UINTN StartBit,\r
509 IN UINTN EndBit,\r
510 IN UINT64 Value\r
511 )\r
512{\r
513 return AsmWriteMsr64 (\r
514 Index,\r
515 BitFieldWrite64 (AsmReadMsr64 (Index), StartBit, EndBit, Value)\r
516 );\r
517}\r
518\r
519/**\r
62991af2 520 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and\r
e1f414b6 521 writes the result back to the bit field in the 64-bit MSR.\r
522\r
62991af2 523 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
e1f414b6 524 between the read result and the value specified by OrData, and writes the\r
525 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
526 returned. Extra left bits in OrData are stripped. The caller must either\r
527 guarantee that Index and the data written is valid, or the caller must set up\r
528 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 529 on IA-32 and x64.\r
e1f414b6 530\r
531 If StartBit is greater than 63, then ASSERT().\r
532 If EndBit is greater than 63, then ASSERT().\r
533 If EndBit is less than StartBit, then ASSERT().\r
534\r
535 @param Index The 32-bit MSR index to write.\r
536 @param StartBit The ordinal of the least significant bit in the bit field.\r
537 Range 0..63.\r
538 @param EndBit The ordinal of the most significant bit in the bit field.\r
539 Range 0..63.\r
540 @param OrData The value to OR with the read value from the bit field.\r
541\r
542 @return The value written back to the MSR.\r
543\r
544**/\r
545UINT64\r
546EFIAPI\r
547AsmMsrBitFieldOr64 (\r
548 IN UINT32 Index,\r
549 IN UINTN StartBit,\r
550 IN UINTN EndBit,\r
551 IN UINT64 OrData\r
552 )\r
553{\r
554 return AsmWriteMsr64 (\r
555 Index,\r
556 BitFieldOr64 (AsmReadMsr64 (Index), StartBit, EndBit, OrData)\r
557 );\r
558}\r
559\r
560/**\r
561 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
562 result back to the bit field in the 64-bit MSR.\r
563\r
564 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
565 read result and the value specified by AndData, and writes the result to the\r
566 64-bit MSR specified by Index. The value written to the MSR is returned.\r
567 Extra left bits in AndData are stripped. The caller must either guarantee\r
568 that Index and the data written is valid, or the caller must set up exception\r
569 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 570 and x64.\r
e1f414b6 571\r
572 If StartBit is greater than 63, then ASSERT().\r
573 If EndBit is greater than 63, then ASSERT().\r
574 If EndBit is less than StartBit, then ASSERT().\r
575\r
576 @param Index The 32-bit MSR index to write.\r
577 @param StartBit The ordinal of the least significant bit in the bit field.\r
578 Range 0..63.\r
579 @param EndBit The ordinal of the most significant bit in the bit field.\r
580 Range 0..63.\r
581 @param AndData The value to AND with the read value from the bit field.\r
582\r
583 @return The value written back to the MSR.\r
584\r
585**/\r
586UINT64\r
587EFIAPI\r
588AsmMsrBitFieldAnd64 (\r
589 IN UINT32 Index,\r
590 IN UINTN StartBit,\r
591 IN UINTN EndBit,\r
592 IN UINT64 AndData\r
593 )\r
594{\r
595 return AsmWriteMsr64 (\r
596 Index,\r
597 BitFieldAnd64 (AsmReadMsr64 (Index), StartBit, EndBit, AndData)\r
598 );\r
599}\r
600\r
601/**\r
602 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 603 bitwise OR, and writes the result back to the bit field in the\r
e1f414b6 604 64-bit MSR.\r
605\r
606 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by\r
62991af2 607 a bitwise OR between the read result and the value specified by\r
e1f414b6 608 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
609 value written to the MSR is returned. Extra left bits in both AndData and\r
610 OrData are stripped. The caller must either guarantee that Index and the data\r
611 written is valid, or the caller must set up exception handlers to catch the\r
030cd1a2 612 exceptions. This function is only available on IA-32 and x64.\r
e1f414b6 613\r
614 If StartBit is greater than 63, then ASSERT().\r
615 If EndBit is greater than 63, then ASSERT().\r
616 If EndBit is less than StartBit, then ASSERT().\r
617\r
618 @param Index The 32-bit MSR index to write.\r
619 @param StartBit The ordinal of the least significant bit in the bit field.\r
620 Range 0..63.\r
621 @param EndBit The ordinal of the most significant bit in the bit field.\r
622 Range 0..63.\r
623 @param AndData The value to AND with the read value from the bit field.\r
624 @param OrData The value to OR with the result of the AND operation.\r
625\r
626 @return The value written back to the MSR.\r
627\r
628**/\r
629UINT64\r
630EFIAPI\r
631AsmMsrBitFieldAndThenOr64 (\r
632 IN UINT32 Index,\r
633 IN UINTN StartBit,\r
634 IN UINTN EndBit,\r
635 IN UINT64 AndData,\r
636 IN UINT64 OrData\r
637 )\r
638{\r
639 return AsmWriteMsr64 (\r
640 Index,\r
641 BitFieldAndThenOr64 (\r
642 AsmReadMsr64 (Index),\r
643 StartBit,\r
644 EndBit,\r
645 AndData,\r
646 OrData\r
647 )\r
648 );\r
649}\r