]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/X86Msr.c
Update the text to use "x64" instead of "X64" in MdePkg.
[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
69 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and\r
70 writes the result back to the 64-bit MSR.\r
71\r
72 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR\r
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
127 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR\r
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
132 preserving the upper 32-bits, performs a bitwise inclusive OR between the\r
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
198 returned. Extra left bits in Value are stripped. The caller must either\r
199 guarantee that Index and the data written is valid, or the caller must set up\r
200 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 201 on IA-32 and x64.\r
e1f414b6 202\r
203 If StartBit is greater than 31, then ASSERT().\r
204 If EndBit is greater than 31, then ASSERT().\r
205 If EndBit is less than StartBit, then ASSERT().\r
206\r
207 @param Index The 32-bit MSR index to write.\r
208 @param StartBit The ordinal of the least significant bit in the bit field.\r
209 Range 0..31.\r
210 @param EndBit The ordinal of the most significant bit in the bit field.\r
211 Range 0..31.\r
212 @param Value New value of the bit field.\r
213\r
214 @return The lower 32-bit of the value written to the MSR.\r
215\r
216**/\r
217UINT32\r
218EFIAPI\r
219AsmMsrBitFieldWrite32 (\r
220 IN UINT32 Index,\r
221 IN UINTN StartBit,\r
222 IN UINTN EndBit,\r
223 IN UINT32 Value\r
224 )\r
225{\r
226 ASSERT (EndBit < sizeof (Value) * 8);\r
227 ASSERT (StartBit <= EndBit);\r
228 return (UINT32)AsmMsrBitFieldWrite64 (Index, StartBit, EndBit, Value);\r
229}\r
230\r
231/**\r
232 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the\r
233 result back to the bit field in the 64-bit MSR.\r
234\r
235 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR\r
236 between the read result and the value specified by OrData, and writes the\r
237 result to the 64-bit MSR specified by Index. The lower 32-bits of the value\r
238 written to the MSR are returned. Extra left bits in OrData are stripped. The\r
239 caller must either guarantee that Index and the data written is valid, or\r
240 the caller must set up exception handlers to catch the exceptions. This\r
030cd1a2 241 function is only available on IA-32 and x64.\r
e1f414b6 242\r
243 If StartBit is greater than 31, then ASSERT().\r
244 If EndBit is greater than 31, then ASSERT().\r
245 If EndBit is less than StartBit, then ASSERT().\r
246\r
247 @param Index The 32-bit MSR index to write.\r
248 @param StartBit The ordinal of the least significant bit in the bit field.\r
249 Range 0..31.\r
250 @param EndBit The ordinal of the most significant bit in the bit field.\r
251 Range 0..31.\r
252 @param OrData The value to OR with the read value from the MSR.\r
253\r
254 @return The lower 32-bit of the value written to the MSR.\r
255\r
256**/\r
257UINT32\r
258EFIAPI\r
259AsmMsrBitFieldOr32 (\r
260 IN UINT32 Index,\r
261 IN UINTN StartBit,\r
262 IN UINTN EndBit,\r
263 IN UINT32 OrData\r
264 )\r
265{\r
266 ASSERT (EndBit < sizeof (OrData) * 8);\r
267 ASSERT (StartBit <= EndBit);\r
268 return (UINT32)AsmMsrBitFieldOr64 (Index, StartBit, EndBit, OrData);\r
269}\r
270\r
271/**\r
272 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
273 result back to the bit field in the 64-bit MSR.\r
274\r
275 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
276 read result and the value specified by AndData, and writes the result to the\r
277 64-bit MSR specified by Index. The lower 32-bits of the value written to the\r
278 MSR are returned. Extra left bits in AndData are stripped. The caller must\r
279 either guarantee that Index and the data written is valid, or the caller must\r
280 set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 281 available on IA-32 and x64.\r
e1f414b6 282\r
283 If StartBit is greater than 31, then ASSERT().\r
284 If EndBit is greater than 31, then ASSERT().\r
285 If EndBit is less than StartBit, then ASSERT().\r
286\r
287 @param Index The 32-bit MSR index to write.\r
288 @param StartBit The ordinal of the least significant bit in the bit field.\r
289 Range 0..31.\r
290 @param EndBit The ordinal of the most significant bit in the bit field.\r
291 Range 0..31.\r
292 @param AndData The value to AND with the read value from the MSR.\r
293\r
294 @return The lower 32-bit of the value written to the MSR.\r
295\r
296**/\r
297UINT32\r
298EFIAPI\r
299AsmMsrBitFieldAnd32 (\r
300 IN UINT32 Index,\r
301 IN UINTN StartBit,\r
302 IN UINTN EndBit,\r
303 IN UINT32 AndData\r
304 )\r
305{\r
306 ASSERT (EndBit < sizeof (AndData) * 8);\r
307 ASSERT (StartBit <= EndBit);\r
308 return (UINT32)AsmMsrBitFieldAnd64 (Index, StartBit, EndBit, AndData);\r
309}\r
310\r
311/**\r
312 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
313 bitwise inclusive OR, and writes the result back to the bit field in the\r
314 64-bit MSR.\r
315\r
316 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a\r
317 bitwise inclusive OR between the read result and the value specified by\r
318 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
319 lower 32-bits of the value written to the MSR are returned. Extra left bits\r
320 in both AndData and OrData are stripped. The caller must either guarantee\r
321 that Index and the data written is valid, or the caller must set up exception\r
322 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 323 and x64.\r
e1f414b6 324\r
325 If StartBit is greater than 31, then ASSERT().\r
326 If EndBit is greater than 31, then ASSERT().\r
327 If EndBit is less than StartBit, then ASSERT().\r
328\r
329 @param Index The 32-bit MSR index to write.\r
330 @param StartBit The ordinal of the least significant bit in the bit field.\r
331 Range 0..31.\r
332 @param EndBit The ordinal of the most significant bit in the bit field.\r
333 Range 0..31.\r
334 @param AndData The value to AND with the read value from the MSR.\r
335 @param OrData The value to OR with the result of the AND operation.\r
336\r
337 @return The lower 32-bit of the value written to the MSR.\r
338\r
339**/\r
340UINT32\r
341EFIAPI\r
342AsmMsrBitFieldAndThenOr32 (\r
343 IN UINT32 Index,\r
344 IN UINTN StartBit,\r
345 IN UINTN EndBit,\r
346 IN UINT32 AndData,\r
347 IN UINT32 OrData\r
348 )\r
349{\r
350 ASSERT (EndBit < sizeof (AndData) * 8);\r
351 ASSERT (StartBit <= EndBit);\r
352 return (UINT32)AsmMsrBitFieldAndThenOr64 (\r
353 Index,\r
354 StartBit,\r
355 EndBit,\r
356 AndData,\r
357 OrData\r
358 );\r
359}\r
360\r
361/**\r
362 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result\r
363 back to the 64-bit MSR.\r
364\r
365 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR\r
366 between the read result and the value specified by OrData, and writes the\r
367 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
368 returned. No parameter checking is performed on Index or OrData, and some of\r
369 these may cause CPU exceptions. The caller must either guarantee that Index\r
370 and OrData are valid, or the caller must establish proper exception handlers.\r
030cd1a2 371 This function is only available on IA-32 and x64.\r
e1f414b6 372\r
373 @param Index The 32-bit MSR index to write.\r
374 @param OrData The value to OR with the read value from the MSR.\r
375\r
376 @return The value written back to the MSR.\r
377\r
378**/\r
379UINT64\r
380EFIAPI\r
381AsmMsrOr64 (\r
382 IN UINT32 Index,\r
383 IN UINT64 OrData\r
384 )\r
385{\r
386 return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) | OrData);\r
387}\r
388\r
389/**\r
390 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the\r
391 64-bit MSR.\r
392\r
393 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
394 read result and the value specified by OrData, and writes the result to the\r
395 64-bit MSR specified by Index. The value written to the MSR is returned. No\r
396 parameter checking is performed on Index or OrData, and some of these may\r
397 cause CPU exceptions. The caller must either guarantee that Index and OrData\r
398 are valid, or the caller must establish proper exception handlers. This\r
030cd1a2 399 function is only available on IA-32 and x64.\r
e1f414b6 400\r
401 @param Index The 32-bit MSR index to write.\r
402 @param AndData The value to AND with the read value from the MSR.\r
403\r
404 @return The value written back to the MSR.\r
405\r
406**/\r
407UINT64\r
408EFIAPI\r
409AsmMsrAnd64 (\r
410 IN UINT32 Index,\r
411 IN UINT64 AndData\r
412 )\r
413{\r
414 return AsmWriteMsr64 (Index, AsmReadMsr64 (Index) & AndData);\r
415}\r
416\r
417/**\r
418 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive\r
419 OR, and writes the result back to the 64-bit MSR.\r
420\r
421 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
422 result and the value specified by AndData, performs a bitwise inclusive OR\r
423 between the result of the AND operation and the value specified by OrData,\r
424 and writes the result to the 64-bit MSR specified by Index. The value written\r
425 to the MSR is returned. No parameter checking is performed on Index, AndData,\r
426 or OrData, and some of these may cause CPU exceptions. The caller must either\r
427 guarantee that Index, AndData, and OrData are valid, or the caller must\r
428 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 429 and x64.\r
e1f414b6 430\r
431 @param Index The 32-bit MSR index to write.\r
432 @param AndData The value to AND with the read value from the MSR.\r
433 @param OrData The value to OR with the result of the AND operation.\r
434\r
435 @return The value written back to the MSR.\r
436\r
437**/\r
438UINT64\r
439EFIAPI\r
440AsmMsrAndThenOr64 (\r
441 IN UINT32 Index,\r
442 IN UINT64 AndData,\r
443 IN UINT64 OrData\r
444 )\r
445{\r
446 return AsmWriteMsr64 (Index, (AsmReadMsr64 (Index) & AndData) | OrData);\r
447}\r
448\r
449/**\r
450 Reads a bit field of an MSR.\r
451\r
452 Reads the bit field in the 64-bit MSR. The bit field is specified by the\r
453 StartBit and the EndBit. The value of the bit field is returned. The caller\r
454 must either guarantee that Index is valid, or the caller must set up\r
455 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 456 on IA-32 and x64.\r
e1f414b6 457\r
458 If StartBit is greater than 63, then ASSERT().\r
459 If EndBit is greater than 63, then ASSERT().\r
460 If EndBit is less than StartBit, then ASSERT().\r
461\r
462 @param Index The 32-bit MSR index to read.\r
463 @param StartBit The ordinal of the least significant bit in the bit field.\r
464 Range 0..63.\r
465 @param EndBit The ordinal of the most significant bit in the bit field.\r
466 Range 0..63.\r
467\r
468 @return The value written back to the MSR.\r
469\r
470**/\r
471UINT64\r
472EFIAPI\r
473AsmMsrBitFieldRead64 (\r
474 IN UINT32 Index,\r
475 IN UINTN StartBit,\r
476 IN UINTN EndBit\r
477 )\r
478{\r
479 return BitFieldRead64 (AsmReadMsr64 (Index), StartBit, EndBit);\r
480}\r
481\r
482/**\r
483 Writes a bit field to an MSR.\r
484\r
485 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
486 the StartBit and the EndBit. All other bits in the destination MSR are\r
487 preserved. The MSR written is returned. Extra left bits in Value are\r
488 stripped. The caller must either guarantee that Index and the data written is\r
489 valid, or the caller must set up exception handlers to catch the exceptions.\r
030cd1a2 490 This function is only available on IA-32 and x64.\r
e1f414b6 491\r
492 If StartBit is greater than 63, then ASSERT().\r
493 If EndBit is greater than 63, then ASSERT().\r
494 If EndBit is less than StartBit, then ASSERT().\r
495\r
496 @param Index The 32-bit MSR index to write.\r
497 @param StartBit The ordinal of the least significant bit in the bit field.\r
498 Range 0..63.\r
499 @param EndBit The ordinal of the most significant bit in the bit field.\r
500 Range 0..63.\r
501 @param Value New value of the bit field.\r
502\r
503 @return The value written back to the MSR.\r
504\r
505**/\r
506UINT64\r
507EFIAPI\r
508AsmMsrBitFieldWrite64 (\r
509 IN UINT32 Index,\r
510 IN UINTN StartBit,\r
511 IN UINTN EndBit,\r
512 IN UINT64 Value\r
513 )\r
514{\r
515 return AsmWriteMsr64 (\r
516 Index,\r
517 BitFieldWrite64 (AsmReadMsr64 (Index), StartBit, EndBit, Value)\r
518 );\r
519}\r
520\r
521/**\r
522 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and\r
523 writes the result back to the bit field in the 64-bit MSR.\r
524\r
525 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR\r
526 between the read result and the value specified by OrData, and writes the\r
527 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
528 returned. Extra left bits in OrData are stripped. The caller must either\r
529 guarantee that Index and the data written is valid, or the caller must set up\r
530 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 531 on IA-32 and x64.\r
e1f414b6 532\r
533 If StartBit is greater than 63, then ASSERT().\r
534 If EndBit is greater than 63, then ASSERT().\r
535 If EndBit is less than StartBit, then ASSERT().\r
536\r
537 @param Index The 32-bit MSR index to write.\r
538 @param StartBit The ordinal of the least significant bit in the bit field.\r
539 Range 0..63.\r
540 @param EndBit The ordinal of the most significant bit in the bit field.\r
541 Range 0..63.\r
542 @param OrData The value to OR with the read value from the bit field.\r
543\r
544 @return The value written back to the MSR.\r
545\r
546**/\r
547UINT64\r
548EFIAPI\r
549AsmMsrBitFieldOr64 (\r
550 IN UINT32 Index,\r
551 IN UINTN StartBit,\r
552 IN UINTN EndBit,\r
553 IN UINT64 OrData\r
554 )\r
555{\r
556 return AsmWriteMsr64 (\r
557 Index,\r
558 BitFieldOr64 (AsmReadMsr64 (Index), StartBit, EndBit, OrData)\r
559 );\r
560}\r
561\r
562/**\r
563 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
564 result back to the bit field in the 64-bit MSR.\r
565\r
566 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
567 read result and the value specified by AndData, and writes the result to the\r
568 64-bit MSR specified by Index. The value written to the MSR is returned.\r
569 Extra left bits in AndData are stripped. The caller must either guarantee\r
570 that Index and the data written is valid, or the caller must set up exception\r
571 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 572 and x64.\r
e1f414b6 573\r
574 If StartBit is greater than 63, then ASSERT().\r
575 If EndBit is greater than 63, then ASSERT().\r
576 If EndBit is less than StartBit, then ASSERT().\r
577\r
578 @param Index The 32-bit MSR index to write.\r
579 @param StartBit The ordinal of the least significant bit in the bit field.\r
580 Range 0..63.\r
581 @param EndBit The ordinal of the most significant bit in the bit field.\r
582 Range 0..63.\r
583 @param AndData The value to AND with the read value from the bit field.\r
584\r
585 @return The value written back to the MSR.\r
586\r
587**/\r
588UINT64\r
589EFIAPI\r
590AsmMsrBitFieldAnd64 (\r
591 IN UINT32 Index,\r
592 IN UINTN StartBit,\r
593 IN UINTN EndBit,\r
594 IN UINT64 AndData\r
595 )\r
596{\r
597 return AsmWriteMsr64 (\r
598 Index,\r
599 BitFieldAnd64 (AsmReadMsr64 (Index), StartBit, EndBit, AndData)\r
600 );\r
601}\r
602\r
603/**\r
604 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
605 bitwise inclusive OR, and writes the result back to the bit field in the\r
606 64-bit MSR.\r
607\r
608 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by\r
609 a bitwise inclusive OR between the read result and the value specified by\r
610 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
611 value written to the MSR is returned. Extra left bits in both AndData and\r
612 OrData are stripped. The caller must either guarantee that Index and the data\r
613 written is valid, or the caller must set up exception handlers to catch the\r
030cd1a2 614 exceptions. This function is only available on IA-32 and x64.\r
e1f414b6 615\r
616 If StartBit is greater than 63, then ASSERT().\r
617 If EndBit is greater than 63, then ASSERT().\r
618 If EndBit is less than StartBit, then ASSERT().\r
619\r
620 @param Index The 32-bit MSR index to write.\r
621 @param StartBit The ordinal of the least significant bit in the bit field.\r
622 Range 0..63.\r
623 @param EndBit The ordinal of the most significant bit in the bit field.\r
624 Range 0..63.\r
625 @param AndData The value to AND with the read value from the bit field.\r
626 @param OrData The value to OR with the result of the AND operation.\r
627\r
628 @return The value written back to the MSR.\r
629\r
630**/\r
631UINT64\r
632EFIAPI\r
633AsmMsrBitFieldAndThenOr64 (\r
634 IN UINT32 Index,\r
635 IN UINTN StartBit,\r
636 IN UINTN EndBit,\r
637 IN UINT64 AndData,\r
638 IN UINT64 OrData\r
639 )\r
640{\r
641 return AsmWriteMsr64 (\r
642 Index,\r
643 BitFieldAndThenOr64 (\r
644 AsmReadMsr64 (Index),\r
645 StartBit,\r
646 EndBit,\r
647 AndData,\r
648 OrData\r
649 )\r
650 );\r
651}\r