gettimeofday.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Userland implementation of gettimeofday() 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_gettimeofday
  18. .type __kernel_gettimeofday,@function
  19. __kernel_gettimeofday:
  20. .cfi_startproc
  21. ahi %r15,-16
  22. basr %r5,0
  23. 0: al %r5,13f-0b(%r5) /* get &_vdso_data */
  24. 1: ltr %r3,%r3 /* check if tz is NULL */
  25. je 2f
  26. mvc 0(8,%r3),__VDSO_TIMEZONE(%r5)
  27. 2: ltr %r2,%r2 /* check if tv is NULL */
  28. je 10f
  29. l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
  30. tml %r4,0x0001 /* pending update ? loop */
  31. jnz 1b
  32. stcke 0(%r15) /* Store TOD clock */
  33. lm %r0,%r1,__VDSO_TS_END(%r5) /* TOD steering end time */
  34. s %r0,1(%r15)
  35. sl %r1,5(%r15)
  36. brc 3,14f
  37. ahi %r0,-1
  38. 14: ltr %r0,%r0 /* past end of steering? */
  39. jm 16f
  40. srdl %r0,15 /* 1 per 2^16 */
  41. tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
  42. jz 15f
  43. lcr %r0,%r0 /* negative TOD offset */
  44. lcr %r1,%r1
  45. je 15f
  46. ahi %r0,-1
  47. 15: a %r0,1(%r15) /* add TOD timestamp */
  48. al %r1,5(%r15)
  49. brc 12,17f
  50. ahi %r0,1
  51. j 17f
  52. 16: lm %r0,%r1,1(%r15) /* load TOD timestamp */
  53. 17: s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  54. sl %r1,__VDSO_XTIME_STAMP+4(%r5)
  55. brc 3,3f
  56. ahi %r0,-1
  57. 3: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
  58. st %r0,0(%r15)
  59. l %r0,__VDSO_TK_MULT(%r5)
  60. ltr %r1,%r1
  61. mr %r0,%r0
  62. jnm 4f
  63. a %r0,__VDSO_TK_MULT(%r5)
  64. 4: al %r0,0(%r15)
  65. al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */
  66. al %r1,__VDSO_XTIME_NSEC+4(%r5)
  67. brc 12,5f
  68. ahi %r0,1
  69. 5: mvc 0(4,%r15),__VDSO_XTIME_SEC+4(%r5)
  70. cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
  71. jne 1b
  72. l %r4,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
  73. srdl %r0,0(%r4) /* >> tk->shift */
  74. l %r4,0(%r15) /* get tv_sec from stack */
  75. basr %r5,0
  76. 6: ltr %r0,%r0
  77. jnz 7f
  78. cl %r1,11f-6b(%r5)
  79. jl 8f
  80. 7: ahi %r4,1
  81. sl %r1,11f-6b(%r5)
  82. brc 3,6b
  83. ahi %r0,-1
  84. j 6b
  85. 8: st %r4,0(%r2) /* store tv->tv_sec */
  86. ltr %r1,%r1
  87. m %r0,12f-6b(%r5)
  88. jnm 9f
  89. al %r0,12f-6b(%r5)
  90. 9: srl %r0,6
  91. st %r0,4(%r2) /* store tv->tv_usec */
  92. 10: slr %r2,%r2
  93. ahi %r15,16
  94. br %r14
  95. 11: .long 1000000000
  96. 12: .long 274877907
  97. 13: .long _vdso_data - 0b
  98. .cfi_endproc
  99. .size __kernel_gettimeofday,.-__kernel_gettimeofday