blob: 92fd1823bbee7e8289ed07fbc969277822b7006e [file] [log] [blame]
Robin Getz479ba602010-05-03 17:23:20 +00001/*
2 * Copyright 2005-2010 Analog Devices Inc.
3 *
Sonic Zhangde450832012-05-17 14:45:27 +08004 * Licensed under the Clear BSD license or the GPL-2 (or later)
Robin Getz479ba602010-05-03 17:23:20 +00005 */
6
7#include <linux/linkage.h>
Robin Getz648eee52010-05-04 14:59:21 +00008#include <asm/context.S>
Robin Getz479ba602010-05-03 17:23:20 +00009
10/* void *strncpy(char *dest, const char *src, size_t n);
11 * R0 = address (dest)
12 * R1 = address (src)
13 * R2 = size
Robin Getz648eee52010-05-04 14:59:21 +000014 * Returns a pointer (R0) to the destination string dest
15 * we do this by not changing R0
Robin Getz479ba602010-05-03 17:23:20 +000016 */
17
18#ifdef CONFIG_STRNCPY_L1
19.section .l1.text
20#else
21.text
22#endif
23
24.align 2
25
26ENTRY(_strncpy)
27 CC = R2 == 0;
Steven Miao5ff61972011-06-01 15:52:41 +080028 if CC JUMP 6f;
Robin Getz648eee52010-05-04 14:59:21 +000029
30 P2 = R2 ; /* size */
Robin Getz479ba602010-05-03 17:23:20 +000031 P0 = R0 ; /* dst*/
32 P1 = R1 ; /* src*/
33
Robin Getz648eee52010-05-04 14:59:21 +000034 LSETUP (1f, 2f) LC0 = P2;
Robin Getz479ba602010-05-03 17:23:20 +0000351:
36 R1 = B [P1++] (Z);
37 B [P0++] = R1;
Robin Getz648eee52010-05-04 14:59:21 +000038 CC = R1 == 0;
Robin Getz479ba602010-05-03 17:23:20 +0000392:
Robin Getz648eee52010-05-04 14:59:21 +000040 if CC jump 3f;
41
42 RTS;
43
44 /* if src is shorter than n, we need to null pad bytes in dest
45 * but, we can get here when the last byte is zero, and we don't
46 * want to copy an extra byte at the end, so we need to check
47 */
Robin Getz479ba602010-05-03 17:23:20 +0000483:
Robin Getz648eee52010-05-04 14:59:21 +000049 R2 = LC0;
50 CC = R2
51 if ! CC jump 6f;
52
53 /* if the required null padded portion is small, do it here, rather than
54 * handling the overhead of memset (which is OK when things are big).
55 */
56 R3 = 0x20;
57 CC = R2 < R3;
58 IF CC jump 4f;
59
Robin Getz479ba602010-05-03 17:23:20 +000060 R2 += -1;
Robin Getz648eee52010-05-04 14:59:21 +000061
62 /* Set things up for memset
63 * R0 = address
64 * R1 = filler byte (this case it's zero, set above)
65 * R2 = count (set above)
66 */
67
68 I1 = R0;
69 R0 = RETS;
70 I0 = R0;
71 R0 = P0;
72 pseudo_long_call _memset, p0;
73 R0 = I0;
74 RETS = R0;
75 R0 = I1;
76 RTS;
Robin Getz479ba602010-05-03 17:23:20 +000077
784:
Robin Getz648eee52010-05-04 14:59:21 +000079 LSETUP(5f, 5f) LC0;
805:
81 B [P0++] = R1;
826:
Robin Getz479ba602010-05-03 17:23:20 +000083 RTS;
84
85ENDPROC(_strncpy)