clock_gettime.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Userland implementation of clock_gettime() for 32 bits processes in a
  3. * s390 kernel for use in the vDSO
  4. *
  5. * Copyright IBM Corp. 2008
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License (version 2 only)
  10. * as published by the Free Software Foundation.
  11. */
  12. #include <asm/vdso.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/unistd.h>
  15. .text
  16. .align 4
  17. .globl __kernel_clock_gettime
  18. .type __kernel_clock_gettime,@function
  19. __kernel_clock_gettime:
  20. .cfi_startproc
  21. ahi %r15,-16
  22. basr %r5,0
  23. 0: al %r5,21f-0b(%r5) /* get &_vdso_data */
  24. chi %r2,__CLOCK_REALTIME_COARSE
  25. je 10f
  26. chi %r2,__CLOCK_REALTIME
  27. je 11f
  28. chi %r2,__CLOCK_MONOTONIC_COARSE
  29. je 9f
  30. chi %r2,__CLOCK_MONOTONIC
  31. jne 19f
  32. /* CLOCK_MONOTONIC */
  33. 1: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  34. tml %r4,0x0001 /* pending update ? loop */
  35. jnz 1b
  36. stcke 0(%r15) /* Store TOD clock */
  37. lm %r0,%r1,1(%r15)
  38. s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  39. sl %r1,__VDSO_XTIME_STAMP+4(%r5)
  40. brc 3,2f
  41. ahi %r0,-1
  42. 2: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
  43. lr %r2,%r0
  44. l %r0,__VDSO_TK_MULT(%r5)
  45. ltr %r1,%r1
  46. mr %r0,%r0
  47. jnm 3f
  48. a %r0,__VDSO_TK_MULT(%r5)
  49. 3: alr %r0,%r2
  50. al %r0,__VDSO_WTOM_NSEC(%r5)
  51. al %r1,__VDSO_WTOM_NSEC+4(%r5)
  52. brc 12,5f
  53. ahi %r0,1
  54. 5: l %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
  55. srdl %r0,0(%r2) /* >> tk->shift */
  56. l %r2,__VDSO_WTOM_SEC+4(%r5)
  57. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  58. jne 1b
  59. basr %r5,0
  60. 6: ltr %r0,%r0
  61. jnz 7f
  62. cl %r1,20f-6b(%r5)
  63. jl 8f
  64. 7: ahi %r2,1
  65. sl %r1,20f-6b(%r5)
  66. brc 3,6b
  67. ahi %r0,-1
  68. j 6b
  69. 8: st %r2,0(%r3) /* store tp->tv_sec */
  70. st %r1,4(%r3) /* store tp->tv_nsec */
  71. lhi %r2,0
  72. ahi %r15,16
  73. br %r14
  74. /* CLOCK_MONOTONIC_COARSE */
  75. 9: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  76. tml %r4,0x0001 /* pending update ? loop */
  77. jnz 9b
  78. l %r2,__VDSO_WTOM_CRS_SEC+4(%r5)
  79. l %r1,__VDSO_WTOM_CRS_NSEC+4(%r5)
  80. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  81. jne 9b
  82. j 8b
  83. /* CLOCK_REALTIME_COARSE */
  84. 10: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  85. tml %r4,0x0001 /* pending update ? loop */
  86. jnz 10b
  87. l %r2,__VDSO_XTIME_CRS_SEC+4(%r5)
  88. l %r1,__VDSO_XTIME_CRS_NSEC+4(%r5)
  89. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  90. jne 10b
  91. j 17f
  92. /* CLOCK_REALTIME */
  93. 11: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  94. tml %r4,0x0001 /* pending update ? loop */
  95. jnz 11b
  96. stcke 0(%r15) /* Store TOD clock */
  97. lm %r0,%r1,1(%r15)
  98. s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  99. sl %r1,__VDSO_XTIME_STAMP+4(%r5)
  100. brc 3,12f
  101. ahi %r0,-1
  102. 12: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
  103. lr %r2,%r0
  104. l %r0,__VDSO_TK_MULT(%r5)
  105. ltr %r1,%r1
  106. mr %r0,%r0
  107. jnm 13f
  108. a %r0,__VDSO_TK_MULT(%r5)
  109. 13: alr %r0,%r2
  110. al %r0,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
  111. al %r1,__VDSO_XTIME_NSEC+4(%r5)
  112. brc 12,14f
  113. ahi %r0,1
  114. 14: l %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
  115. srdl %r0,0(%r2) /* >> tk->shift */
  116. l %r2,__VDSO_XTIME_SEC+4(%r5)
  117. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  118. jne 11b
  119. basr %r5,0
  120. 15: ltr %r0,%r0
  121. jnz 16f
  122. cl %r1,20f-15b(%r5)
  123. jl 17f
  124. 16: ahi %r2,1
  125. sl %r1,20f-15b(%r5)
  126. brc 3,15b
  127. ahi %r0,-1
  128. j 15b
  129. 17: st %r2,0(%r3) /* store tp->tv_sec */
  130. st %r1,4(%r3) /* store tp->tv_nsec */
  131. lhi %r2,0
  132. ahi %r15,16
  133. br %r14
  134. /* Fallback to system call */
  135. 19: lhi %r1,__NR_clock_gettime
  136. svc 0
  137. ahi %r15,16
  138. br %r14
  139. 20: .long 1000000000
  140. 21: .long _vdso_data - 0b
  141. .cfi_endproc
  142. .size __kernel_clock_gettime,.-__kernel_clock_gettime