/*1* Copyright 2005-2010 Analog Devices Inc.2*3* Licensed under the ADI BSD license or the GPL-2 (or later)4*/56#include <linux/linkage.h>7#include <asm/context.S>89/* void *strncpy(char *dest, const char *src, size_t n);10* R0 = address (dest)11* R1 = address (src)12* R2 = size13* Returns a pointer (R0) to the destination string dest14* we do this by not changing R015*/1617#ifdef CONFIG_STRNCPY_L118.section .l1.text19#else20.text21#endif2223.align 22425ENTRY(_strncpy)26CC = R2 == 0;27if CC JUMP 6f;2829P2 = R2 ; /* size */30P0 = R0 ; /* dst*/31P1 = R1 ; /* src*/3233LSETUP (1f, 2f) LC0 = P2;341:35R1 = B [P1++] (Z);36B [P0++] = R1;37CC = R1 == 0;382:39if CC jump 3f;4041RTS;4243/* if src is shorter than n, we need to null pad bytes in dest44* but, we can get here when the last byte is zero, and we don't45* want to copy an extra byte at the end, so we need to check46*/473:48R2 = LC0;49CC = R250if ! CC jump 6f;5152/* if the required null padded portion is small, do it here, rather than53* handling the overhead of memset (which is OK when things are big).54*/55R3 = 0x20;56CC = R2 < R3;57IF CC jump 4f;5859R2 += -1;6061/* Set things up for memset62* R0 = address63* R1 = filler byte (this case it's zero, set above)64* R2 = count (set above)65*/6667I1 = R0;68R0 = RETS;69I0 = R0;70R0 = P0;71pseudo_long_call _memset, p0;72R0 = I0;73RETS = R0;74R0 = I1;75RTS;76774:78LSETUP(5f, 5f) LC0;795:80B [P0++] = R1;816:82RTS;8384ENDPROC(_strncpy)858687