]>
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 Returns the lower 32-bits of a Machine Specific Register(MSR).
20 Reads and returns the lower 32-bits of the MSR specified by Index.
21 No parameter checking is performed on Index, and some Index values may cause
22 CPU exceptions. The caller must either guarantee that Index is valid, or the
23 caller must set up exception handlers to catch the exceptions. This function
24 is only available on IA-32 and X64.
26 @param Index The 32-bit MSR index to read.
28 @return The lower 32 bits of the MSR identified by Index.
37 return (UINT32
)AsmReadMsr64 (Index
);
41 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
43 Writes the 32-bit value specified by Value to the MSR specified by Index. The
44 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
45 the MSR is returned. No parameter checking is performed on Index or Value,
46 and some of these may cause CPU exceptions. The caller must either guarantee
47 that Index and Value are valid, or the caller must establish proper exception
48 handlers. This function is only available on IA-32 and X64.
50 @param Index The 32-bit MSR index to write.
51 @param Value The 32-bit value to write to the MSR.
63 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
67 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
68 writes the result back to the 64-bit MSR.
70 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
71 between the lower 32-bits of the read result and the value specified by
72 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
73 32-bits of the value written to the MSR is returned. No parameter checking is
74 performed on Index or OrData, and some of these may cause CPU exceptions. The
75 caller must either guarantee that Index and OrData are valid, or the caller
76 must establish proper exception handlers. This function is only available on
79 @param Index The 32-bit MSR index to write.
80 @param OrData The value to OR with the read value from the MSR.
82 @return The lower 32-bit value written to the MSR.
92 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
96 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
97 the result back to the 64-bit MSR.
99 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
100 lower 32-bits of the read result and the value specified by AndData, and
101 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
102 the value written to the MSR is returned. No parameter checking is performed
103 on Index or AndData, and some of these may cause CPU exceptions. The caller
104 must either guarantee that Index and AndData are valid, or the caller must
105 establish proper exception handlers. This function is only available on IA-32
108 @param Index The 32-bit MSR index to write.
109 @param AndData The value to AND with the read value from the MSR.
111 @return The lower 32-bit value written to the MSR.
121 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
125 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
126 on the lower 32-bits, and writes the result back to the 64-bit MSR.
128 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
129 lower 32-bits of the read result and the value specified by AndData
130 preserving the upper 32-bits, performs a bitwise inclusive OR between the
131 result of the AND operation and the value specified by OrData, and writes the
132 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
133 written to the MSR is returned. No parameter checking is performed on Index,
134 AndData, or OrData, and some of these may cause CPU exceptions. The caller
135 must either guarantee that Index, AndData, and OrData are valid, or the
136 caller must establish proper exception handlers. This function is only
137 available on IA-32 and X64.
139 @param Index The 32-bit MSR index to write.
140 @param AndData The value to AND with the read value from the MSR.
141 @param OrData The value to OR with the result of the AND operation.
143 @return The lower 32-bit value written to the MSR.
154 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
158 Reads a bit field of an MSR.
160 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
161 specified by the StartBit and the EndBit. The value of the bit field is
162 returned. The caller must either guarantee that Index is valid, or the caller
163 must set up exception handlers to catch the exceptions. This function is only
164 available on IA-32 and X64.
166 If StartBit is greater than 31, then ASSERT().
167 If EndBit is greater than 31, then ASSERT().
168 If EndBit is less than StartBit, then ASSERT().
170 @param Index The 32-bit MSR index to read.
171 @param StartBit The ordinal of the least significant bit in the bit field.
173 @param EndBit The ordinal of the most significant bit in the bit field.
176 @return The bit field read from the MSR.
181 AsmMsrBitFieldRead32 (
187 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
191 Writes a bit field to an MSR.
193 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
194 field is specified by the StartBit and the EndBit. All other bits in the
195 destination MSR are preserved. The lower 32-bits of the MSR written is
196 returned. Extra left bits in Value are stripped. The caller must either
197 guarantee that Index and the data written is valid, or the caller must set up
198 exception handlers to catch the exceptions. This function is only available
201 If StartBit is greater than 31, then ASSERT().
202 If EndBit is greater than 31, then ASSERT().
203 If EndBit is less than StartBit, then ASSERT().
205 @param Index The 32-bit MSR index to write.
206 @param StartBit The ordinal of the least significant bit in the bit field.
208 @param EndBit The ordinal of the most significant bit in the bit field.
210 @param Value New value of the bit field.
212 @return The lower 32-bit of the value written to the MSR.
217 AsmMsrBitFieldWrite32 (
224 ASSERT (EndBit
< sizeof (Value
) * 8);
225 ASSERT (StartBit
<= EndBit
);
226 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
230 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
231 result back to the bit field in the 64-bit MSR.
233 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
234 between the read result and the value specified by OrData, and writes the
235 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
236 written to the MSR are returned. Extra left bits in OrData are stripped. The
237 caller must either guarantee that Index and the data written is valid, or
238 the caller must set up exception handlers to catch the exceptions. This
239 function is only available on IA-32 and X64.
241 If StartBit is greater than 31, then ASSERT().
242 If EndBit is greater than 31, then ASSERT().
243 If EndBit is less than StartBit, then ASSERT().
245 @param Index The 32-bit MSR index to write.
246 @param StartBit The ordinal of the least significant bit in the bit field.
248 @param EndBit The ordinal of the most significant bit in the bit field.
250 @param OrData The value to OR with the read value from the MSR.
252 @return The lower 32-bit of the value written to the MSR.
264 ASSERT (EndBit
< sizeof (OrData
) * 8);
265 ASSERT (StartBit
<= EndBit
);
266 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
270 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
271 result back to the bit field in the 64-bit MSR.
273 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
274 read result and the value specified by AndData, and writes the result to the
275 64-bit MSR specified by Index. The lower 32-bits of the value written to the
276 MSR are returned. Extra left bits in AndData are stripped. The caller must
277 either guarantee that Index and the data written is valid, or the caller must
278 set up exception handlers to catch the exceptions. This function is only
279 available on IA-32 and X64.
281 If StartBit is greater than 31, then ASSERT().
282 If EndBit is greater than 31, then ASSERT().
283 If EndBit is less than StartBit, then ASSERT().
285 @param Index The 32-bit MSR index to write.
286 @param StartBit The ordinal of the least significant bit in the bit field.
288 @param EndBit The ordinal of the most significant bit in the bit field.
290 @param AndData The value to AND with the read value from the MSR.
292 @return The lower 32-bit of the value written to the MSR.
297 AsmMsrBitFieldAnd32 (
304 ASSERT (EndBit
< sizeof (AndData
) * 8);
305 ASSERT (StartBit
<= EndBit
);
306 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
310 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
311 bitwise inclusive OR, and writes the result back to the bit field in the
314 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
315 bitwise inclusive OR between the read result and the value specified by
316 AndData, and writes the result to the 64-bit MSR specified by Index. The
317 lower 32-bits of the value written to the MSR are returned. Extra left bits
318 in both AndData and OrData are stripped. The caller must either guarantee
319 that Index and the data written is valid, or the caller must set up exception
320 handlers to catch the exceptions. This function is only available on IA-32
323 If StartBit is greater than 31, then ASSERT().
324 If EndBit is greater than 31, then ASSERT().
325 If EndBit is less than StartBit, then ASSERT().
327 @param Index The 32-bit MSR index to write.
328 @param StartBit The ordinal of the least significant bit in the bit field.
330 @param EndBit The ordinal of the most significant bit in the bit field.
332 @param AndData The value to AND with the read value from the MSR.
333 @param OrData The value to OR with the result of the AND operation.
335 @return The lower 32-bit of the value written to the MSR.
340 AsmMsrBitFieldAndThenOr32 (
348 ASSERT (EndBit
< sizeof (AndData
) * 8);
349 ASSERT (StartBit
<= EndBit
);
350 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
360 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
361 back to the 64-bit MSR.
363 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
364 between the read result and the value specified by OrData, and writes the
365 result to the 64-bit MSR specified by Index. The value written to the MSR is
366 returned. No parameter checking is performed on Index or OrData, and some of
367 these may cause CPU exceptions. The caller must either guarantee that Index
368 and OrData are valid, or the caller must establish proper exception handlers.
369 This function is only available on IA-32 and X64.
371 @param Index The 32-bit MSR index to write.
372 @param OrData The value to OR with the read value from the MSR.
374 @return The value written back to the MSR.
384 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
388 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
391 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
392 read result and the value specified by OrData, and writes the result to the
393 64-bit MSR specified by Index. The value written to the MSR is returned. No
394 parameter checking is performed on Index or OrData, and some of these may
395 cause CPU exceptions. The caller must either guarantee that Index and OrData
396 are valid, or the caller must establish proper exception handlers. This
397 function is only available on IA-32 and X64.
399 @param Index The 32-bit MSR index to write.
400 @param AndData The value to AND with the read value from the MSR.
402 @return The value written back to the MSR.
412 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
416 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
417 OR, and writes the result back to the 64-bit MSR.
419 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
420 result and the value specified by AndData, performs a bitwise inclusive OR
421 between the result of the AND operation and the value specified by OrData,
422 and writes the result to the 64-bit MSR specified by Index. The value written
423 to the MSR is returned. No parameter checking is performed on Index, AndData,
424 or OrData, and some of these may cause CPU exceptions. The caller must either
425 guarantee that Index, AndData, and OrData are valid, or the caller must
426 establish proper exception handlers. This function is only available on IA-32
429 @param Index The 32-bit MSR index to write.
430 @param AndData The value to AND with the read value from the MSR.
431 @param OrData The value to OR with the result of the AND operation.
433 @return The value written back to the MSR.
444 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
448 Reads a bit field of an MSR.
450 Reads the bit field in the 64-bit MSR. The bit field is specified by the
451 StartBit and the EndBit. The value of the bit field is returned. The caller
452 must either guarantee that Index is valid, or the caller must set up
453 exception handlers to catch the exceptions. This function is only available
456 If StartBit is greater than 63, then ASSERT().
457 If EndBit is greater than 63, then ASSERT().
458 If EndBit is less than StartBit, then ASSERT().
460 @param Index The 32-bit MSR index to read.
461 @param StartBit The ordinal of the least significant bit in the bit field.
463 @param EndBit The ordinal of the most significant bit in the bit field.
466 @return The value written back to the MSR.
471 AsmMsrBitFieldRead64 (
477 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
481 Writes a bit field to an MSR.
483 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
484 the StartBit and the EndBit. All other bits in the destination MSR are
485 preserved. The MSR written is returned. Extra left bits in Value are
486 stripped. The caller must either guarantee that Index and the data written is
487 valid, or the caller must set up exception handlers to catch the exceptions.
488 This function is only available on IA-32 and X64.
490 If StartBit is greater than 63, then ASSERT().
491 If EndBit is greater than 63, then ASSERT().
492 If EndBit is less than StartBit, then ASSERT().
494 @param Index The 32-bit MSR index to write.
495 @param StartBit The ordinal of the least significant bit in the bit field.
497 @param EndBit The ordinal of the most significant bit in the bit field.
499 @param Value New value of the bit field.
501 @return The value written back to the MSR.
506 AsmMsrBitFieldWrite64 (
513 return AsmWriteMsr64 (
515 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
520 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
521 writes the result back to the bit field in the 64-bit MSR.
523 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
524 between the read result and the value specified by OrData, and writes the
525 result to the 64-bit MSR specified by Index. The value written to the MSR is
526 returned. Extra left bits in OrData are stripped. The caller must either
527 guarantee that Index and the data written is valid, or the caller must set up
528 exception handlers to catch the exceptions. This function is only available
531 If StartBit is greater than 63, then ASSERT().
532 If EndBit is greater than 63, then ASSERT().
533 If EndBit is less than StartBit, then ASSERT().
535 @param Index The 32-bit MSR index to write.
536 @param StartBit The ordinal of the least significant bit in the bit field.
538 @param EndBit The ordinal of the most significant bit in the bit field.
540 @param OrData The value to OR with the read value from the bit field.
542 @return The value written back to the MSR.
554 return AsmWriteMsr64 (
556 BitFieldOr64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, OrData
)
561 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
562 result back to the bit field in the 64-bit MSR.
564 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
565 read result and the value specified by AndData, and writes the result to the
566 64-bit MSR specified by Index. The value written to the MSR is returned.
567 Extra left bits in AndData are stripped. The caller must either guarantee
568 that Index and the data written is valid, or the caller must set up exception
569 handlers to catch the exceptions. This function is only available on IA-32
572 If StartBit is greater than 63, then ASSERT().
573 If EndBit is greater than 63, then ASSERT().
574 If EndBit is less than StartBit, then ASSERT().
576 @param Index The 32-bit MSR index to write.
577 @param StartBit The ordinal of the least significant bit in the bit field.
579 @param EndBit The ordinal of the most significant bit in the bit field.
581 @param AndData The value to AND with the read value from the bit field.
583 @return The value written back to the MSR.
588 AsmMsrBitFieldAnd64 (
595 return AsmWriteMsr64 (
597 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
602 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
603 bitwise inclusive OR, and writes the result back to the bit field in the
606 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
607 a bitwise inclusive OR between the read result and the value specified by
608 AndData, and writes the result to the 64-bit MSR specified by Index. The
609 value written to the MSR is returned. Extra left bits in both AndData and
610 OrData are stripped. The caller must either guarantee that Index and the data
611 written is valid, or the caller must set up exception handlers to catch the
612 exceptions. This function is only available on IA-32 and X64.
614 If StartBit is greater than 63, then ASSERT().
615 If EndBit is greater than 63, then ASSERT().
616 If EndBit is less than StartBit, then ASSERT().
618 @param Index The 32-bit MSR index to write.
619 @param StartBit The ordinal of the least significant bit in the bit field.
621 @param EndBit The ordinal of the most significant bit in the bit field.
623 @param AndData The value to AND with the read value from the bit field.
624 @param OrData The value to OR with the result of the AND operation.
626 @return The value written back to the MSR.
631 AsmMsrBitFieldAndThenOr64 (
639 return AsmWriteMsr64 (
641 BitFieldAndThenOr64 (
642 AsmReadMsr64 (Index
),