[v2,1/2] newlib: xtensa: remove sys/xtensa. use machine/xtensa

Message ID 5c62325468951c4acfeb002da0fcaa41f2f4c4ac.camel@espressif.com
State New
Headers
Series [v2,1/2] newlib: xtensa: remove sys/xtensa. use machine/xtensa |

Commit Message

Alexey Lapshin Aug. 30, 2024, 9:35 a.m. UTC
  Remove sys/xtensa that is actually duplicate newlib's code.
Move used code to machine/xtensa or to libgloss

---
 libgloss/xtensa/Makefile.inc                  |  1 +
 .../sys => libgloss}/xtensa/clibrary_init.c   |  6 ++--
 newlib/Makefile.am                            |  6 +++-
 newlib/configure                              | 13 --------
 newlib/libc/acinclude.m4                      |  1 -
 .../xtensa/include/xtensa/config/core-isa.h   |  0
 .../include => machine/xtensa/sys}/fenv.h     |  6 ++--
 newlib/libc/sys/Makefile.inc                  |  3 --
 newlib/libc/sys/xtensa/Makefile.inc           |  1 -
 newlib/libc/sys/xtensa/creat.c                |  9 -----
 newlib/libc/sys/xtensa/crt0.c                 | 16 ---------
 newlib/libc/sys/xtensa/include/unistd.h       | 13 --------
 newlib/libc/sys/xtensa/isatty.c               | 18 ----------
 newlib/libc/sys/xtensa/sys/file.h             | 33 -------------------
 newlib/libm/machine/xtensa/acinclude.m4       |  2 +-
 15 files changed, 13 insertions(+), 115 deletions(-)
 rename {newlib/libc/sys => libgloss}/xtensa/clibrary_init.c (91%)
 rename newlib/libc/{sys => machine}/xtensa/include/xtensa/config/core-isa.h (100%)
 rename newlib/libc/{sys/xtensa/include => machine/xtensa/sys}/fenv.h (97%)
 delete mode 100644 newlib/libc/sys/xtensa/Makefile.inc
 delete mode 100644 newlib/libc/sys/xtensa/creat.c
 delete mode 100644 newlib/libc/sys/xtensa/crt0.c
 delete mode 100644 newlib/libc/sys/xtensa/include/unistd.h
 delete mode 100644 newlib/libc/sys/xtensa/isatty.c
 delete mode 100644 newlib/libc/sys/xtensa/sys/file.h

-- 
2.43.0
  

Patch

diff --git a/libgloss/xtensa/Makefile.inc b/libgloss/xtensa/Makefile.inc
index b4c818732..5cdb4ef39 100644
--- a/libgloss/xtensa/Makefile.inc
+++ b/libgloss/xtensa/Makefile.inc
@@ -22,6 +22,7 @@  multilibtool_DATA += \
 	%D%/crt1-boards.o
 
 %C%_libgloss_a_SOURCES = \
+	%D%/clibrary_init.c \
 	%D%/sleep.S \
 	%D%/syscalls.c \
 	%D%/window-vectors.S
