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.

84 lines
2.4 KiB

  1. // TITLE("Get Tick Count")
  2. //++
  3. //
  4. // Copyright (c) 1992 Microsoft Corporation
  5. // Copyright (c) 1992 Digital Equipment Corporation
  6. //
  7. // Module Name:
  8. //
  9. // gettick.s
  10. //
  11. // Abstract:
  12. //
  13. // This module contains the implementation for the get tick count
  14. // system service that returns the number of milliseconds since the
  15. // system was booted.
  16. //
  17. // Author:
  18. //
  19. // David N. Cutler (davec) 10-Sep-1992
  20. //
  21. // Environment:
  22. //
  23. // Kernel mode.
  24. //
  25. // Revision History:
  26. //
  27. // Thomas Van Baak (tvb) 5-Oct-1992
  28. //
  29. // Adapted for Alpha AXP.
  30. //
  31. //--
  32. #include "ksalpha.h"
  33. SBTTL("Get Tick Count")
  34. //++
  35. //
  36. // ULONG
  37. // NtGetTickCount (
  38. // VOID
  39. // )
  40. //
  41. // Routine Description:
  42. //
  43. // This function computes the number of milliseconds since the system
  44. // was booted. The computation is performed by multiplying the clock
  45. // interrupt count by a scaled fixed binary multiplier and then right
  46. // shifting the 64-bit result to extract the 32-bit millisecond count.
  47. //
  48. // The multiplier fraction is scaled by 24 bits. Thus for a 100 Hz clock
  49. // rate, there are 10 ticks per millisecond, and the multiplier is
  50. // 0x0a000000 (10 << 24). For a 128 Hz clock rate, there are 7.8125, or
  51. // 7 13/16 ticks per millisecond, and so the multiplier is 0x07d00000.
  52. //
  53. // This effectively replaces a (slow) divide instruction with a (fast)
  54. // multiply instruction. The multiplier value is only calculated once
  55. // based on the TimeIncrement value (clock tick interval in 100ns units).
  56. //
  57. // N.B. The tick count value wraps every 2^32 milliseconds (49.71 days).
  58. //
  59. // Arguments:
  60. //
  61. // None.
  62. //
  63. // Return Value:
  64. //
  65. // The number of milliseconds since the system was booted is returned
  66. // as the function value.
  67. //
  68. //--
  69. LEAF_ENTRY(NtGetTickCount)
  70. ldl t0, KeTickCount // get current tick count value
  71. zap t0, 0xf0, t0 // convert to unsigned longword
  72. ldl t1, ExpTickCountMultiplier // get tick count multiplier
  73. zap t1, 0xf0, t1 // convert to unsigned longword
  74. mulq t0, t1, v0 // compute 64-bit product
  75. srl v0, 24, v0 // shift off 24-bit fraction part
  76. addl v0, 0, v0 // keep 32-bit canonical ULONG integer part
  77. ret zero, (ra) // return
  78. .end NtGetTickCount