2019-05-27 14:55:01 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-09-26 14:04:21 +08:00
|
|
|
/*
|
|
|
|
* String handling functions for PowerPC.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Mackerras.
|
|
|
|
*/
|
|
|
|
#include <asm/ppc_asm.h>
|
2016-01-14 12:33:46 +08:00
|
|
|
#include <asm/export.h>
|
2018-05-18 21:01:16 +08:00
|
|
|
#include <asm/cache.h>
|
2005-09-26 14:04:21 +08:00
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/* This clears out any unused part of the destination buffer,
|
|
|
|
just as the libc version does. -- paulus */
|
|
|
|
_GLOBAL(strncpy)
|
2010-05-18 16:15:21 +08:00
|
|
|
PPC_LCMPI 0,r5,0
|
2005-09-26 14:04:21 +08:00
|
|
|
beqlr
|
|
|
|
mtctr r5
|
|
|
|
addi r6,r3,-1
|
|
|
|
addi r4,r4,-1
|
2018-05-18 21:01:16 +08:00
|
|
|
.balign IFETCH_ALIGN_BYTES
|
2005-09-26 14:04:21 +08:00
|
|
|
1: lbzu r0,1(r4)
|
|
|
|
cmpwi 0,r0,0
|
|
|
|
stbu r0,1(r6)
|
|
|
|
bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
|
|
|
|
bnelr /* if we didn't hit a null char, we're done */
|
|
|
|
mfctr r5
|
2010-05-18 16:15:21 +08:00
|
|
|
PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
|
2005-09-26 14:04:21 +08:00
|
|
|
beqlr /* we know r0 == 0 here */
|
|
|
|
2: stbu r0,1(r6) /* clear it out if so */
|
|
|
|
bdnz 2b
|
|
|
|
blr
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(strncpy)
|
2005-09-26 14:04:21 +08:00
|
|
|
|
2008-03-01 00:04:57 +08:00
|
|
|
_GLOBAL(strncmp)
|
2010-05-18 16:15:21 +08:00
|
|
|
PPC_LCMPI 0,r5,0
|
|
|
|
beq- 2f
|
2008-03-01 00:04:57 +08:00
|
|
|
mtctr r5
|
|
|
|
addi r5,r3,-1
|
|
|
|
addi r4,r4,-1
|
2018-05-18 21:01:16 +08:00
|
|
|
.balign IFETCH_ALIGN_BYTES
|
2008-03-01 00:04:57 +08:00
|
|
|
1: lbzu r3,1(r5)
|
|
|
|
cmpwi 1,r3,0
|
|
|
|
lbzu r0,1(r4)
|
|
|
|
subf. r3,r0,r3
|
|
|
|
beqlr 1
|
|
|
|
bdnzt eq,1b
|
|
|
|
blr
|
2010-03-17 18:55:51 +08:00
|
|
|
2: li r3,0
|
|
|
|
blr
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(strncmp)
|
2008-03-01 00:04:57 +08:00
|
|
|
|
2005-09-26 14:04:21 +08:00
|
|
|
_GLOBAL(memchr)
|
2010-05-18 16:15:21 +08:00
|
|
|
PPC_LCMPI 0,r5,0
|
|
|
|
beq- 2f
|
2005-09-26 14:04:21 +08:00
|
|
|
mtctr r5
|
|
|
|
addi r3,r3,-1
|
2018-05-18 21:01:16 +08:00
|
|
|
.balign IFETCH_ALIGN_BYTES
|
2005-09-26 14:04:21 +08:00
|
|
|
1: lbzu r0,1(r3)
|
|
|
|
cmpw 0,r0,r4
|
|
|
|
bdnzf 2,1b
|
|
|
|
beqlr
|
|
|
|
2: li r3,0
|
|
|
|
blr
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(memchr)
|