diff --git a/newlib/libc/sys/xtensa/clibrary_init.c b/libgloss/xtensa/clibrary_init.c
similarity index 91%
rename from newlib/libc/sys/xtensa/clibrary_init.c
rename to libgloss/xtensa/clibrary_init.c
index 24d4cf94c..b8c7d3a6a 100644
--- a/newlib/libc/sys/xtensa/clibrary_init.c
+++ b/libgloss/xtensa/clibrary_init.c
@@ -1,6 +1,6 @@ 
 /* Copyright (c) 2003-2006 Tensilica Inc.  ALL RIGHTS RESERVED.
 
-   Redistribution and use in source and binary forms, with or without
+  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
@@ -29,8 +29,8 @@  const char * __progname = 0;
 
 void
 __clibrary_init (int argc, char **argv, char **envp,
-		 void (*init)(void),
-		 void (*fini)(void))
+                void (*init)(void),
+                void (*fini)(void))
 {
   if (argv != 0)
     __progname = *argv;
diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 4ab36b8d8..87a7f8597 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -233,7 +233,11 @@  stmp-targ-include: config.status
 	  fi
 	$(AM_V_at)s=machine/$(machine_dir)/machine d=machine $(TARG_INCLUDE_CP_DIR)
 	$(AM_V_at)s=machine/$(machine_dir)/sys d=sys $(TARG_INCLUDE_CP_DIR)
-	$(AM_V_at)s=machine/$(machine_dir)/include d= $(TARG_INCLUDE_CP_DIR)
+	$(AM_V_at)for i in $(call rwildcard,$(srcdir)/libc/machine/$(machine_dir)/include/,*.h); do \
+	  f=`echo $$i | sed s:^$(srcdir)/libc/machine/$(machine_dir)/include/::`; \
+	  $(MKDIR_P) targ-include/`dirname $$f`; \
+	  cp $$i targ-include/$$f; \
+	done
 	$(AM_V_at)s=sys/$(sys_dir)/include d= $(TARG_INCLUDE_CP_DIR)
 	$(AM_V_at)for i in $(call rwildcard,$(srcdir)/libc/sys/$(sys_dir)/include/,*.h); do \
 	  f=`echo $$i | sed s:^$(srcdir)/libc/sys/$(sys_dir)/include/::`; \
diff --git a/newlib/configure b/newlib/configure
index 14ed85e30..cb4747880 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -777,8 +777,6 @@  HAVE_LONG_DOUBLE_FALSE
 HAVE_LONG_DOUBLE_TRUE
 HAVE_LIBC_SYS_Z8KSIM_DIR_FALSE
 HAVE_LIBC_SYS_Z8KSIM_DIR_TRUE
-HAVE_LIBC_SYS_XTENSA_DIR_FALSE
-HAVE_LIBC_SYS_XTENSA_DIR_TRUE
 HAVE_LIBC_SYS_W65_DIR_FALSE
 HAVE_LIBC_SYS_W65_DIR_TRUE
 HAVE_LIBC_SYS_TIRTOS_DIR_FALSE
@@ -5513,13 +5511,6 @@  fi
 else
   HAVE_LIBC_SYS_W65_DIR_TRUE='#'
   HAVE_LIBC_SYS_W65_DIR_FALSE=
-fi
- if test "${sys_dir}" = xtensa; then
-  HAVE_LIBC_SYS_XTENSA_DIR_TRUE=
-  HAVE_LIBC_SYS_XTENSA_DIR_FALSE='#'
-else
-  HAVE_LIBC_SYS_XTENSA_DIR_TRUE='#'
-  HAVE_LIBC_SYS_XTENSA_DIR_FALSE=
 fi
  if test "${sys_dir}" = z8ksim; then
   HAVE_LIBC_SYS_Z8KSIM_DIR_TRUE=
@@ -7708,10 +7699,6 @@  if test -z "${HAVE_LIBC_SYS_W65_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_W65_DIR_F
   as_fn_error $? "conditional \"HAVE_LIBC_SYS_W65_DIR\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
-if test -z "${HAVE_LIBC_SYS_XTENSA_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_XTENSA_DIR_FALSE}"; then
-  as_fn_error $? "conditional \"HAVE_LIBC_SYS_XTENSA_DIR\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
-fi
 if test -z "${HAVE_LIBC_SYS_Z8KSIM_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_Z8KSIM_DIR_FALSE}"; then
   as_fn_error $? "conditional \"HAVE_LIBC_SYS_Z8KSIM_DIR\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/acinclude.m4 b/newlib/libc/acinclude.m4
index 48a7dee51..52a6c57cf 100644
--- a/newlib/libc/acinclude.m4
+++ b/newlib/libc/acinclude.m4
@@ -23,7 +23,6 @@  m4_foreach_w([SYS_DIR], [
   sh sysmec sysnec810 sysnecv850 sysvi386 sysvnecv70
   tic80 tirtos
   w65
-  xtensa
   z8ksim
 ], [AM_CONDITIONAL([HAVE_LIBC_SYS_]m4_toupper(SYS_DIR)[_DIR], test "${sys_dir}" = SYS_DIR)])
 
diff --git a/newlib/libc/sys/xtensa/include/xtensa/config/core-isa.h b/newlib/libc/machine/xtensa/include/xtensa/config/core-isa.h
similarity index 100%
rename from newlib/libc/sys/xtensa/include/xtensa/config/core-isa.h
rename to newlib/libc/machine/xtensa/include/xtensa/config/core-isa.h
diff --git a/newlib/libc/sys/xtensa/include/fenv.h b/newlib/libc/machine/xtensa/sys/fenv.h
similarity index 97%
rename from newlib/libc/sys/xtensa/include/fenv.h
rename to newlib/libc/machine/xtensa/sys/fenv.h
index 2fa76f758..69c94f0cf 100644
--- a/newlib/libc/sys/xtensa/include/fenv.h
+++ b/newlib/libc/machine/xtensa/sys/fenv.h
@@ -26,8 +26,8 @@ 
    OF THE POSSIBILITY OF SUCH DAMAGE.  */
 
 
