2 * String handling functions for PowerPC.
4 * Copyright (C) 1996 Paul Mackerras.
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.
11 #include "../kernel/ppc_asm.tmpl"
12 #include <asm/processor.h>
13 #include <asm/errno.h>
35 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
85 rlwinm r0,r5,32-2,2,31
114 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
117 beq 2f /* if less than 8 bytes to do */
118 andi. r0,r6,3 /* get dest word aligned */
149 rlwinm. r7,r5,32-3,3,31
154 .globl backwards_memcpy
156 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
186 rlwinm. r7,r5,32-3,3,31
219 .globl __copy_tofrom_user
224 li r3,0 /* success return value */
225 beq 2f /* if less than 8 bytes to do */
226 andi. r0,r6,3 /* get dest word aligned */
240 3: cmpwi 0,r5,0 /* do 1 byte at a time for the remainder */
249 5: subfic r0,r0,4 /* copy bytes until we have the */
250 mtctr r0 /* destination 4-byte aligned */
261 /* we come here on a fault in the 8-byte-at-a-time loop */
262 88: subi r4,r4,8 /* compensate for the lwzu */
264 rlwimi r5,r0,3,0,28 /* use the byte-at-a-time loop to */
265 b 3b /* copy up to the byte at fault */
266 /* here on a write fault in the single-word copy */
269 /* here on a read fault in the initial single-byte copy */
273 /* here on a read fault in the final single-byte copy */
276 /* clear out the rest of the destination: r3 bytes starting at 4(r6) */
298 /* here on a write fault in the initial single-byte copy */
302 /* here on a write fault in the final single-byte copy */
306 .section __ex_table,"a"
330 /* clear a single word */
333 /* clear word sized chunks */
337 /*rlwinm r0,r4,32-2,2,31*/
344 /* clear byte sized chunks */
354 .section __ex_table,"a"
361 .globl __strncpy_from_user
371 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
378 .section __ex_table,"a"
383 /* r3 = str, r4 = len (> 0), r5 = top (highest addr) */
384 .globl __strnlen_user
387 subf r6,r7,r5 /* top+1 - str */
391 0: mtctr r6 /* ctr = min(len, top - str) */
392 1: lbzu r0,1(r7) /* get next byte */
394 bdnzf 2,1b /* loop if --ctr != 0 && byte != 0 */
396 subf r3,r3,r7 /* number of bytes we have looked at */
397 beqlr /* return if we found a 0 byte */
398 cmpw 0,r3,r4 /* did we look at all len bytes? */
399 blt 99f /* if not, must have hit top */
400 addi r3,r4,1 /* return len + 1 to indicate no null found */
402 99: li r3,0 /* bad address, return 0 */
404 .section __ex_table,"a"