Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.2 KiB

  1. //++
  2. //
  3. // Module Name:
  4. //
  5. // gettick.s
  6. //
  7. // Abstract:
  8. //
  9. // This module implements the system service that returns the number
  10. // of milliseconds since the system was booted.
  11. //
  12. // Author:
  13. //
  14. // William K. Cheung (wcheung) 25-Sep-95
  15. //
  16. // Revision History:
  17. //
  18. // 02-Feb-96 Updated to EAS2.1
  19. //
  20. //--
  21. #include "ksia64.h"
  22. .file "gettick.s"
  23. .global KeTickCount
  24. .global ExpTickCountMultiplier
  25. //++
  26. //
  27. // ULONG
  28. // NtGetTickCount (
  29. // VOID
  30. // )
  31. //
  32. // Routine Description:
  33. //
  34. // This function computes the number of milliseconds since the system
  35. // was booted. The computation is performed by multiplying the clock
  36. // interrupt count by a scaled fixed binary multiplier and then right
  37. // shifting the 64-bit result to extract the 32-bit millisecond count.
  38. //
  39. // The multiplier fraction is scaled by 24 bits. Thus for a 100 Hz clock
  40. // rate, there are 10 ticks per millisecond, and the multiplier is
  41. // 0x0a000000 (10 << 24). For a 128 Hz clock rate, there are 7.8125, or
  42. // 7 13/16 ticks per millisecond, and so the multiplier is 0x07d00000.
  43. //
  44. // This effectively replaces a (slow) divide instruction with a (fast)
  45. // multiply instruction. The multiplier value is only calculated once
  46. // based on the TimeIncrement value (clock tick interval in 100ns units).
  47. //
  48. // N.B. The tick count value wraps every 2^32 milliseconds (49.71 days).
  49. //
  50. // Arguments:
  51. //
  52. // None.
  53. //
  54. // Return Value:
  55. //
  56. // The number of milliseconds since the system was booted is returned
  57. // as the function value.
  58. //
  59. //--
  60. LEAF_ENTRY(NtGetTickCount)
  61. //
  62. // load zero-extended operands
  63. //
  64. add t0 = @gprel(KeTickCount), gp
  65. add t1 = @gprel(ExpTickCountMultiplier), gp
  66. ;;
  67. ld4 t2 = [t0]
  68. ld4 t3 = [t1]
  69. ;;
  70. //
  71. // compute 64-bit product
  72. //
  73. setf.sig fs2 = t2
  74. setf.sig fs3 = t3
  75. ;;
  76. xmpy.lu fs1 = fs2, fs3
  77. ;;
  78. //
  79. // shift off 24-bit fraction part and
  80. // the 32-bit canonical ULONG integer part.
  81. //
  82. getf.sig v0 = fs1
  83. ;;
  84. extr.u v0 = v0, 24, 32
  85. br.ret.sptk.clr brp // return
  86. LEAF_EXIT(NtGetTickCount)