/arch/ppc64/kernel/vdso64/gettimeofday.S

https://bitbucket.org/evzijst/gittest · Assembly · 91 lines · 56 code · 8 blank · 27 comment · 0 complexity · 6200aa918e9ecda3cdddb4301d6e35c2 MD5 · raw file

  1. /*
  2. * Userland implementation of gettimeofday() for 64 bits processes in a
  3. * ppc64 kernel for use in the vDSO
  4. *
  5. * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org),
  6. * IBM Corp.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/config.h>
  14. #include <asm/processor.h>
  15. #include <asm/ppc_asm.h>
  16. #include <asm/vdso.h>
  17. #include <asm/offsets.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 r11,r3 /* r11 holds tv */
  30. mr r10,r4 /* r10 holds tz */
  31. bl V_LOCAL_FUNC(__get_datapage) /* get data page */
  32. bl V_LOCAL_FUNC(__do_get_xsec) /* get xsec from tb & kernel */
  33. lis r7,15 /* r7 = 1000000 = USEC_PER_SEC */
  34. ori r7,r7,16960
  35. rldicl r5,r4,44,20 /* r5 = sec = xsec / XSEC_PER_SEC */
  36. rldicr r6,r5,20,43 /* r6 = sec * XSEC_PER_SEC */
  37. std r5,TVAL64_TV_SEC(r11) /* store sec in tv */
  38. subf r0,r6,r4 /* r0 = xsec = (xsec - r6) */
  39. mulld r0,r0,r7 /* usec = (xsec * USEC_PER_SEC) / XSEC_PER_SEC */
  40. rldicl r0,r0,44,20
  41. cmpldi cr0,r10,0 /* check if tz is NULL */
  42. std r0,TVAL64_TV_USEC(r11) /* store usec in tv */
  43. beq 1f
  44. lwz r4,CFG_TZ_MINUTEWEST(r3)/* fill tz */
  45. lwz r5,CFG_TZ_DSTTIME(r3)
  46. stw r4,TZONE_TZ_MINWEST(r10)
  47. stw r5,TZONE_TZ_DSTTIME(r10)
  48. 1: mtlr r12
  49. li r3,0 /* always success */
  50. blr
  51. .cfi_endproc
  52. V_FUNCTION_END(__kernel_gettimeofday)
  53. /*
  54. * This is the core of gettimeofday(), it returns the xsec
  55. * value in r4 and expects the datapage ptr (non clobbered)
  56. * in r3. clobbers r0,r4,r5,r6,r7,r8
  57. */
  58. V_FUNCTION_BEGIN(__do_get_xsec)
  59. .cfi_startproc
  60. /* check for update count & load values */
  61. 1: ld r7,CFG_TB_UPDATE_COUNT(r3)
  62. andi. r0,r4,1 /* pending update ? loop */
  63. bne- 1b
  64. xor r0,r4,r4 /* create dependency */
  65. add r3,r3,r0
  66. /* Get TB & offset it */
  67. mftb r8
  68. ld r9,CFG_TB_ORIG_STAMP(r3)
  69. subf r8,r9,r8
  70. /* Scale result */
  71. ld r5,CFG_TB_TO_XS(r3)
  72. mulhdu r8,r8,r5
  73. /* Add stamp since epoch */
  74. ld r6,CFG_STAMP_XSEC(r3)
  75. add r4,r6,r8
  76. xor r0,r4,r4
  77. add r3,r3,r0
  78. ld r0,CFG_TB_UPDATE_COUNT(r3)
  79. cmpld cr0,r0,r7 /* check if updated */
  80. bne- 1b
  81. blr
  82. .cfi_endproc
  83. V_FUNCTION_END(__do_get_xsec)