2 * Userland implementation of gettimeofday() for 64 bits processes in a
3 * ppc64 kernel for use in the vDSO
5 * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org),
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.
13 #include <linux/config.h>
14 #include <asm/processor.h>
15 #include <asm/ppc_asm.h>
17 #include <asm/offsets.h>
21 * Exact prototype of gettimeofday
23 * int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz);
26 V_FUNCTION_BEGIN(__kernel_gettimeofday)
31 mr r11,r3 /* r11 holds tv */
32 mr r10,r4 /* r10 holds tz */
33 bl V_LOCAL_FUNC(__get_datapage) /* get data page */
34 bl V_LOCAL_FUNC(__do_get_xsec) /* get xsec from tb & kernel */
35 lis r7,15 /* r7 = 1000000 = USEC_PER_SEC */
37 rldicl r5,r4,44,20 /* r5 = sec = xsec / XSEC_PER_SEC */
38 rldicr r6,r5,20,43 /* r6 = sec * XSEC_PER_SEC */
39 std r5,TVAL64_TV_SEC(r11) /* store sec in tv */
40 subf r0,r6,r4 /* r0 = xsec = (xsec - r6) */
41 mulld r0,r0,r7 /* usec = (xsec * USEC_PER_SEC) / XSEC_PER_SEC */
43 cmpldi cr0,r10,0 /* check if tz is NULL */
44 std r0,TVAL64_TV_USEC(r11) /* store usec in tv */
46 lwz r4,CFG_TZ_MINUTEWEST(r3)/* fill tz */
47 lwz r5,CFG_TZ_DSTTIME(r3)
48 stw r4,TZONE_TZ_MINWEST(r10)
49 stw r5,TZONE_TZ_DSTTIME(r10)
51 li r3,0 /* always success */
54 V_FUNCTION_END(__kernel_gettimeofday)
58 * This is the core of gettimeofday(), it returns the xsec
59 * value in r4 and expects the datapage ptr (non clobbered)
60 * in r3. clobbers r0,r4,r5,r6,r7,r8
62 V_FUNCTION_BEGIN(__do_get_xsec)
64 /* check for update count & load values */
65 1: ld r7,CFG_TB_UPDATE_COUNT(r3)
66 andi. r0,r4,1 /* pending update ? loop */
68 xor r0,r4,r4 /* create dependency */
71 /* Get TB & offset it */
73 ld r9,CFG_TB_ORIG_STAMP(r3)
77 ld r5,CFG_TB_TO_XS(r3)
80 /* Add stamp since epoch */
81 ld r6,CFG_STAMP_XSEC(r3)
86 ld r0,CFG_TB_UPDATE_COUNT(r3)
87 cmpld cr0,r0,r7 /* check if updated */
91 V_FUNCTION_END(__do_get_xsec)