Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * String handling functions for PowerPC. |
| 3 | * |
| 4 | * Copyright (C) 1996 Paul Mackerras. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 11 | #include <asm/processor.h> |
| 12 | #include <asm/errno.h> |
| 13 | #include <asm/ppc_asm.h> |
| 14 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 15 | .section __ex_table,"a" |
Michael Ellerman | 76bfdcf | 2008-07-17 17:17:52 +1000 | [diff] [blame] | 16 | PPC_LONG_ALIGN |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 17 | .text |
| 18 | |
| 19 | _GLOBAL(strcpy) |
| 20 | addi r5,r3,-1 |
| 21 | addi r4,r4,-1 |
| 22 | 1: lbzu r0,1(r4) |
| 23 | cmpwi 0,r0,0 |
| 24 | stbu r0,1(r5) |
| 25 | bne 1b |
| 26 | blr |
| 27 | |
| 28 | /* This clears out any unused part of the destination buffer, |
| 29 | just as the libc version does. -- paulus */ |
| 30 | _GLOBAL(strncpy) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 31 | PPC_LCMPI 0,r5,0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 32 | beqlr |
| 33 | mtctr r5 |
| 34 | addi r6,r3,-1 |
| 35 | addi r4,r4,-1 |
| 36 | 1: lbzu r0,1(r4) |
| 37 | cmpwi 0,r0,0 |
| 38 | stbu r0,1(r6) |
| 39 | bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ |
| 40 | bnelr /* if we didn't hit a null char, we're done */ |
| 41 | mfctr r5 |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 42 | PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 43 | beqlr /* we know r0 == 0 here */ |
| 44 | 2: stbu r0,1(r6) /* clear it out if so */ |
| 45 | bdnz 2b |
| 46 | blr |
| 47 | |
| 48 | _GLOBAL(strcat) |
| 49 | addi r5,r3,-1 |
| 50 | addi r4,r4,-1 |
| 51 | 1: lbzu r0,1(r5) |
| 52 | cmpwi 0,r0,0 |
| 53 | bne 1b |
| 54 | addi r5,r5,-1 |
| 55 | 1: lbzu r0,1(r4) |
| 56 | cmpwi 0,r0,0 |
| 57 | stbu r0,1(r5) |
| 58 | bne 1b |
| 59 | blr |
| 60 | |
| 61 | _GLOBAL(strcmp) |
| 62 | addi r5,r3,-1 |
| 63 | addi r4,r4,-1 |
| 64 | 1: lbzu r3,1(r5) |
| 65 | cmpwi 1,r3,0 |
| 66 | lbzu r0,1(r4) |
| 67 | subf. r3,r0,r3 |
| 68 | beqlr 1 |
| 69 | beq 1b |
| 70 | blr |
| 71 | |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 72 | _GLOBAL(strncmp) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 73 | PPC_LCMPI 0,r5,0 |
| 74 | beq- 2f |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 75 | mtctr r5 |
| 76 | addi r5,r3,-1 |
| 77 | addi r4,r4,-1 |
| 78 | 1: lbzu r3,1(r5) |
| 79 | cmpwi 1,r3,0 |
| 80 | lbzu r0,1(r4) |
| 81 | subf. r3,r0,r3 |
| 82 | beqlr 1 |
| 83 | bdnzt eq,1b |
| 84 | blr |
Jeff Mahoney | 637a990 | 2010-03-17 10:55:51 +0000 | [diff] [blame] | 85 | 2: li r3,0 |
| 86 | blr |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 87 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 88 | _GLOBAL(strlen) |
| 89 | addi r4,r3,-1 |
| 90 | 1: lbzu r0,1(r4) |
| 91 | cmpwi 0,r0,0 |
| 92 | bne 1b |
| 93 | subf r3,r3,r4 |
| 94 | blr |
| 95 | |
| 96 | _GLOBAL(memcmp) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 97 | PPC_LCMPI 0,r5,0 |
| 98 | beq- 2f |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 99 | mtctr r5 |
| 100 | addi r6,r3,-1 |
| 101 | addi r4,r4,-1 |
| 102 | 1: lbzu r3,1(r6) |
| 103 | lbzu r0,1(r4) |
| 104 | subf. r3,r0,r3 |
| 105 | bdnzt 2,1b |
| 106 | blr |
| 107 | 2: li r3,0 |
| 108 | blr |
| 109 | |
| 110 | _GLOBAL(memchr) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 111 | PPC_LCMPI 0,r5,0 |
| 112 | beq- 2f |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 113 | mtctr r5 |
| 114 | addi r3,r3,-1 |
| 115 | 1: lbzu r0,1(r3) |
| 116 | cmpw 0,r0,r4 |
| 117 | bdnzf 2,1b |
| 118 | beqlr |
| 119 | 2: li r3,0 |
| 120 | blr |
| 121 | |
Anton Blanchard | 17968fb | 2012-05-27 19:54:03 +0000 | [diff] [blame] | 122 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 123 | _GLOBAL(__clear_user) |
| 124 | addi r6,r3,-4 |
| 125 | li r3,0 |
| 126 | li r5,0 |
| 127 | cmplwi 0,r4,4 |
| 128 | blt 7f |
| 129 | /* clear a single word */ |
| 130 | 11: stwu r5,4(r6) |
| 131 | beqlr |
| 132 | /* clear word sized chunks */ |
| 133 | andi. r0,r6,3 |
| 134 | add r4,r0,r4 |
| 135 | subf r6,r0,r6 |
| 136 | srwi r0,r4,2 |
| 137 | andi. r4,r4,3 |
| 138 | mtctr r0 |
| 139 | bdz 7f |
| 140 | 1: stwu r5,4(r6) |
| 141 | bdnz 1b |
| 142 | /* clear byte sized chunks */ |
| 143 | 7: cmpwi 0,r4,0 |
| 144 | beqlr |
| 145 | mtctr r4 |
| 146 | addi r6,r6,3 |
| 147 | 8: stbu r5,1(r6) |
| 148 | bdnz 8b |
| 149 | blr |
| 150 | 90: mr r3,r4 |
| 151 | blr |
| 152 | 91: mfctr r3 |
| 153 | slwi r3,r3,2 |
| 154 | add r3,r3,r4 |
| 155 | blr |
| 156 | 92: mfctr r3 |
| 157 | blr |
| 158 | |
| 159 | .section __ex_table,"a" |
Michael Ellerman | 76bfdcf | 2008-07-17 17:17:52 +1000 | [diff] [blame] | 160 | PPC_LONG 11b,90b |
| 161 | PPC_LONG 1b,91b |
| 162 | PPC_LONG 8b,92b |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 163 | .text |
Anton Blanchard | 17968fb | 2012-05-27 19:54:03 +0000 | [diff] [blame] | 164 | #endif |