Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/lib/uaccess.S |
| 3 | * __copy_{from|to}_user functions. |
| 4 | * |
| 5 | * s390 |
| 6 | * Copyright (C) 2000,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 7 | * Authors(s): Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 8 | * |
| 9 | * These functions have standard call interface |
| 10 | */ |
| 11 | |
| 12 | #include <linux/errno.h> |
| 13 | #include <asm/lowcore.h> |
Sam Ravnborg | 0013a85 | 2005-09-09 20:57:26 +0200 | [diff] [blame] | 14 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | .text |
| 17 | .align 4 |
| 18 | .globl __copy_from_user_asm |
| 19 | # %r2 = to, %r3 = n, %r4 = from |
| 20 | __copy_from_user_asm: |
| 21 | slr %r0,%r0 |
| 22 | 0: mvcp 0(%r3,%r2),0(%r4),%r0 |
| 23 | jnz 1f |
| 24 | slr %r2,%r2 |
| 25 | br %r14 |
| 26 | 1: la %r2,256(%r2) |
| 27 | la %r4,256(%r4) |
| 28 | ahi %r3,-256 |
| 29 | 2: mvcp 0(%r3,%r2),0(%r4),%r0 |
| 30 | jnz 1b |
| 31 | 3: slr %r2,%r2 |
| 32 | br %r14 |
| 33 | 4: lhi %r0,-4096 |
| 34 | lr %r5,%r4 |
| 35 | slr %r5,%r0 |
| 36 | nr %r5,%r0 # %r5 = (%r4 + 4096) & -4096 |
| 37 | slr %r5,%r4 # %r5 = #bytes to next user page boundary |
| 38 | clr %r3,%r5 # copy crosses next page boundary ? |
| 39 | jnh 6f # no, the current page faulted |
| 40 | # move with the reduced length which is < 256 |
| 41 | 5: mvcp 0(%r5,%r2),0(%r4),%r0 |
| 42 | slr %r3,%r5 |
| 43 | 6: lr %r2,%r3 |
| 44 | br %r14 |
| 45 | .section __ex_table,"a" |
| 46 | .long 0b,4b |
| 47 | .long 2b,4b |
| 48 | .long 5b,6b |
| 49 | .previous |
| 50 | |
| 51 | .align 4 |
| 52 | .text |
| 53 | .globl __copy_to_user_asm |
| 54 | # %r2 = from, %r3 = n, %r4 = to |
| 55 | __copy_to_user_asm: |
| 56 | slr %r0,%r0 |
| 57 | 0: mvcs 0(%r3,%r4),0(%r2),%r0 |
| 58 | jnz 1f |
| 59 | slr %r2,%r2 |
| 60 | br %r14 |
| 61 | 1: la %r2,256(%r2) |
| 62 | la %r4,256(%r4) |
| 63 | ahi %r3,-256 |
| 64 | 2: mvcs 0(%r3,%r4),0(%r2),%r0 |
| 65 | jnz 1b |
| 66 | 3: slr %r2,%r2 |
| 67 | br %r14 |
| 68 | 4: lhi %r0,-4096 |
| 69 | lr %r5,%r4 |
| 70 | slr %r5,%r0 |
| 71 | nr %r5,%r0 # %r5 = (%r4 + 4096) & -4096 |
| 72 | slr %r5,%r4 # %r5 = #bytes to next user page boundary |
| 73 | clr %r3,%r5 # copy crosses next page boundary ? |
| 74 | jnh 6f # no, the current page faulted |
| 75 | # move with the reduced length which is < 256 |
| 76 | 5: mvcs 0(%r5,%r4),0(%r2),%r0 |
| 77 | slr %r3,%r5 |
| 78 | 6: lr %r2,%r3 |
| 79 | br %r14 |
| 80 | .section __ex_table,"a" |
| 81 | .long 0b,4b |
| 82 | .long 2b,4b |
| 83 | .long 5b,6b |
| 84 | .previous |
| 85 | |
| 86 | .align 4 |
| 87 | .text |
| 88 | .globl __copy_in_user_asm |
| 89 | # %r2 = from, %r3 = n, %r4 = to |
| 90 | __copy_in_user_asm: |
| 91 | sacf 256 |
| 92 | bras 1,1f |
| 93 | mvc 0(1,%r4),0(%r2) |
| 94 | 0: mvc 0(256,%r4),0(%r2) |
| 95 | la %r2,256(%r2) |
| 96 | la %r4,256(%r4) |
| 97 | 1: ahi %r3,-256 |
| 98 | jnm 0b |
| 99 | 2: ex %r3,0(%r1) |
| 100 | sacf 0 |
| 101 | slr %r2,%r2 |
| 102 | br 14 |
| 103 | 3: mvc 0(1,%r4),0(%r2) |
| 104 | la %r2,1(%r2) |
| 105 | la %r4,1(%r4) |
| 106 | ahi %r3,-1 |
| 107 | jnm 3b |
| 108 | 4: lr %r2,%r3 |
| 109 | sacf 0 |
| 110 | br %r14 |
| 111 | .section __ex_table,"a" |
| 112 | .long 0b,3b |
| 113 | .long 2b,3b |
| 114 | .long 3b,4b |
| 115 | .previous |
| 116 | |
| 117 | .align 4 |
| 118 | .text |
| 119 | .globl __clear_user_asm |
| 120 | # %r2 = to, %r3 = n |
| 121 | __clear_user_asm: |
| 122 | bras %r5,0f |
| 123 | .long empty_zero_page |
| 124 | 0: l %r5,0(%r5) |
| 125 | slr %r0,%r0 |
| 126 | 1: mvcs 0(%r3,%r2),0(%r5),%r0 |
| 127 | jnz 2f |
| 128 | slr %r2,%r2 |
| 129 | br %r14 |
| 130 | 2: la %r2,256(%r2) |
| 131 | ahi %r3,-256 |
| 132 | 3: mvcs 0(%r3,%r2),0(%r5),%r0 |
| 133 | jnz 2b |
| 134 | 4: slr %r2,%r2 |
| 135 | br %r14 |
| 136 | 5: lhi %r0,-4096 |
| 137 | lr %r4,%r2 |
| 138 | slr %r4,%r0 |
| 139 | nr %r4,%r0 # %r4 = (%r2 + 4096) & -4096 |
| 140 | slr %r4,%r2 # %r4 = #bytes to next user page boundary |
| 141 | clr %r3,%r4 # clear crosses next page boundary ? |
| 142 | jnh 7f # no, the current page faulted |
| 143 | # clear with the reduced length which is < 256 |
| 144 | 6: mvcs 0(%r4,%r2),0(%r5),%r0 |
| 145 | slr %r3,%r4 |
| 146 | 7: lr %r2,%r3 |
| 147 | br %r14 |
| 148 | .section __ex_table,"a" |
| 149 | .long 1b,5b |
| 150 | .long 3b,5b |
| 151 | .long 6b,7b |
| 152 | .previous |
| 153 | |
| 154 | .align 4 |
| 155 | .text |
| 156 | .globl __strncpy_from_user_asm |
| 157 | # %r2 = count, %r3 = dst, %r4 = src |
| 158 | __strncpy_from_user_asm: |
| 159 | lhi %r0,0 |
| 160 | lr %r1,%r4 |
| 161 | la %r4,0(%r4) # clear high order bit from %r4 |
| 162 | la %r2,0(%r2,%r4) # %r2 points to first byte after string |
| 163 | sacf 256 |
| 164 | 0: srst %r2,%r1 |
| 165 | jo 0b |
| 166 | sacf 0 |
| 167 | lr %r1,%r2 |
| 168 | jh 1f # \0 found in string ? |
| 169 | ahi %r1,1 # include \0 in copy |
| 170 | 1: slr %r1,%r4 # %r1 = copy length (without \0) |
| 171 | slr %r2,%r4 # %r2 = return length (including \0) |
| 172 | 2: mvcp 0(%r1,%r3),0(%r4),%r0 |
| 173 | jnz 3f |
| 174 | br %r14 |
| 175 | 3: la %r3,256(%r3) |
| 176 | la %r4,256(%r4) |
| 177 | ahi %r1,-256 |
| 178 | mvcp 0(%r1,%r3),0(%r4),%r0 |
| 179 | jnz 3b |
| 180 | br %r14 |
| 181 | 4: sacf 0 |
| 182 | lhi %r2,-EFAULT |
| 183 | br %r14 |
| 184 | .section __ex_table,"a" |
| 185 | .long 0b,4b |
| 186 | .previous |
| 187 | |
| 188 | .align 4 |
| 189 | .text |
| 190 | .globl __strnlen_user_asm |
| 191 | # %r2 = count, %r3 = src |
| 192 | __strnlen_user_asm: |
| 193 | lhi %r0,0 |
| 194 | lr %r1,%r3 |
| 195 | la %r3,0(%r3) # clear high order bit from %r4 |
| 196 | la %r2,0(%r2,%r3) # %r2 points to first byte after string |
| 197 | sacf 256 |
| 198 | 0: srst %r2,%r1 |
| 199 | jo 0b |
| 200 | sacf 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | ahi %r2,1 # strnlen_user result includes the \0 |
Gerald Schaefer | 331c465 | 2006-03-07 21:55:37 -0800 | [diff] [blame] | 202 | # or return count+1 if \0 not found |
| 203 | slr %r2,%r3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | br %r14 |
| 205 | 2: sacf 0 |
Gerald Schaefer | 331c465 | 2006-03-07 21:55:37 -0800 | [diff] [blame] | 206 | slr %r2,%r2 # return 0 on exception |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | br %r14 |
| 208 | .section __ex_table,"a" |
| 209 | .long 0b,2b |
| 210 | .previous |