blob: beabc68d9a1e4cdb7e40d26045a906173e652790 [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
Paul Mackerras14cf11a2005-09-26 16:04:21 +100019/* This clears out any unused part of the destination buffer,
20 just as the libc version does. -- paulus */
21_GLOBAL(strncpy)
Andreas Schwabca5d0672010-05-18 08:15:21 +000022 PPC_LCMPI 0,r5,0
Paul Mackerras14cf11a2005-09-26 16:04:21 +100023 beqlr
24 mtctr r5
25 addi r6,r3,-1
26 addi r4,r4,-1
Anton Blanchard87a156f2016-05-26 08:39:55 +100027 .balign 16
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000281: 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
Andreas Schwabca5d0672010-05-18 08:15:21 +000034 PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100035 beqlr /* we know r0 == 0 here */
362: stbu r0,1(r6) /* clear it out if so */
37 bdnz 2b
38 blr
39
Steven Rostedt01195362008-03-01 03:04:57 +110040_GLOBAL(strncmp)
Andreas Schwabca5d0672010-05-18 08:15:21 +000041 PPC_LCMPI 0,r5,0
42 beq- 2f
Steven Rostedt01195362008-03-01 03:04:57 +110043 mtctr r5
44 addi r5,r3,-1
45 addi r4,r4,-1
Anton Blanchard87a156f2016-05-26 08:39:55 +100046 .balign 16
Steven Rostedt01195362008-03-01 03:04:57 +1100471: 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
Jeff Mahoney637a9902010-03-17 10:55:51 +0000542: li r3,0
55 blr
Steven Rostedt01195362008-03-01 03:04:57 +110056
Anton Blanchard15c2d452015-01-21 12:27:38 +110057#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +100058_GLOBAL(memcmp)
Andreas Schwabca5d0672010-05-18 08:15:21 +000059 PPC_LCMPI 0,r5,0
60 beq- 2f
Paul Mackerras14cf11a2005-09-26 16:04:21 +100061 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
Anton Blanchard15c2d452015-01-21 12:27:38 +110071#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +100072
73_GLOBAL(memchr)
Andreas Schwabca5d0672010-05-18 08:15:21 +000074 PPC_LCMPI 0,r5,0
75 beq- 2f
Paul Mackerras14cf11a2005-09-26 16:04:21 +100076 mtctr r5
77 addi r3,r3,-1
Anton Blanchard87a156f2016-05-26 08:39:55 +100078 .balign 16
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000791: lbzu r0,1(r3)
80 cmpw 0,r0,r4
81 bdnzf 2,1b
82 beqlr
832: li r3,0
84 blr
85
Anton Blanchard17968fb2012-05-27 19:54:03 +000086#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +100087_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"
Michael Ellerman76bfdcf2008-07-17 17:17:52 +1000124 PPC_LONG 11b,90b
125 PPC_LONG 1b,91b
126 PPC_LONG 8b,92b
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000127 .text
Anton Blanchard17968fb2012-05-27 19:54:03 +0000128#endif