David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * String handling functions for PowerPC. |
| 4 | * |
| 5 | * Copyright (C) 1996 Paul Mackerras. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <asm/ppc_asm.h> |
| 8 | #include <asm/export.h> |
| 9 | #include <asm/cache.h> |
| 10 | |
| 11 | .text |
| 12 | |
| 13 | /* This clears out any unused part of the destination buffer, |
| 14 | just as the libc version does. -- paulus */ |
| 15 | _GLOBAL(strncpy) |
| 16 | PPC_LCMPI 0,r5,0 |
| 17 | beqlr |
| 18 | mtctr r5 |
| 19 | addi r6,r3,-1 |
| 20 | addi r4,r4,-1 |
| 21 | .balign IFETCH_ALIGN_BYTES |
| 22 | 1: lbzu r0,1(r4) |
| 23 | cmpwi 0,r0,0 |
| 24 | stbu r0,1(r6) |
| 25 | bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ |
| 26 | bnelr /* if we didn't hit a null char, we're done */ |
| 27 | mfctr r5 |
| 28 | PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ |
| 29 | beqlr /* we know r0 == 0 here */ |
| 30 | 2: stbu r0,1(r6) /* clear it out if so */ |
| 31 | bdnz 2b |
| 32 | blr |
| 33 | EXPORT_SYMBOL(strncpy) |
| 34 | |
| 35 | _GLOBAL(strncmp) |
| 36 | PPC_LCMPI 0,r5,0 |
| 37 | beq- 2f |
| 38 | mtctr r5 |
| 39 | addi r5,r3,-1 |
| 40 | addi r4,r4,-1 |
| 41 | .balign IFETCH_ALIGN_BYTES |
| 42 | 1: lbzu r3,1(r5) |
| 43 | cmpwi 1,r3,0 |
| 44 | lbzu r0,1(r4) |
| 45 | subf. r3,r0,r3 |
| 46 | beqlr 1 |
| 47 | bdnzt eq,1b |
| 48 | blr |
| 49 | 2: li r3,0 |
| 50 | blr |
| 51 | EXPORT_SYMBOL(strncmp) |
| 52 | |
| 53 | _GLOBAL(memchr) |
| 54 | PPC_LCMPI 0,r5,0 |
| 55 | beq- 2f |
| 56 | mtctr r5 |
| 57 | addi r3,r3,-1 |
| 58 | .balign IFETCH_ALIGN_BYTES |
| 59 | 1: lbzu r0,1(r3) |
| 60 | cmpw 0,r0,r4 |
| 61 | bdnzf 2,1b |
| 62 | beqlr |
| 63 | 2: li r3,0 |
| 64 | blr |
| 65 | EXPORT_SYMBOL(memchr) |