gettimeofday.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Userland implementation of gettimeofday() for 64 bits processes in a
  4. * s390 kernel for use in the vDSO
  5. *
  6. * Copyright IBM Corp. 2008
  7. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License (version 2 only)
  11. * as published by the Free Software Foundation.
  12. */
  13. #include <asm/vdso.h>
  14. #include <asm/asm-offsets.h>
  15. #include <asm/unistd.h>
  16. .text
  17. .align 4
  18. .globl __kernel_gettimeofday
  19. .type __kernel_gettimeofday,@function
  20. __kernel_gettimeofday:
  21. .cfi_startproc
  22. aghi %r15,-16
  23. larl %r5,_vdso_data
  24. 0: ltgr %r3,%r3 /* check if tz is NULL */
  25. je 1f
  26. mvc 0(8,%r3),__VDSO_TIMEZONE(%r5)
  27. 1: ltgr %r2,%r2 /* check if tv is NULL */
  28. je 4f
  29. lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
  30. tmll %r4,0x0001 /* pending update ? loop */
  31. jnz 0b
  32. stcke 0(%r15) /* Store TOD clock */
  33. lg %r1,1(%r15)
  34. lg %r0,__VDSO_TS_END(%r5) /* TOD steering end time */
  35. slgr %r0,%r1 /* now - ts_steering_end */
  36. ltgr %r0,%r0 /* past end of steering ? */
  37. jm 6f
  38. srlg %r0,%r0,15 /* 1 per 2^16 */
  39. tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
  40. jz 7f
  41. lcgr %r0,%r0 /* negative TOD offset */
  42. 7: algr %r1,%r0 /* add steering offset */
  43. 6: sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
  44. msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
  45. alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
  46. lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */
  47. clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
  48. jne 0b
  49. lgf %r5,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
  50. srlg %r1,%r1,0(%r5) /* >> tk->shift */
  51. larl %r5,5f
  52. 2: clg %r1,0(%r5)
  53. jl 3f
  54. slg %r1,0(%r5)
  55. aghi %r0,1
  56. j 2b
  57. 3: stg %r0,0(%r2) /* store tv->tv_sec */
  58. slgr %r0,%r0 /* tv_nsec -> tv_usec */
  59. ml %r0,8(%r5)
  60. srlg %r0,%r0,6
  61. stg %r0,8(%r2) /* store tv->tv_usec */
  62. 4: lghi %r2,0
  63. aghi %r15,16
  64. br %r14
  65. 5: .quad 1000000000
  66. .long 274877907
  67. .cfi_endproc
  68. .size __kernel_gettimeofday,.-__kernel_gettimeofday