]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/x86Msr.c
2 IA-32/x64 MSR functions.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // Include common header file for this module.
20 #include <BaseLibInternals.h>
24 Returns the lower 32-bits of a Machine Specific Register(MSR).
26 Reads and returns the lower 32-bits of the MSR specified by Index.
27 No parameter checking is performed on Index, and some Index values may cause
28 CPU exceptions. The caller must either guarantee that Index is valid, or the
29 caller must set up exception handlers to catch the exceptions. This function
30 is only available on IA-32 and X64.
32 @param Index The 32-bit MSR index to read.
34 @return The lower 32 bits of the MSR identified by Index.
43 return (UINT32
)AsmReadMsr64 (Index
);
47 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
49 Writes the 32-bit value specified by Value to the MSR specified by Index. The
50 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
51 the MSR is returned. No parameter checking is performed on Index or Value,
52 and some of these may cause CPU exceptions. The caller must either guarantee
53 that Index and Value are valid, or the caller must establish proper exception
54 handlers. This function is only available on IA-32 and X64.
56 @param Index The 32-bit MSR index to write.
57 @param Value The 32-bit value to write to the MSR.
69 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
73 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
74 writes the result back to the 64-bit MSR.
76 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
77 between the lower 32-bits of the read result and the value specified by
78 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
79 32-bits of the value written to the MSR is returned. No parameter checking is
80 performed on Index or OrData, and some of these may cause CPU exceptions. The
81 caller must either guarantee that Index and OrData are valid, or the caller
82 must establish proper exception handlers. This function is only available on
85 @param Index The 32-bit MSR index to write.
86 @param OrData The value to OR with the read value from the MSR.
88 @return The lower 32-bit value written to the MSR.
98 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
102 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
103 the result back to the 64-bit MSR.
105 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
106 lower 32-bits of the read result and the value specified by AndData, and
107 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
108 the value written to the MSR is returned. No parameter checking is performed
109 on Index or AndData, and some of these may cause CPU exceptions. The caller
110 must either guarantee that Index and AndData are valid, or the caller must
111 establish proper exception handlers. This function is only available on IA-32
114 @param Index The 32-bit MSR index to write.
115 @param AndData The value to AND with the read value from the MSR.
117 @return The lower 32-bit value written to the MSR.
127 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
131 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
132 on the lower 32-bits, and writes the result back to the 64-bit MSR.
134 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
135 lower 32-bits of the read result and the value specified by AndData
136 preserving the upper 32-bits, performs a bitwise inclusive OR between the
137 result of the AND operation and the value specified by OrData, and writes the
138 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
139 written to the MSR is returned. No parameter checking is performed on Index,
140 AndData, or OrData, and some of these may cause CPU exceptions. The caller
141 must either guarantee that Index, AndData, and OrData are valid, or the
142 caller must establish proper exception handlers. This function is only
143 available on IA-32 and X64.
145 @param Index The 32-bit MSR index to write.
146 @param AndData The value to AND with the read value from the MSR.
147 @param OrData The value to OR with the result of the AND operation.
149 @return The lower 32-bit value written to the MSR.
160 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
164 Reads a bit field of an MSR.
166 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
167 specified by the StartBit and the EndBit. The value of the bit field is
168 returned. The caller must either guarantee that Index is valid, or the caller
169 must set up exception handlers to catch the exceptions. This function is only
170 available on IA-32 and X64.
172 If StartBit is greater than 31, then ASSERT().
173 If EndBit is greater than 31, then ASSERT().
174 If EndBit is less than StartBit, then ASSERT().
176 @param Index The 32-bit MSR index to read.
177 @param StartBit The ordinal of the least significant bit in the bit field.
179 @param EndBit The ordinal of the most significant bit in the bit field.
182 @return The bit field read from the MSR.
187 AsmMsrBitFieldRead32 (
193 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
197 Writes a bit field to an MSR.
199 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
200 field is specified by the StartBit and the EndBit. All other bits in the
201 destination MSR are preserved. The lower 32-bits of the MSR written is
202 returned. Extra left bits in Value are stripped. The caller must either
203 guarantee that Index and the data written is valid, or the caller must set up
204 exception handlers to catch the exceptions. This function is only available
207 If StartBit is greater than 31, then ASSERT().
208 If EndBit is greater than 31, then ASSERT().
209 If EndBit is less than StartBit, then ASSERT().
211 @param Index The 32-bit MSR index to write.
212 @param StartBit The ordinal of the least significant bit in the bit field.
214 @param EndBit The ordinal of the most significant bit in the bit field.
216 @param Value New value of the bit field.
218 @return The lower 32-bit of the value written to the MSR.
223 AsmMsrBitFieldWrite32 (
230 ASSERT (EndBit
< sizeof (Value
) * 8);
231 ASSERT (StartBit
<= EndBit
);
232 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
236 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
237 result back to the bit field in the 64-bit MSR.
239 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
240 between the read result and the value specified by OrData, and writes the
241 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
242 written to the MSR are returned. Extra left bits in OrData are stripped. The
243 caller must either guarantee that Index and the data written is valid, or
244 the caller must set up exception handlers to catch the exceptions. This
245 function is only available on IA-32 and X64.
247 If StartBit is greater than 31, then ASSERT().
248 If EndBit is greater than 31, then ASSERT().
249 If EndBit is less than StartBit, then ASSERT().
251 @param Index The 32-bit MSR index to write.
252 @param StartBit The ordinal of the least significant bit in the bit field.
254 @param EndBit The ordinal of the most significant bit in the bit field.
256 @param OrData The value to OR with the read value from the MSR.
258 @return The lower 32-bit of the value written to the MSR.
270 ASSERT (EndBit
< sizeof (OrData
) * 8);
271 ASSERT (StartBit
<= EndBit
);
272 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
276 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
277 result back to the bit field in the 64-bit MSR.
279 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
280 read result and the value specified by AndData, and writes the result to the
281 64-bit MSR specified by Index. The lower 32-bits of the value written to the
282 MSR are returned. Extra left bits in AndData are stripped. The caller must
283 either guarantee that Index and the data written is valid, or the caller must
284 set up exception handlers to catch the exceptions. This function is only
285 available on IA-32 and X64.
287 If StartBit is greater than 31, then ASSERT().
288 If EndBit is greater than 31, then ASSERT().
289 If EndBit is less than StartBit, then ASSERT().
291 @param Index The 32-bit MSR index to write.
292 @param StartBit The ordinal of the least significant bit in the bit field.
294 @param EndBit The ordinal of the most significant bit in the bit field.
296 @param AndData The value to AND with the read value from the MSR.
298 @return The lower 32-bit of the value written to the MSR.
303 AsmMsrBitFieldAnd32 (
310 ASSERT (EndBit
< sizeof (AndData
) * 8);
311 ASSERT (StartBit
<= EndBit
);
312 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
316 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
317 bitwise inclusive OR, and writes the result back to the bit field in the
320 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
321 bitwise inclusive OR between the read result and the value specified by
322 AndData, and writes the result to the 64-bit MSR specified by Index. The
323 lower 32-bits of the value written to the MSR are returned. Extra left bits
324 in both AndData and OrData are stripped. The caller must either guarantee
325 that Index and the data written is valid, or the caller must set up exception
326 handlers to catch the exceptions. This function is only available on IA-32
329 If StartBit is greater than 31, then ASSERT().
330 If EndBit is greater than 31, then ASSERT().
331 If EndBit is less than StartBit, then ASSERT().
333 @param Index The 32-bit MSR index to write.
334 @param StartBit The ordinal of the least significant bit in the bit field.
336 @param EndBit The ordinal of the most significant bit in the bit field.
338 @param AndData The value to AND with the read value from the MSR.
339 @param OrData The value to OR with the result of the AND operation.
341 @return The lower 32-bit of the value written to the MSR.
346 AsmMsrBitFieldAndThenOr32 (
354 ASSERT (EndBit
< sizeof (AndData
) * 8);
355 ASSERT (StartBit
<= EndBit
);
356 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
366 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
367 back to the 64-bit MSR.
369 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
370 between the read result and the value specified by OrData, and writes the
371 result to the 64-bit MSR specified by Index. The value written to the MSR is
372 returned. No parameter checking is performed on Index or OrData, and some of
373 these may cause CPU exceptions. The caller must either guarantee that Index
374 and OrData are valid, or the caller must establish proper exception handlers.
375 This function is only available on IA-32 and X64.
377 @param Index The 32-bit MSR index to write.
378 @param OrData The value to OR with the read value from the MSR.
380 @return The value written back to the MSR.
390 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
394 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
397 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
398 read result and the value specified by OrData, and writes the result to the
399 64-bit MSR specified by Index. The value written to the MSR is returned. No
400 parameter checking is performed on Index or OrData, and some of these may
401 cause CPU exceptions. The caller must either guarantee that Index and OrData
402 are valid, or the caller must establish proper exception handlers. This
403 function is only available on IA-32 and X64.
405 @param Index The 32-bit MSR index to write.
406 @param AndData The value to AND with the read value from the MSR.
408 @return The value written back to the MSR.
418 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
422 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
423 OR, and writes the result back to the 64-bit MSR.
425 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
426 result and the value specified by AndData, performs a bitwise inclusive OR
427 between the result of the AND operation and the value specified by OrData,
428 and writes the result to the 64-bit MSR specified by Index. The value written
429 to the MSR is returned. No parameter checking is performed on Index, AndData,
430 or OrData, and some of these may cause CPU exceptions. The caller must either
431 guarantee that Index, AndData, and OrData are valid, or the caller must
432 establish proper exception handlers. This function is only available on IA-32
435 @param Index The 32-bit MSR index to write.
436 @param AndData The value to AND with the read value from the MSR.
437 @param OrData The value to OR with the result of the AND operation.
439 @return The value written back to the MSR.
450 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
454 Reads a bit field of an MSR.
456 Reads the bit field in the 64-bit MSR. The bit field is specified by the
457 StartBit and the EndBit. The value of the bit field is returned. The caller
458 must either guarantee that Index is valid, or the caller must set up
459 exception handlers to catch the exceptions. This function is only available
462 If StartBit is greater than 63, then ASSERT().
463 If EndBit is greater than 63, then ASSERT().
464 If EndBit is less than StartBit, then ASSERT().
466 @param Index The 32-bit MSR index to read.
467 @param StartBit The ordinal of the least significant bit in the bit field.
469 @param EndBit The ordinal of the most significant bit in the bit field.
472 @return The value written back to the MSR.
477 AsmMsrBitFieldRead64 (
483 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
487 Writes a bit field to an MSR.
489 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
490 the StartBit and the EndBit. All other bits in the destination MSR are
491 preserved. The MSR written is returned. Extra left bits in Value are
492 stripped. The caller must either guarantee that Index and the data written is
493 valid, or the caller must set up exception handlers to catch the exceptions.
494 This function is only available on IA-32 and X64.
496 If StartBit is greater than 63, then ASSERT().
497 If EndBit is greater than 63, then ASSERT().
498 If EndBit is less than StartBit, then ASSERT().
500 @param Index The 32-bit MSR index to write.
501 @param StartBit The ordinal of the least significant bit in the bit field.
503 @param EndBit The ordinal of the most significant bit in the bit field.
505 @param Value New value of the bit field.
507 @return The value written back to the MSR.
512 AsmMsrBitFieldWrite64 (
519 return AsmWriteMsr64 (
521 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
526 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
527 writes the result back to the bit field in the 64-bit MSR.
529 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
530 between the read result and the value specified by OrData, and writes the
531 result to the 64-bit MSR specified by Index. The value written to the MSR is
532 returned. Extra left bits in OrData are stripped. The caller must either
533 guarantee that Index and the data written is valid, or the caller must set up
534 exception handlers to catch the exceptions. This function is only available
537 If StartBit is greater than 63, then ASSERT().
538 If EndBit is greater than 63, then ASSERT().
539 If EndBit is less than StartBit, then ASSERT().
541 @param Index The 32-bit MSR index to write.
542 @param StartBit The ordinal of the least significant bit in the bit field.
544 @param EndBit The ordinal of the most significant bit in the bit field.
546 @param OrData The value to OR with the read value from the bit field.
548 @return The value written back to the MSR.
560 return AsmWriteMsr64 (
562 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
567 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
568 result back to the bit field in the 64-bit MSR.
570 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
571 read result and the value specified by AndData, and writes the result to the
572 64-bit MSR specified by Index. The value written to the MSR is returned.
573 Extra left bits in AndData are stripped. The caller must either guarantee
574 that Index and the data written is valid, or the caller must set up exception
575 handlers to catch the exceptions. This function is only available on IA-32
578 If StartBit is greater than 63, then ASSERT().
579 If EndBit is greater than 63, then ASSERT().
580 If EndBit is less than StartBit, then ASSERT().
582 @param Index The 32-bit MSR index to write.
583 @param StartBit The ordinal of the least significant bit in the bit field.
585 @param EndBit The ordinal of the most significant bit in the bit field.
587 @param AndData The value to AND with the read value from the bit field.
589 @return The value written back to the MSR.
594 AsmMsrBitFieldAnd64 (
601 return AsmWriteMsr64 (
603 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
608 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
609 bitwise inclusive OR, and writes the result back to the bit field in the
612 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
613 a bitwise inclusive OR between the read result and the value specified by
614 AndData, and writes the result to the 64-bit MSR specified by Index. The
615 value written to the MSR is returned. Extra left bits in both AndData and
616 OrData are stripped. The caller must either guarantee that Index and the data
617 written is valid, or the caller must set up exception handlers to catch the
618 exceptions. This function is only available on IA-32 and X64.
620 If StartBit is greater than 63, then ASSERT().
621 If EndBit is greater than 63, then ASSERT().
622 If EndBit is less than StartBit, then ASSERT().
624 @param Index The 32-bit MSR index to write.
625 @param StartBit The ordinal of the least significant bit in the bit field.
627 @param EndBit The ordinal of the most significant bit in the bit field.
629 @param AndData The value to AND with the read value from the bit field.
630 @param OrData The value to OR with the result of the AND operation.
632 @return The value written back to the MSR.
637 AsmMsrBitFieldAndThenOr64 (
645 return AsmWriteMsr64 (
647 BitFieldAndThenOr64 (
648 AsmReadMsr64 (Index
),