strncpy.S 1.4 KB
Newer Older
1 2 3 4 5 6 7
/*
 * Copyright 2005-2010 Analog Devices Inc.
 *
 * Licensed under the ADI BSD license or the GPL-2 (or later)
 */

#include <linux/linkage.h>
R
Robin Getz 已提交
8
#include <asm/context.S>
9 10 11 12 13

/* void *strncpy(char *dest, const char *src, size_t n);
 * R0 = address (dest)
 * R1 = address (src)
 * R2 = size
R
Robin Getz 已提交
14 15
 * Returns a pointer (R0) to the destination string dest
 *  we do this by not changing R0
16 17 18 19 20 21 22 23 24 25 26 27
 */

#ifdef CONFIG_STRNCPY_L1
.section .l1.text
#else
.text
#endif

.align 2

ENTRY(_strncpy)
	CC = R2 == 0;
28
	if CC JUMP 6f;
R
Robin Getz 已提交
29 30

	P2 = R2 ;       /* size */
31 32 33
	P0 = R0 ;       /* dst*/
	P1 = R1 ;       /* src*/

R
Robin Getz 已提交
34
	LSETUP (1f, 2f) LC0 = P2;
35 36 37
1:
	R1 = B [P1++] (Z);
	B [P0++] = R1;
R
Robin Getz 已提交
38
	CC = R1 == 0;
39
2:
R
Robin Getz 已提交
40 41 42 43 44 45 46 47
	if CC jump 3f;

	RTS;

	/* if src is shorter than n, we need to null pad bytes in dest
	 * but, we can get here when the last byte is zero, and we don't
	 * want to copy an extra byte at the end, so we need to check
	 */
48
3:
R
Robin Getz 已提交
49 50 51 52 53 54 55 56 57 58 59
	R2 = LC0;
	CC = R2
	if ! CC jump 6f;

	/* if the required null padded portion is small, do it here, rather than
	 * handling the overhead of memset (which is OK when things are big).
	 */
	R3 = 0x20;
	CC = R2 < R3;
	IF CC jump 4f;

60
	R2 += -1;
R
Robin Getz 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

	/* Set things up for memset
	 * R0 = address
	 * R1 = filler byte (this case it's zero, set above)
	 * R2 = count (set above)
	 */

	I1 = R0;
	R0 = RETS;
	I0 = R0;
	R0 = P0;
	pseudo_long_call _memset, p0;
	R0 = I0;
	RETS = R0;
	R0 = I1;
	RTS;
77 78

4:
R
Robin Getz 已提交
79 80 81 82
	LSETUP(5f, 5f) LC0;
5:
	B [P0++] = R1;
6:
83 84 85
	RTS;

ENDPROC(_strncpy)