rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [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 | */ |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/errno.h> |
| 13 | #include <asm/ppc_asm.h> |
| 14 | #include <asm/export.h> |
| 15 | #include <asm/cache.h> |
| 16 | |
| 17 | .text |
| 18 | |
| 19 | /* This clears out any unused part of the destination buffer, |
| 20 | just as the libc version does. -- paulus */ |
| 21 | _GLOBAL(strncpy) |
| 22 | PPC_LCMPI 0,r5,0 |
| 23 | beqlr |
| 24 | mtctr r5 |
| 25 | addi r6,r3,-1 |
| 26 | addi r4,r4,-1 |
| 27 | .balign IFETCH_ALIGN_BYTES |
| 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 |
| 34 | PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ |
| 35 | beqlr /* we know r0 == 0 here */ |
| 36 | 2: stbu r0,1(r6) /* clear it out if so */ |
| 37 | bdnz 2b |
| 38 | blr |
| 39 | EXPORT_SYMBOL(strncpy) |
| 40 | |
| 41 | _GLOBAL(strncmp) |
| 42 | PPC_LCMPI 0,r5,0 |
| 43 | beq- 2f |
| 44 | mtctr r5 |
| 45 | addi r5,r3,-1 |
| 46 | addi r4,r4,-1 |
| 47 | .balign IFETCH_ALIGN_BYTES |
| 48 | 1: lbzu r3,1(r5) |
| 49 | cmpwi 1,r3,0 |
| 50 | lbzu r0,1(r4) |
| 51 | subf. r3,r0,r3 |
| 52 | beqlr 1 |
| 53 | bdnzt eq,1b |
| 54 | blr |
| 55 | 2: li r3,0 |
| 56 | blr |
| 57 | EXPORT_SYMBOL(strncmp) |
| 58 | |
| 59 | #ifdef CONFIG_PPC32 |
| 60 | _GLOBAL(memcmp) |
| 61 | PPC_LCMPI 0,r5,0 |
| 62 | beq- 2f |
| 63 | mtctr r5 |
| 64 | addi r6,r3,-1 |
| 65 | addi r4,r4,-1 |
| 66 | 1: lbzu r3,1(r6) |
| 67 | lbzu r0,1(r4) |
| 68 | subf. r3,r0,r3 |
| 69 | bdnzt 2,1b |
| 70 | blr |
| 71 | 2: li r3,0 |
| 72 | blr |
| 73 | EXPORT_SYMBOL(memcmp) |
| 74 | #endif |
| 75 | |
| 76 | _GLOBAL(memchr) |
| 77 | PPC_LCMPI 0,r5,0 |
| 78 | beq- 2f |
| 79 | mtctr r5 |
| 80 | addi r3,r3,-1 |
| 81 | .balign IFETCH_ALIGN_BYTES |
| 82 | 1: lbzu r0,1(r3) |
| 83 | cmpw 0,r0,r4 |
| 84 | bdnzf 2,1b |
| 85 | beqlr |
| 86 | 2: li r3,0 |
| 87 | blr |
| 88 | EXPORT_SYMBOL(memchr) |
| 89 | |
| 90 | #ifdef CONFIG_PPC32 |
| 91 | _GLOBAL(__clear_user) |
| 92 | addi r6,r3,-4 |
| 93 | li r3,0 |
| 94 | li r5,0 |
| 95 | cmplwi 0,r4,4 |
| 96 | blt 7f |
| 97 | /* clear a single word */ |
| 98 | 11: stwu r5,4(r6) |
| 99 | beqlr |
| 100 | /* clear word sized chunks */ |
| 101 | andi. r0,r6,3 |
| 102 | add r4,r0,r4 |
| 103 | subf r6,r0,r6 |
| 104 | srwi r0,r4,2 |
| 105 | andi. r4,r4,3 |
| 106 | mtctr r0 |
| 107 | bdz 7f |
| 108 | 1: stwu r5,4(r6) |
| 109 | bdnz 1b |
| 110 | /* clear byte sized chunks */ |
| 111 | 7: cmpwi 0,r4,0 |
| 112 | beqlr |
| 113 | mtctr r4 |
| 114 | addi r6,r6,3 |
| 115 | 8: stbu r5,1(r6) |
| 116 | bdnz 8b |
| 117 | blr |
| 118 | 90: mr r3,r4 |
| 119 | blr |
| 120 | 91: mfctr r3 |
| 121 | slwi r3,r3,2 |
| 122 | add r3,r3,r4 |
| 123 | blr |
| 124 | 92: mfctr r3 |
| 125 | blr |
| 126 | |
| 127 | EX_TABLE(11b, 90b) |
| 128 | EX_TABLE(1b, 91b) |
| 129 | EX_TABLE(8b, 92b) |
| 130 | |
| 131 | EXPORT_SYMBOL(__clear_user) |
| 132 | #endif |