clock_gettime.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. basr %r5,0
  22. 0: al %r5,21f-0b(%r5) /* get &_vdso_data */
  23. chi %r2,__CLOCK_REALTIME
  24. je 10f
  25. chi %r2,__CLOCK_MONOTONIC
  26. jne 19f
  27. /* CLOCK_MONOTONIC */
  28. ltr %r3,%r3
  29. jz 9f /* tp == NULL */
  30. 1: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  31. tml %r4,0x0001 /* pending update ? loop */
  32. jnz 1b
  33. stck 24(%r15) /* Store TOD clock */
  34. lm %r0,%r1,24(%r15)
  35. s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  36. sl %r1,__VDSO_XTIME_STAMP+4(%r5)
  37. brc 3,2f
  38. ahi %r0,-1
  39. 2: ms %r0,__VDSO_NTP_MULT(%r5) /* cyc2ns(clock,cycle_delta) */
  40. lr %r2,%r0
  41. l %r0,__VDSO_NTP_MULT(%r5)
  42. ltr %r1,%r1
  43. mr %r0,%r0
  44. jnm 3f
  45. a %r0,__VDSO_NTP_MULT(%r5)
  46. 3: alr %r0,%r2
  47. srdl %r0,12
  48. al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */
  49. al %r1,__VDSO_XTIME_NSEC+4(%r5)
  50. brc 12,4f
  51. ahi %r0,1
  52. 4: l %r2,__VDSO_XTIME_SEC+4(%r5)
  53. al %r0,__VDSO_WTOM_NSEC(%r5) /* + wall_to_monotonic */
  54. al %r1,__VDSO_WTOM_NSEC+4(%r5)
  55. brc 12,5f
  56. ahi %r0,1
  57. 5: al %r2,__VDSO_WTOM_SEC+4(%r5)
  58. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  59. jne 1b
  60. basr %r5,0
  61. 6: ltr %r0,%r0
  62. jnz 7f
  63. cl %r1,20f-6b(%r5)
  64. jl 8f
  65. 7: ahi %r2,1
  66. sl %r1,20f-6b(%r5)
  67. brc 3,6b
  68. ahi %r0,-1
  69. j 6b
  70. 8: st %r2,0(%r3) /* store tp->tv_sec */
  71. st %r1,4(%r3) /* store tp->tv_nsec */
  72. 9: lhi %r2,0
  73. br %r14
  74. /* CLOCK_REALTIME */
  75. 10: ltr %r3,%r3 /* tp == NULL */
  76. jz 18f
  77. 11: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  78. tml %r4,0x0001 /* pending update ? loop */
  79. jnz 11b
  80. stck 24(%r15) /* Store TOD clock */
  81. lm %r0,%r1,24(%r15)
  82. s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  83. sl %r1,__VDSO_XTIME_STAMP+4(%r5)
  84. brc 3,12f
  85. ahi %r0,-1
  86. 12: ms %r0,__VDSO_NTP_MULT(%r5) /* cyc2ns(clock,cycle_delta) */
  87. lr %r2,%r0
  88. l %r0,__VDSO_NTP_MULT(%r5)
  89. ltr %r1,%r1
  90. mr %r0,%r0
  91. jnm 13f
  92. a %r0,__VDSO_NTP_MULT(%r5)
  93. 13: alr %r0,%r2
  94. srdl %r0,12
  95. al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */
  96. al %r1,__VDSO_XTIME_NSEC+4(%r5)
  97. brc 12,14f
  98. ahi %r0,1
  99. 14: l %r2,__VDSO_XTIME_SEC+4(%r5)
  100. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  101. jne 11b
  102. basr %r5,0
  103. 15: ltr %r0,%r0
  104. jnz 16f
  105. cl %r1,20f-15b(%r5)
  106. jl 17f
  107. 16: ahi %r2,1
  108. sl %r1,20f-15b(%r5)
  109. brc 3,15b
  110. ahi %r0,-1
  111. j 15b
  112. 17: st %r2,0(%r3) /* store tp->tv_sec */
  113. st %r1,4(%r3) /* store tp->tv_nsec */
  114. 18: lhi %r2,0
  115. br %r14
  116. /* Fallback to system call */
  117. 19: lhi %r1,__NR_clock_gettime
  118. svc 0
  119. br %r14
  120. 20: .long 1000000000
  121. 21: .long _vdso_data - 0b
  122. .cfi_endproc
  123. .size __kernel_clock_gettime,.-__kernel_clock_gettime