xref: /openbmc/linux/arch/powerpc/lib/string.S (revision e983940270f10fe8551baf0098be76ea478294a3)
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#include <asm/export.h>
15
16	.section __ex_table,"a"
17	PPC_LONG_ALIGN
18	.text
19
20/* This clears out any unused part of the destination buffer,
21   just as the libc version does.  -- paulus */
22_GLOBAL(strncpy)
23	PPC_LCMPI 0,r5,0
24	beqlr
25	mtctr	r5
26	addi	r6,r3,-1
27	addi	r4,r4,-1
28	.balign 16
291:	lbzu	r0,1(r4)
30	cmpwi	0,r0,0
31	stbu	r0,1(r6)
32	bdnzf	2,1b		/* dec ctr, branch if ctr != 0 && !cr0.eq */
33	bnelr			/* if we didn't hit a null char, we're done */
34	mfctr	r5
35	PPC_LCMPI 0,r5,0	/* any space left in destination buffer? */
36	beqlr			/* we know r0 == 0 here */
372:	stbu	r0,1(r6)	/* clear it out if so */
38	bdnz	2b
39	blr
40EXPORT_SYMBOL(strncpy)
41
42_GLOBAL(strncmp)
43	PPC_LCMPI 0,r5,0
44	beq-	2f
45	mtctr	r5
46	addi	r5,r3,-1
47	addi	r4,r4,-1
48	.balign 16
491:	lbzu	r3,1(r5)
50	cmpwi	1,r3,0
51	lbzu	r0,1(r4)
52	subf.	r3,r0,r3
53	beqlr	1
54	bdnzt	eq,1b
55	blr
562:	li	r3,0
57	blr
58EXPORT_SYMBOL(strncmp)
59
60#ifdef CONFIG_PPC32
61_GLOBAL(memcmp)
62	PPC_LCMPI 0,r5,0
63	beq-	2f
64	mtctr	r5
65	addi	r6,r3,-1
66	addi	r4,r4,-1
671:	lbzu	r3,1(r6)
68	lbzu	r0,1(r4)
69	subf.	r3,r0,r3
70	bdnzt	2,1b
71	blr
722:	li	r3,0
73	blr
74EXPORT_SYMBOL(memcmp)
75#endif
76
77_GLOBAL(memchr)
78	PPC_LCMPI 0,r5,0
79	beq-	2f
80	mtctr	r5
81	addi	r3,r3,-1
82	.balign 16
831:	lbzu	r0,1(r3)
84	cmpw	0,r0,r4
85	bdnzf	2,1b
86	beqlr
872:	li	r3,0
88	blr
89EXPORT_SYMBOL(memchr)
90
91#ifdef CONFIG_PPC32
92_GLOBAL(__clear_user)
93	addi	r6,r3,-4
94	li	r3,0
95	li	r5,0
96	cmplwi	0,r4,4
97	blt	7f
98	/* clear a single word */
9911:	stwu	r5,4(r6)
100	beqlr
101	/* clear word sized chunks */
102	andi.	r0,r6,3
103	add	r4,r0,r4
104	subf	r6,r0,r6
105	srwi	r0,r4,2
106	andi.	r4,r4,3
107	mtctr	r0
108	bdz	7f
1091:	stwu	r5,4(r6)
110	bdnz	1b
111	/* clear byte sized chunks */
1127:	cmpwi	0,r4,0
113	beqlr
114	mtctr	r4
115	addi	r6,r6,3
1168:	stbu	r5,1(r6)
117	bdnz	8b
118	blr
11990:	mr	r3,r4
120	blr
12191:	mfctr	r3
122	slwi	r3,r3,2
123	add	r3,r3,r4
124	blr
12592:	mfctr	r3
126	blr
127
128	.section __ex_table,"a"
129	PPC_LONG	11b,90b
130	PPC_LONG	1b,91b
131	PPC_LONG	8b,92b
132	.text
133EXPORT_SYMBOL(__clear_user)
134#endif
135