Page MenuHomeFreeBSD

D15369.id59538.diff
No OneTemporary

D15369.id59538.diff

Index: lib/libc/powerpc64/string/Makefile.inc
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/Makefile.inc
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+MDSRCS+= \
+ strncpy.S
Index: lib/libc/powerpc64/string/strncpy.S
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/strncpy.S
@@ -0,0 +1,165 @@
+/*-
+ * Copyright (c) 2018 Instituto de Pesquisas Eldorado
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+#if 0
+ RCSID("$NetBSD: strncpy.S,v 1.0 2018/05/08 13:00:05 lbianc Exp $")
+#endif
+
+ENTRY(strncpy)
+ std %r3,-8(%r1)
+
+ xor %r6,%r6,%r6 /* Prepare register with zero value. */
+
+ cmpdi %cr7,%r5,0
+ ble %cr7,.Lexit
+
+/* Copy by double word. */
+.Lcopy_dw:
+ cmpdi %cr7,%r5,8
+ blt %cr7,.Lstd_byte
+ ld %r0,0(%r4)
+ cmpb %r7,%r0,%r6
+ cmpdi %cr7,%r7,0
+ bne %cr7,.Lcheck_zero
+ std %r0,0(%r3)
+ addi %r5,%r5,-8
+ cmpdi %cr7,%r5,0
+ beq %cr7,.Lexit
+ cmpdi %cr7,%r5,8
+ blt %cr7,.Lstd_byte_fix
+.Lcopy_dw_loop:
+ ldu %r0,8(%r4)
+ cmpb %r7,%r0,%r6
+ cmpdi %cr7,%r7,0
+ bne %cr7,.Lcheck_zero_fix
+ stdu %r0,8(%r3)
+ addi %r5,%r5,-8
+ cmpdi %cr7,%r5,8
+ bge %cr7,.Lcopy_dw_loop
+ cmpdi %cr7,%r5,0
+ bne %cr7,.Lstd_byte_fix
+ ld %r3,-8(%r1)
+ blr
+
+/* Copy by byte */
+.Lstd_byte_fix:
+ addi %r3,%r3,8 /* Fix addresses from update instructions. */
+ addi %r4,%r4,8
+.Lstd_byte:
+ cmpdi %r5,0
+ beqlr
+ addi %r9,%r5,-1
+ addi %r10,%r3,-1
+ rldicl %r9,%r9,0,32
+ addi %r9,%r9,1
+ mtctr %r9
+.Lstd_byte_loop:
+ lbz %r9,0(%r4)
+ addic %r8,%r9,-1
+ stbu %r9,1(%r10)
+ addze %r4,%r4
+ bdnz .Lstd_byte_loop
+ blr
+
+/* Store zeros by byte. */
+.Lstd_byte_z:
+ stb %r6,0(%r3)
+ addi %r5,%r5,-1
+ cmpdi %cr7,%r5,0
+ beq %cr7,.Lexit
+ addi %r3,%r3,1
+ b .Lstd_byte_z
+
+/* Find where the zero is located. */
+.Lcheck_zero_fix:
+ addi %r3,%r3,8
+.Lcheck_zero:
+ addi %r5,%r5,-8
+ rldicr. %r7,%r0,0,7
+ beq .Lfound_on_byte_1
+ rldicr. %r7,%r0,8,7
+ beq .Lfound_on_byte_2
+ rldicr. %r7,%r0,16,7
+ beq .Lfound_on_byte_3
+ rldicr. %r7,%r0,24,7
+ beq .Lfound_on_byte_4
+ andis. %r7,%r0,0xff00
+ beq .Lfound_on_byte_5
+ andis. %r7,%r0,0xff
+ beq .Lfound_on_byte_6
+ andi. %r7,%r0,0xff00
+ beq .Lfound_on_byte_7
+
+/* As zero was found in a double word before r5 be zero, store the entire
+ register with zeros after the end of the string */
+.Lstd_dw:
+ std %r0,0(%r3)
+ addi %r3,%r3,8
+ cmpdi %cr7,%r5,0
+ beq %cr7,.Lexit
+ b .Lstd_byte_z
+
+/* Treatment of each byte where the zero my be found. */
+.Lfound_on_byte_7:
+ rldicr %r0,%r0,0,56
+ b .Lstd_dw
+
+.Lfound_on_byte_6:
+ rldicr %r0,%r0,0,48
+ b .Lstd_dw
+
+.Lfound_on_byte_5:
+ rldicr %r0,%r0,0,40
+ b .Lstd_dw
+
+.Lfound_on_byte_4:
+ rldicr %r0,%r0,0,32
+ b .Lstd_dw
+
+.Lfound_on_byte_3:
+ rldicr %r0,%r0,0,24
+ b .Lstd_dw
+
+.Lfound_on_byte_2:
+ rldicr %r0,%r0,0,16
+ b .Lstd_dw
+
+.Lfound_on_byte_1:
+ mr %r0,%r6
+ b .Lstd_dw
+
+.Lexit:
+ ld %r3,-8(%r1)
+ blr
+
+END(strncpy)
+
+ .section .note.GNU-stack,"",%progbits

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 4, 11:00 AM (18 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40184843
Default Alt Text
D15369.id59538.diff (4 KB)

Event Timeline