From 1b113fad2c4f20118f8c33844c17be09028dc484 Mon Sep 17 00:00:00 2001
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
Date: Mon, 7 Aug 2006 11:11:08 +0200
Subject: [PATCH] AVR32 string fixes

Various fixes to make the AVR32-specific stringops work:
  - Define hidden symbols that can be rjmp'ed to in shared libs
  - Remove dead code
  - Update Makefile based on ARM version
---
 libc/string/avr32/Makefile  |   21 ++++++++-------------
 libc/string/avr32/bcopy.S   |    2 +-
 libc/string/avr32/bzero.S   |    2 +-
 libc/string/avr32/memcpy.S  |    5 +++++
 libc/string/avr32/memmove.S |   20 ++++++--------------
 libc/string/avr32/memset.S  |    6 ++++++
 libc/string/avr32/strcmp.S  |    3 +++
 7 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/libc/string/avr32/Makefile b/libc/string/avr32/Makefile
index 4e421cd..b01e3bb 100644
--- a/libc/string/avr32/Makefile
+++ b/libc/string/avr32/Makefile
@@ -22,24 +22,19 @@ include $(TOPDIR)Rules.mak
 SSRC	:= bcopy.S bzero.S memcmp.S memcpy.S memmove.S
 SSRC	+= memset.S strcmp.S strlen.S
 # memchr.S, strcat.S, strcpy.S, strncpy.S is broken
-SOBJS	:= $(addprefix __avr32_,$(addsuffix .o,$(basename $(SSRC))))
+SOBJS	:= $(patsubst %.S,%.o, $(SSRC))
+OBJS	:= $(SOBJS)
 
-all: $(SOBJS) $(LIBC)
+OBJ_LIST:= ../../obj.string.$(TARGET_ARCH)
 
-$(LIBC): ar-target
+all: $(OBJ_LIST)
 
-ar-target: $(SOBJS)
-	$(AR) $(ARFLAGS) $(LIBC) $(SOBJS)
+$(OBJ_LIST): $(OBJS)
+	echo $(addprefix string/$(TARGET_ARCH)/, $(OBJS)) > $@
 
-$(SOBJS): __avr32_%.o: %.S
-	$(CC) $(ASFLAGS) -D$*=__avr32_$* -c $< -o $@
+$(SOBJS): %.o: %.S
+	$(CC) $(ASFLAGS) -c $< -o $@
 	$(STRIPTOOL) -x -R .note -R .comment $@
 
 clean:
 	$(RM) *.[oa] *~ core
-
-stringtest.o: stringtest.c
-	$(CC) $(CFLAGS) -c $< -o $@
-
-stringtest: stringtest.o $(SOBJS)
-	$(CC) -static -o $@ $^
diff --git a/libc/string/avr32/bcopy.S b/libc/string/avr32/bcopy.S
index a3202fe..66b8f3d 100644
--- a/libc/string/avr32/bcopy.S
+++ b/libc/string/avr32/bcopy.S
@@ -11,5 +11,5 @@ bcopy:
 	eor	r11, r12
 	eor	r12, r11
 	eor	r11, r12
-	rjmp	memmove
+	rjmp	__memmove
 	.size	bcopy, . - bcopy
diff --git a/libc/string/avr32/bzero.S b/libc/string/avr32/bzero.S
index 716b5d4..761790e 100644
--- a/libc/string/avr32/bzero.S
+++ b/libc/string/avr32/bzero.S
@@ -9,4 +9,4 @@
 bzero:
 	mov	r10, r11
 	mov	r11, 0
-	rjmp	memset
+	rjmp	__memset
diff --git a/libc/string/avr32/memcpy.S b/libc/string/avr32/memcpy.S
index 3e196fc..e9f14c5 100644
--- a/libc/string/avr32/memcpy.S
+++ b/libc/string/avr32/memcpy.S
@@ -10,7 +10,12 @@ #define len r10
 	.text
 	.global	memcpy
 	.type	memcpy, @function
+
+	.global	__memcpy
+	.hidden	__memcpy
+	.type	__memcpy, @function
 memcpy:
+__memcpy:
 	pref	src[0]
 	mov	dst, r12
 
diff --git a/libc/string/avr32/memmove.S b/libc/string/avr32/memmove.S
index 216933d..2574409 100644
--- a/libc/string/avr32/memmove.S
+++ b/libc/string/avr32/memmove.S
@@ -9,13 +9,14 @@ #define len r10
 	.text
 	.global memmove
 	.type	memmove, @function
+
+	.global	__memmove
+	.hidden	__memmove
+	.type	__memmove, @function
 memmove:
+__memmove:
 	cp.w	src, dst
-#ifdef memmove
-	brge	optimized_memcpy
-#else
-	brge	memcpy
-#endif
+	brge	__memcpy
 
 	add	dst, len
 	add	src, len
@@ -72,21 +73,12 @@ #endif
 
 .Lless_than_16:
 	/* Do the remaining as byte copies */
-#if 1
 	sub	len, -16
 	breq	2f
 1:	ld.ub	r0, --src
 	st.b	--dst, r0
 	sub	len, 1
 	brne	1b
-#else
-	neg	len
-	add	pc, pc, len << 2
-	.rept	15
-	ld.ub	r0, --src
-	st.b	--dst, r0
-	.endr
-#endif
 
 2:	popm	r0-r7, pc
 
diff --git a/libc/string/avr32/memset.S b/libc/string/avr32/memset.S
index 9ccfb06..1b94d72 100644
--- a/libc/string/avr32/memset.S
+++ b/libc/string/avr32/memset.S
@@ -9,8 +9,14 @@ #define n r10
 	.text
 	.global memset
 	.type	memset, @function
+
+	.global	__memset
+	.hidden	__memset
+	.type	__memset, @function
+
 	.align	1
 memset:
+__memset:
 	cp.w	n, 32
 	mov	r9, s
 	brge	.Llarge_memset
diff --git a/libc/string/avr32/strcmp.S b/libc/string/avr32/strcmp.S
index 2b729c6..221ffe6 100644
--- a/libc/string/avr32/strcmp.S
+++ b/libc/string/avr32/strcmp.S
@@ -75,3 +75,6 @@ strcmp:
 	cp.w	r9, 0
 	brne	1b
 	retal	0
+
+	.weak	strcoll
+	strcoll	= strcmp
-- 
1.4.0

