blob: c80fb49ce607f6da3f195fa4263eabec35c03e66 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
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 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100011#include <asm/processor.h>
12#include <asm/errno.h>
13#include <asm/ppc_asm.h>
14
Paul Mackerras14cf11a2005-09-26 16:04:21 +100015 .section __ex_table,"a"
Michael Ellerman76bfdcf2008-07-17 17:17:52 +100016 PPC_LONG_ALIGN
Paul Mackerras14cf11a2005-09-26 16:04:21 +100017 .text
18
19_GLOBAL(strcpy)
20 addi r5,r3,-1
21 addi r4,r4,-1
221: lbzu r0,1(r4)
23 cmpwi 0,r0,0
24 stbu r0,1(r5)
25 bne 1b
26 blr
27
28/* This clears out any unused part of the destination buffer,
29 just as the libc version does. -- paulus */
30_GLOBAL(strncpy)
Andreas Schwabca5d0672010-05-18 08:15:21 +000031 PPC_LCMPI 0,r5,0
Paul Mackerras14cf11a2005-09-26 16:04:21 +100032 beqlr
33 mtctr r5
34 addi r6,r3,-1
35 addi r4,r4,-1
361: lbzu r0,1(r4)
37 cmpwi 0,r0,0
38 stbu r0,1(r6)
39 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
40 bnelr /* if we didn't hit a null char, we're done */
41 mfctr r5
Andreas Schwabca5d0672010-05-18 08:15:21 +000042 PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100043 beqlr /* we know r0 == 0 here */
442: stbu r0,1(r6) /* clear it out if so */
45 bdnz 2b
46 blr
47
48_GLOBAL(strcat)
49 addi r5,r3,-1
50 addi r4,r4,-1
511: lbzu r0,1(r5)
52 cmpwi 0,r0,0
53 bne 1b
54 addi r5,r5,-1
551: lbzu r0,1(r4)
56 cmpwi 0,r0,0
57 stbu r0,1(r5)
58 bne 1b
59 blr
60
61_GLOBAL(strcmp)
62 addi r5,r3,-1
63 addi r4,r4,-1
641: lbzu r3,1(r5)
65 cmpwi 1,r3,0
66 lbzu r0,1(r4)
67 subf. r3,r0,r3
68 beqlr 1
69 beq 1b
70 blr
71
Steven Rostedt01195362008-03-01 03:04:57 +110072_GLOBAL(strncmp)
Andreas Schwabca5d0672010-05-18 08:15:21 +000073 PPC_LCMPI 0,r5,0
74 beq- 2f
Steven Rostedt01195362008-03-01 03:04:57 +110075 mtctr r5
76 addi r5,r3,-1
77 addi r4,r4,-1
781: lbzu r3,1(r5)
79 cmpwi 1,r3,0
80 lbzu r0,1(r4)
81 subf. r3,r0,r3
82 beqlr 1
83 bdnzt eq,1b
84 blr
Jeff Mahoney637a9902010-03-17 10:55:51 +0000852: li r3,0
86 blr
Steven Rostedt01195362008-03-01 03:04:57 +110087
Paul Mackerras14cf11a2005-09-26 16:04:21 +100088_GLOBAL(strlen)
89 addi r4,r3,-1
901: lbzu r0,1(r4)
91 cmpwi 0,r0,0
92 bne 1b
93 subf r3,r3,r4
94 blr
95
Anton Blanchard15c2d452015-01-21 12:27:38 +110096#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +100097_GLOBAL(memcmp)
Andreas Schwabca5d0672010-05-18 08:15:21 +000098 PPC_LCMPI 0,r5,0
99 beq- 2f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000100 mtctr r5
101 addi r6,r3,-1
102 addi r4,r4,-1
1031: lbzu r3,1(r6)
104 lbzu r0,1(r4)
105 subf. r3,r0,r3
106 bdnzt 2,1b
107 blr
1082: li r3,0
109 blr
Anton Blanchard15c2d452015-01-21 12:27:38 +1100110#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000111
112_GLOBAL(memchr)
Andreas Schwabca5d0672010-05-18 08:15:21 +0000113 PPC_LCMPI 0,r5,0
114 beq- 2f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000115 mtctr r5
116 addi r3,r3,-1
1171: lbzu r0,1(r3)
118 cmpw 0,r0,r4
119 bdnzf 2,1b
120 beqlr
1212: li r3,0
122 blr
123
Anton Blanchard17968fb2012-05-27 19:54:03 +0000124#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000125_GLOBAL(__clear_user)
126 addi r6,r3,-4
127 li r3,0
128 li r5,0
129 cmplwi 0,r4,4
130 blt 7f
131 /* clear a single word */
13211: stwu r5,4(r6)
133 beqlr
134 /* clear word sized chunks */
135 andi. r0,r6,3
136 add r4,r0,r4
137 subf r6,r0,r6
138 srwi r0,r4,2
139 andi. r4,r4,3
140 mtctr r0
141 bdz 7f
1421: stwu r5,4(r6)
143 bdnz 1b
144 /* clear byte sized chunks */
1457: cmpwi 0,r4,0
146 beqlr
147 mtctr r4
148 addi r6,r6,3
1498: stbu r5,1(r6)
150 bdnz 8b
151 blr
15290: mr r3,r4
153 blr
15491: mfctr r3
155 slwi r3,r3,2
156 add r3,r3,r4
157 blr
15892: mfctr r3
159 blr
160
161 .section __ex_table,"a"
Michael Ellerman76bfdcf2008-07-17 17:17:52 +1000162 PPC_LONG 11b,90b
163 PPC_LONG 1b,91b
164 PPC_LONG 8b,92b
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000165 .text
Anton Blanchard17968fb2012-05-27 19:54:03 +0000166#endif