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