Leaked source code of windows server 2003
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.

124 lines
2.8 KiB

  1. // TITLE("Compute Timer Table Index")
  2. //++
  3. //
  4. // Module Name:
  5. //
  6. // timindex.s
  7. //
  8. // Abstract:
  9. //
  10. // This module implements the code necessary to compute the timer table
  11. // index for a timer.
  12. //
  13. // Author:
  14. //
  15. // David N. Cutler (davec) 17-May-1993
  16. // Joe Notarangelo 20-Jul-1993 (Alpha AXP version)
  17. //
  18. // Environment:
  19. //
  20. // Kernel mode only.
  21. //
  22. // Revision History:
  23. //
  24. //--
  25. #include "ksia64.h"
  26. SBTTL("Compute Timer Table Index")
  27. //++
  28. //
  29. // ULONG
  30. // KiComputeTimerTableIndex (
  31. // IN LARGE_INTEGER Interval,
  32. // IN LARGE_INTEGER CurrentTime,
  33. // IN PKTIMER Timer
  34. // )
  35. //
  36. // Routine Description:
  37. //
  38. // This function computes the timer table index for the specified timer
  39. // object and stores the due time in the timer object.
  40. //
  41. // N.B. The interval parameter is guaranteed to be negative since it is
  42. // expressed as relative time.
  43. //
  44. // The formula for due time calculation is:
  45. //
  46. // Due Time = Current Time - Interval
  47. //
  48. // The formula for the index calculation is:
  49. //
  50. // Index = (Due Time / Maximum Time) & (Table Size - 1)
  51. //
  52. // The index division is performed using reciprocal multiplication.
  53. //
  54. // Arguments:
  55. //
  56. // Interval (a0) - Supplies the relative time at which the timer is
  57. // to expire.
  58. //
  59. // CurrentTime (a1) - Supplies the current interrupt time.
  60. //
  61. // Timer (a2) - Supplies a pointer to a dispatch object of type timer.
  62. //
  63. // Return Value:
  64. //
  65. // The time table index is returned as the function value and the due
  66. // time is stored in the timer object.
  67. //
  68. //--
  69. .global KiTimeIncrementReciprocal
  70. .global KiTimeIncrementShiftCount
  71. LEAF_ENTRY(KiComputeTimerTableIndex)
  72. add t2 = @gprel(KiTimeIncrementReciprocal), gp
  73. add t3 = @gprel(KiTimeIncrementShiftCount), gp
  74. sub t4 = a1, a0
  75. ;;
  76. //
  77. // Capture global values for magic divide, the reciprocal multiply value
  78. // and the shift count.
  79. //
  80. ld8.nta t2 = [t2]
  81. ld1.nta t3 = [t3]
  82. add t0 = TiDueTime, a2
  83. ;;
  84. //
  85. // Compute the due time and store in the timer object.
  86. //
  87. setf.sig ft1 = t2
  88. setf.sig ft0 = t4
  89. ;;
  90. //
  91. // Do the reciprocal multiply and capture the upper 64 bits of the
  92. // 128 bit product with xma.h instruction.
  93. //
  94. st8 [t0] = t4
  95. xma.hu ft2 = ft0, ft1, f0
  96. ;;
  97. getf.sig v0 = ft2
  98. movl t4 = TIMER_TABLE_SIZE - 1
  99. ;;
  100. //
  101. // Right shift the result by the specified shift count and mask off extra
  102. // bits.
  103. //
  104. shr v0 = v0, t3
  105. ;;
  106. and v0 = v0, t4
  107. LEAF_RETURN
  108. LEAF_EXIT(KiComputeTimerTableIndex)