/* Stalls the CPU for the number of nanoseconds specified by NanoSeconds. */
UINTN EFIAPI NanoSecondDelay(IN UINTN NanoSeconds)
/* Stalls the CPU for the number of nanoseconds specified by NanoSeconds. */
UINTN EFIAPI NanoSecondDelay(IN UINTN NanoSeconds)
{
  EFI_STATUS  Status;
  UINT64      HundredNanoseconds;
  UINTN       Index;
  if ((gTimerPeriod != 0) &&
      ((UINT64)NanoSeconds > gTimerPeriod) &&
      (EfiGetCurrentTpl () == TPL_APPLICATION))
  {
    HundredNanoseconds = DivU64x32 (NanoSeconds, 100);
    Status             = gBS->SetTimer (gTimerEvent, TimerRelative, HundredNanoseconds);
    ASSERT_EFI_ERROR (Status);
    Status = gBS->WaitForEvent (sizeof (gTimerEvent)/sizeof (EFI_EVENT), &gTimerEvent, &Index);
    ASSERT_EFI_ERROR (Status);
  } else {
    gEmuThunk->Sleep (NanoSeconds);
  }
  return NanoSeconds;
}