#include <Library/BaseLib.h>\r
#include <Library/IoLib.h>\r
#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
\r
#define APIC_LVTERR 0x370\r
-#define APIC_TMICT 0x380 \r
+#define APIC_TMICT 0x380\r
#define APIC_TMCCT 0x390\r
#define APIC_TDCR 0x3e0\r
\r
// Delay > 2^31 could not be handled by this function\r
// Timer wrap-arounds are handled correctly by this function\r
//\r
- while (InternalX86GetTimerTick (ApicBase) - Ticks >= 0);\r
+ while (((UINT32)(InternalX86GetTimerTick (ApicBase) - Ticks) & GetPowerOfTwo32 ((MmioRead32 (ApicBase + APIC_TMICT)))) == 0) {\r
+ CpuPause ();\r
+ }\r
}\r
\r
/**\r
\r
if (StartValue != NULL) {\r
*StartValue = MmioRead32 (ApicBase + APIC_TMICT);\r
+ //\r
+ // make sure StartValue is all 1s from High Bit\r
+ //\r
+ ASSERT ((*StartValue & (*StartValue + 1)) == 0);\r
}\r
\r
if (EndValue != NULL) {\r