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 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 19 | /* This clears out any unused part of the destination buffer, |
| 20 | just as the libc version does. -- paulus */ |
| 21 | _GLOBAL(strncpy) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 22 | PPC_LCMPI 0,r5,0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 23 | beqlr |
| 24 | mtctr r5 |
| 25 | addi r6,r3,-1 |
| 26 | addi r4,r4,-1 |
Anton Blanchard | 87a156f | 2016-05-26 08:39:55 +1000 | [diff] [blame] | 27 | .balign 16 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 28 | 1: lbzu r0,1(r4) |
| 29 | cmpwi 0,r0,0 |
| 30 | stbu r0,1(r6) |
| 31 | bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ |
| 32 | bnelr /* if we didn't hit a null char, we're done */ |
| 33 | mfctr r5 |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 34 | PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 35 | beqlr /* we know r0 == 0 here */ |
| 36 | 2: stbu r0,1(r6) /* clear it out if so */ |
| 37 | bdnz 2b |
| 38 | blr |
| 39 | |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 40 | _GLOBAL(strncmp) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 41 | PPC_LCMPI 0,r5,0 |
| 42 | beq- 2f |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 43 | mtctr r5 |
| 44 | addi r5,r3,-1 |
| 45 | addi r4,r4,-1 |
Anton Blanchard | 87a156f | 2016-05-26 08:39:55 +1000 | [diff] [blame] | 46 | .balign 16 |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 47 | 1: lbzu r3,1(r5) |
| 48 | cmpwi 1,r3,0 |
| 49 | lbzu r0,1(r4) |
| 50 | subf. r3,r0,r3 |
| 51 | beqlr 1 |
| 52 | bdnzt eq,1b |
| 53 | blr |
Jeff Mahoney | 637a990 | 2010-03-17 10:55:51 +0000 | [diff] [blame] | 54 | 2: li r3,0 |
| 55 | blr |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 56 | |
Anton Blanchard | 15c2d45 | 2015-01-21 12:27:38 +1100 | [diff] [blame] | 57 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 58 | _GLOBAL(memcmp) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 59 | PPC_LCMPI 0,r5,0 |
| 60 | beq- 2f |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 61 | mtctr r5 |
| 62 | addi r6,r3,-1 |
| 63 | addi r4,r4,-1 |
| 64 | 1: lbzu r3,1(r6) |
| 65 | lbzu r0,1(r4) |
| 66 | subf. r3,r0,r3 |
| 67 | bdnzt 2,1b |
| 68 | blr |
| 69 | 2: li r3,0 |
| 70 | blr |
Anton Blanchard | 15c2d45 | 2015-01-21 12:27:38 +1100 | [diff] [blame] | 71 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 72 | |
| 73 | _GLOBAL(memchr) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 74 | PPC_LCMPI 0,r5,0 |
| 75 | beq- 2f |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 76 | mtctr r5 |
| 77 | addi r3,r3,-1 |
Anton Blanchard | 87a156f | 2016-05-26 08:39:55 +1000 | [diff] [blame] | 78 | .balign 16 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 79 | 1: lbzu r0,1(r3) |
| 80 | cmpw 0,r0,r4 |
| 81 | bdnzf 2,1b |
| 82 | beqlr |
| 83 | 2: li r3,0 |
| 84 | blr |
| 85 | |
Anton Blanchard | 17968fb | 2012-05-27 19:54:03 +0000 | [diff] [blame] | 86 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 87 | _GLOBAL(__clear_user) |
| 88 | addi r6,r3,-4 |
| 89 | li r3,0 |
| 90 | li r5,0 |
| 91 | cmplwi 0,r4,4 |
| 92 | blt 7f |
| 93 | /* clear a single word */ |
| 94 | 11: stwu r5,4(r6) |
| 95 | beqlr |
| 96 | /* clear word sized chunks */ |
| 97 | andi. r0,r6,3 |
| 98 | add r4,r0,r4 |
| 99 | subf r6,r0,r6 |
| 100 | srwi r0,r4,2 |
| 101 | andi. r4,r4,3 |
| 102 | mtctr r0 |
| 103 | bdz 7f |
| 104 | 1: stwu r5,4(r6) |
| 105 | bdnz 1b |
| 106 | /* clear byte sized chunks */ |
| 107 | 7: cmpwi 0,r4,0 |
| 108 | beqlr |
| 109 | mtctr r4 |
| 110 | addi r6,r6,3 |
| 111 | 8: stbu r5,1(r6) |
| 112 | bdnz 8b |
| 113 | blr |
| 114 | 90: mr r3,r4 |
| 115 | blr |
| 116 | 91: mfctr r3 |
| 117 | slwi r3,r3,2 |
| 118 | add r3,r3,r4 |
| 119 | blr |
| 120 | 92: mfctr r3 |
| 121 | blr |
| 122 | |
| 123 | .section __ex_table,"a" |
Michael Ellerman | 76bfdcf | 2008-07-17 17:17:52 +1000 | [diff] [blame] | 124 | PPC_LONG 11b,90b |
| 125 | PPC_LONG 1b,91b |
| 126 | PPC_LONG 8b,92b |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 127 | .text |
Anton Blanchard | 17968fb | 2012-05-27 19:54:03 +0000 | [diff] [blame] | 128 | #endif |