gettimeofday.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Userland implementation of gettimeofday() for processes
  4. * for use in the vDSO
  5. *
  6. * Copyright (C) 2004 Benjamin Herrenschmuidt ([email protected],
  7. * IBM Corp.
  8. */
  9. #include <asm/processor.h>
  10. #include <asm/ppc_asm.h>
  11. #include <asm/vdso.h>
  12. #include <asm/vdso_datapage.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/unistd.h>
  15. /*
  16. * The macro sets two stack frames, one for the caller and one for the callee
  17. * because there are no requirement for the caller to set a stack frame when
  18. * calling VDSO so it may have omitted to set one, especially on PPC64
  19. */
  20. .macro cvdso_call funct call_time=0
  21. .cfi_startproc
  22. PPC_STLU r1, -PPC_MIN_STKFRM(r1)
  23. .cfi_adjust_cfa_offset PPC_MIN_STKFRM
  24. mflr r0
  25. PPC_STLU r1, -PPC_MIN_STKFRM(r1)
  26. .cfi_adjust_cfa_offset PPC_MIN_STKFRM
  27. PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
  28. .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF
  29. #ifdef __powerpc64__
  30. PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1)
  31. .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT
  32. #endif
  33. get_datapage r5
  34. .ifeq \call_time
  35. addi r5, r5, VDSO_DATA_OFFSET
  36. .else
  37. addi r4, r5, VDSO_DATA_OFFSET
  38. .endif
  39. bl DOTSYM(\funct)
  40. PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
  41. #ifdef __powerpc64__
  42. PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1)
  43. .cfi_restore r2
  44. #endif
  45. .ifeq \call_time
  46. cmpwi r3, 0
  47. .endif
  48. mtlr r0
  49. addi r1, r1, 2 * PPC_MIN_STKFRM
  50. .cfi_restore lr
  51. .cfi_def_cfa_offset 0
  52. crclr so
  53. .ifeq \call_time
  54. beqlr+
  55. crset so
  56. neg r3, r3
  57. .endif
  58. blr
  59. .cfi_endproc
  60. .endm
  61. .text
  62. /*
  63. * Exact prototype of gettimeofday
  64. *
  65. * int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz);
  66. *
  67. */
  68. V_FUNCTION_BEGIN(__kernel_gettimeofday)
  69. cvdso_call __c_kernel_gettimeofday
  70. V_FUNCTION_END(__kernel_gettimeofday)
  71. /*
  72. * Exact prototype of clock_gettime()
  73. *
  74. * int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp);
  75. *
  76. */
  77. V_FUNCTION_BEGIN(__kernel_clock_gettime)
  78. cvdso_call __c_kernel_clock_gettime
  79. V_FUNCTION_END(__kernel_clock_gettime)
  80. /*
  81. * Exact prototype of clock_gettime64()
  82. *
  83. * int __kernel_clock_gettime64(clockid_t clock_id, struct __timespec64 *ts);
  84. *
  85. */
  86. #ifndef __powerpc64__
  87. V_FUNCTION_BEGIN(__kernel_clock_gettime64)
  88. cvdso_call __c_kernel_clock_gettime64
  89. V_FUNCTION_END(__kernel_clock_gettime64)
  90. #endif
  91. /*
  92. * Exact prototype of clock_getres()
  93. *
  94. * int __kernel_clock_getres(clockid_t clock_id, struct timespec *res);
  95. *
  96. */
  97. V_FUNCTION_BEGIN(__kernel_clock_getres)
  98. cvdso_call __c_kernel_clock_getres
  99. V_FUNCTION_END(__kernel_clock_getres)
  100. /*
  101. * Exact prototype of time()
  102. *
  103. * time_t time(time *t);
  104. *
  105. */
  106. V_FUNCTION_BEGIN(__kernel_time)
  107. cvdso_call __c_kernel_time call_time=1
  108. V_FUNCTION_END(__kernel_time)
  109. /* Routines for restoring integer registers, called by the compiler. */
  110. /* Called with r11 pointing to the stack header word of the caller of the */
  111. /* function, just beyond the end of the integer restore area. */
  112. #ifndef __powerpc64__
  113. _GLOBAL(_restgpr_31_x)
  114. _GLOBAL(_rest32gpr_31_x)
  115. lwz r0,4(r11)
  116. lwz r31,-4(r11)
  117. mtlr r0
  118. mr r1,r11
  119. blr
  120. #endif