blob: 2752b1cc1d45f0496ac1effa410d24d46bca0244 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002/*
3 * String handling functions for PowerPC.
4 *
5 * Copyright (C) 1996 Paul Mackerras.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10006 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10007#include <asm/ppc_asm.h>
Al Viro9445aa12016-01-13 23:33:46 -05008#include <asm/export.h>
Christophe Leroy1128bb72018-05-18 15:01:16 +02009#include <asm/cache.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100010
Paul Mackerras14cf11a2005-09-26 16:04:21 +100011 .text
12
Paul Mackerras14cf11a2005-09-26 16:04:21 +100013/* This clears out any unused part of the destination buffer,
14 just as the libc version does. -- paulus */
15_GLOBAL(strncpy)
Andreas Schwabca5d0672010-05-18 08:15:21 +000016 PPC_LCMPI 0,r5,0
Paul Mackerras14cf11a2005-09-26 16:04:21 +100017 beqlr
18 mtctr r5
19 addi r6,r3,-1
20 addi r4,r4,-1
Christophe Leroy1128bb72018-05-18 15:01:16 +020021 .balign IFETCH_ALIGN_BYTES
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000221: 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 Schwabca5d0672010-05-18 08:15:21 +000028 PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029 beqlr /* we know r0 == 0 here */
302: stbu r0,1(r6) /* clear it out if so */
31 bdnz 2b
32 blr
Al Viro9445aa12016-01-13 23:33:46 -050033EXPORT_SYMBOL(strncpy)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100034
Steven Rostedt01195362008-03-01 03:04:57 +110035_GLOBAL(strncmp)
Andreas Schwabca5d0672010-05-18 08:15:21 +000036 PPC_LCMPI 0,r5,0
37 beq- 2f
Steven Rostedt01195362008-03-01 03:04:57 +110038 mtctr r5
39 addi r5,r3,-1
40 addi r4,r4,-1
Christophe Leroy1128bb72018-05-18 15:01:16 +020041 .balign IFETCH_ALIGN_BYTES
Steven Rostedt01195362008-03-01 03:04:57 +1100421: 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 Mahoney637a9902010-03-17 10:55:51 +0000492: li r3,0
50 blr
Al Viro9445aa12016-01-13 23:33:46 -050051EXPORT_SYMBOL(strncmp)
Steven Rostedt01195362008-03-01 03:04:57 +110052
Paul Mackerras14cf11a2005-09-26 16:04:21 +100053_GLOBAL(memchr)
Andreas Schwabca5d0672010-05-18 08:15:21 +000054 PPC_LCMPI 0,r5,0
55 beq- 2f
Paul Mackerras14cf11a2005-09-26 16:04:21 +100056 mtctr r5
57 addi r3,r3,-1
Christophe Leroy1128bb72018-05-18 15:01:16 +020058 .balign IFETCH_ALIGN_BYTES
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000591: lbzu r0,1(r3)
60 cmpw 0,r0,r4
61 bdnzf 2,1b
62 beqlr
632: li r3,0
64 blr
Al Viro9445aa12016-01-13 23:33:46 -050065EXPORT_SYMBOL(memchr)