aboutsummaryrefslogtreecommitdiff
path: root/arch/powerpc/kernel/vdso32/gettimeofday.S
blob: 05909f75430707677ace1f5237245f1fb27442a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * Userland implementation of gettimeofday() for 32 bits processes in a
 * ppc64 kernel for use in the vDSO
 *
 * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org,
 *                    IBM Corp.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */
#include <asm/processor.h>
#include <asm/ppc_asm.h>
#include <asm/vdso.h>
#include <asm/asm-offsets.h>
#include <asm/unistd.h>

	.text
/*
 * Exact prototype of gettimeofday
 *
 * int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz);
 *
 */
V_FUNCTION_BEGIN(__kernel_gettimeofday)
  .cfi_startproc
	mflr	r12
  .cfi_register lr,r12

	mr	r10,r3			/* r10 saves tv */
	mr	r11,r4			/* r11 saves tz */
	bl	__get_datapage@local	/* get data page */
	mr	r9, r3			/* datapage ptr in r9 */
	bl	__do_get_xsec@local	/* get xsec from tb & kernel */
	bne-	2f			/* out of line -> do syscall */

	/* seconds are xsec >> 20 */
	rlwinm	r5,r4,12,20,31
	rlwimi	r5,r3,12,0,19
	stw	r5,TVAL32_TV_SEC(r10)

	/* get remaining xsec and convert to usec. we scale
	 * up remaining xsec by 12 bits and get the top 32 bits
	 * of the multiplication
	 */
	rlwinm	r5,r4,12,0,19
	lis	r6,1000000@h
	ori	r6,r6,1000000@l
	mulhwu	r5,r5,r6
	stw	r5,TVAL32_TV_USEC(r10)

	cmpli	cr0,r11,0		/* check if tz is NULL */
	beq	1f
	lwz	r4,CFG_TZ_MINUTEWEST(r9)/* fill tz */
	lwz	r5,CFG_TZ_DSTTIME(r9)
	stw	r4,TZONE_TZ_MINWEST(r11)
	stw	r5,TZONE_TZ_DSTTIME(r11)

1:	mtlr	r12
	crclr	cr0*4+so
	li	r3,0
	blr

2:
	mtlr	r12
	mr	r3,r10
	mr	r4,r11
	li	r0,__NR_gettimeofday
	sc
	blr
  .cfi_endproc
V_FUNCTION_END(__kernel_gettimeofday)

/*
 * Exact prototype of clock_gettime()
 *
 * int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp);
 *
 */
V_FUNCTION_BEGIN(__kernel_clock_gettime)
  .cfi_startproc
	/* Check for supported clock IDs */
	cmpli	cr0,r3,CLOCK_REALTIME
	cmpli	cr1,r3,CLOCK_MONOTONIC
	cror	cr0*4+eq,cr0*4+eq,cr1*4+eq
	bne	cr0,99f

	mflr	r12			/* r12 saves lr */
  .cfi_register lr,r12
	mr	r10,r3			/* r10 saves id */
	mr	r11,r4			/* r11 saves tp */
	bl	__get_datapage@local	/* get data page */
	mr	r9,r3			/* datapage ptr in r9 */
	beq	cr1,50f			/* if monotonic -> jump there */

	/*
	 * CLOCK_REALTIME
	 */

	bl	__do_get_xsec@local	/* get xsec from tb & kernel */
	bne-	98f			/* out of line -> do syscall */

	/* seconds are xsec >> 20 */
	rlwinm	r5,r4,12,20,31
	rlwimi	r5,r3,12,0,19
	stw	r5,TSPC32_TV_SEC(r11)

	/* get remaining xsec and convert to nsec. we scale
	 * up remaining xsec by 12 bits and get the top 32 bits
	 * of the multiplication, then we multiply by 1000
	 */
	rlwinm	r5,r4,12,0,19
	lis	r6,1000000@h
	ori	r6,r6,1000000@l
	mulhwu	r5,r5,r6
	mulli	r5,r5,1000
	stw	r5,TSPC32_TV_NSEC(r11)
	mtlr	r12
	crclr	cr0*4+so
	li	r3,0
	blr

	/*
	 * CLOCK_MONOTONIC
	 */

50:	bl	__do_get_xsec@local	/* get xsec from tb & kernel */
	bne-	98f			/* out of line -> do syscall */

	/* seconds are xsec >> 20 */
	rlwinm	r6,r4,12,20,31
	rlwimi	r6,r3,12,0,19

	/* get remaining xsec and convert to nsec. we scale
	 * up remaining xsec by 12 bits and get the top 32 bits
	 * of the multiplication, then we multiply by 1000
	 */
	rlwinm	r7,r4,12,0,19
	lis	r5,1000000@h
	ori	r5,r5,1000000@l
	mulhwu	r7,r7,r5
	mulli	r7,r7,1000

	/* now we must fixup using wall to monotonic. We need to snapshot
	 * that value and do the counter trick again. Fortunately, we still
	 * have the counter value in r8 that was returned by __do_get_xsec.
	 * At this point, r6,r7 contain our sec/nsec values, r3,r4 and r5
	 * can be used
	 */

	lwz	r3,WTOM_CLOCK_SEC(r9)
	lwz	r4,WTOM_CLOCK_NSEC(r9)

	/* We now have our result in r3,r4. We create a fake dependency
	 * on that result and re-check the counter
	 */
	or	r5,r4,r3
	xor	r0,r5,r5
	add	r9,r9,r0
#ifdef CONFIG_PPC64
	lwz	r0,(CFG_TB_UPDATE_COUNT+4)(r9)
#else
	lwz	r0,(CFG_TB_UPDATE_COUNT)(r9)
#endif
        cmpl    cr0,r8,r0		/* check if updated */
	bne-	50b

	/* Calculate and store result. Note that this mimmics the C code,
	 * which may cause funny results if nsec goes negative... is that
	 * possible at all ?
	 */
	add	r3,r3,r6
	add	r4,r4,r7
	lis	r5,NSEC_PER_SEC@h
	ori	r5,r5,NSEC_PER_SEC@l
	cmpl	cr0,r4,r5
	cmpli	cr1,r4,0
	blt	1f
	subf	r4,r5,r4
	addi	r3,r3,1
1:	bge	cr1,1f
	addi	r3,r3,-1
	add	r4,r4,r5
1:	stw	r3,TSPC32_TV_SEC(r11)
	stw	r4,TSPC32_TV_NSEC(r11)

	mtlr	r12
	crclr	cr0*4+so
	li	r3,0
	blr

	/*
	 * syscall fallback
	 */
98:
	mtlr	r12
	mr	r3,r10
	mr	r4,r11
99:
	li	r0,__NR_clock_gettime
	sc
	blr
  .cfi_endproc
V_FUNCTION_END(__kernel_clock_gettime)


/*
 * Exact prototype of clock_getres()
 *
 * int __