blob: 39fbbe6523e54dc89bf49856aed85a356d725611 [file] [log] [blame]
Robin Getz479ba602010-05-03 17:23:20 +00001/*
2 * Copyright 2005-2010 Analog Devices Inc.
3 *
4 * Licensed under the ADI BSD license or the GPL-2 (or later)
5 */
6
7#include <linux/linkage.h>
8
9/* void *strncpy(char *dest, const char *src, size_t n);
10 * R0 = address (dest)
11 * R1 = address (src)
12 * R2 = size
13 * Returns a pointer to the destination string dest
14 */
15
16#ifdef CONFIG_STRNCPY_L1
17.section .l1.text
18#else
19.text
20#endif
21
22.align 2
23
24ENTRY(_strncpy)
25 CC = R2 == 0;
26 if CC JUMP 4f;
27 P0 = R0 ; /* dst*/
28 P1 = R1 ; /* src*/
29
301:
31 R1 = B [P1++] (Z);
32 B [P0++] = R1;
33 CC = R1;
34 if ! cc jump 2f;
35 R2 += -1;
36 CC = R2 == 0;
37 if ! cc jump 1b (bp);
38 jump 4f;
392:
40 /* if src is shorter than n, we need to null pad bytes in dest */
41 R1 = 0;
423:
43 R2 += -1;
44 CC = R2 == 0;
45 if cc jump 4f;
46 B [P0++] = R1;
47 jump 3b;
48
494:
50 RTS;
51
52ENDPROC(_strncpy)