-#ifndef _FENV_H
-#define _FENV_H
+#ifndef _SYS_FENV_H
+#define _SYS_FENV_H
 
 #ifdef __cplusplus
 extern "C" {
@@ -85,4 +85,4 @@  int fegetexcept(void);
 }
 #endif
 
-#endif
+#endif // _SYS_FENV_H
diff --git a/newlib/libc/sys/Makefile.inc b/newlib/libc/sys/Makefile.inc
index 24d8407d5..9f8758934 100644
--- a/newlib/libc/sys/Makefile.inc
+++ b/newlib/libc/sys/Makefile.inc
@@ -64,9 +64,6 @@  endif
 if HAVE_LIBC_SYS_W65_DIR
 include %D%/w65/Makefile.inc
 endif
-if HAVE_LIBC_SYS_XTENSA_DIR
-include %D%/xtensa/Makefile.inc
-endif
 if HAVE_LIBC_SYS_Z8KSIM_DIR
 include %D%/z8ksim/Makefile.inc
 endif
diff --git a/newlib/libc/sys/xtensa/Makefile.inc b/newlib/libc/sys/xtensa/Makefile.inc
deleted file mode 100644
index ddee58ae1..000000000
--- a/newlib/libc/sys/xtensa/Makefile.inc
+++ /dev/null
@@ -1 +0,0 @@ 
-libc_a_SOURCES += %D%/creat.c %D%/isatty.c %D%/clibrary_init.c
diff --git a/newlib/libc/sys/xtensa/creat.c b/newlib/libc/sys/xtensa/creat.c
deleted file mode 100644
index 21e6a1874..000000000
--- a/newlib/libc/sys/xtensa/creat.c
+++ /dev/null
@@ -1,9 +0,0 @@ 
-/* creat() "system call" (copied from libc/posix/creat.c) */
-
-#include <fcntl.h>
-
-int
-creat (const char *path, mode_t mode)
-{
-  return open (path, O_WRONLY | O_CREAT | O_TRUNC, mode);
-}
diff --git a/newlib/libc/sys/xtensa/crt0.c b/newlib/libc/sys/xtensa/crt0.c
deleted file mode 100644
index 11725dca5..000000000
--- a/newlib/libc/sys/xtensa/crt0.c
+++ /dev/null
@@ -1,16 +0,0 @@ 
-/* Dummy crt0 code.  */
-
-/* Copyright (c) 2003 by Tensilica Inc.  ALL RIGHTS RESERVED.
-   These coded instructions, statements, and computer programs are the
-   copyrighted works and confidential proprietary information of Tensilica Inc.
-   They may not be modified, copied, reproduced, distributed, or disclosed to
-   third parties in any manner, medium, or form, in whole or in part, without
-   the prior written consent of Tensilica Inc.  */
-
-/* Xtensa systems normally use a crt1 file associated with a particular
-   linker support package (LSP).  There is no need for this crt0 file,
-   except that the newlib makefiles require it to exist if there is a
-   sys/xtensa directory.  The directory exists only to hold the header
-   files for the Xtensa ISS semihosting "platform".  */
-
-void crt0_unused (void) {}
diff --git a/newlib/libc/sys/xtensa/include/unistd.h b/newlib/libc/sys/xtensa/include/unistd.h
deleted file mode 100644
index 4f6fd29a4..000000000
--- a/newlib/libc/sys/xtensa/include/unistd.h
+++ /dev/null
@@ -1,13 +0,0 @@ 
-#ifndef _UNISTD_H_
-#define _UNISTD_H_
-
-# include <sys/unistd.h>
-
-#ifndef L_SET
-/* Old BSD names for the same constants; just for compatibility.  */
-#define		L_SET		SEEK_SET
-#define		L_INCR		SEEK_CUR
-#define		L_XTND		SEEK_END
-#endif
-
-#endif /* _UNISTD_H_ */
diff --git a/newlib/libc/sys/xtensa/isatty.c b/newlib/libc/sys/xtensa/isatty.c
deleted file mode 100644
index fe64209b9..000000000
--- a/newlib/libc/sys/xtensa/isatty.c
+++ /dev/null
@@ -1,18 +0,0 @@ 
-/* isatty.c */
-
-/* Dumb implementation so programs will at least run.  */
-
-#include <sys/stat.h>
-#include <reent.h>
-
-int
-_isatty_r (struct _reent *ptr, int fd)
-{
-  struct stat buf;
-
-  if (_fstat_r (ptr, fd, &buf) < 0)
-    return 0;
-  if (S_ISCHR (buf.st_mode))
-    return 1;
-  return 0;
-}
diff --git a/newlib/libc/sys/xtensa/sys/file.h b/newlib/libc/sys/xtensa/sys/file.h
deleted file mode 100644
index 48a2ca06d..000000000
--- a/newlib/libc/sys/xtensa/sys/file.h
+++ /dev/null
@@ -1,33 +0,0 @@ 
-/* Copyright (c) 2005-2006 Tensilica Inc.  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.
-
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 TENSILICA
-   INCORPORATED 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 <sys/fcntl.h>
-
-/* Alternate names for values for the WHENCE argument to `lseek'.
-   These are the same as SEEK_SET, SEEK_CUR, and SEEK_END, respectively. */
-#ifndef L_SET
-#define L_SET   0       /* Seek from beginning of file.  */
-#define L_INCR  1       /* Seek from current position.  */
-#define L_XTND  2       /* Seek from end of file.  */
-#endif
diff --git a/newlib/libm/machine/xtensa/acinclude.m4 b/newlib/libm/machine/xtensa/acinclude.m4
index 4d242e057..fc5001da0 100644
--- a/newlib/libm/machine/xtensa/acinclude.m4
+++ b/newlib/libm/machine/xtensa/acinclude.m4
@@ -2,7 +2,7 @@  AC_CACHE_CHECK([for XCHAL_HAVE_FP_SQRT], newlib_cv_xchal_have_fp_sqrt, [dnl
     AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
 [[#define _LIBM
 // targ-include does not exist yet, use relative path
-#include "../sys/xtensa/include/xtensa/config/core-isa.h"
+#include "../machine/xtensa/include/xtensa/config/core-isa.h"
 #if (!XCHAL_HAVE_FP_SQRT)
 # error "Have not XCHAL_HAVE_FP_SQRT"
 #endif