This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[Patch, microblaze]: Add little-endian support
- From: David Holsgrove <david dot holsgrove at xilinx dot com>
- To: <newlib at sourceware dot org>
- Cc: <eager at eagerm dot com>, <edgari at xilinx dot com>, <nmekala at xilinx dot com>
- Date: Mon, 15 Jul 2013 15:28:54 +1000
- Subject: [Patch, microblaze]: Add little-endian support
From: "David Holsgrove" <david.holsgrove@xilinx.com>
Add MicroBlaze little endian support (microblazeel)
newlib/ChangeLog
2013-07-15 David Holsgrove <david.holsgrove@xilinx.com>
* configure.host: Change to microblaze*.
* libc/include/machine/ieeefp.h: Add __MICROBLAZEEL__.
* libc/machine/microblaze/mb_endian.h: New file.
* newlib/libc/machine/microblaze/strcmp.c: Add little endian support.
* newlib/libc/machine/microblaze/strcpy.c: Likewise.
* newlib/libc/machine/microblaze/strlen.c: Likewise.
libgloss/ChangeLog
2013-07-15 David Holsgrove <david.holsgrove@xilinx.com>
* configure.in: Change to microblaze*.
* configure: Regenerate.
* microblaze/xilinx.ld: Remove OUTPUT_FORMAT.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
Signed-off by: Nagaraju Mekala <nmekala@xilinx.com>
---
libgloss/configure | 2 +-
libgloss/configure.in | 2 +-
libgloss/microblaze/xilinx.ld | 2 --
newlib/configure.host | 6 +++---
newlib/libc/include/machine/ieeefp.h | 4 ++++
newlib/libc/machine/microblaze/mb_endian.h | 15 +++++++++++++++
newlib/libc/machine/microblaze/strcmp.c | 11 +++++++----
newlib/libc/machine/microblaze/strcpy.c | 16 ++++++++++------
newlib/libc/machine/microblaze/strlen.c | 7 +++++--
9 files changed, 46 insertions(+), 19 deletions(-)
create mode 100644 newlib/libc/machine/microblaze/mb_endian.h
diff --git a/libgloss/configure b/libgloss/configure
index d2cb52e..41d91d6 100755
--- a/libgloss/configure
+++ b/libgloss/configure
@@ -2504,7 +2504,7 @@ case "${target}" in
subdirs="$subdirs moxie"
;;
- microblaze-*-*)
+ microblaze*-*-*)
subdirs="$subdirs microblaze"
;;
diff --git a/libgloss/configure.in b/libgloss/configure.in
index c571eeb..14287e7 100644
--- a/libgloss/configure.in
+++ b/libgloss/configure.in
@@ -117,7 +117,7 @@ case "${target}" in
moxie-*-*)
AC_CONFIG_SUBDIRS([moxie])
;;
- microblaze-*-*)
+ microblaze*-*-*)
AC_CONFIG_SUBDIRS([microblaze])
;;
mt-*-*)
diff --git a/libgloss/microblaze/xilinx.ld b/libgloss/microblaze/xilinx.ld
index 58594c4..7789ea9 100644
--- a/libgloss/microblaze/xilinx.ld
+++ b/libgloss/microblaze/xilinx.ld
@@ -1,6 +1,4 @@
/* Default linker script, for normal executables */
-OUTPUT_FORMAT("elf32-microblaze", "",
- "")
/*SEARCH_DIR("/proj/fv1/gnu_builds/head/mb/release/lin/mb/microblaze-xilinx-elf/lib");*/
/*SEARCH_DIR("/proj/fv1/gnu_builds/head/mb/release/lin/mb/microblaze-xilinx-elf/lib");*/
ENTRY(_start)
diff --git a/newlib/configure.host b/newlib/configure.host
index d577ce9..e7047f0 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -203,7 +203,7 @@ case "${host_cpu}" in
;;
mcore)
;;
- microblaze)
+ microblaze*)
machine_dir=microblaze
;;
mep)
@@ -479,7 +479,7 @@ case "${host}" in
default_newlib_io_long_long="yes"
newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
;;
- microblaze-*-*)
+ microblaze*-*-*)
machine_dir=microblaze
;;
mips*-dec-*)
@@ -696,7 +696,7 @@ case "${host}" in
mcore-*-*)
syscall_dir=syscalls
;;
- microblaze-*-*)
+ microblaze*-*-*)
default_newlib_io_long_long="yes"
newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DSMALL_MEMORY -D_REENT_SMALL"
;;
diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index 256a781..042e7f4 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -364,7 +364,11 @@
#endif
#ifdef __MICROBLAZE__
+#ifndef __MICROBLAZEEL__
#define __IEEE_BIG_ENDIAN
+#else
+#define __IEEE_LITTLE_ENDIAN
+#endif
#endif
#ifdef __MSP430__
diff --git a/newlib/libc/machine/microblaze/mb_endian.h b/newlib/libc/machine/microblaze/mb_endian.h
new file mode 100644
index 0000000..fb217ec
--- /dev/null
+++ b/newlib/libc/machine/microblaze/mb_endian.h
@@ -0,0 +1,15 @@
+#ifndef _MB_ENDIAN_H
+#define _MB_ENDIAN_H
+
+/* Convenience macros for loading and store 4 bytes in a byte invariant way with
+ * a singe instruction. Endianess affects this and we rely on MicroBlaze
+ * load/store reverse instructions to do the trick on little-endian systems.
+ */
+#ifdef __LITTLE_ENDIAN__
+#define LOAD4BYTES(rD,rA,rB) "\tlwr\t" rD ", " rA ", " rB "\n"
+#define STORE4BYTES(rD,rA,rB) "\tswr\t" rD ", " rA ", " rB "\n"
+#else
+#define LOAD4BYTES(rD,rA,rB) "\tlw\t" rD ", " rA ", " rB "\n"
+#define STORE4BYTES(rD,rA,rB) "\tsw\t" rD ", " rA ", " rB "\n"
+#endif
+#endif
diff --git a/newlib/libc/machine/microblaze/strcmp.c b/newlib/libc/machine/microblaze/strcmp.c
index dbac387..2f03374 100644
--- a/newlib/libc/machine/microblaze/strcmp.c
+++ b/newlib/libc/machine/microblaze/strcmp.c
@@ -138,16 +138,19 @@ _DEFUN (strcmp, (s1, s2),
#else
+#include "mb_endian.h"
+
asm volatile (" \n\
- or r9, r0, r0 /* Index register */ \n\
+ or r9, r0, r0 /* Index register */\n\
check_alignment: \n\
andi r3, r5, 3 \n\
andi r4, r6, 3 \n\
bnei r3, try_align_args \n\
bnei r4, regular_strcmp /* At this point we don't have a choice */ \n\
-cmp_loop: \n\
- lw r3, r5, r9 \n\
- lw r4, r6, r9 \n\
+cmp_loop: \n"
+ LOAD4BYTES("r3", "r5", "r9")
+ LOAD4BYTES("r4", "r6", "r9")
+" \n\
pcmpbf r7, r3, r0 /* See if there is Null byte */ \n\
bnei r7, end_cmp_loop /* IF yes (r7 > 0) use byte compares in end_cmp_loop */ \n\
cmpu r7, r4, r3 /* ELSE compare whole word */ \n\
diff --git a/newlib/libc/machine/microblaze/strcpy.c b/newlib/libc/machine/microblaze/strcpy.c
index 6f0ad05..d5430a3 100644
--- a/newlib/libc/machine/microblaze/strcpy.c
+++ b/newlib/libc/machine/microblaze/strcpy.c
@@ -131,18 +131,22 @@ _DEFUN (strcpy, (dst0, src0),
#else
- asm volatile (" \
- or r9, r0, r0 /* Index register */ \n\
+#include "mb_endian.h"
+
+ asm volatile (" \n\
+ or r9, r0, r0 /* Index register */ \n\
check_alignment: \n\
andi r3, r5, 3 \n\
andi r4, r6, 3 \n\
bnei r3, try_align_args \n\
bnei r4, regular_strcpy /* At this point we dont have a choice */ \n\
-cpy_loop: \n\
- lw r3, r6, r9 \n\
+cpy_loop: \n"
+ LOAD4BYTES("r3", "r6", "r9")
+" \n\
pcmpbf r4, r0, r3 \n\
- bnei r4, cpy_bytes /* If r4 != 0, then null present within string */\n\
- sw r3, r5, r9 \n\
+ bnei r4, cpy_bytes /* If r4 != 0, then null present within string */\n"
+ STORE4BYTES("r3", "r5", "r9")
+" \n\
brid cpy_loop \n\
addik r9, r9, 4 \n\
cpy_bytes: \n\
diff --git a/newlib/libc/machine/microblaze/strlen.c b/newlib/libc/machine/microblaze/strlen.c
index 82eede8..51387cd 100644
--- a/newlib/libc/machine/microblaze/strlen.c
+++ b/newlib/libc/machine/microblaze/strlen.c
@@ -120,13 +120,16 @@ _DEFUN (strlen, (str),
#else
+#include "mb_endian.h"
+
asm volatile (" \n\
or r9, r0, r0 /* Index register */ \n\
check_alignment: \n\
andi r3, r5, 3 \n\
bnei r3, align_arg \n\
-len_loop: \n\
- lw r3, r5, r9 \n\
+len_loop: \n"
+ LOAD4BYTES("r3", "r5", "r9")
+" \n\
pcmpbf r4, r3, r0 \n\
bnei r4, end_len \n\
brid len_loop \n\
--
1.7.9.5