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