1/* 2 * String handling functions for PowerPC. 3 * 4 * Copyright (C) 1996 Paul Mackerras. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 9 * 2 of the License, or (at your option) any later version. 10 */ 11#include <asm/processor.h> 12#include <asm/errno.h> 13#include <asm/ppc_asm.h> 14 15 .section __ex_table,"a" 16 PPC_LONG_ALIGN 17 .text 18 19/* This clears out any unused part of the destination buffer, 20 just as the libc version does. -- paulus */ 21_GLOBAL(strncpy) 22 PPC_LCMPI 0,r5,0 23 beqlr 24 mtctr r5 25 addi r6,r3,-1 26 addi r4,r4,-1 27 .balign 16 281: lbzu r0,1(r4) 29 cmpwi 0,r0,0 30 stbu r0,1(r6) 31 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ 32 bnelr /* if we didn't hit a null char, we're done */ 33 mfctr r5 34 PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */ 35 beqlr /* we know r0 == 0 here */ 362: stbu r0,1(r6) /* clear it out if so */ 37 bdnz 2b 38 blr 39 40_GLOBAL(strncmp) 41 PPC_LCMPI 0,r5,0 42 beq- 2f 43 mtctr r5 44 addi r5,r3,-1 45 addi r4,r4,-1 46 .balign 16 471: lbzu r3,1(r5) 48 cmpwi 1,r3,0 49 lbzu r0,1(r4) 50 subf. r3,r0,r3 51 beqlr 1 52 bdnzt eq,1b 53 blr 542: li r3,0 55 blr 56 57#ifdef CONFIG_PPC32 58_GLOBAL(memcmp) 59 PPC_LCMPI 0,r5,0 60 beq- 2f 61 mtctr r5 62 addi r6,r3,-1 63 addi r4,r4,-1 641: lbzu r3,1(r6) 65 lbzu r0,1(r4) 66 subf. r3,r0,r3 67 bdnzt 2,1b 68 blr 692: li r3,0 70 blr 71#endif 72 73_GLOBAL(memchr) 74 PPC_LCMPI 0,r5,0 75 beq- 2f 76 mtctr r5 77 addi r3,r3,-1 78 .balign 16 791: lbzu r0,1(r3) 80 cmpw 0,r0,r4 81 bdnzf 2,1b 82 beqlr 832: li r3,0 84 blr 85 86#ifdef CONFIG_PPC32 87_GLOBAL(__clear_user) 88 addi r6,r3,-4 89 li r3,0 90 li r5,0 91 cmplwi 0,r4,4 92 blt 7f 93 /* clear a single word */ 9411: stwu r5,4(r6) 95 beqlr 96 /* clear word sized chunks */ 97 andi. r0,r6,3 98 add r4,r0,r4 99 subf r6,r0,r6 100 srwi r0,r4,2 101 andi. r4,r4,3 102 mtctr r0 103 bdz 7f 1041: stwu r5,4(r6) 105 bdnz 1b 106 /* clear byte sized chunks */ 1077: cmpwi 0,r4,0 108 beqlr 109 mtctr r4 110 addi r6,r6,3 1118: stbu r5,1(r6) 112 bdnz 8b 113 blr 11490: mr r3,r4 115 blr 11691: mfctr r3 117 slwi r3,r3,2 118 add r3,r3,r4 119 blr 12092: mfctr r3 121 blr 122 123 .section __ex_table,"a" 124 PPC_LONG 11b,90b 125 PPC_LONG 1b,91b 126 PPC_LONG 8b,92b 127 .text 128#endif 129