]>
git.proxmox.com Git - mirror_edk2.git/blob - x86Msr.c
a9ad2425ae62b4183a954c7f6a84f001cf4b5bd7
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 "CommonHeader.h"
23 Returns the lower 32-bits of a Machine Specific Register(MSR).
25 Reads and returns the lower 32-bits of the MSR specified by Index.
26 No parameter checking is performed on Index, and some Index values may cause
27 CPU exceptions. The caller must either guarantee that Index is valid, or the
28 caller must set up exception handlers to catch the exceptions. This function
29 is only available on IA-32 and X64.
31 @param Index The 32-bit MSR index to read.
33 @return The lower 32 bits of the MSR identified by Index.
42 return (UINT32
)AsmReadMsr64 (Index
);
46 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
48 Writes the 32-bit value specified by Value to the MSR specified by Index. The
49 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
50 the MSR is returned. No parameter checking is performed on Index or Value,
51 and some of these may cause CPU exceptions. The caller must either guarantee
52 that Index and Value are valid, or the caller must establish proper exception
53 handlers. This function is only available on IA-32 and X64.
55 @param Index The 32-bit MSR index to write.
56 @param Value The 32-bit value to write to the MSR.
68 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
72 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
73 writes the result back to the 64-bit MSR.
75 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
76 between the lower 32-bits of the read result and the value specified by
77 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
78 32-bits of the value written to the MSR is returned. No parameter checking is
79 performed on Index or OrData, and some of these may cause CPU exceptions. The
80 caller must either guarantee that Index and OrData are valid, or the caller
81 must establish proper exception handlers. This function is only available on
84 @param Index The 32-bit MSR index to write.
85 @param OrData The value to OR with the read value from the MSR.
87 @return The lower 32-bit value written to the MSR.
97 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
101 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
102 the result back to the 64-bit MSR.
104 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
105 lower 32-bits of the read result and the value specified by AndData, and
106 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
107 the value written to the MSR is returned. No parameter checking is performed
108 on Index or AndData, and some of these may cause CPU exceptions. The caller
109 must either guarantee that Index and AndData are valid, or the caller must
110 establish proper exception handlers. This function is only available on IA-32
113 @param Index The 32-bit MSR index to write.
114 @param AndData The value to AND with the read value from the MSR.
116 @return The lower 32-bit value written to the MSR.
126 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
130 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
131 on the lower 32-bits, and writes the result back to the 64-bit MSR.
133 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
134 lower 32-bits of the read result and the value specified by AndData
135 preserving the upper 32-bits, performs a bitwise inclusive OR between the
136 result of the AND operation and the value specified by OrData, and writes the
137 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
138 written to the MSR is returned. No parameter checking is performed on Index,
139 AndData, or OrData, and some of these may cause CPU exceptions. The caller
140 must either guarantee that Index, AndData, and OrData are valid, or the
141 caller must establish proper exception handlers. This function is only
142 available on IA-32 and X64.
144 @param Index The 32-bit MSR index to write.
145 @param AndData The value to AND with the read value from the MSR.
146 @param OrData The value to OR with the result of the AND operation.
148 @return The lower 32-bit value written to the MSR.
159 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
163 Reads a bit field of an MSR.
165 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
166 specified by the StartBit and the EndBit. The value of the bit field is
167 returned. The caller must either guarantee that Index is valid, or the caller
168 must set up exception handlers to catch the exceptions. This function is only
169 available on IA-32 and X64.
171 If StartBit is greater than 31, then ASSERT().
172 If EndBit is greater than 31, then ASSERT().
173 If EndBit is less than StartBit, then ASSERT().
175 @param Index The 32-bit MSR index to read.
176 @param StartBit The ordinal of the least significant bit in the bit field.
178 @param EndBit The ordinal of the most significant bit in the bit field.
181 @return The bit field read from the MSR.
186 AsmMsrBitFieldRead32 (
192 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
196 Writes a bit field to an MSR.
198 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
199 field is specified by the StartBit and the EndBit. All other bits in the
200 destination MSR are preserved. The lower 32-bits of the MSR written is
201 returned. Extra left bits in Value are stripped. The caller must either
202 guarantee that Index and the data written is valid, or the caller must set up
203 exception handlers to catch the exceptions. This function is only available
206 If StartBit is greater than 31, then ASSERT().
207 If EndBit is greater than 31, then ASSERT().
208 If EndBit is less than StartBit, then ASSERT().
210 @param Index The 32-bit MSR index to write.
211 @param StartBit The ordinal of the least significant bit in the bit field.
213 @param EndBit The ordinal of the most significant bit in the bit field.
215 @param Value New value of the bit field.
217 @return The lower 32-bit of the value written to the MSR.
222 AsmMsrBitFieldWrite32 (
229 ASSERT (EndBit
< sizeof (Value
) * 8);
230 ASSERT (StartBit
<= EndBit
);
231 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
235 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
236 result back to the bit field in the 64-bit MSR.
238 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
239 between the read result and the value specified by OrData, and writes the
240 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
241 written to the MSR are returned. Extra left bits in OrData are stripped. The
242 caller must either guarantee that Index and the data written is valid, or
243 the caller must set up exception handlers to catch the exceptions. This
244 function is only available on IA-32 and X64.
246 If StartBit is greater than 31, then ASSERT().
247 If EndBit is greater than 31, then ASSERT().
248 If EndBit is less than StartBit, then ASSERT().
250 @param Index The 32-bit MSR index to write.
251 @param StartBit The ordinal of the least significant bit in the bit field.
253 @param EndBit The ordinal of the most significant bit in the bit field.
255 @param OrData The value to OR with the read value from the MSR.
257 @return The lower 32-bit of the value written to the MSR.
269 ASSERT (EndBit
< sizeof (OrData
) * 8);
270 ASSERT (StartBit
<= EndBit
);
271 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
275 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
276 result back to the bit field in the 64-bit MSR.
278 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
279 read result and the value specified by AndData, and writes the result to the
280 64-bit MSR specified by Index. The lower 32-bits of the value written to the
281 MSR are returned. Extra left bits in AndData are stripped. The caller must
282 either guarantee that Index and the data written is valid, or the caller must
283 set up exception handlers to catch the exceptions. This function is only
284 available on IA-32 and X64.
286 If StartBit is greater than 31, then ASSERT().
287 If EndBit is greater than 31, then ASSERT().
288 If EndBit is less than StartBit, 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 inclusive 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 inclusive 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().
332 @param Index The 32-bit MSR index to write.
333 @param StartBit The ordinal of the least significant bit in the bit field.
335 @param EndBit The ordinal of the most significant bit in the bit field.
337 @param AndData The value to AND with the read value from the MSR.
338 @param OrData The value to OR with the result of the AND operation.
340 @return The lower 32-bit of the value written to the MSR.
345 AsmMsrBitFieldAndThenOr32 (
353 ASSERT (EndBit
< sizeof (AndData
) * 8);
354 ASSERT (StartBit
<= EndBit
);
355 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
365 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
366 back to the 64-bit MSR.
368 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
369 between the read result and the value specified by OrData, and writes the
370 result to the 64-bit MSR specified by Index. The value written to the MSR is
371 returned. No parameter checking is performed on Index or OrData, and some of
372 these may cause CPU exceptions. The caller must either guarantee that Index
373 and OrData are valid, or the caller must establish proper exception handlers.
374 This function is only available on IA-32 and X64.
376 @param Index The 32-bit MSR index to write.
377 @param OrData The value to OR with the read value from the MSR.
379 @return The value written back to the MSR.
389 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
393 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
396 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
397 read result and the value specified by OrData, and writes the result to the
398 64-bit MSR specified by Index. The value written to the MSR is returned. No
399 parameter checking is performed on Index or OrData, and some of these may
400 cause CPU exceptions. The caller must either guarantee that Index and OrData
401 are valid, or the caller must establish proper exception handlers. This
402 function is only available on IA-32 and X64.
404 @param Index The 32-bit MSR index to write.
405 @param AndData The value to AND with the read value from the MSR.
407 @return The value written back to the MSR.
417 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
421 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
422 OR, and writes the result back to the 64-bit MSR.
424 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
425 result and the value specified by AndData, performs a bitwise inclusive OR
426 between the result of the AND operation and the value specified by OrData,
427 and writes the result to the 64-bit MSR specified by Index. The value written
428 to the MSR is returned. No parameter checking is performed on Index, AndData,
429 or OrData, and some of these may cause CPU exceptions. The caller must either
430 guarantee that Index, AndData, and OrData are valid, or the caller must
431 establish proper exception handlers. This function is only available on IA-32
434 @param Index The 32-bit MSR index to write.
435 @param AndData The value to AND with the read value from the MSR.
436 @param OrData The value to OR with the result of the AND operation.
438 @return The value written back to the MSR.
449 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
453 Reads a bit field of an MSR.
455 Reads the bit field in the 64-bit MSR. The bit field is specified by the
456 StartBit and the EndBit. The value of the bit field is returned. The caller
457 must either guarantee that Index is valid, or the caller must set up
458 exception handlers to catch the exceptions. This function is only available
461 If StartBit is greater than 63, then ASSERT().
462 If EndBit is greater than 63, then ASSERT().
463 If EndBit is less than StartBit, then ASSERT().
465 @param Index The 32-bit MSR index to read.
466 @param StartBit The ordinal of the least significant bit in the bit field.
468 @param EndBit The ordinal of the most significant bit in the bit field.
471 @return The value written back to the MSR.
476 AsmMsrBitFieldRead64 (
482 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
486 Writes a bit field to an MSR.
488 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
489 the StartBit and the EndBit. All other bits in the destination MSR are
490 preserved. The MSR written is returned. Extra left bits in Value are
491 stripped. The caller must either guarantee that Index and the data written is
492 valid, or the caller must set up exception handlers to catch the exceptions.
493 This function is only available on IA-32 and X64.
495 If StartBit is greater than 63, then ASSERT().
496 If EndBit is greater than 63, then ASSERT().
497 If EndBit is less than StartBit, then ASSERT().
499 @param Index The 32-bit MSR index to write.
500 @param StartBit The ordinal of the least significant bit in the bit field.
502 @param EndBit The ordinal of the most significant bit in the bit field.
504 @param Value New value of the bit field.
506 @return The value written back to the MSR.
511 AsmMsrBitFieldWrite64 (
518 return AsmWriteMsr64 (
520 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
525 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
526 writes the result back to the bit field in the 64-bit MSR.
528 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
529 between the read result and the value specified by OrData, and writes the
530 result to the 64-bit MSR specified by Index. The value written to the MSR is
531 returned. Extra left bits in OrData are stripped. The caller must either
532 guarantee that Index and the data written is valid, or the caller must set up
533 exception handlers to catch the exceptions. This function is only available
536 If StartBit is greater than 63, then ASSERT().
537 If EndBit is greater than 63, then ASSERT().
538 If EndBit is less than StartBit, then ASSERT().
540 @param Index The 32-bit MSR index to write.
541 @param StartBit The ordinal of the least significant bit in the bit field.
543 @param EndBit The ordinal of the most significant bit in the bit field.
545 @param OrData The value to OR with the read value from the bit field.
547 @return The value written back to the MSR.
559 return AsmWriteMsr64 (
561 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
566 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
567 result back to the bit field in the 64-bit MSR.
569 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
570 read result and the value specified by AndData, and writes the result to the
571 64-bit MSR specified by Index. The value written to the MSR is returned.
572 Extra left bits in AndData are stripped. The caller must either guarantee
573 that Index and the data written is valid, or the caller must set up exception
574 handlers to catch the exceptions. This function is only available on IA-32
577 If StartBit is greater than 63, then ASSERT().
578 If EndBit is greater than 63, then ASSERT().
579 If EndBit is less than StartBit, then ASSERT().
581 @param Index The 32-bit MSR index to write.
582 @param StartBit The ordinal of the least significant bit in the bit field.
584 @param EndBit The ordinal of the most significant bit in the bit field.
586 @param AndData The value to AND with the read value from the bit field.
588 @return The value written back to the MSR.
593 AsmMsrBitFieldAnd64 (
600 return AsmWriteMsr64 (
602 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
607 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
608 bitwise inclusive OR, and writes the result back to the bit field in the
611 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
612 a bitwise inclusive OR between the read result and the value specified by
613 AndData, and writes the result to the 64-bit MSR specified by Index. The
614 value written to the MSR is returned. Extra left bits in both AndData and
615 OrData are stripped. The caller must either guarantee that Index and the data
616 written is valid, or the caller must set up exception handlers to catch the
617 exceptions. This function is only available on IA-32 and X64.
619 If StartBit is greater than 63, then ASSERT().
620 If EndBit is greater than 63, then ASSERT().
621 If EndBit is less than StartBit, then ASSERT().
623 @param Index The 32-bit MSR index to write.
624 @param StartBit The ordinal of the least significant bit in the bit field.
626 @param EndBit The ordinal of the most significant bit in the bit field.
628 @param AndData The value to AND with the read value from the bit field.
629 @param OrData The value to OR with the result of the AND operation.
631 @return The value written back to the MSR.
636 AsmMsrBitFieldAndThenOr64 (
644 return AsmWriteMsr64 (
646 BitFieldAndThenOr64 (
647 AsmReadMsr64 (Index
),