1/* 2Copyright (c) 2009 Nick Clifton <nickc@redhat.com> 3 */ 4#include <picolibc.h> 5 6 .file "strncpy.S" 7 8 .section .text 9 .global _strncpy 10 .type _strncpy,@function 11_strncpy: 12#ifdef __RX_DISALLOW_STRING_INSNS__ 13 cmp #0, r3 14 beq 3f 15 16 mov r1, r4 ; Preserve R1 for the return value. 17 182: mov.b [r2+], r5 ; Copy bytes until... 19 mov.b r5, [r4+] 20 sub #1, r3 21 beq 3f ; ... our count reaches zero 22 cmp #0, r5 23 bne 2b ; ... or we have written a NUL byte 24 254: mov.b r5, [r4+] ; Continue to write further NUL bytes 26 sub #1, r3 27 bne 4b ; until the count reaches zero. 28 293: rts 30 31#else 32 mov r1, r4 ; Save a copy of the dest pointer. 33 mov r3, r5 ; Save a copy of the byte count 34 smovu ; Copy the bytes 35 cmp #0, r3 ; If we have copied the number of bytes requested 36 beq 1f ; then skip the next bit: 37 add r4, r5, r1 ; Point to the last byte that we are supposed to write. 38 sub r3, r1 ; Subtract the number of bytes left to be written. 39 mov #0, r2 ; Fill the remaining bytes with NULs, 40 sstr.b 411: 42 mov r4, r1 ; Return the destination pointer 43 rts 44#endif 45 .size _strncpy, . - _strncpy 46 47