]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X86Msr.c
2 IA-32/x64 MSR functions.
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 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.
16 #include "BaseLibInternals.h"
20 Returns the lower 32-bits of a Machine Specific Register(MSR).
22 Reads and returns the lower 32-bits of the MSR specified by Index.
23 No parameter checking is performed on Index, and some Index values may cause
24 CPU exceptions. The caller must either guarantee that Index is valid, or the
25 caller must set up exception handlers to catch the exceptions. This function
26 is only available on IA-32 and x64.
28 @param Index The 32-bit MSR index to read.
30 @return The lower 32 bits of the MSR identified by Index.
39 return (UINT32
)AsmReadMsr64 (Index
);
43 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
44 The upper 32-bits of the MSR are set to zero.
46 Writes the 32-bit value specified by Value to the MSR specified by Index. The
47 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
48 the MSR is returned. No parameter checking is performed on Index or Value,
49 and some of these may cause CPU exceptions. The caller must either guarantee
50 that Index and Value are valid, or the caller must establish proper exception
51 handlers. This function is only available on IA-32 and x64.
53 @param Index The 32-bit MSR index to write.
54 @param Value The 32-bit value to write to the MSR.
66 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
70 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
71 writes the result back to the 64-bit MSR.
73 Reads the 64-bit MSR specified by Index, performs a bitwise OR
74 between the lower 32-bits of the read result and the value specified by
75 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
76 32-bits of the value written to the MSR is returned. No parameter checking is
77 performed on Index or OrData, and some of these may cause CPU exceptions. The
78 caller must either guarantee that Index and OrData are valid, or the caller
79 must establish proper exception handlers. This function is only available on
82 @param Index The 32-bit MSR index to write.
83 @param OrData The value to OR with the read value from the MSR.
85 @return The lower 32-bit value written to the MSR.
95 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
99 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
100 the result back to the 64-bit MSR.
102 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
103 lower 32-bits of the read result and the value specified by AndData, and
104 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
105 the value written to the MSR is returned. No parameter checking is performed
106 on Index or AndData, and some of these may cause CPU exceptions. The caller
107 must either guarantee that Index and AndData are valid, or the caller must
108 establish proper exception handlers. This function is only available on IA-32
111 @param Index The 32-bit MSR index to write.
112 @param AndData The value to AND with the read value from the MSR.
114 @return The lower 32-bit value written to the MSR.
124 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
128 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
129 on the lower 32-bits, and writes the result back to the 64-bit MSR.
131 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
132 lower 32-bits of the read result and the value specified by AndData
133 preserving the upper 32-bits, performs a bitwise OR between the
134 result of the AND operation and the value specified by OrData, and writes the
135 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
136 written to the MSR is returned. No parameter checking is performed on Index,
137 AndData, or OrData, and some of these may cause CPU exceptions. The caller
138 must either guarantee that Index, AndData, and OrData are valid, or the
139 caller must establish proper exception handlers. This function is only
140 available on IA-32 and x64.
142 @param Index The 32-bit MSR index to write.
143 @param AndData The value to AND with the read value from the MSR.
144 @param OrData The value to OR with the result of the AND operation.
146 @return The lower 32-bit value written to the MSR.
157 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
161 Reads a bit field of an MSR.
163 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
164 specified by the StartBit and the EndBit. The value of the bit field is
165 returned. The caller must either guarantee that Index is valid, or the caller
166 must set up exception handlers to catch the exceptions. This function is only
167 available on IA-32 and x64.
169 If StartBit is greater than 31, then ASSERT().
170 If EndBit is greater than 31, then ASSERT().
171 If EndBit is less than StartBit, then ASSERT().
173 @param Index The 32-bit MSR index to read.
174 @param StartBit The ordinal of the least significant bit in the bit field.
176 @param EndBit The ordinal of the most significant bit in the bit field.
179 @return The bit field read from the MSR.
184 AsmMsrBitFieldRead32 (
190 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
194 Writes a bit field to an MSR.
196 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
197 field is specified by the StartBit and the EndBit. All other bits in the
198 destination MSR are preserved. The lower 32-bits of the MSR written is
199 returned. The caller must either guarantee that Index and the data written
200 is valid, or the caller must set up exception handlers to catch the exceptions.
201 This function is only available on IA-32 and x64.
203 If StartBit is greater than 31, then ASSERT().
204 If EndBit is greater than 31, then ASSERT().
205 If EndBit is less than StartBit, then ASSERT().
206 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
208 @param Index The 32-bit MSR index to write.
209 @param StartBit The ordinal of the least significant bit in the bit field.
211 @param EndBit The ordinal of the most significant bit in the bit field.
213 @param Value The new value of the bit field.
215 @return The lower 32-bit of the value written to the MSR.
220 AsmMsrBitFieldWrite32 (
227 ASSERT (EndBit
< sizeof (Value
) * 8);
228 ASSERT (StartBit
<= EndBit
);
229 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
233 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
234 result back to the bit field in the 64-bit MSR.
236 Reads the 64-bit MSR specified by Index, performs a bitwise OR
237 between the read result and the value specified by OrData, and writes the
238 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
239 written to the MSR are returned. Extra left bits in OrData are stripped. The
240 caller must either guarantee that Index and the data written is valid, or
241 the caller must set up exception handlers to catch the exceptions. This
242 function is only available on IA-32 and x64.
244 If StartBit is greater than 31, then ASSERT().
245 If EndBit is greater than 31, then ASSERT().
246 If EndBit is less than StartBit, then ASSERT().
247 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
249 @param Index The 32-bit MSR index to write.
250 @param StartBit The ordinal of the least significant bit in the bit field.
252 @param EndBit The ordinal of the most significant bit in the bit field.
254 @param OrData The value to OR with the read value from the MSR.
256 @return The lower 32-bit of the value written to the MSR.
268 ASSERT (EndBit
< sizeof (OrData
) * 8);
269 ASSERT (StartBit
<= EndBit
);
270 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
274 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
275 result back to the bit field in the 64-bit MSR.
277 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
278 read result and the value specified by AndData, and writes the result to the
279 64-bit MSR specified by Index. The lower 32-bits of the value written to the
280 MSR are returned. Extra left bits in AndData are stripped. The caller must
281 either guarantee that Index and the data written is valid, or the caller must
282 set up exception handlers to catch the exceptions. This function is only
283 available on IA-32 and x64.
285 If StartBit is greater than 31, then ASSERT().
286 If EndBit is greater than 31, then ASSERT().
287 If EndBit is less than StartBit, then ASSERT().
288 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
290 @param Index The 32-bit MSR index to write.
291 @param StartBit The ordinal of the least significant bit in the bit field.
293 @param EndBit The ordinal of the most significant bit in the bit field.
295 @param AndData The value to AND with the read value from the MSR.
297 @return The lower 32-bit of the value written to the MSR.
302 AsmMsrBitFieldAnd32 (
309 ASSERT (EndBit
< sizeof (AndData
) * 8);
310 ASSERT (StartBit
<= EndBit
);
311 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
315 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
316 bitwise OR, and writes the result back to the bit field in the
319 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
320 bitwise OR between the read result and the value specified by
321 AndData, and writes the result to the 64-bit MSR specified by Index. The
322 lower 32-bits of the value written to the MSR are returned. Extra left bits
323 in both AndData and OrData are stripped. The caller must either guarantee
324 that Index and the data written is valid, or the caller must set up exception
325 handlers to catch the exceptions. This function is only available on IA-32
328 If StartBit is greater than 31, then ASSERT().
329 If EndBit is greater than 31, then ASSERT().
330 If EndBit is less than StartBit, then ASSERT().
331 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
332 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
334 @param Index The 32-bit MSR index to write.
335 @param StartBit The ordinal of the least significant bit in the bit field.
337 @param EndBit The ordinal of the most significant bit in the bit field.
339 @param AndData The value to AND with the read value from the MSR.
340 @param OrData The value to OR with the result of the AND operation.
342 @return The lower 32-bit of the value written to the MSR.
347 AsmMsrBitFieldAndThenOr32 (
355 ASSERT (EndBit
< sizeof (AndData
) * 8);
356 ASSERT (StartBit
<= EndBit
);
357 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
367 Reads a 64-bit MSR, performs a bitwise OR, and writes the result
368 back to the 64-bit MSR.
370 Reads the 64-bit MSR specified by Index, performs a bitwise OR
371 between the read result and the value specified by OrData, and writes the
372 result to the 64-bit MSR specified by Index. The value written to the MSR is
373 returned. No parameter checking is performed on Index or OrData, and some of
374 these may cause CPU exceptions. The caller must either guarantee that Index
375 and OrData are valid, or the caller must establish proper exception handlers.
376 This function is only available on IA-32 and x64.
378 @param Index The 32-bit MSR index to write.
379 @param OrData The value to OR with the read value from the MSR.
381 @return The value written back to the MSR.
391 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
395 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
398 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
399 read result and the value specified by OrData, and writes the result to the
400 64-bit MSR specified by Index. The value written to the MSR is returned. No
401 parameter checking is performed on Index or OrData, and some of these may
402 cause CPU exceptions. The caller must either guarantee that Index and OrData
403 are valid, or the caller must establish proper exception handlers. This
404 function is only available on IA-32 and x64.
406 @param Index The 32-bit MSR index to write.
407 @param AndData The value to AND with the read value from the MSR.
409 @return The value written back to the MSR.
419 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
423 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
424 OR, and writes the result back to the 64-bit MSR.
426 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
427 result and the value specified by AndData, performs a bitwise OR
428 between the result of the AND operation and the value specified by OrData,
429 and writes the result to the 64-bit MSR specified by Index. The value written
430 to the MSR is returned. No parameter checking is performed on Index, AndData,
431 or OrData, and some of these may cause CPU exceptions. The caller must either
432 guarantee that Index, AndData, and OrData are valid, or the caller must
433 establish proper exception handlers. This function is only available on IA-32
436 @param Index The 32-bit MSR index to write.
437 @param AndData The value to AND with the read value from the MSR.
438 @param OrData The value to OR with the result of the AND operation.
440 @return The value written back to the MSR.
451 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
455 Reads a bit field of an MSR.
457 Reads the bit field in the 64-bit MSR. The bit field is specified by the
458 StartBit and the EndBit. The value of the bit field is returned. The caller
459 must either guarantee that Index is valid, or the caller must set up
460 exception handlers to catch the exceptions. This function is only available
463 If StartBit is greater than 63, then ASSERT().
464 If EndBit is greater than 63, then ASSERT().
465 If EndBit is less than StartBit, then ASSERT().
467 @param Index The 32-bit MSR index to read.
468 @param StartBit The ordinal of the least significant bit in the bit field.
470 @param EndBit The ordinal of the most significant bit in the bit field.
473 @return The value read from the MSR.
478 AsmMsrBitFieldRead64 (
484 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
488 Writes a bit field to an MSR.
490 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
491 the StartBit and the EndBit. All other bits in the destination MSR are
492 preserved. The MSR written is returned. The caller must either guarantee
493 that Index and the data written is valid, or the caller must set up exception
494 handlers to catch the exceptions. 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().
499 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
501 @param Index The 32-bit MSR index to write.
502 @param StartBit The ordinal of the least significant bit in the bit field.
504 @param EndBit The ordinal of the most significant bit in the bit field.
506 @param Value The new value of the bit field.
508 @return The value written back to the MSR.
513 AsmMsrBitFieldWrite64 (
520 return AsmWriteMsr64 (
522 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
527 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
528 writes the result back to the bit field in the 64-bit MSR.
530 Reads the 64-bit MSR specified by Index, performs a bitwise OR
531 between the read result and the value specified by OrData, and writes the
532 result to the 64-bit MSR specified by Index. The value written to the MSR is
533 returned. Extra left bits in OrData are stripped. The caller must either
534 guarantee that Index and the data written is valid, or the caller must set up
535 exception handlers to catch the exceptions. This function is only available
538 If StartBit is greater than 63, then ASSERT().
539 If EndBit is greater than 63, then ASSERT().
540 If EndBit is less than StartBit, then ASSERT().
541 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
543 @param Index The 32-bit MSR index to write.
544 @param StartBit The ordinal of the least significant bit in the bit field.
546 @param EndBit The ordinal of the most significant bit in the bit field.
548 @param OrData The value to OR with the read value from the bit field.
550 @return The value written back to the MSR.
562 return AsmWriteMsr64 (
564 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
569 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
570 result back to the bit field in the 64-bit MSR.
572 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
573 read result and the value specified by AndData, and writes the result to the
574 64-bit MSR specified by Index. The value written to the MSR is returned.
575 Extra left bits in AndData are stripped. The caller must either guarantee
576 that Index and the data written is valid, or the caller must set up exception
577 handlers to catch the exceptions. This function is only available on IA-32
580 If StartBit is greater than 63, then ASSERT().
581 If EndBit is greater than 63, then ASSERT().
582 If EndBit is less than StartBit, then ASSERT().
583 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
585 @param Index The 32-bit MSR index to write.
586 @param StartBit The ordinal of the least significant bit in the bit field.
588 @param EndBit The ordinal of the most significant bit in the bit field.
590 @param AndData The value to AND with the read value from the bit field.
592 @return The value written back to the MSR.
597 AsmMsrBitFieldAnd64 (
604 return AsmWriteMsr64 (
606 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
611 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
612 bitwise OR, and writes the result back to the bit field in the
615 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
616 a bitwise OR between the read result and the value specified by
617 AndData, and writes the result to the 64-bit MSR specified by Index. The
618 value written to the MSR is returned. Extra left bits in both AndData and
619 OrData are stripped. The caller must either guarantee that Index and the data
620 written is valid, or the caller must set up exception handlers to catch the
621 exceptions. This function is only available on IA-32 and x64.
623 If StartBit is greater than 63, then ASSERT().
624 If EndBit is greater than 63, then ASSERT().
625 If EndBit is less than StartBit, then ASSERT().
626 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
627 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
629 @param Index The 32-bit MSR index to write.
630 @param StartBit The ordinal of the least significant bit in the bit field.
632 @param EndBit The ordinal of the most significant bit in the bit field.
634 @param AndData The value to AND with the read value from the bit field.
635 @param OrData The value to OR with the result of the AND operation.
637 @return The value written back to the MSR.
642 AsmMsrBitFieldAndThenOr64 (
650 return AsmWriteMsr64 (
652 BitFieldAndThenOr64 (
653 AsmReadMsr64 (Index
),