tbitimer.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * tbitimer.S
  3. *
  4. * Copyright (C) 2001, 2002, 2007, 2012 Imagination Technologies.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU General Public License version 2 as published by the
  8. * Free Software Foundation.
  9. *
  10. * TBI timer support routines and data values
  11. */
  12. .file "tbitimer.S"
  13. /*
  14. * Get data structures and defines from the main C header
  15. */
  16. #include <asm/tbx.h>
  17. .data
  18. .balign 8
  19. .global ___TBITimeB
  20. .type ___TBITimeB,object
  21. ___TBITimeB:
  22. .quad 0 /* Background 'lost' ticks */
  23. .size ___TBITimeB,.-___TBITimeB
  24. .data
  25. .balign 8
  26. .global ___TBITimeI
  27. .type ___TBITimeI,object
  28. ___TBITimeI:
  29. .quad 0 /* Interrupt 'lost' ticks */
  30. .size ___TBITimeI,.-___TBITimeI
  31. .data
  32. .balign 8
  33. .global ___TBITimes
  34. .type ___TBITimes,object
  35. ___TBITimes:
  36. .long ___TBITimeB /* Table of 'lost' tick values */
  37. .long ___TBITimeI
  38. .size ___TBITimes,.-___TBITimes
  39. /*
  40. * Flag bits for control of ___TBITimeCore
  41. */
  42. #define TIMER_SET_BIT 1
  43. #define TIMER_ADD_BIT 2
  44. /*
  45. * Initialise or stop timer support
  46. *
  47. * Register Usage: D1Ar1 holds Id, D1Ar2 is initial delay or 0
  48. * D0FrT is used to call ___TBITimeCore
  49. * D0Re0 is used for the result which is TXSTAT_TIMER_BIT
  50. * D0Ar4, D1Ar5, D0Ar6 are all used as scratch
  51. * Other registers are those set by ___TBITimeCore
  52. * A0.3 is assumed to point at ___TBITime(I/B)
  53. */
  54. .text
  55. .balign 4
  56. .global ___TBITimerCtrl
  57. .type ___TBITimerCtrl,function
  58. ___TBITimerCtrl:
  59. MOV D1Ar5,#TIMER_SET_BIT /* Timer SET request */
  60. MOVT D0FrT,#HI(___TBITimeCore) /* Get timer core reg values */
  61. CALL D0FrT,#LO(___TBITimeCore) /* and perform register update */
  62. NEGS D0Ar6,D0Ar2 /* Set flags from time-stamp */
  63. ASR D1Ar5,D0Ar6,#31 /* Sign extend D0Ar6 into D1Ar5 */
  64. SETLNZ [A0.3],D0Ar6,D1Ar5 /* ___TBITime(B/I)=-Start if enable */
  65. MOV PC,D1RtP /* Return */
  66. .size ___TBITimerCtrl,.-___TBITimerCtrl
  67. /*
  68. * Return ___TBITimeStamp value
  69. *
  70. * Register Usage: D1Ar1 holds Id
  71. * D0FrT is used to call ___TBITimeCore
  72. * D0Re0, D1Re0 is used for the result
  73. * D1Ar3, D0Ar4, D1Ar5
  74. * Other registers are those set by ___TBITimeCore
  75. * D0Ar6 is assumed to be the timer value read
  76. * A0.3 is assumed to point at ___TBITime(I/B)
  77. */
  78. .text
  79. .balign 4
  80. .global ___TBITimeStamp
  81. .type ___TBITimeStamp,function
  82. ___TBITimeStamp:
  83. MOV D1Ar5,#0 /* Timer GET request */
  84. MOVT D0FrT,#HI(___TBITimeCore) /* Get timer core reg values */
  85. CALL D0FrT,#LO(___TBITimeCore) /* with no register update */
  86. ADDS D0Re0,D0Ar4,D0Ar6 /* Add current time value */
  87. ADD D1Re0,D1Ar3,D1Ar5 /* to 64-bit signed extend time */
  88. ADDCS D1Re0,D1Re0,#1 /* Support borrow too */
  89. MOV PC,D1RtP /* Return */
  90. .size ___TBITimeStamp,.-___TBITimeStamp
  91. /*
  92. * Perform ___TBITimerAdd logic
  93. *
  94. * Register Usage: D1Ar1 holds Id, D0Ar2 holds value to be added to the timer
  95. * D0Re0 is used for the result - new TIMER value
  96. * D1Ar5, D0Ar6 are used as scratch
  97. * Other registers are those set by ___TBITimeCore
  98. * D0Ar6 is assumed to be the timer value read
  99. * D0Ar4, D1Ar3 is the current value of ___TBITime(B/I)
  100. */
  101. .text
  102. .balign 4
  103. .global ___TBITimerAdd
  104. .type ___TBITimerAdd,function
  105. ___TBITimerAdd:
  106. MOV D1Ar5,#TIMER_ADD_BIT /* Timer ADD request */
  107. MOVT D0FrT,#HI(___TBITimeCore) /* Get timer core reg values */
  108. CALL D0FrT,#LO(___TBITimeCore) /* with no register update */
  109. ADD D0Re0,D0Ar2,D0Ar6 /* Regenerate new value = result */
  110. NEG D0Ar2,D0Ar2 /* Negate delta */
  111. ASR D1Re0,D0Ar2,#31 /* Sign extend negated delta */
  112. ADDS D0Ar4,D0Ar4,D0Ar2 /* Add time added to ... */
  113. ADD D1Ar3,D1Ar3,D1Re0 /* ... real timer ... */
  114. ADDCS D1Ar3,D1Ar3,#1 /* ... with carry */
  115. SETL [A0.3],D0Ar4,D1Ar3 /* Update ___TBITime(B/I) */
  116. MOV PC,D1RtP /* Return */
  117. .size ___TBITimerAdd,.-___TBITimerAdd
  118. #ifdef TBI_1_4
  119. /*
  120. * Perform ___TBITimerDeadline logic
  121. * NB: Delays are positive compared to the Wait values which are -ive
  122. *
  123. * Register Usage: D1Ar1 holds Id
  124. * D0Ar2 holds Delay requested
  125. * D0Re0 is used for the result - old TIMER Delay value
  126. * D1Ar5, D0Ar6 are used as scratch
  127. * Other registers are those set by ___TBITimeCore
  128. * D0Ar6 is assumed to be the timer value read
  129. * D0Ar4, D1Ar3 is the current value of ___TBITime(B/I)
  130. *
  131. */
  132. .text
  133. .type ___TBITimerDeadline,function
  134. .global ___TBITimerDeadline
  135. .align 2
  136. ___TBITimerDeadline:
  137. MOV D1Ar5,#TIMER_SET_BIT /* Timer SET request */
  138. MOVT D0FrT,#HI(___TBITimeCore) /* Get timer core reg values */
  139. CALL D0FrT,#LO(___TBITimeCore) /* with no register update */
  140. MOV D0Re0,D0Ar6 /* Old value read = result */
  141. SUB D0Ar2,D0Ar6,D0Ar2 /* Delta from (old - new) */
  142. ASR D1Re0,D0Ar2,#31 /* Sign extend delta */
  143. ADDS D0Ar4,D0Ar4,D0Ar2 /* Add time added to ... */
  144. ADD D1Ar3,D1Ar3,D1Re0 /* ... real timer ... */
  145. ADDCS D1Ar3,D1Ar3,#1 /* ... with carry */
  146. SETL [A0.3],D0Ar4,D1Ar3 /* Update ___TBITime(B/I) */
  147. MOV PC,D1RtP /* Return */
  148. .size ___TBITimerDeadline,.-___TBITimerDeadline
  149. #endif /* TBI_1_4 */
  150. /*
  151. * Perform core timer access logic
  152. *
  153. * Register Usage: D1Ar1 holds Id, D0Ar2 holds input value for SET and
  154. * input value for ADD
  155. * D1Ar5 controls op as SET or ADD as bit values
  156. * On return D0Ar6, D1Ar5 holds the old 64-bit timer value
  157. * A0.3 is setup to point at ___TBITime(I/B)
  158. * A1.3 is setup to point at ___TBITimes
  159. * D0Ar4, D1Ar3 is setup to value of ___TBITime(I/B)
  160. */
  161. .text
  162. .balign 4
  163. .global ___TBITimeCore
  164. .type ___TBITimeCore,function
  165. ___TBITimeCore:
  166. #ifndef METAC_0_1
  167. TSTT D1Ar1,#HI(TBID_ISTAT_BIT) /* Interrupt level timer? */
  168. #endif
  169. MOVT A1LbP,#HI(___TBITimes)
  170. ADD A1LbP,A1LbP,#LO(___TBITimes)
  171. MOV A1.3,A1LbP /* Get ___TBITimes address */
  172. #ifndef METAC_0_1
  173. BNZ $LTimeCoreI /* Yes: Service TXTIMERI! */
  174. #endif
  175. LSRS D1Ar5,D1Ar5,#1 /* Carry = SET, Zero = !ADD */
  176. GETD A0.3,[A1.3+#0] /* A0.3 == &___TBITimeB */
  177. MOV D0Ar6,TXTIMER /* Always GET old value */
  178. MOVCS TXTIMER,D0Ar2 /* Conditional SET operation */
  179. ADDNZ TXTIMER,D0Ar2,D0Ar6 /* Conditional ADD operation */
  180. #ifndef METAC_0_1
  181. B $LTimeCoreEnd
  182. $LTimeCoreI:
  183. LSRS D1Ar5,D1Ar5,#1 /* Carry = SET, Zero = !ADD */
  184. GETD A0.3,[A1.3+#4] /* A0.3 == &___TBITimeI */
  185. MOV D0Ar6,TXTIMERI /* Always GET old value */
  186. MOVCS TXTIMERI,D0Ar2 /* Conditional SET operation */
  187. ADDNZ TXTIMERI,D0Ar2,D0Ar6 /* Conditional ADD operation */
  188. $LTimeCoreEnd:
  189. #endif
  190. ASR D1Ar5,D0Ar6,#31 /* Sign extend D0Ar6 into D1Ar5 */
  191. GETL D0Ar4,D1Ar3,[A0.3] /* Read ___TBITime(B/I) */
  192. MOV PC,D0FrT /* Return quickly */
  193. .size ___TBITimeCore,.-___TBITimeCore
  194. /*
  195. * End of tbitimer.S
  196. */