Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * String handling functions for PowerPC.
0004  *
0005  * Copyright (C) 1996 Paul Mackerras.
0006  */
0007 #include <asm/ppc_asm.h>
0008 #include <asm/export.h>
0009 #include <asm/cache.h>
0010 
0011     .text
0012     
0013 /* This clears out any unused part of the destination buffer,
0014    just as the libc version does.  -- paulus */
0015 _GLOBAL(strncpy)
0016     PPC_LCMPI 0,r5,0
0017     beqlr
0018     mtctr   r5
0019     addi    r6,r3,-1
0020     addi    r4,r4,-1
0021     .balign IFETCH_ALIGN_BYTES
0022 1:  lbzu    r0,1(r4)
0023     cmpwi   0,r0,0
0024     stbu    r0,1(r6)
0025     bdnzf   2,1b        /* dec ctr, branch if ctr != 0 && !cr0.eq */
0026     bnelr           /* if we didn't hit a null char, we're done */
0027     mfctr   r5
0028     PPC_LCMPI 0,r5,0    /* any space left in destination buffer? */
0029     beqlr           /* we know r0 == 0 here */
0030 2:  stbu    r0,1(r6)    /* clear it out if so */
0031     bdnz    2b
0032     blr
0033 EXPORT_SYMBOL(strncpy)
0034 
0035 _GLOBAL(strncmp)
0036     PPC_LCMPI 0,r5,0
0037     beq-    2f
0038     mtctr   r5
0039     addi    r5,r3,-1
0040     addi    r4,r4,-1
0041     .balign IFETCH_ALIGN_BYTES
0042 1:  lbzu    r3,1(r5)
0043     cmpwi   1,r3,0
0044     lbzu    r0,1(r4)
0045     subf.   r3,r0,r3
0046     beqlr   1
0047     bdnzt   eq,1b
0048     blr
0049 2:  li  r3,0
0050     blr
0051 EXPORT_SYMBOL(strncmp)
0052 
0053 _GLOBAL(memchr)
0054     PPC_LCMPI 0,r5,0
0055     beq-    2f
0056     mtctr   r5
0057     addi    r3,r3,-1
0058     .balign IFETCH_ALIGN_BYTES
0059 1:  lbzu    r0,1(r3)
0060     cmpw    0,r0,r4
0061     bdnzf   2,1b
0062     beqlr
0063 2:  li  r3,0
0064     blr
0065 EXPORT_SYMBOL(memchr)