[PATCH 08/21] newlib: Necessary fixes related to MIPS.
Aleksandar Rikalo
arikalo@gmail.com
Thu Oct 31 05:49:24 GMT 2024
From: Jaydeep Patil <jaydeep.patil@imgtec.com>
Signed-off-by: Jaydeep Patil <jaydeep.patil@imgtec.com>
Signed-off-by: Aleksandar Rikalo <arikalo@gmail.com>
---
newlib/Makefile.am | 2 +-
newlib/Makefile.in | 2 +-
newlib/configure.host | 1 +
newlib/libc/include/machine/endian.h | 5 +++++
newlib/libc/include/machine/ieeefp.h | 6 ++++++
newlib/libc/include/sys/config.h | 2 +-
newlib/libc/include/sys/stat.h | 4 ++++
newlib/libc/machine/mips/strlen.c | 20 ++++++--------------
8 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 00088b6c3..65a9a6af6 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -260,7 +260,7 @@ CLEANFILES += stmp-targ-include
install-data-local: install-toollibLIBRARIES install-multi $(INSTALL_DATA_LOCAL)
rm -f $(DESTDIR)$(toollibdir)/libg.a
ln $(DESTDIR)$(toollibdir)/libc.a $(DESTDIR)$(toollibdir)/libg.a >/dev/null 2>/dev/null || cp $(DESTDIR)$(toollibdir)/libc.a $(DESTDIR)$(toollibdir)/libg.a
- -if [ -z "$(MULTISUBDIR)" ]; then \
+ -if [ -z "$(MULTISUBDIR)" -o -n "$(MULTIDIRS)" ]; then \
$(mkinstalldirs) $(DESTDIR)$(tooldir)/include; \
for i in $(srcdir)/libc/include/*.h; do \
$(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index f25db3b0a..efb642473 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -51009,7 +51009,7 @@ stmp-targ-include: config.status
install-data-local: install-toollibLIBRARIES install-multi $(INSTALL_DATA_LOCAL)
rm -f $(DESTDIR)$(toollibdir)/libg.a
ln $(DESTDIR)$(toollibdir)/libc.a $(DESTDIR)$(toollibdir)/libg.a >/dev/null 2>/dev/null || cp $(DESTDIR)$(toollibdir)/libc.a $(DESTDIR)$(toollibdir)/libg.a
- -if [ -z "$(MULTISUBDIR)" ]; then \
+ -if [ -z "$(MULTISUBDIR)" -o -n "$(MULTIDIRS)" ]; then \
$(mkinstalldirs) $(DESTDIR)$(tooldir)/include; \
for i in $(srcdir)/libc/include/*.h; do \
$(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
diff --git a/newlib/configure.host b/newlib/configure.host
index ff2e51275..846148c25 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -251,6 +251,7 @@ case "${host_cpu}" in
mips*)
machine_dir=mips
libm_machine_dir=mips
+ newlib_cflags="${newlib_cflags}"
;;
mmix)
;;
diff --git a/newlib/libc/include/machine/endian.h b/newlib/libc/include/machine/endian.h
index 34a5726e6..a00002893 100644
--- a/newlib/libc/include/machine/endian.h
+++ b/newlib/libc/include/machine/endian.h
@@ -1,8 +1,11 @@
#ifndef __MACHINE_ENDIAN_H__
#define __MACHINE_ENDIAN_H__
+#ifndef __ASSEMBLER__
#include <sys/cdefs.h>
#include <sys/_types.h>
+#endif
+
#include <machine/_endian.h>
#if _BYTE_ORDER == _LITTLE_ENDIAN
@@ -20,6 +23,7 @@
#define BYTE_ORDER _BYTE_ORDER
#endif
+#ifndef __ASSEMBLER__
#ifdef __GNUC__
#define __bswap16(_x) __builtin_bswap16(_x)
#define __bswap32(_x) __builtin_bswap32(_x)
@@ -65,5 +69,6 @@ __bswap64(__uint64_t _x)
#define __ntohs(_x) ((__uint16_t)(_x))
#endif
#endif /* __machine_host_to_from_network_defined */
+#endif /* __ASSEMBLER__ */
#endif /* __MACHINE_ENDIAN_H__ */
diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index f99577bea..c5fafcf05 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -263,9 +263,15 @@
#ifdef __MIPSEL__
#define __IEEE_LITTLE_ENDIAN
+#if __SIZEOF_DOUBLE__ == 4
+#define _DOUBLE_IS_32BITS
+#endif
#endif
#ifdef __MIPSEB__
#define __IEEE_BIG_ENDIAN
+#if __SIZEOF_DOUBLE__ == 4
+#define _DOUBLE_IS_32BITS
+#endif
#endif
#ifdef __MMIX__
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 5dcc77a80..4c9acc55c 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -4,7 +4,7 @@
#include <machine/ieeefp.h> /* floating point macros */
#include <sys/features.h> /* POSIX defs */
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__mips__)
#define MALLOC_ALIGNMENT 16
#endif
diff --git a/newlib/libc/include/sys/stat.h b/newlib/libc/include/sys/stat.h
index b4e27f22e..86b3435c0 100644
--- a/newlib/libc/include/sys/stat.h
+++ b/newlib/libc/include/sys/stat.h
@@ -136,7 +136,11 @@ struct stat
int chmod (const char *__path, mode_t __mode );
int fchmod (int __fd, mode_t __mode);
+#if defined(__mips__) && defined(__mips16)
+int __attribute__((nomips16)) fstat (int __fd, struct stat *__sbuf );
+#else
int fstat (int __fd, struct stat *__sbuf );
+#endif // __mips__
int mkdir (const char *_path, mode_t __mode );
int mkfifo (const char *__path, mode_t __mode );
int stat (const char *__restrict __path, struct stat *__restrict __sbuf );
diff --git a/newlib/libc/machine/mips/strlen.c b/newlib/libc/machine/mips/strlen.c
index a87bddd11..65cbaf3a6 100644
--- a/newlib/libc/machine/mips/strlen.c
+++ b/newlib/libc/machine/mips/strlen.c
@@ -33,27 +33,21 @@ strlen (const char *str)
}
#elif defined(__mips64)
__asm__("" /* 64-bit MIPS targets */
- " .set noreorder\n"
- " .set nomacro\n"
" .globl strlen\n"
" .ent strlen\n"
"strlen:\n"
" daddiu $2,$4,1\n"
"\n"
"1: lbu $3,0($4)\n"
- " bnez $3,1b\n"
" daddiu $4,$4,1\n"
+ " bnez $3,1b\n"
"\n"
- " jr $31\n"
" dsubu $2,$4,$2\n"
- " .end strlen\n"
- " .set macro\n"
- " .set reorder\n");
+ " jr $31\n"
+ " .end strlen\n");
#else
__asm__("" /* 32-bit MIPS targets */
- " .set noreorder\n"
- " .set nomacro\n"
" .globl strlen\n"
" .ent strlen\n"
"strlen:\n"
@@ -63,12 +57,10 @@ __asm__("" /* 32-bit MIPS targets */
#if defined(_R3000)
" nop \n"
#endif
- " bnez $3,1b\n"
" addiu $4,$4,1\n"
+ " bnez $3,1b\n"
"\n"
- " jr $31\n"
" subu $2,$4,$2\n"
- " .end strlen\n"
- " .set macro\n"
- " .set reorder\n");
+ " jr $31\n"
+ " .end strlen\n");
#endif
--
2.25.1
More information about the Newlib
mailing list