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