]>
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.
16 // Include common header file for this module.
18 #include <BaseLibInternals.h>
22 Returns the lower 32-bits of a Machine Specific Register(MSR).
24 Reads and returns the lower 32-bits of the MSR specified by Index.
25 No parameter checking is performed on Index, and some Index values may cause
26 CPU exceptions. The caller must either guarantee that Index is valid, or the
27 caller must set up exception handlers to catch the exceptions. This function
28 is only available on IA-32 and X64.
30 @param Index The 32-bit MSR index to read.
32 @return The lower 32 bits of the MSR identified by Index.
41 return (UINT32
)AsmReadMsr64 (Index
);
45 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
47 Writes the 32-bit value specified by Value to the MSR specified by Index. The
48 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
49 the MSR is returned. No parameter checking is performed on Index or Value,
50 and some of these may cause CPU exceptions. The caller must either guarantee
51 that Index and Value are valid, or the caller must establish proper exception
52 handlers. This function is only available on IA-32 and X64.
54 @param Index The 32-bit MSR index to write.
55 @param Value The 32-bit value to write to the MSR.
67 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
71 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
72 writes the result back to the 64-bit MSR.
74 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
75 between the lower 32-bits of the read result and the value specified by
76 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
77 32-bits of the value written to the MSR is returned. No parameter checking is
78 performed on Index or OrData, and some of these may cause CPU exceptions. The
79 caller must either guarantee that Index and OrData are valid, or the caller
80 must establish proper exception handlers. This function is only available on
83 @param Index The 32-bit MSR index to write.
84 @param OrData The value to OR with the read value from the MSR.
86 @return The lower 32-bit value written to the MSR.
96 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
100 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
101 the result back to the 64-bit MSR.
103 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
104 lower 32-bits of the read result and the value specified by AndData, and
105 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
106 the value written to the MSR is returned. No parameter checking is performed
107 on Index or AndData, and some of these may cause CPU exceptions. The caller
108 must either guarantee that Index and AndData are valid, or the caller must
109 establish proper exception handlers. This function is only available on IA-32
112 @param Index The 32-bit MSR index to write.
113 @param AndData The value to AND with the read value from the MSR.
115 @return The lower 32-bit value written to the MSR.
125 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
129 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
130 on the lower 32-bits, and writes the result back to the 64-bit MSR.
132 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
133 lower 32-bits of the read result and the value specified by AndData
134 preserving the upper 32-bits, performs a bitwise inclusive OR between the
135 result of the AND operation and the value specified by OrData, and writes the
136 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
137 written to the MSR is returned. No parameter checking is performed on Index,
138 AndData, or OrData, and some of these may cause CPU exceptions. The caller
139 must either guarantee that Index, AndData, and OrData are valid, or the
140 caller must establish proper exception handlers. This function is only
141 available on IA-32 and X64.
143 @param Index The 32-bit MSR index to write.
144 @param AndData The value to AND with the read value from the MSR.
145 @param OrData The value to OR with the result of the AND operation.
147 @return The lower 32-bit value written to the MSR.
158 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
162 Reads a bit field of an MSR.
164 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
165 specified by the StartBit and the EndBit. The value of the bit field is
166 returned. The caller must either guarantee that Index is valid, or the caller
167 must set up exception handlers to catch the exceptions. This function is only
168 available on IA-32 and X64.
170 If StartBit is greater than 31, then ASSERT().
171 If EndBit is greater than 31, then ASSERT().
172 If EndBit is less than StartBit, then ASSERT().
174 @param Index The 32-bit MSR index to read.
175 @param StartBit The ordinal of the least significant bit in the bit field.
177 @param EndBit The ordinal of the most significant bit in the bit field.
180 @return The bit field read from the MSR.
185 AsmMsrBitFieldRead32 (
191 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
195 Writes a bit field to an MSR.
197 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
198 field is specified by the StartBit and the EndBit. All other bits in the
199 destination MSR are preserved. The lower 32-bits of the MSR written is
200 returned. Extra left bits in Value are stripped. The caller must either
201 guarantee that Index and the data written is valid, or the caller must set up
202 exception handlers to catch the exceptions. This function is only available
205 If StartBit is greater than 31, then ASSERT().
206 If EndBit is greater than 31, then ASSERT().
207 If EndBit is less than StartBit, then ASSERT().
209 @param Index The 32-bit MSR index to write.
210 @param StartBit The ordinal of the least significant bit in the bit field.
212 @param EndBit The ordinal of the most significant bit in the bit field.
214 @param Value New value of the bit field.
216 @return The lower 32-bit of the value written to the MSR.
221 AsmMsrBitFieldWrite32 (
228 ASSERT (EndBit
< sizeof (Value
) * 8);
229 ASSERT (StartBit
<= EndBit
);
230 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
234 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
235 result back to the bit field in the 64-bit MSR.
237 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
238 between the read result and the value specified by OrData, and writes the
239 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
240 written to the MSR are returned. Extra left bits in OrData are stripped. The
241 caller must either guarantee that Index and the data written is valid, or
242 the caller must set up exception handlers to catch the exceptions. This
243 function is only available on IA-32 and X64.
245 If StartBit is greater than 31, then ASSERT().
246 If EndBit is greater than 31, then ASSERT().
247 If EndBit is less than StartBit, 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().
289 @param Index The 32-bit MSR index to write.
290 @param StartBit The ordinal of the least significant bit in the bit field.
292 @param EndBit The ordinal of the most significant bit in the bit field.
294 @param AndData The value to AND with the read value from the MSR.
296 @return The lower 32-bit of the value written to the MSR.
301 AsmMsrBitFieldAnd32 (
308 ASSERT (EndBit
< sizeof (AndData
) * 8);
309 ASSERT (StartBit
<= EndBit
);
310 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
314 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
315 bitwise inclusive OR, and writes the result back to the bit field in the
318 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
319 bitwise inclusive OR between the read result and the value specified by
320 AndData, and writes the result to the 64-bit MSR specified by Index. The
321 lower 32-bits of the value written to the MSR are returned. Extra left bits
322 in both AndData and OrData are stripped. The caller must either guarantee
323 that Index and the data written is valid, or the caller must set up exception
324 handlers to catch the exceptions. This function is only available on IA-32
327 If StartBit is greater than 31, then ASSERT().
328 If EndBit is greater than 31, then ASSERT().
329 If EndBit is less than StartBit, then ASSERT().
331 @param Index The 32-bit MSR index to write.
332 @param StartBit The ordinal of the least significant bit in the bit field.
334 @param EndBit The ordinal of the most significant bit in the bit field.
336 @param AndData The value to AND with the read value from the MSR.
337 @param OrData The value to OR with the result of the AND operation.
339 @return The lower 32-bit of the value written to the MSR.
344 AsmMsrBitFieldAndThenOr32 (
352 ASSERT (EndBit
< sizeof (AndData
) * 8);
353 ASSERT (StartBit
<= EndBit
);
354 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
364 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
365 back to the 64-bit MSR.
367 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
368 between the read result and the value specified by OrData, and writes the
369 result to the 64-bit MSR specified by Index. The value written to the MSR is
370 returned. No parameter checking is performed on Index or OrData, and some of
371 these may cause CPU exceptions. The caller must either guarantee that Index
372 and OrData are valid, or the caller must establish proper exception handlers.
373 This function is only available on IA-32 and X64.
375 @param Index The 32-bit MSR index to write.
376 @param OrData The value to OR with the read value from the MSR.
378 @return The value written back to the MSR.
388 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
392 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
395 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
396 read result and the value specified by OrData, and writes the result to the
397 64-bit MSR specified by Index. The value written to the MSR is returned. No
398 parameter checking is performed on Index or OrData, and some of these may
399 cause CPU exceptions. The caller must either guarantee that Index and OrData
400 are valid, or the caller must establish proper exception handlers. This
401 function is only available on IA-32 and X64.
403 @param Index The 32-bit MSR index to write.
404 @param AndData The value to AND with the read value from the MSR.
406 @return The value written back to the MSR.
416 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
420 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
421 OR, and writes the result back to the 64-bit MSR.
423 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
424 result and the value specified by AndData, performs a bitwise inclusive OR
425 between the result of the AND operation and the value specified by OrData,
426 and writes the result to the 64-bit MSR specified by Index. The value written
427 to the MSR is returned. No parameter checking is performed on Index, AndData,
428 or OrData, and some of these may cause CPU exceptions. The caller must either
429 guarantee that Index, AndData, and OrData are valid, or the caller must
430 establish proper exception handlers. This function is only available on IA-32
433 @param Index The 32-bit MSR index to write.
434 @param AndData The value to AND with the read value from the MSR.
435 @param OrData The value to OR with the result of the AND operation.
437 @return The value written back to the MSR.
448 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
452 Reads a bit field of an MSR.
454 Reads the bit field in the 64-bit MSR. The bit field is specified by the
455 StartBit and the EndBit. The value of the bit field is returned. The caller
456 must either guarantee that Index is valid, or the caller must set up
457 exception handlers to catch the exceptions. This function is only available
460 If StartBit is greater than 63, then ASSERT().
461 If EndBit is greater than 63, then ASSERT().
462 If EndBit is less than StartBit, then ASSERT().
464 @param Index The 32-bit MSR index to read.
465 @param StartBit The ordinal of the least significant bit in the bit field.
467 @param EndBit The ordinal of the most significant bit in the bit field.
470 @return The value written back to the MSR.
475 AsmMsrBitFieldRead64 (
481 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
485 Writes a bit field to an MSR.
487 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
488 the StartBit and the EndBit. All other bits in the destination MSR are
489 preserved. The MSR written is returned. Extra left bits in Value are
490 stripped. The caller must either guarantee that Index and the data written is
491 valid, or the caller must set up exception handlers to catch the exceptions.
492 This function is only available on IA-32 and X64.
494 If StartBit is greater than 63, then ASSERT().
495 If EndBit is greater than 63, then ASSERT().
496 If EndBit is less than StartBit, then ASSERT().
498 @param Index The 32-bit MSR index to write.
499 @param StartBit The ordinal of the least significant bit in the bit field.
501 @param EndBit The ordinal of the most significant bit in the bit field.
503 @param Value New value of the bit field.
505 @return The value written back to the MSR.
510 AsmMsrBitFieldWrite64 (
517 return AsmWriteMsr64 (
519 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
524 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
525 writes the result back to the bit field in the 64-bit MSR.
527 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
528 between the read result and the value specified by OrData, and writes the
529 result to the 64-bit MSR specified by Index. The value written to the MSR is
530 returned. Extra left bits in OrData are stripped. The caller must either
531 guarantee that Index and the data written is valid, or the caller must set up
532 exception handlers to catch the exceptions. This function is only available
535 If StartBit is greater than 63, then ASSERT().
536 If EndBit is greater than 63, then ASSERT().
537 If EndBit is less than StartBit, then ASSERT().
539 @param Index The 32-bit MSR index to write.
540 @param StartBit The ordinal of the least significant bit in the bit field.
542 @param EndBit The ordinal of the most significant bit in the bit field.
544 @param OrData The value to OR with the read value from the bit field.
546 @return The value written back to the MSR.
558 return AsmWriteMsr64 (
560 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
565 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
566 result back to the bit field in the 64-bit MSR.
568 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
569 read result and the value specified by AndData, and writes the result to the
570 64-bit MSR specified by Index. The value written to the MSR is returned.
571 Extra left bits in AndData are stripped. The caller must either guarantee
572 that Index and the data written is valid, or the caller must set up exception
573 handlers to catch the exceptions. This function is only available on IA-32
576 If StartBit is greater than 63, then ASSERT().
577 If EndBit is greater than 63, then ASSERT().
578 If EndBit is less than StartBit, then ASSERT().
580 @param Index The 32-bit MSR index to write.
581 @param StartBit The ordinal of the least significant bit in the bit field.
583 @param EndBit The ordinal of the most significant bit in the bit field.
585 @param AndData The value to AND with the read value from the bit field.
587 @return The value written back to the MSR.
592 AsmMsrBitFieldAnd64 (
599 return AsmWriteMsr64 (
601 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
606 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
607 bitwise inclusive OR, and writes the result back to the bit field in the
610 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
611 a bitwise inclusive OR between the read result and the value specified by
612 AndData, and writes the result to the 64-bit MSR specified by Index. The
613 value written to the MSR is returned. Extra left bits in both AndData and
614 OrData are stripped. The caller must either guarantee that Index and the data
615 written is valid, or the caller must set up exception handlers to catch the
616 exceptions. This function is only available on IA-32 and X64.
618 If StartBit is greater than 63, then ASSERT().
619 If EndBit is greater than 63, then ASSERT().
620 If EndBit is less than StartBit, then ASSERT().
622 @param Index The 32-bit MSR index to write.
623 @param StartBit The ordinal of the least significant bit in the bit field.
625 @param EndBit The ordinal of the most significant bit in the bit field.
627 @param AndData The value to AND with the read value from the bit field.
628 @param OrData The value to OR with the result of the AND operation.
630 @return The value written back to the MSR.
635 AsmMsrBitFieldAndThenOr64 (
643 return AsmWriteMsr64 (
645 BitFieldAndThenOr64 (
646 AsmReadMsr64 (Index
),