gettimeofday.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Userland implementation of gettimeofday() for 32 bits processes in a
  3. * ppc64 kernel for use in the vDSO
  4. *
  5. * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org), IBM Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/config.h>
  13. #include <asm/processor.h>
  14. #include <asm/ppc_asm.h>
  15. #include <asm/vdso.h>
  16. #include <asm/offsets.h>
  17. #include <asm/unistd.h>
  18. .text
  19. /*
  20. * Exact prototype of gettimeofday
  21. *
  22. * int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz);
  23. *
  24. */
  25. V_FUNCTION_BEGIN(__kernel_gettimeofday)
  26. .cfi_startproc
  27. mflr r12
  28. .cfi_register lr,r12
  29. mr r10,r3 /* r10 saves tv */
  30. mr r11,r4 /* r11 saves tz */
  31. bl __get_datapage@local /* get data page */
  32. mr r9, r3 /* datapage ptr in r9 */
  33. bl __do_get_xsec@local /* get xsec from tb & kernel */
  34. bne- 2f /* out of line -> do syscall */
  35. /* seconds are xsec >> 20 */
  36. rlwinm r5,r4,12,20,31
  37. rlwimi r5,r3,12,0,19
  38. stw r5,TVAL32_TV_SEC(r10)
  39. /* get remaining xsec and convert to usec. we scale
  40. * up remaining xsec by 12 bits and get the top 32 bits
  41. * of the multiplication
  42. */
  43. rlwinm r5,r4,12,0,19
  44. lis r6,1000000@h
  45. ori r6,r6,1000000@l
  46. mulhwu r5,r5,r6
  47. stw r5,TVAL32_TV_USEC(r10)
  48. cmpli cr0,r11,0 /* check if tz is NULL */
  49. beq 1f
  50. lwz r4,CFG_TZ_MINUTEWEST(r9)/* fill tz */
  51. lwz r5,CFG_TZ_DSTTIME(r9)
  52. stw r4,TZONE_TZ_MINWEST(r11)
  53. stw r5,TZONE_TZ_DSTTIME(r11)
  54. 1: mtlr r12
  55. li r3,0
  56. blr
  57. 2: mr r3,r10
  58. mr r4,r11
  59. li r0,__NR_gettimeofday
  60. sc
  61. b 1b
  62. .cfi_endproc
  63. V_FUNCTION_END(__kernel_gettimeofday)
  64. /*
  65. * This is the core of gettimeofday(), it returns the xsec
  66. * value in r3 & r4 and expects the datapage ptr (non clobbered)
  67. * in r9. clobbers r0,r4,r5,r6,r7,r8
  68. */
  69. __do_get_xsec:
  70. .cfi_startproc
  71. /* Check for update count & load values. We use the low
  72. * order 32 bits of the update count
  73. */
  74. 1: lwz r8,(CFG_TB_UPDATE_COUNT+4)(r9)
  75. andi. r0,r8,1 /* pending update ? loop */
  76. bne- 1b
  77. xor r0,r8,r8 /* create dependency */
  78. add r9,r9,r0
  79. /* Load orig stamp (offset to TB) */
  80. lwz r5,CFG_TB_ORIG_STAMP(r9)
  81. lwz r6,(CFG_TB_ORIG_STAMP+4)(r9)
  82. /* Get a stable TB value */
  83. 2: mftbu r3
  84. mftbl r4
  85. mftbu r0
  86. cmpl cr0,r3,r0
  87. bne- 2b
  88. /* Substract tb orig stamp. If the high part is non-zero, we jump to the
  89. * slow path which call the syscall. If it's ok, then we have our 32 bits
  90. * tb_ticks value in r7
  91. */
  92. subfc r7,r6,r4
  93. subfe. r0,r5,r3
  94. bne- 3f
  95. /* Load scale factor & do multiplication */
  96. lwz r5,CFG_TB_TO_XS(r9) /* load values */
  97. lwz r6,(CFG_TB_TO_XS+4)(r9)
  98. mulhwu r4,r7,r5
  99. mulhwu r6,r7,r6
  100. mullw r6,r7,r5
  101. addc r6,r6,r0
  102. /* At this point, we have the scaled xsec value in r4 + XER:CA
  103. * we load & add the stamp since epoch
  104. */
  105. lwz r5,CFG_STAMP_XSEC(r9)
  106. lwz r6,(CFG_STAMP_XSEC+4)(r9)
  107. adde r4,r4,r6
  108. addze r3,r5
  109. /* We now have our result in r3,r4. We create a fake dependency
  110. * on that result and re-check the counter
  111. */
  112. xor r0,r4,r4
  113. add r9,r9,r0
  114. lwz r0,(CFG_TB_UPDATE_COUNT+4)(r9)
  115. cmpl cr0,r8,r0 /* check if updated */
  116. bne- 1b
  117. /* Warning ! The caller expects CR:EQ to be set to indicate a
  118. * successful calculation (so it won't fallback to the syscall
  119. * method). We have overriden that CR bit in the counter check,
  120. * but fortunately, the loop exit condition _is_ CR:EQ set, so
  121. * we can exit safely here. If you change this code, be careful
  122. * of that side effect.
  123. */
  124. 3: blr
  125. .cfi_endproc