Anton Blanchard | 17968fb | 2012-05-27 19:54:03 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 15 | * |
| 16 | * Copyright (C) IBM Corporation, 2012 |
| 17 | * |
| 18 | * Author: Anton Blanchard <anton@au.ibm.com> |
| 19 | */ |
| 20 | |
| 21 | #include <asm/ppc_asm.h> |
| 22 | |
| 23 | /** |
| 24 | * __clear_user: - Zero a block of memory in user space, with less checking. |
| 25 | * @to: Destination address, in user space. |
| 26 | * @n: Number of bytes to zero. |
| 27 | * |
| 28 | * Zero a block of memory in user space. Caller must check |
| 29 | * the specified block with access_ok() before calling this function. |
| 30 | * |
| 31 | * Returns number of bytes that could not be cleared. |
| 32 | * On success, this will be zero. |
| 33 | */ |
| 34 | |
| 35 | .macro err1 |
| 36 | 100: |
| 37 | .section __ex_table,"a" |
| 38 | .align 3 |
| 39 | .llong 100b,.Ldo_err1 |
| 40 | .previous |
| 41 | .endm |
| 42 | |
| 43 | .macro err2 |
| 44 | 200: |
| 45 | .section __ex_table,"a" |
| 46 | .align 3 |
| 47 | .llong 200b,.Ldo_err2 |
| 48 | .previous |
| 49 | .endm |
| 50 | |
| 51 | .macro err3 |
| 52 | 300: |
| 53 | .section __ex_table,"a" |
| 54 | .align 3 |
| 55 | .llong 300b,.Ldo_err3 |
| 56 | .previous |
| 57 | .endm |
| 58 | |
| 59 | .Ldo_err1: |
| 60 | mr r3,r8 |
| 61 | |
| 62 | .Ldo_err2: |
| 63 | mtctr r4 |
| 64 | 1: |
| 65 | err3; stb r0,0(r3) |
| 66 | addi r3,r3,1 |
| 67 | addi r4,r4,-1 |
| 68 | bdnz 1b |
| 69 | |
| 70 | .Ldo_err3: |
| 71 | mr r3,r4 |
| 72 | blr |
| 73 | |
| 74 | _GLOBAL(__clear_user) |
| 75 | cmpdi r4,32 |
| 76 | neg r6,r3 |
| 77 | li r0,0 |
| 78 | blt .Lshort_clear |
| 79 | mr r8,r3 |
| 80 | mtocrf 0x01,r6 |
| 81 | clrldi r6,r6,(64-3) |
| 82 | |
| 83 | /* Get the destination 8 byte aligned */ |
| 84 | bf cr7*4+3,1f |
| 85 | err1; stb r0,0(r3) |
| 86 | addi r3,r3,1 |
| 87 | |
| 88 | 1: bf cr7*4+2,2f |
| 89 | err1; sth r0,0(r3) |
| 90 | addi r3,r3,2 |
| 91 | |
| 92 | 2: bf cr7*4+1,3f |
| 93 | err1; stw r0,0(r3) |
| 94 | addi r3,r3,4 |
| 95 | |
| 96 | 3: sub r4,r4,r6 |
| 97 | srdi r6,r4,5 |
| 98 | cmpdi r4,32 |
| 99 | blt .Lshort_clear |
| 100 | mtctr r6 |
| 101 | |
| 102 | /* Do 32 byte chunks */ |
| 103 | 4: |
| 104 | err2; std r0,0(r3) |
| 105 | err2; std r0,8(r3) |
| 106 | err2; std r0,16(r3) |
| 107 | err2; std r0,24(r3) |
| 108 | addi r3,r3,32 |
| 109 | addi r4,r4,-32 |
| 110 | bdnz 4b |
| 111 | |
| 112 | .Lshort_clear: |
| 113 | /* up to 31 bytes to go */ |
| 114 | cmpdi r4,16 |
| 115 | blt 6f |
| 116 | err2; std r0,0(r3) |
| 117 | err2; std r0,8(r3) |
| 118 | addi r3,r3,16 |
| 119 | addi r4,r4,-16 |
| 120 | |
| 121 | /* Up to 15 bytes to go */ |
| 122 | 6: mr r8,r3 |
| 123 | clrldi r4,r4,(64-4) |
| 124 | mtocrf 0x01,r4 |
| 125 | bf cr7*4+0,7f |
| 126 | err1; std r0,0(r3) |
| 127 | addi r3,r3,8 |
| 128 | |
| 129 | 7: bf cr7*4+1,8f |
| 130 | err1; stw r0,0(r3) |
| 131 | addi r3,r3,4 |
| 132 | |
| 133 | 8: bf cr7*4+2,9f |
| 134 | err1; sth r0,0(r3) |
| 135 | addi r3,r3,2 |
| 136 | |
| 137 | 9: bf cr7*4+3,10f |
| 138 | err1; stb r0,0(r3) |
| 139 | |
| 140 | 10: li r3,0 |
| 141 | blr |