Module Name: src Committed By: matt Date: Wed Jan 23 06:59:55 UTC 2013
Modified Files: src/common/lib/libc/arch/arm/string: strlen_arm.S strlen_naive.S Log Message: Add support for strnlen. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/common/lib/libc/arch/arm/string/strlen_arm.S \ src/common/lib/libc/arch/arm/string/strlen_naive.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libc/arch/arm/string/strlen_arm.S diff -u src/common/lib/libc/arch/arm/string/strlen_arm.S:1.2 src/common/lib/libc/arch/arm/string/strlen_arm.S:1.3 --- src/common/lib/libc/arch/arm/string/strlen_arm.S:1.2 Wed Jan 9 00:01:07 2013 +++ src/common/lib/libc/arch/arm/string/strlen_arm.S Wed Jan 23 06:59:55 2013 @@ -29,7 +29,7 @@ #include <machine/asm.h> -RCSID("$NetBSD: strlen_arm.S,v 1.2 2013/01/09 00:01:07 matt Exp $") +RCSID("$NetBSD: strlen_arm.S,v 1.3 2013/01/23 06:59:55 matt Exp $") #ifdef __ARMEL__ #define BYTE0 0x000000ff @@ -43,16 +43,34 @@ RCSID("$NetBSD: strlen_arm.S,v 1.2 2013/ #define BYTE3 0x000000ff #endif +#ifdef STRNLEN +#define FUNCNAME strnlen +#else +#define FUNCNAME strlen +#endif + .text -ENTRY(strlen) +ENTRY(FUNCNAME) +#ifdef STRNLEN + push {r4,r5} /* save some registers */ + add r5, r0, r1 /* get ptr to end of string */ + mov r4, r1 /* save maxlen */ +#endif add ip, r0, #4 /* for the final post-inc */ 1: tst r0, #3 /* test for word alignment */ beq .Lpre_main_loop /* finally word aligned */ +#ifdef STRNLEN + cmp r0, r5 /* have we gone too far? */ + beq .Lmaxed_out /* yes, return maxlen */ +#endif ldrb r3, [r0], #1 /* load a byte */ teq r3, #0 /* is it 0? */ bne 1b /* no, try next byte */ sub ip, ip, #3 /* subtract (4 - the NUL) */ sub r0, r0, ip /* subtract start */ +#ifdef STRNLEN + pop {r4, r5} /* restore registers */ +#endif RET /* return */ .Lpre_main_loop: #if defined(_ARM_ARCH_7) @@ -64,6 +82,10 @@ ENTRY(strlen) orr r1, r1, r1, lsl #16 /* move to next halfword */ #endif /* _ARM_ARCH_6 */ .Lmain_loop: +#ifdef STRNLEN + cmp r0, r5 /* gone too far? */ + bge .Lmaxed_out /* yes, return maxlen */ +#endif ldr r3, [r0], #4 /* load next word */ #if defined(_ARM_ARCH_6) /* @@ -116,5 +138,17 @@ ENTRY(strlen) * the post-inc. */ sub r0, r0, ip /* subtract start to get length */ - RET -END(strlen) +#ifdef STRNLEN + cmp r0, r4 /* is it larger than maxlen? */ + movgt r0, r4 /* yes, return maxlen */ + pop {r4, r5} /* restore registers */ +#endif + RET /* return */ + +#ifdef STRNLEN +.Lmaxed_out: + mov r0, r4 /* return maxlen */ + pop {r4, r5} /* restore registers */ + RET /* return */ +#endif +END(FUNCNAME) Index: src/common/lib/libc/arch/arm/string/strlen_naive.S diff -u src/common/lib/libc/arch/arm/string/strlen_naive.S:1.2 src/common/lib/libc/arch/arm/string/strlen_naive.S:1.3 --- src/common/lib/libc/arch/arm/string/strlen_naive.S:1.2 Tue Jan 8 16:58:59 2013 +++ src/common/lib/libc/arch/arm/string/strlen_naive.S Wed Jan 23 06:59:55 2013 @@ -28,8 +28,24 @@ */ #include <machine/asm.h> -RCSID("$NetBSD: strlen_naive.S,v 1.2 2013/01/08 16:58:59 pgoyette Exp $") +RCSID("$NetBSD: strlen_naive.S,v 1.3 2013/01/23 06:59:55 matt Exp $") +#ifdef STRNLEN +/* LINTSTUB: size_t strnlen(const char *, size_t) */ +ENTRY(strnlen) + add ip, r0, #1 /* start of src + NUL */ + add r2, r0, r1 /* &src[maxlen] */ +1: cmp r0, r2 /* is this of string? */ + beq 2f /* yes it is */ + ldrb r3, [r0], #1 /* read a byte */ + teq r3, #0 /* is it a NUL? */ + bne 1b /* no, get next byte */ + sub r0, r0, ip /* get difference between start and end */ + RET /* return */ +2: mov r0, r1 /* get maxlen */ + RET /* return */ +END(strnlen) +#else /* STRNLEN */ /* LINTSTUB: size_t strlen(const char *) */ ENTRY(strlen) add ip, r0, #1 /* start of src + NUL */ @@ -39,3 +55,4 @@ ENTRY(strlen) sub r0, r0, ip /* return difference between start and end */ RET END(strlen) +#endif /* !STRNLEN */