]>
git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Library/UnixBaseLib/X86Msr.c
2 IA-32/x64 MSR functions.
4 Copyright (c) 2006 - 2008, 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().
207 @param Index The 32-bit MSR index to write.
208 @param StartBit The ordinal of the least significant bit in the bit field.
210 @param EndBit The ordinal of the most significant bit in the bit field.
212 @param Value The new value of the bit field.
214 @return The lower 32-bit of the value written to the MSR.
219 AsmMsrBitFieldWrite32 (
226 ASSERT (EndBit
< sizeof (Value
) * 8);
227 ASSERT (StartBit
<= EndBit
);
228 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
232 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
233 result back to the bit field in the 64-bit MSR.
235 Reads the 64-bit MSR specified by Index, performs a bitwise OR
236 between the read result and the value specified by OrData, and writes the
237 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
238 written to the MSR are returned. Extra left bits in OrData are stripped. The
239 caller must either guarantee that Index and the data written is valid, or
240 the caller must set up exception handlers to catch the exceptions. This
241 function is only available on IA-32 and x64.
243 If StartBit is greater than 31, then ASSERT().
244 If EndBit is greater than 31, then ASSERT().
245 If EndBit is less than StartBit, then ASSERT().
247 @param Index The 32-bit MSR index to write.
248 @param StartBit The ordinal of the least significant bit in the bit field.
250 @param EndBit The ordinal of the most significant bit in the bit field.
252 @param OrData The value to OR with the read value from the MSR.
254 @return The lower 32-bit of the value written to the MSR.
266 ASSERT (EndBit
< sizeof (OrData
) * 8);
267 ASSERT (StartBit
<= EndBit
);
268 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
272 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
273 result back to the bit field in the 64-bit MSR.
275 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
276 read result and the value specified by AndData, and writes the result to the
277 64-bit MSR specified by Index. The lower 32-bits of the value written to the
278 MSR are returned. Extra left bits in AndData are stripped. The caller must
279 either guarantee that Index and the data written is valid, or the caller must
280 set up exception handlers to catch the exceptions. This function is only
281 available on IA-32 and x64.
283 If StartBit is greater than 31, then ASSERT().
284 If EndBit is greater than 31, then ASSERT().
285 If EndBit is less than StartBit, then ASSERT().
287 @param Index The 32-bit MSR index to write.
288 @param StartBit The ordinal of the least significant bit in the bit field.
290 @param EndBit The ordinal of the most significant bit in the bit field.
292 @param AndData The value to AND with the read value from the MSR.
294 @return The lower 32-bit of the value written to the MSR.
299 AsmMsrBitFieldAnd32 (
306 ASSERT (EndBit
< sizeof (AndData
) * 8);
307 ASSERT (StartBit
<= EndBit
);
308 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
312 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
313 bitwise OR, and writes the result back to the bit field in the
316 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
317 bitwise OR between the read result and the value specified by
318 AndData, and writes the result to the 64-bit MSR specified by Index. The
319 lower 32-bits of the value written to the MSR are returned. Extra left bits
320 in both AndData and OrData are stripped. The caller must either guarantee
321 that Index and the data written is valid, or the caller must set up exception
322 handlers to catch the exceptions. This function is only available on IA-32
325 If StartBit is greater than 31, then ASSERT().
326 If EndBit is greater than 31, then ASSERT().
327 If EndBit is less than StartBit, then ASSERT().
329 @param Index The 32-bit MSR index to write.
330 @param StartBit The ordinal of the least significant bit in the bit field.
332 @param EndBit The ordinal of the most significant bit in the bit field.
334 @param AndData The value to AND with the read value from the MSR.
335 @param OrData The value to OR with the result of the AND operation.
337 @return The lower 32-bit of the value written to the MSR.
342 AsmMsrBitFieldAndThenOr32 (
350 ASSERT (EndBit
< sizeof (AndData
) * 8);
351 ASSERT (StartBit
<= EndBit
);
352 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
362 Reads a 64-bit MSR, performs a bitwise OR, and writes the result
363 back to the 64-bit MSR.
365 Reads the 64-bit MSR specified by Index, performs a bitwise OR
366 between the read result and the value specified by OrData, and writes the
367 result to the 64-bit MSR specified by Index. The value written to the MSR is
368 returned. No parameter checking is performed on Index or OrData, and some of
369 these may cause CPU exceptions. The caller must either guarantee that Index
370 and OrData are valid, or the caller must establish proper exception handlers.
371 This function is only available on IA-32 and x64.
373 @param Index The 32-bit MSR index to write.
374 @param OrData The value to OR with the read value from the MSR.
376 @return The value written back to the MSR.
386 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
390 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
393 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
394 read result and the value specified by OrData, and writes the result to the
395 64-bit MSR specified by Index. The value written to the MSR is returned. No
396 parameter checking is performed on Index or OrData, and some of these may
397 cause CPU exceptions. The caller must either guarantee that Index and OrData
398 are valid, or the caller must establish proper exception handlers. This
399 function is only available on IA-32 and x64.
401 @param Index The 32-bit MSR index to write.
402 @param AndData The value to AND with the read value from the MSR.
404 @return The value written back to the MSR.
414 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
418 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
419 OR, and writes the result back to the 64-bit MSR.
421 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
422 result and the value specified by AndData, performs a bitwise OR
423 between the result of the AND operation and the value specified by OrData,
424 and writes the result to the 64-bit MSR specified by Index. The value written
425 to the MSR is returned. No parameter checking is performed on Index, AndData,
426 or OrData, and some of these may cause CPU exceptions. The caller must either
427 guarantee that Index, AndData, and OrData are valid, or the caller must
428 establish proper exception handlers. This function is only available on IA-32
431 @param Index The 32-bit MSR index to write.
432 @param AndData The value to AND with the read value from the MSR.
433 @param OrData The value to OR with the result of the AND operation.
435 @return The value written back to the MSR.
446 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
450 Reads a bit field of an MSR.
452 Reads the bit field in the 64-bit MSR. The bit field is specified by the
453 StartBit and the EndBit. The value of the bit field is returned. The caller
454 must either guarantee that Index is valid, or the caller must set up
455 exception handlers to catch the exceptions. This function is only available
458 If StartBit is greater than 63, then ASSERT().
459 If EndBit is greater than 63, then ASSERT().
460 If EndBit is less than StartBit, then ASSERT().
462 @param Index The 32-bit MSR index to read.
463 @param StartBit The ordinal of the least significant bit in the bit field.
465 @param EndBit The ordinal of the most significant bit in the bit field.
468 @return The value read from the MSR.
473 AsmMsrBitFieldRead64 (
479 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
483 Writes a bit field to an MSR.
485 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
486 the StartBit and the EndBit. All other bits in the destination MSR are
487 preserved. The MSR written is returned. The caller must either guarantee
488 that Index and the data written is valid, or the caller must set up exception
489 handlers to catch the exceptions. This function is only available on IA-32 and x64.
491 If StartBit is greater than 63, then ASSERT().
492 If EndBit is greater than 63, then ASSERT().
493 If EndBit is less than StartBit, then ASSERT().
495 @param Index The 32-bit MSR index to write.
496 @param StartBit The ordinal of the least significant bit in the bit field.
498 @param EndBit The ordinal of the most significant bit in the bit field.
500 @param Value The new value of the bit field.
502 @return The value written back to the MSR.
507 AsmMsrBitFieldWrite64 (
514 return AsmWriteMsr64 (
516 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
521 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
522 writes the result back to the bit field in the 64-bit MSR.
524 Reads the 64-bit MSR specified by Index, performs a bitwise OR
525 between the read result and the value specified by OrData, and writes the
526 result to the 64-bit MSR specified by Index. The value written to the MSR is
527 returned. Extra left bits in OrData are stripped. The caller must either
528 guarantee that Index and the data written is valid, or the caller must set up
529 exception handlers to catch the exceptions. This function is only available
532 If StartBit is greater than 63, then ASSERT().
533 If EndBit is greater than 63, then ASSERT().
534 If EndBit is less than StartBit, then ASSERT().
536 @param Index The 32-bit MSR index to write.
537 @param StartBit The ordinal of the least significant bit in the bit field.
539 @param EndBit The ordinal of the most significant bit in the bit field.
541 @param OrData The value to OR with the read value from the bit field.
543 @return The value written back to the MSR.
555 return AsmWriteMsr64 (
557 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
562 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
563 result back to the bit field in the 64-bit MSR.
565 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
566 read result and the value specified by AndData, and writes the result to the
567 64-bit MSR specified by Index. The value written to the MSR is returned.
568 Extra left bits in AndData are stripped. The caller must either guarantee
569 that Index and the data written is valid, or the caller must set up exception
570 handlers to catch the exceptions. This function is only available on IA-32
573 If StartBit is greater than 63, then ASSERT().
574 If EndBit is greater than 63, then ASSERT().
575 If EndBit is less than StartBit, then ASSERT().
577 @param Index The 32-bit MSR index to write.
578 @param StartBit The ordinal of the least significant bit in the bit field.
580 @param EndBit The ordinal of the most significant bit in the bit field.
582 @param AndData The value to AND with the read value from the bit field.
584 @return The value written back to the MSR.
589 AsmMsrBitFieldAnd64 (
596 return AsmWriteMsr64 (
598 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
603 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
604 bitwise OR, and writes the result back to the bit field in the
607 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
608 a bitwise OR between the read result and the value specified by
609 AndData, and writes the result to the 64-bit MSR specified by Index. The
610 value written to the MSR is returned. Extra left bits in both AndData and
611 OrData are stripped. The caller must either guarantee that Index and the data
612 written is valid, or the caller must set up exception handlers to catch the
613 exceptions. This function is only available on IA-32 and x64.
615 If StartBit is greater than 63, then ASSERT().
616 If EndBit is greater than 63, then ASSERT().
617 If EndBit is less than StartBit, then ASSERT().
619 @param Index The 32-bit MSR index to write.
620 @param StartBit The ordinal of the least significant bit in the bit field.
622 @param EndBit The ordinal of the most significant bit in the bit field.
624 @param AndData The value to AND with the read value from the bit field.
625 @param OrData The value to OR with the result of the AND operation.
627 @return The value written back to the MSR.
632 AsmMsrBitFieldAndThenOr64 (
640 return AsmWriteMsr64 (
642 BitFieldAndThenOr64 (
643 AsmReadMsr64 (Index
),