blob: 0378def28d411debec742d282991b8ef5c3ba097 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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#include <asm/cache.h>
16
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 IFETCH_ALIGN_BYTES
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
39EXPORT_SYMBOL(strncpy)
40
41_GLOBAL(strncmp)
42 PPC_LCMPI 0,r5,0
43 beq- 2f
44 mtctr r5
45 addi r5,r3,-1
46 addi r4,r4,-1
47 .balign IFETCH_ALIGN_BYTES
481: lbzu r3,1(r5)
49 cmpwi 1,r3,0
50 lbzu r0,1(r4)
51 subf. r3,r0,r3
52 beqlr 1
53 bdnzt eq,1b
54 blr
552: li r3,0
56 blr
57EXPORT_SYMBOL(strncmp)
58
59#ifdef CONFIG_PPC32
60_GLOBAL(memcmp)
61 PPC_LCMPI 0,r5,0
62 beq- 2f
63 mtctr r5
64 addi r6,r3,-1
65 addi r4,r4,-1
661: lbzu r3,1(r6)
67 lbzu r0,1(r4)
68 subf. r3,r0,r3
69 bdnzt 2,1b
70 blr
712: li r3,0
72 blr
73EXPORT_SYMBOL(memcmp)
74#endif
75
76_GLOBAL(memchr)
77 PPC_LCMPI 0,r5,0
78 beq- 2f
79 mtctr r5
80 addi r3,r3,-1
81 .balign IFETCH_ALIGN_BYTES
821: lbzu r0,1(r3)
83 cmpw 0,r0,r4
84 bdnzf 2,1b
85 beqlr
862: li r3,0
87 blr
88EXPORT_SYMBOL(memchr)
89
90#ifdef CONFIG_PPC32
91_GLOBAL(__clear_user)
92 addi r6,r3,-4
93 li r3,0
94 li r5,0
95 cmplwi 0,r4,4
96 blt 7f
97 /* clear a single word */
9811: stwu r5,4(r6)
99 beqlr
100 /* clear word sized chunks */
101 andi. r0,r6,3
102 add r4,r0,r4
103 subf r6,r0,r6
104 srwi r0,r4,2
105 andi. r4,r4,3
106 mtctr r0
107 bdz 7f
1081: stwu r5,4(r6)
109 bdnz 1b
110 /* clear byte sized chunks */
1117: cmpwi 0,r4,0
112 beqlr
113 mtctr r4
114 addi r6,r6,3
1158: stbu r5,1(r6)
116 bdnz 8b
117 blr
11890: mr r3,r4
119 blr
12091: mfctr r3
121 slwi r3,r3,2
122 add r3,r3,r4
123 blr
12492: mfctr r3
125 blr
126
127 EX_TABLE(11b, 90b)
128 EX_TABLE(1b, 91b)
129 EX_TABLE(8b, 92b)
130
131EXPORT_SYMBOL(__clear_user)
132#endif