2017-11-24 15:00:32 +01:00
/* SPDX-License-Identifier: GPL-2.0 */
2008-12-25 13:38:36 +01:00
/ *
* Userland i m p l e m e n t a t i o n o f c l o c k _ g e t t i m e ( ) f o r 3 2 b i t s p r o c e s s e s i n a
* s3 9 0 k e r n e l f o r u s e i n t h e v D S O
*
* Copyright I B M C o r p . 2 0 0 8
* Author( s ) : M a r t i n S c h w i d e f s k y ( s c h w i d e f s k y @de.ibm.com)
* /
# include < a s m / v d s o . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / u n i s t d . h >
2017-11-20 11:41:07 +01:00
# include < a s m / d w a r f . h >
2018-09-14 18:08:10 +02:00
# include < a s m / p t r a c e . h >
2008-12-25 13:38:36 +01:00
.text
.align 4
.globl __kernel_clock_gettime
.type _ _ kernel_ c l o c k _ g e t t i m e ,@function
__kernel_clock_gettime :
2017-11-20 11:46:13 +01:00
CFI_ S T A R T P R O C
2014-10-27 08:28:08 +01:00
ahi % r15 ,- 1 6
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D + 1 6
CFI_ V A L _ O F F S E T 1 5 , - S T A C K _ F R A M E _ O V E R H E A D
2008-12-25 13:38:36 +01:00
basr % r5 ,0
0 : al % r5 ,2 1 f - 0 b ( % r5 ) / * g e t & _ v d s o _ d a t a * /
2014-08-29 12:31:45 +02:00
chi % r2 ,_ _ C L O C K _ R E A L T I M E _ C O A R S E
je 1 0 f
2010-10-29 16:50:41 +02:00
chi % r2 ,_ _ C L O C K _ R E A L T I M E
2014-08-29 10:16:03 +02:00
je 1 1 f
2014-08-29 12:31:45 +02:00
chi % r2 ,_ _ C L O C K _ M O N O T O N I C _ C O A R S E
je 9 f
2010-10-29 16:50:41 +02:00
chi % r2 ,_ _ C L O C K _ M O N O T O N I C
2008-12-25 13:38:36 +01:00
jne 1 9 f
/* CLOCK_MONOTONIC */
1 : l % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * l o a d u p d a t e c o u n t e r * /
tml % r4 ,0 x00 0 1 / * p e n d i n g u p d a t e ? l o o p * /
jnz 1 b
2014-10-27 08:28:08 +01:00
stcke 0 ( % r15 ) / * S t o r e T O D c l o c k * /
lm % r0 ,% r1 ,1 ( % r15 )
2008-12-25 13:38:36 +01:00
s % r0 ,_ _ V D S O _ X T I M E _ S T A M P ( % r5 ) / * T O D - c y c l e _ l a s t * /
sl % r1 ,_ _ V D S O _ X T I M E _ S T A M P + 4 ( % r5 )
brc 3 ,2 f
ahi % r0 ,- 1
2013-11-22 10:04:53 +01:00
2 : ms % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 ) / * * t k - > m u l t * /
2008-12-25 13:38:36 +01:00
lr % r2 ,% r0
2013-11-22 10:04:53 +01:00
l % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 )
2008-12-25 13:38:36 +01:00
ltr % r1 ,% r1
mr % r0 ,% r0
jnm 3 f
2013-11-22 10:04:53 +01:00
a % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 )
2008-12-25 13:38:36 +01:00
3 : alr % r0 ,% r2
2013-12-02 18:00:36 +01:00
al % r0 ,_ _ V D S O _ W T O M _ N S E C ( % r5 )
2008-12-25 13:38:36 +01:00
al % r1 ,_ _ V D S O _ W T O M _ N S E C + 4 ( % r5 )
brc 1 2 ,5 f
ahi % r0 ,1
2013-11-22 10:04:53 +01:00
5 : l % r2 ,_ _ V D S O _ T K _ S H I F T ( % r5 ) / * T i m e k e e p e r s h i f t * /
srdl % r0 ,0 ( % r2 ) / * > > t k - > s h i f t * /
2013-12-02 18:00:36 +01:00
l % r2 ,_ _ V D S O _ W T O M _ S E C + 4 ( % r5 )
2008-12-25 13:38:36 +01:00
cl % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * c h e c k u p d a t e c o u n t e r * /
jne 1 b
basr % r5 ,0
6 : ltr % r0 ,% r0
jnz 7 f
cl % r1 ,2 0 f - 6 b ( % r5 )
jl 8 f
7 : ahi % r2 ,1
sl % r1 ,2 0 f - 6 b ( % r5 )
brc 3 ,6 b
ahi % r0 ,- 1
j 6 b
8 : st % r2 ,0 ( % r3 ) / * s t o r e t p - > t v _ s e c * /
st % r1 ,4 ( % r3 ) / * s t o r e t p - > t v _ n s e c * /
2014-08-29 10:16:03 +02:00
lhi % r2 ,0
2014-10-27 08:28:08 +01:00
ahi % r15 ,1 6
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D
2017-11-20 11:46:13 +01:00
CFI_ R E S T O R E 1 5
2008-12-25 13:38:36 +01:00
br % r14
2014-08-29 12:31:45 +02:00
/* CLOCK_MONOTONIC_COARSE */
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D + 1 6
CFI_ V A L _ O F F S E T 1 5 , - S T A C K _ F R A M E _ O V E R H E A D
2014-08-29 12:31:45 +02:00
9 : l % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * l o a d u p d a t e c o u n t e r * /
tml % r4 ,0 x00 0 1 / * p e n d i n g u p d a t e ? l o o p * /
jnz 9 b
l % r2 ,_ _ V D S O _ W T O M _ C R S _ S E C + 4 ( % r5 )
l % r1 ,_ _ V D S O _ W T O M _ C R S _ N S E C + 4 ( % r5 )
cl % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * c h e c k u p d a t e c o u n t e r * /
jne 9 b
j 8 b
/* CLOCK_REALTIME_COARSE */
10 : l % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * l o a d u p d a t e c o u n t e r * /
tml % r4 ,0 x00 0 1 / * p e n d i n g u p d a t e ? l o o p * /
jnz 1 0 b
l % r2 ,_ _ V D S O _ X T I M E _ C R S _ S E C + 4 ( % r5 )
l % r1 ,_ _ V D S O _ X T I M E _ C R S _ N S E C + 4 ( % r5 )
cl % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * c h e c k u p d a t e c o u n t e r * /
jne 1 0 b
j 1 7 f
2008-12-25 13:38:36 +01:00
/* CLOCK_REALTIME */
11 : l % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * l o a d u p d a t e c o u n t e r * /
tml % r4 ,0 x00 0 1 / * p e n d i n g u p d a t e ? l o o p * /
jnz 1 1 b
2014-10-27 08:28:08 +01:00
stcke 0 ( % r15 ) / * S t o r e T O D c l o c k * /
2016-10-11 12:49:50 +02:00
lm % r0 ,% r1 ,_ _ V D S O _ T S _ E N D ( % r5 ) / * T O D s t e e r i n g e n d t i m e * /
s % r0 ,1 ( % r15 ) / * n o - t s _ s t e e r i n g _ e n d * /
sl % r1 ,5 ( % r15 )
brc 3 ,2 2 f
ahi % r0 ,- 1
22 : ltr % r0 ,% r0 / * p a s t e n d o f s t e e r i n g ? * /
jm 2 4 f
srdl % r0 ,1 5 / * 1 p e r 2 ^ 1 6 * /
tm _ _ V D S O _ T S _ D I R + 3 ( % r5 ) ,0 x01 / * s t e e r i n g d i r e c t i o n ? * /
jz 2 3 f
lcr % r0 ,% r0 / * n e g a t i v e T O D o f f s e t * /
lcr % r1 ,% r1
je 2 3 f
ahi % r0 ,- 1
23 : a % r0 ,1 ( % r15 ) / * a d d T O D t i m e s t a m p * /
al % r1 ,5 ( % r15 )
brc 1 2 ,2 5 f
ahi % r0 ,1
j 2 5 f
24 : lm % r0 ,% r1 ,1 ( % r15 ) / * l o a d T O D t i m e s t a m p * /
25 : s % r0 ,_ _ V D S O _ X T I M E _ S T A M P ( % r5 ) / * T O D - c y c l e _ l a s t * /
2008-12-25 13:38:36 +01:00
sl % r1 ,_ _ V D S O _ X T I M E _ S T A M P + 4 ( % r5 )
brc 3 ,1 2 f
ahi % r0 ,- 1
2013-11-22 10:04:53 +01:00
12 : ms % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 ) / * * t k - > m u l t * /
2008-12-25 13:38:36 +01:00
lr % r2 ,% r0
2013-11-22 10:04:53 +01:00
l % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 )
2008-12-25 13:38:36 +01:00
ltr % r1 ,% r1
mr % r0 ,% r0
jnm 1 3 f
2013-11-22 10:04:53 +01:00
a % r0 ,_ _ V D S O _ T K _ M U L T ( % r5 )
2008-12-25 13:38:36 +01:00
13 : alr % r0 ,% r2
2013-11-22 10:04:53 +01:00
al % r0 ,_ _ V D S O _ X T I M E _ N S E C ( % r5 ) / * + t k - > x t i m e _ n s e c * /
2008-12-25 13:38:36 +01:00
al % r1 ,_ _ V D S O _ X T I M E _ N S E C + 4 ( % r5 )
brc 1 2 ,1 4 f
ahi % r0 ,1
2013-11-22 10:04:53 +01:00
14 : l % r2 ,_ _ V D S O _ T K _ S H I F T ( % r5 ) / * T i m e k e e p e r s h i f t * /
srdl % r0 ,0 ( % r2 ) / * > > t k - > s h i f t * /
l % r2 ,_ _ V D S O _ X T I M E _ S E C + 4 ( % r5 )
2008-12-25 13:38:36 +01:00
cl % r4 ,_ _ V D S O _ U P D _ C O U N T + 4 ( % r5 ) / * c h e c k u p d a t e c o u n t e r * /
jne 1 1 b
basr % r5 ,0
15 : ltr % r0 ,% r0
jnz 1 6 f
cl % r1 ,2 0 f - 1 5 b ( % r5 )
jl 1 7 f
16 : ahi % r2 ,1
sl % r1 ,2 0 f - 1 5 b ( % r5 )
brc 3 ,1 5 b
ahi % r0 ,- 1
j 1 5 b
17 : st % r2 ,0 ( % r3 ) / * s t o r e t p - > t v _ s e c * /
st % r1 ,4 ( % r3 ) / * s t o r e t p - > t v _ n s e c * /
2014-08-29 10:16:03 +02:00
lhi % r2 ,0
2014-10-27 08:28:08 +01:00
ahi % r15 ,1 6
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D
2017-11-20 11:46:13 +01:00
CFI_ R E S T O R E 1 5
2008-12-25 13:38:36 +01:00
br % r14
/* Fallback to system call */
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D + 1 6
CFI_ V A L _ O F F S E T 1 5 , - S T A C K _ F R A M E _ O V E R H E A D
2008-12-25 13:38:36 +01:00
19 : lhi % r1 ,_ _ N R _ c l o c k _ g e t t i m e
svc 0
2014-10-27 08:28:08 +01:00
ahi % r15 ,1 6
2018-09-14 18:08:10 +02:00
CFI_ D E F _ C F A _ O F F S E T S T A C K _ F R A M E _ O V E R H E A D
2017-11-20 11:46:13 +01:00
CFI_ R E S T O R E 1 5
2008-12-25 13:38:36 +01:00
br % r14
2017-11-20 11:46:13 +01:00
CFI_ E N D P R O C
2008-12-25 13:38:36 +01:00
20 : .long 1000000000
21 : .long _ v d s o _ d a t a - 0 b
.size _ _ kernel_ c l o c k _ g e t t i m e ,. - _ _ k e r n e l _ c l o c k _ g e t t i m e