1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Userland implementation of clock_gettime() for 32 bits processes in a
4 * s390 kernel for use in the vDSO
6 * Copyright IBM Corp. 2008
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #include <asm/asm-offsets.h>
11 #include <asm/unistd.h>
12 #include <asm/dwarf.h>
13 #include <asm/ptrace.h>
17 .globl __kernel_clock_gettime
18 .type __kernel_clock_gettime,@function
19 __kernel_clock_gettime:
22 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16
23 CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD
25 0: al %r5,21f-0b(%r5) /* get &_vdso_data */
26 chi %r2,__CLOCK_REALTIME_COARSE
28 chi %r2,__CLOCK_REALTIME
30 chi %r2,__CLOCK_MONOTONIC_COARSE
32 chi %r2,__CLOCK_MONOTONIC
36 1: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
37 tml %r4,0x0001 /* pending update ? loop */
39 stcke 0(%r15) /* Store TOD clock */
41 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
42 sl %r1,__VDSO_XTIME_STAMP+4(%r5)
45 2: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
47 l %r0,__VDSO_TK_MULT(%r5)
51 a %r0,__VDSO_TK_MULT(%r5)
53 al %r0,__VDSO_WTOM_NSEC(%r5)
54 al %r1,__VDSO_WTOM_NSEC+4(%r5)
57 5: l %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
58 srdl %r0,0(%r2) /* >> tk->shift */
59 l %r2,__VDSO_WTOM_SEC+4(%r5)
60 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
72 8: st %r2,0(%r3) /* store tp->tv_sec */
73 st %r1,4(%r3) /* store tp->tv_nsec */
76 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD
80 /* CLOCK_MONOTONIC_COARSE */
81 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16
82 CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD
83 9: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
84 tml %r4,0x0001 /* pending update ? loop */
86 l %r2,__VDSO_WTOM_CRS_SEC+4(%r5)
87 l %r1,__VDSO_WTOM_CRS_NSEC+4(%r5)
88 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
92 /* CLOCK_REALTIME_COARSE */
93 10: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
94 tml %r4,0x0001 /* pending update ? loop */
96 l %r2,__VDSO_XTIME_CRS_SEC+4(%r5)
97 l %r1,__VDSO_XTIME_CRS_NSEC+4(%r5)
98 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
103 11: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
104 tml %r4,0x0001 /* pending update ? loop */
106 stcke 0(%r15) /* Store TOD clock */
107 lm %r0,%r1,__VDSO_TS_END(%r5) /* TOD steering end time */
108 s %r0,1(%r15) /* no - ts_steering_end */
112 22: ltr %r0,%r0 /* past end of steering? */
114 srdl %r0,15 /* 1 per 2^16 */
115 tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
117 lcr %r0,%r0 /* negative TOD offset */
121 23: a %r0,1(%r15) /* add TOD timestamp */
126 24: lm %r0,%r1,1(%r15) /* load TOD timestamp */
127 25: s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
128 sl %r1,__VDSO_XTIME_STAMP+4(%r5)
131 12: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
133 l %r0,__VDSO_TK_MULT(%r5)
137 a %r0,__VDSO_TK_MULT(%r5)
139 al %r0,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
140 al %r1,__VDSO_XTIME_NSEC+4(%r5)
143 14: l %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
144 srdl %r0,0(%r2) /* >> tk->shift */
145 l %r2,__VDSO_XTIME_SEC+4(%r5)
146 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
158 17: st %r2,0(%r3) /* store tp->tv_sec */
159 st %r1,4(%r3) /* store tp->tv_nsec */
162 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD
166 /* Fallback to system call */
167 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD+16
168 CFI_VAL_OFFSET 15, -STACK_FRAME_OVERHEAD
169 19: lhi %r1,__NR_clock_gettime
172 CFI_DEF_CFA_OFFSET STACK_FRAME_OVERHEAD
178 21: .long _vdso_data - 0b
179 .size __kernel_clock_gettime,.-__kernel_clock_gettime