Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Michal Simek <monstr@monstr.eu> |
| 3 | * Copyright (C) 2009 PetaLogix |
| 4 | * Copyright (C) 2007 LynuxWorks, Inc. |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/linkage.h> |
| 13 | |
| 14 | /* |
| 15 | * int __strncpy_user(char *to, char *from, int len); |
| 16 | * |
| 17 | * Returns: |
| 18 | * -EFAULT for an exception |
| 19 | * len if we hit the buffer limit |
| 20 | * bytes copied |
| 21 | */ |
| 22 | |
| 23 | .text |
| 24 | .globl __strncpy_user; |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 25 | .type __strncpy_user, @function |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 26 | .align 4; |
| 27 | __strncpy_user: |
| 28 | |
| 29 | /* |
| 30 | * r5 - to |
| 31 | * r6 - from |
| 32 | * r7 - len |
| 33 | * r3 - temp count |
| 34 | * r4 - temp val |
| 35 | */ |
| 36 | addik r3,r7,0 /* temp_count = len */ |
| 37 | beqi r3,3f |
| 38 | 1: |
| 39 | lbu r4,r6,r0 |
| 40 | sb r4,r5,r0 |
| 41 | |
| 42 | addik r3,r3,-1 |
| 43 | beqi r3,2f /* break on len */ |
| 44 | |
| 45 | addik r5,r5,1 |
| 46 | bneid r4,1b |
| 47 | addik r6,r6,1 /* delay slot */ |
| 48 | addik r3,r3,1 /* undo "temp_count--" */ |
| 49 | 2: |
| 50 | rsubk r3,r3,r7 /* temp_count = len - temp_count */ |
| 51 | 3: |
| 52 | rtsd r15,8 |
| 53 | nop |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 54 | .size __strncpy_user, . - __strncpy_user |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 55 | |
| 56 | |
| 57 | .section .fixup, "ax" |
| 58 | .align 2 |
| 59 | 4: |
| 60 | brid 3b |
| 61 | addik r3,r0, -EFAULT |
| 62 | |
| 63 | .section __ex_table, "a" |
| 64 | .word 1b,4b |
| 65 | |
| 66 | /* |
| 67 | * int __strnlen_user(char __user *str, int maxlen); |
| 68 | * |
| 69 | * Returns: |
| 70 | * 0 on error |
| 71 | * maxlen + 1 if no NUL byte found within maxlen bytes |
| 72 | * size of the string (including NUL byte) |
| 73 | */ |
| 74 | |
| 75 | .text |
| 76 | .globl __strnlen_user; |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 77 | .type __strnlen_user, @function |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 78 | .align 4; |
| 79 | __strnlen_user: |
| 80 | addik r3,r6,0 |
| 81 | beqi r3,3f |
| 82 | 1: |
| 83 | lbu r4,r5,r0 |
| 84 | beqid r4,2f /* break on NUL */ |
| 85 | addik r3,r3,-1 /* delay slot */ |
| 86 | |
| 87 | bneid r3,1b |
| 88 | addik r5,r5,1 /* delay slot */ |
| 89 | |
| 90 | addik r3,r3,-1 /* for break on len */ |
| 91 | 2: |
| 92 | rsubk r3,r3,r6 |
| 93 | 3: |
| 94 | rtsd r15,8 |
| 95 | nop |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 96 | .size __strnlen_user, . - __strnlen_user |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 97 | |
| 98 | |
| 99 | .section .fixup,"ax" |
| 100 | 4: |
| 101 | brid 3b |
| 102 | addk r3,r0,r0 |
| 103 | |
| 104 | .section __ex_table,"a" |
| 105 | .word 1b,4b |
| 106 | |
| 107 | /* |
| 108 | * int __copy_tofrom_user(char *to, char *from, int len) |
| 109 | * Return: |
| 110 | * 0 on success |
| 111 | * number of not copied bytes on error |
| 112 | */ |
| 113 | .text |
| 114 | .globl __copy_tofrom_user; |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 115 | .type __copy_tofrom_user, @function |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 116 | .align 4; |
| 117 | __copy_tofrom_user: |
| 118 | /* |
| 119 | * r5 - to |
| 120 | * r6 - from |
| 121 | * r7, r3 - count |
| 122 | * r4 - tempval |
| 123 | */ |
| 124 | addik r3,r7,0 |
| 125 | beqi r3,3f |
| 126 | 1: |
| 127 | lbu r4,r6,r0 |
| 128 | addik r6,r6,1 |
| 129 | 2: |
| 130 | sb r4,r5,r0 |
| 131 | addik r3,r3,-1 |
| 132 | bneid r3,1b |
| 133 | addik r5,r5,1 /* delay slot */ |
| 134 | 3: |
| 135 | rtsd r15,8 |
| 136 | nop |
Michal Simek | 1385196 | 2010-03-23 08:09:32 +0100 | [diff] [blame] | 137 | .size __copy_tofrom_user, . - __copy_tofrom_user |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 138 | |
| 139 | |
| 140 | .section __ex_table,"a" |
| 141 | .word 1b,3b,2b,3b |