From 4253a9dcdbfb025f8422129af78f2a2ab1bfee27 Mon Sep 17 00:00:00 2001 From: Maurice Ma Date: Tue, 23 Mar 2021 09:52:47 -0700 Subject: [PATCH] Fix Shell MTRR print issue Current MTRR lib assumes the MTRR number is always 10. Instead, this patch follows the IA manual to get the actual MTRR number through MTRR capability register. Signed-off-by: Maurice Ma --- BootloaderCommonPkg/Library/MtrrLib/MtrrLib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BootloaderCommonPkg/Library/MtrrLib/MtrrLib.c b/BootloaderCommonPkg/Library/MtrrLib/MtrrLib.c index 6d018df5..1524dace 100644 --- a/BootloaderCommonPkg/Library/MtrrLib/MtrrLib.c +++ b/BootloaderCommonPkg/Library/MtrrLib/MtrrLib.c @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include /** Convert the MTRR memory type to a readable str @@ -67,6 +68,7 @@ PrintMtrr ( UINT64 Mask; UINT64 Range; UINT64 Limit; + MSR_IA32_MTRRCAP_REGISTER MtrrCap; if (Str != NULL) { CONSOLE_PRINT_CONDITION (ConsoleOut, (DEBUG_INFO, "%a\n", Str)); @@ -85,7 +87,8 @@ PrintMtrr ( // Dump Variable MTRR registers CONSOLE_PRINT_CONDITION (ConsoleOut, (DEBUG_INFO, "Variable MTRRs\n")); - for (Index = 0; Index < 10; Index++) { + MtrrCap.Uint64 = AsmReadMsr64 (MSR_IA32_MTRRCAP); + for (Index = 0; Index < MtrrCap.Bits.VCNT; Index++) { BaseMsr = 0x200 + (Index * 2); MaskMsr = BaseMsr + 1;