From 1553d073632e1307950f8648444071a0ec27759f Mon Sep 17 00:00:00 2001 From: vanjeff Date: Wed, 14 Jan 2009 03:05:45 +0000 Subject: [PATCH] fixed assumption 32bit Local Apic timer counter. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7266 6f19259b-4bc3-4df7-8a09-765794883524 --- .../SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf | 1 + MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf b/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf index c2a4199fb0..67a3c2cff8 100644 --- a/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf +++ b/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf @@ -49,6 +49,7 @@ [LibraryClasses.IA32, LibraryClasses.X64] PcdLib IoLib + DebugLib [LibraryClasses.IPF] PalLib diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c b/MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c index 72c684e236..aff51932f6 100644 --- a/MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c +++ b/MdePkg/Library/SecPeiDxeTimerLibCpu/X86TimerLib.c @@ -17,9 +17,10 @@ #include #include #include +#include #define APIC_LVTERR 0x370 -#define APIC_TMICT 0x380 +#define APIC_TMICT 0x380 #define APIC_TMCCT 0x390 #define APIC_TDCR 0x3e0 @@ -115,7 +116,9 @@ InternalX86Delay ( // Delay > 2^31 could not be handled by this function // Timer wrap-arounds are handled correctly by this function // - while (InternalX86GetTimerTick (ApicBase) - Ticks >= 0); + while (((UINT32)(InternalX86GetTimerTick (ApicBase) - Ticks) & GetPowerOfTwo32 ((MmioRead32 (ApicBase + APIC_TMICT)))) == 0) { + CpuPause (); + } } /** @@ -238,6 +241,10 @@ GetPerformanceCounterProperties ( if (StartValue != NULL) { *StartValue = MmioRead32 (ApicBase + APIC_TMICT); + // + // make sure StartValue is all 1s from High Bit + // + ASSERT ((*StartValue & (*StartValue + 1)) == 0); } if (EndValue != NULL) { -- 2.39.2