Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Userland implementation of clock_gettime() for 32 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 | basr %r5,0 |
| 23 | 0: al %r5,21f-0b(%r5) /* get &_vdso_data */ |
Heiko Carstens | b342398 | 2010-10-29 16:50:41 +0200 | [diff] [blame^] | 24 | chi %r2,__CLOCK_REALTIME |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 25 | je 10f |
Heiko Carstens | b342398 | 2010-10-29 16:50:41 +0200 | [diff] [blame^] | 26 | chi %r2,__CLOCK_MONOTONIC |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 27 | jne 19f |
| 28 | |
| 29 | /* CLOCK_MONOTONIC */ |
| 30 | ltr %r3,%r3 |
| 31 | jz 9f /* tp == NULL */ |
| 32 | 1: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */ |
| 33 | tml %r4,0x0001 /* pending update ? loop */ |
| 34 | jnz 1b |
| 35 | stck 24(%r15) /* Store TOD clock */ |
| 36 | lm %r0,%r1,24(%r15) |
| 37 | s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ |
| 38 | sl %r1,__VDSO_XTIME_STAMP+4(%r5) |
| 39 | brc 3,2f |
| 40 | ahi %r0,-1 |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 41 | 2: ms %r0,__VDSO_NTP_MULT(%r5) /* cyc2ns(clock,cycle_delta) */ |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 42 | lr %r2,%r0 |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 43 | l %r0,__VDSO_NTP_MULT(%r5) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 44 | ltr %r1,%r1 |
| 45 | mr %r0,%r0 |
| 46 | jnm 3f |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 47 | a %r0,__VDSO_NTP_MULT(%r5) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 48 | 3: alr %r0,%r2 |
| 49 | srdl %r0,12 |
| 50 | al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */ |
| 51 | al %r1,__VDSO_XTIME_NSEC+4(%r5) |
| 52 | brc 12,4f |
| 53 | ahi %r0,1 |
| 54 | 4: l %r2,__VDSO_XTIME_SEC+4(%r5) |
| 55 | al %r0,__VDSO_WTOM_NSEC(%r5) /* + wall_to_monotonic */ |
| 56 | al %r1,__VDSO_WTOM_NSEC+4(%r5) |
| 57 | brc 12,5f |
| 58 | ahi %r0,1 |
| 59 | 5: al %r2,__VDSO_WTOM_SEC+4(%r5) |
| 60 | cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */ |
| 61 | jne 1b |
| 62 | basr %r5,0 |
| 63 | 6: ltr %r0,%r0 |
| 64 | jnz 7f |
| 65 | cl %r1,20f-6b(%r5) |
| 66 | jl 8f |
| 67 | 7: ahi %r2,1 |
| 68 | sl %r1,20f-6b(%r5) |
| 69 | brc 3,6b |
| 70 | ahi %r0,-1 |
| 71 | j 6b |
| 72 | 8: st %r2,0(%r3) /* store tp->tv_sec */ |
| 73 | st %r1,4(%r3) /* store tp->tv_nsec */ |
| 74 | 9: lhi %r2,0 |
| 75 | br %r14 |
| 76 | |
| 77 | /* CLOCK_REALTIME */ |
| 78 | 10: ltr %r3,%r3 /* tp == NULL */ |
| 79 | jz 18f |
| 80 | 11: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */ |
| 81 | tml %r4,0x0001 /* pending update ? loop */ |
| 82 | jnz 11b |
| 83 | stck 24(%r15) /* Store TOD clock */ |
| 84 | lm %r0,%r1,24(%r15) |
| 85 | s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ |
| 86 | sl %r1,__VDSO_XTIME_STAMP+4(%r5) |
| 87 | brc 3,12f |
| 88 | ahi %r0,-1 |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 89 | 12: ms %r0,__VDSO_NTP_MULT(%r5) /* cyc2ns(clock,cycle_delta) */ |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 90 | lr %r2,%r0 |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 91 | l %r0,__VDSO_NTP_MULT(%r5) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 92 | ltr %r1,%r1 |
| 93 | mr %r0,%r0 |
| 94 | jnm 13f |
Hendrik Brueckner | 157a1a2 | 2010-04-22 17:17:06 +0200 | [diff] [blame] | 95 | a %r0,__VDSO_NTP_MULT(%r5) |
Martin Schwidefsky | b020632 | 2008-12-25 13:38:36 +0100 | [diff] [blame] | 96 | 13: alr %r0,%r2 |
| 97 | srdl %r0,12 |
| 98 | al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */ |
| 99 | al %r1,__VDSO_XTIME_NSEC+4(%r5) |
| 100 | brc 12,14f |
| 101 | ahi %r0,1 |
| 102 | 14: l %r2,__VDSO_XTIME_SEC+4(%r5) |
| 103 | cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */ |
| 104 | jne 11b |
| 105 | basr %r5,0 |
| 106 | 15: ltr %r0,%r0 |
| 107 | jnz 16f |
| 108 | cl %r1,20f-15b(%r5) |
| 109 | jl 17f |
| 110 | 16: ahi %r2,1 |
| 111 | sl %r1,20f-15b(%r5) |
| 112 | brc 3,15b |
| 113 | ahi %r0,-1 |
| 114 | j 15b |
| 115 | 17: st %r2,0(%r3) /* store tp->tv_sec */ |
| 116 | st %r1,4(%r3) /* store tp->tv_nsec */ |
| 117 | 18: lhi %r2,0 |
| 118 | br %r14 |
| 119 | |
| 120 | /* Fallback to system call */ |
| 121 | 19: lhi %r1,__NR_clock_gettime |
| 122 | svc 0 |
| 123 | br %r14 |
| 124 | |
| 125 | 20: .long 1000000000 |
| 126 | 21: .long _vdso_data - 0b |
| 127 | .cfi_endproc |
| 128 | .size __kernel_clock_gettime,.-__kernel_clock_gettime |