Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-drm-fsl-dcu.git] / arch / s390 / kernel / vdso64 / clock_gettime.S
1 /*
2  * Userland implementation of clock_gettime() for 64 bits processes in a
3  * s390 kernel for use in the vDSO
4  *
5  *  Copyright IBM Corp. 2008
6  *  Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License (version 2 only)
10  * as published by the Free Software Foundation.
11  */
12 #include <asm/vdso.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/unistd.h>
15
16         .text
17         .align 4
18         .globl __kernel_clock_gettime
19         .type  __kernel_clock_gettime,@function
20 __kernel_clock_gettime:
21         .cfi_startproc
22         larl    %r5,_vdso_data
23         cghi    %r2,__CLOCK_REALTIME
24         je      4f
25         cghi    %r2,-2          /* CLOCK_THREAD_CPUTIME_ID for this thread */
26         je      9f
27         cghi    %r2,__CLOCK_MONOTONIC
28         jne     12f
29
30         /* CLOCK_MONOTONIC */
31         ltgr    %r3,%r3
32         jz      3f                              /* tp == NULL */
33 0:      lg      %r4,__VDSO_UPD_COUNT(%r5)       /* load update counter */
34         tmll    %r4,0x0001                      /* pending update ? loop */
35         jnz     0b
36         stck    48(%r15)                        /* Store TOD clock */
37         lgf     %r2,__VDSO_TK_SHIFT(%r5)        /* Timekeeper shift */
38         lg      %r0,__VDSO_XTIME_SEC(%r5)       /* tk->xtime_sec */
39         alg     %r0,__VDSO_WTOM_SEC(%r5)        /*  + wall_to_monotonic.sec */
40         lg      %r1,48(%r15)
41         sg      %r1,__VDSO_XTIME_STAMP(%r5)     /* TOD - cycle_last */
42         msgf    %r1,__VDSO_TK_MULT(%r5)         /*  * tk->mult */
43         alg     %r1,__VDSO_XTIME_NSEC(%r5)      /*  + tk->xtime_nsec */
44         alg     %r1,__VDSO_WTOM_NSEC(%r5)       /*  + wall_to_monotonic.nsec */
45         srlg    %r1,%r1,0(%r2)                  /*  >> tk->shift */
46         clg     %r4,__VDSO_UPD_COUNT(%r5)       /* check update counter */
47         jne     0b
48         larl    %r5,13f
49 1:      clg     %r1,0(%r5)
50         jl      2f
51         slg     %r1,0(%r5)
52         aghi    %r0,1
53         j       1b
54 2:      stg     %r0,0(%r3)                      /* store tp->tv_sec */
55         stg     %r1,8(%r3)                      /* store tp->tv_nsec */
56 3:      lghi    %r2,0
57         br      %r14
58
59         /* CLOCK_REALTIME */
60 4:      ltr     %r3,%r3                         /* tp == NULL */
61         jz      8f
62 5:      lg      %r4,__VDSO_UPD_COUNT(%r5)       /* load update counter */
63         tmll    %r4,0x0001                      /* pending update ? loop */
64         jnz     5b
65         stck    48(%r15)                        /* Store TOD clock */
66         lgf     %r2,__VDSO_TK_SHIFT(%r5)        /* Timekeeper shift */
67         lg      %r1,48(%r15)
68         sg      %r1,__VDSO_XTIME_STAMP(%r5)     /* TOD - cycle_last */
69         msgf    %r1,__VDSO_TK_MULT(%r5)         /*  * tk->mult */
70         alg     %r1,__VDSO_XTIME_NSEC(%r5)      /*  + tk->xtime_nsec */
71         srlg    %r1,%r1,0(%r2)                  /*  >> tk->shift */
72         lg      %r0,__VDSO_XTIME_SEC(%r5)       /* tk->xtime_sec */
73         clg     %r4,__VDSO_UPD_COUNT(%r5)       /* check update counter */
74         jne     5b
75         larl    %r5,13f
76 6:      clg     %r1,0(%r5)
77         jl      7f
78         slg     %r1,0(%r5)
79         aghi    %r0,1
80         j       6b
81 7:      stg     %r0,0(%r3)                      /* store tp->tv_sec */
82         stg     %r1,8(%r3)                      /* store tp->tv_nsec */
83 8:      lghi    %r2,0
84         br      %r14
85
86         /* CLOCK_THREAD_CPUTIME_ID for this thread */
87 9:      icm     %r0,15,__VDSO_ECTG_OK(%r5)
88         jz      12f
89         ear     %r2,%a4
90         llilh   %r4,0x0100
91         sar     %a4,%r4
92         lghi    %r4,0
93         epsw    %r5,0
94         sacf    512                             /* Magic ectg instruction */
95         .insn   ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
96         tml     %r5,0x4000
97         jo      11f
98         tml     %r5,0x8000
99         jno     10f
100         sacf    256
101         j       11f
102 10:     sacf    0
103 11:     sar     %a4,%r2
104         algr    %r1,%r0                         /* r1 = cputime as TOD value */
105         mghi    %r1,1000                        /* convert to nanoseconds */
106         srlg    %r1,%r1,12                      /* r1 = cputime in nanosec */
107         lgr     %r4,%r1
108         larl    %r5,13f
109         srlg    %r1,%r1,9                       /* divide by 1000000000 */
110         mlg     %r0,8(%r5)
111         srlg    %r0,%r0,11                      /* r0 = tv_sec */
112         stg     %r0,0(%r3)
113         msg     %r0,0(%r5)                      /* calculate tv_nsec */
114         slgr    %r4,%r0                         /* r4 = tv_nsec */
115         stg     %r4,8(%r3)
116         lghi    %r2,0
117         br      %r14
118
119         /* Fallback to system call */
120 12:     lghi    %r1,__NR_clock_gettime
121         svc     0
122         br      %r14
123
124 13:     .quad   1000000000
125 14:     .quad   19342813113834067
126         .cfi_endproc
127         .size   __kernel_clock_gettime,.-__kernel_clock_gettime