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.

111 lines
2.7 KiB

  1. // TITLE("Compute Timer Table Index")
  2. //++
  3. //
  4. // Copyright (c) 1993 Microsoft Corporation
  5. //
  6. // Module Name:
  7. //
  8. // timindex.s
  9. //
  10. // Abstract:
  11. //
  12. // This module implements the code necessary to compute the timer table
  13. // index for a timer.
  14. //
  15. // Author:
  16. //
  17. // David N. Cutler (davec) 17-May-1993
  18. // Joe Notarangelo 20-Jul-1993 (Alpha AXP version)
  19. //
  20. // Environment:
  21. //
  22. // Kernel mode only.
  23. //
  24. // Revision History:
  25. //
  26. //--
  27. #include "ksalpha.h"
  28. SBTTL("Compute Timer Table Index")
  29. //++
  30. //
  31. // ULONG
  32. // KiComputeTimerTableIndex (
  33. // IN LARGE_INTEGER Interval,
  34. // IN LARGE_INTEGER CurrentTime,
  35. // IN PKTIMER Timer
  36. // )
  37. //
  38. // Routine Description:
  39. //
  40. // This function computes the timer table index for the specified timer
  41. // object and stores the due time in the timer object.
  42. //
  43. // N.B. The interval parameter is guaranteed to be negative since it is
  44. // expressed as relative time.
  45. //
  46. // The formula for due time calculation is:
  47. //
  48. // Due Time = Current Time - Interval
  49. //
  50. // The formula for the index calculation is:
  51. //
  52. // Index = (Due Time / Maximum Time) & (Table Size - 1)
  53. //
  54. // The index division is performed using reciprocal multiplication.
  55. //
  56. // Arguments:
  57. //
  58. // Interval (a0) - Supplies the relative time at which the timer is
  59. // to expire.
  60. //
  61. // CurrentTime (a1) - Supplies the current interrupt time.
  62. //
  63. // Timer (a2) - Supplies a pointer to a dispatch object of type timer.
  64. //
  65. // Return Value:
  66. //
  67. // The time table index is returned as the function value and the due
  68. // time is stored in the timer object.
  69. //
  70. //--
  71. LEAF_ENTRY(KiComputeTimerTableIndex)
  72. //
  73. // Compute the due time and store in the timer object.
  74. //
  75. subq a1, a0, t0 // compute due time
  76. stq t0, TiDueTime(a2) // set due time of timer object
  77. //
  78. // Capture global values for magic divide, the reciprocal multiply value
  79. // and the shift count.
  80. //
  81. lda t2, KiTimeIncrementReciprocal // get address of reciprocal
  82. ldq t1, 0(t2) // get timer reciprocal for magic divide
  83. lda t2, KiTimeIncrementShiftCount // get address of shift count
  84. ldq_u t10, 0(t2) // read surrounding quadword
  85. extbl t10, t2, t10 // extract shift count for magic divide
  86. //
  87. // Do the reciprocal multiply and capture the upper 64 bits of the
  88. // 128 bit product with umulh instruction.
  89. //
  90. umulh t0, t1, t11 // t11 = upper 64 bits of product
  91. //
  92. // Right shift the result by the specified shift count and mask off extra
  93. // bits.
  94. //
  95. srl t11, t10, t0 // t0 = division result
  96. ldil t3, TIMER_TABLE_SIZE - 1 // get mask value
  97. and t0, t3, v0 // v0 = mask result
  98. ret zero, (ra) // return
  99. .end KiComputeTimerTableIndex