]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/X86Msr.c
ea95be584632316e3ee8b42fc250deb873534559
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 IA-32/x64 specific functions.
23 #include "BaseLibInternals.h"
26 Returns the lower 32-bits of a Machine Specific Register(MSR).
28 Reads and returns the lower 32-bits of the MSR specified by Index.
29 No parameter checking is performed on Index, and some Index values may cause
30 CPU exceptions. The caller must either guarantee that Index is valid, or the
31 caller must set up exception handlers to catch the exceptions. This function
32 is only available on IA-32 and X64.
34 @param Index The 32-bit MSR index to read.
36 @return The lower 32 bits of the MSR identified by Index.
45 return (UINT32
)AsmReadMsr64 (Index
);
49 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
51 Writes the 32-bit value specified by Value to the MSR specified by Index. The
52 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
53 the MSR is returned. No parameter checking is performed on Index or Value,
54 and some of these may cause CPU exceptions. The caller must either guarantee
55 that Index and Value are valid, or the caller must establish proper exception
56 handlers. This function is only available on IA-32 and X64.
58 @param Index The 32-bit MSR index to write.
59 @param Value The 32-bit value to write to the MSR.
71 return (UINT32
)AsmWriteMsr64 (Index
, Value
);
75 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
76 writes the result back to the 64-bit MSR.
78 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
79 between the lower 32-bits of the read result and the value specified by
80 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
81 32-bits of the value written to the MSR is returned. No parameter checking is
82 performed on Index or OrData, and some of these may cause CPU exceptions. The
83 caller must either guarantee that Index and OrData are valid, or the caller
84 must establish proper exception handlers. This function is only available on
87 @param Index The 32-bit MSR index to write.
88 @param OrData The value to OR with the read value from the MSR.
90 @return The lower 32-bit value written to the MSR.
100 return (UINT32
)AsmMsrOr64 (Index
, OrData
);
104 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
105 the result back to the 64-bit MSR.
107 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
108 lower 32-bits of the read result and the value specified by AndData, and
109 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
110 the value written to the MSR is returned. No parameter checking is performed
111 on Index or AndData, and some of these may cause CPU exceptions. The caller
112 must either guarantee that Index and AndData are valid, or the caller must
113 establish proper exception handlers. This function is only available on IA-32
116 @param Index The 32-bit MSR index to write.
117 @param AndData The value to AND with the read value from the MSR.
119 @return The lower 32-bit value written to the MSR.
129 return (UINT32
)AsmMsrAnd64 (Index
, AndData
);
133 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
134 on the lower 32-bits, and writes the result back to the 64-bit MSR.
136 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
137 lower 32-bits of the read result and the value specified by AndData
138 preserving the upper 32-bits, performs a bitwise inclusive OR between the
139 result of the AND operation and the value specified by OrData, and writes the
140 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
141 written to the MSR is returned. No parameter checking is performed on Index,
142 AndData, or OrData, and some of these may cause CPU exceptions. The caller
143 must either guarantee that Index, AndData, and OrData are valid, or the
144 caller must establish proper exception handlers. This function is only
145 available on IA-32 and X64.
147 @param Index The 32-bit MSR index to write.
148 @param AndData The value to AND with the read value from the MSR.
149 @param OrData The value to OR with the result of the AND operation.
151 @return The lower 32-bit value written to the MSR.
162 return (UINT32
)AsmMsrAndThenOr64 (Index
, AndData
, OrData
);
166 Reads a bit field of an MSR.
168 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
169 specified by the StartBit and the EndBit. The value of the bit field is
170 returned. The caller must either guarantee that Index is valid, or the caller
171 must set up exception handlers to catch the exceptions. This function is only
172 available on IA-32 and X64.
174 If StartBit is greater than 31, then ASSERT().
175 If EndBit is greater than 31, then ASSERT().
176 If EndBit is less than StartBit, then ASSERT().
178 @param Index The 32-bit MSR index to read.
179 @param StartBit The ordinal of the least significant bit in the bit field.
181 @param EndBit The ordinal of the most significant bit in the bit field.
184 @return The bit field read from the MSR.
189 AsmMsrBitFieldRead32 (
195 return BitFieldRead32 (AsmReadMsr32 (Index
), StartBit
, EndBit
);
199 Writes a bit field to an MSR.
201 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
202 field is specified by the StartBit and the EndBit. All other bits in the
203 destination MSR are preserved. The lower 32-bits of the MSR written is
204 returned. Extra left bits in Value are stripped. The caller must either
205 guarantee that Index and the data written is valid, or the caller must set up
206 exception handlers to catch the exceptions. This function is only available
209 If StartBit is greater than 31, then ASSERT().
210 If EndBit is greater than 31, then ASSERT().
211 If EndBit is less than StartBit, then ASSERT().
213 @param Index The 32-bit MSR index to write.
214 @param StartBit The ordinal of the least significant bit in the bit field.
216 @param EndBit The ordinal of the most significant bit in the bit field.
218 @param Value New value of the bit field.
220 @return The lower 32-bit of the value written to the MSR.
225 AsmMsrBitFieldWrite32 (
232 ASSERT (EndBit
< sizeof (Value
) * 8);
233 ASSERT (StartBit
<= EndBit
);
234 return (UINT32
)AsmMsrBitFieldWrite64 (Index
, StartBit
, EndBit
, Value
);
238 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
239 result back to the bit field in the 64-bit MSR.
241 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
242 between the read result and the value specified by OrData, and writes the
243 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
244 written to the MSR are returned. Extra left bits in OrData are stripped. The
245 caller must either guarantee that Index and the data written is valid, or
246 the caller must set up exception handlers to catch the exceptions. This
247 function is only available on IA-32 and X64.
249 If StartBit is greater than 31, then ASSERT().
250 If EndBit is greater than 31, then ASSERT().
251 If EndBit is less than StartBit, then ASSERT().
253 @param Index The 32-bit MSR index to write.
254 @param StartBit The ordinal of the least significant bit in the bit field.
256 @param EndBit The ordinal of the most significant bit in the bit field.
258 @param OrData The value to OR with the read value from the MSR.
260 @return The lower 32-bit of the value written to the MSR.
272 ASSERT (EndBit
< sizeof (OrData
) * 8);
273 ASSERT (StartBit
<= EndBit
);
274 return (UINT32
)AsmMsrBitFieldOr64 (Index
, StartBit
, EndBit
, OrData
);
278 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
279 result back to the bit field in the 64-bit MSR.
281 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
282 read result and the value specified by AndData, and writes the result to the
283 64-bit MSR specified by Index. The lower 32-bits of the value written to the
284 MSR are returned. Extra left bits in AndData are stripped. The caller must
285 either guarantee that Index and the data written is valid, or the caller must
286 set up exception handlers to catch the exceptions. This function is only
287 available on IA-32 and X64.
289 If StartBit is greater than 31, then ASSERT().
290 If EndBit is greater than 31, then ASSERT().
291 If EndBit is less than StartBit, then ASSERT().
293 @param Index The 32-bit MSR index to write.
294 @param StartBit The ordinal of the least significant bit in the bit field.
296 @param EndBit The ordinal of the most significant bit in the bit field.
298 @param AndData The value to AND with the read value from the MSR.
300 @return The lower 32-bit of the value written to the MSR.
305 AsmMsrBitFieldAnd32 (
312 ASSERT (EndBit
< sizeof (AndData
) * 8);
313 ASSERT (StartBit
<= EndBit
);
314 return (UINT32
)AsmMsrBitFieldAnd64 (Index
, StartBit
, EndBit
, AndData
);
318 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
319 bitwise inclusive OR, and writes the result back to the bit field in the
322 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
323 bitwise inclusive OR between the read result and the value specified by
324 AndData, and writes the result to the 64-bit MSR specified by Index. The
325 lower 32-bits of the value written to the MSR are returned. Extra left bits
326 in both AndData and OrData are stripped. The caller must either guarantee
327 that Index and the data written is valid, or the caller must set up exception
328 handlers to catch the exceptions. This function is only available on IA-32
331 If StartBit is greater than 31, then ASSERT().
332 If EndBit is greater than 31, then ASSERT().
333 If EndBit is less than StartBit, then ASSERT().
335 @param Index The 32-bit MSR index to write.
336 @param StartBit The ordinal of the least significant bit in the bit field.
338 @param EndBit The ordinal of the most significant bit in the bit field.
340 @param AndData The value to AND with the read value from the MSR.
341 @param OrData The value to OR with the result of the AND operation.
343 @return The lower 32-bit of the value written to the MSR.
348 AsmMsrBitFieldAndThenOr32 (
356 ASSERT (EndBit
< sizeof (AndData
) * 8);
357 ASSERT (StartBit
<= EndBit
);
358 return (UINT32
)AsmMsrBitFieldAndThenOr64 (
368 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
369 back to the 64-bit MSR.
371 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
372 between the read result and the value specified by OrData, and writes the
373 result to the 64-bit MSR specified by Index. The value written to the MSR is
374 returned. No parameter checking is performed on Index or OrData, and some of
375 these may cause CPU exceptions. The caller must either guarantee that Index
376 and OrData are valid, or the caller must establish proper exception handlers.
377 This function is only available on IA-32 and X64.
379 @param Index The 32-bit MSR index to write.
380 @param OrData The value to OR with the read value from the MSR.
382 @return The value written back to the MSR.
392 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) | OrData
);
396 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
399 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
400 read result and the value specified by OrData, and writes the result to the
401 64-bit MSR specified by Index. The value written to the MSR is returned. No
402 parameter checking is performed on Index or OrData, and some of these may
403 cause CPU exceptions. The caller must either guarantee that Index and OrData
404 are valid, or the caller must establish proper exception handlers. This
405 function is only available on IA-32 and X64.
407 @param Index The 32-bit MSR index to write.
408 @param AndData The value to AND with the read value from the MSR.
410 @return The value written back to the MSR.
420 return AsmWriteMsr64 (Index
, AsmReadMsr64 (Index
) & AndData
);
424 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
425 OR, and writes the result back to the 64-bit MSR.
427 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
428 result and the value specified by AndData, performs a bitwise inclusive OR
429 between the result of the AND operation and the value specified by OrData,
430 and writes the result to the 64-bit MSR specified by Index. The value written
431 to the MSR is returned. No parameter checking is performed on Index, AndData,
432 or OrData, and some of these may cause CPU exceptions. The caller must either
433 guarantee that Index, AndData, and OrData are valid, or the caller must
434 establish proper exception handlers. This function is only available on IA-32
437 @param Index The 32-bit MSR index to write.
438 @param AndData The value to AND with the read value from the MSR.
439 @param OrData The value to OR with the result of the AND operation.
441 @return The value written back to the MSR.
452 return AsmWriteMsr64 (Index
, (AsmReadMsr64 (Index
) & AndData
) | OrData
);
456 Reads a bit field of an MSR.
458 Reads the bit field in the 64-bit MSR. The bit field is specified by the
459 StartBit and the EndBit. The value of the bit field is returned. The caller
460 must either guarantee that Index is valid, or the caller must set up
461 exception handlers to catch the exceptions. This function is only available
464 If StartBit is greater than 63, then ASSERT().
465 If EndBit is greater than 63, then ASSERT().
466 If EndBit is less than StartBit, then ASSERT().
468 @param Index The 32-bit MSR index to read.
469 @param StartBit The ordinal of the least significant bit in the bit field.
471 @param EndBit The ordinal of the most significant bit in the bit field.
474 @return The value written back to the MSR.
479 AsmMsrBitFieldRead64 (
485 return BitFieldRead64 (AsmReadMsr64 (Index
), StartBit
, EndBit
);
489 Writes a bit field to an MSR.
491 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
492 the StartBit and the EndBit. All other bits in the destination MSR are
493 preserved. The MSR written is returned. Extra left bits in Value are
494 stripped. The caller must either guarantee that Index and the data written is
495 valid, or the caller must set up exception handlers to catch the exceptions.
496 This function is only available on IA-32 and X64.
498 If StartBit is greater than 63, then ASSERT().
499 If EndBit is greater than 63, then ASSERT().
500 If EndBit is less than StartBit, then ASSERT().
502 @param Index The 32-bit MSR index to write.
503 @param StartBit The ordinal of the least significant bit in the bit field.
505 @param EndBit The ordinal of the most significant bit in the bit field.
507 @param Value New value of the bit field.
509 @return The value written back to the MSR.
514 AsmMsrBitFieldWrite64 (
521 return AsmWriteMsr64 (
523 BitFieldWrite64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, Value
)
528 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
529 writes the result back to the bit field in the 64-bit MSR.
531 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
532 between the read result and the value specified by OrData, and writes the
533 result to the 64-bit MSR specified by Index. The value written to the MSR is
534 returned. Extra left bits in OrData are stripped. The caller must either
535 guarantee that Index and the data written is valid, or the caller must set up
536 exception handlers to catch the exceptions. This function is only available
539 If StartBit is greater than 63, then ASSERT().
540 If EndBit is greater than 63, then ASSERT().
541 If EndBit is less than StartBit, 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().
584 @param Index The 32-bit MSR index to write.
585 @param StartBit The ordinal of the least significant bit in the bit field.
587 @param EndBit The ordinal of the most significant bit in the bit field.
589 @param AndData The value to AND with the read value from the bit field.
591 @return The value written back to the MSR.
596 AsmMsrBitFieldAnd64 (
603 return AsmWriteMsr64 (
605 BitFieldAnd64 (AsmReadMsr64 (Index
), StartBit
, EndBit
, AndData
)
610 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
611 bitwise inclusive OR, and writes the result back to the bit field in the
614 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
615 a bitwise inclusive OR between the read result and the value specified by
616 AndData, and writes the result to the 64-bit MSR specified by Index. The
617 value written to the MSR is returned. Extra left bits in both AndData and
618 OrData are stripped. The caller must either guarantee that Index and the data
619 written is valid, or the caller must set up exception handlers to catch the
620 exceptions. This function is only available on IA-32 and X64.
622 If StartBit is greater than 63, then ASSERT().
623 If EndBit is greater than 63, then ASSERT().
624 If EndBit is less than StartBit, then ASSERT().
626 @param Index The 32-bit MSR index to write.
627 @param StartBit The ordinal of the least significant bit in the bit field.
629 @param EndBit The ordinal of the most significant bit in the bit field.
631 @param AndData The value to AND with the read value from the bit field.
632 @param OrData The value to OR with the result of the AND operation.
634 @return The value written back to the MSR.
639 AsmMsrBitFieldAndThenOr64 (
647 return AsmWriteMsr64 (
649 BitFieldAndThenOr64 (
650 AsmReadMsr64 (Index
),