Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2 | /* |
| 3 | * String handling functions for PowerPC. |
| 4 | * |
| 5 | * Copyright (C) 1996 Paul Mackerras. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 6 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 7 | #include <asm/ppc_asm.h> |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 8 | #include <asm/export.h> |
Christophe Leroy | 1128bb7 | 2018-05-18 15:01:16 +0200 | [diff] [blame] | 9 | #include <asm/cache.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 10 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 11 | .text |
| 12 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 13 | /* This clears out any unused part of the destination buffer, |
| 14 | just as the libc version does. -- paulus */ |
| 15 | _GLOBAL(strncpy) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 16 | PPC_LCMPI 0,r5,0 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 17 | beqlr |
| 18 | mtctr r5 |
| 19 | addi r6,r3,-1 |
| 20 | addi r4,r4,-1 |
Christophe Leroy | 1128bb7 | 2018-05-18 15:01:16 +0200 | [diff] [blame] | 21 | .balign IFETCH_ALIGN_BYTES |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 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 |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 28 | PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 29 | beqlr /* we know r0 == 0 here */ |
| 30 | 2: stbu r0,1(r6) /* clear it out if so */ |
| 31 | bdnz 2b |
| 32 | blr |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 33 | EXPORT_SYMBOL(strncpy) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 34 | |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 35 | _GLOBAL(strncmp) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 36 | PPC_LCMPI 0,r5,0 |
| 37 | beq- 2f |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 38 | mtctr r5 |
| 39 | addi r5,r3,-1 |
| 40 | addi r4,r4,-1 |
Christophe Leroy | 1128bb7 | 2018-05-18 15:01:16 +0200 | [diff] [blame] | 41 | .balign IFETCH_ALIGN_BYTES |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 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 |
Jeff Mahoney | 637a990 | 2010-03-17 10:55:51 +0000 | [diff] [blame] | 49 | 2: li r3,0 |
| 50 | blr |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 51 | EXPORT_SYMBOL(strncmp) |
Steven Rostedt | 0119536 | 2008-03-01 03:04:57 +1100 | [diff] [blame] | 52 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 53 | _GLOBAL(memchr) |
Andreas Schwab | ca5d067 | 2010-05-18 08:15:21 +0000 | [diff] [blame] | 54 | PPC_LCMPI 0,r5,0 |
| 55 | beq- 2f |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 56 | mtctr r5 |
| 57 | addi r3,r3,-1 |
Christophe Leroy | 1128bb7 | 2018-05-18 15:01:16 +0200 | [diff] [blame] | 58 | .balign IFETCH_ALIGN_BYTES |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 59 | 1: lbzu r0,1(r3) |
| 60 | cmpw 0,r0,r4 |
| 61 | bdnzf 2,1b |
| 62 | beqlr |
| 63 | 2: li r3,0 |
| 64 | blr |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 65 | EXPORT_SYMBOL(memchr) |