* [PATCH 1/2] libgloss: merge pru into top-level Makefile @ 2024-01-02 8:24 Dimitar Dimitrov 2024-01-02 8:24 ` [PATCH 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Dimitar Dimitrov @ 2024-01-02 8:24 UTC (permalink / raw) To: newlib; +Cc: Dimitar Dimitrov Avoid a recursive make to speed things up a bit. This change was inspired by the recent similar patch for c6x: https://sourceware.org/pipermail/newlib/2023/020869.html While at it, fork crt0-minrt.S into a separate source file instead of relying on a predefined macro to generate two different object files. This improves clarity, simplifies the build rules, and would allow further optimization in crt0-minrt.S to be implemented more cleanly. Regression tested with clean toolchain build (Binutils+GCC+Newlib) and running the GCC testsuite. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu> --- libgloss/Makefile.am | 3 + libgloss/configure.ac | 5 +- libgloss/pru/Makefile.in | 145 -------------------------------------- libgloss/pru/Makefile.inc | 19 +++++ libgloss/pru/crt0-minrt.S | 59 ++++++++++++++++ libgloss/pru/crt0.S | 6 -- 6 files changed, 83 insertions(+), 154 deletions(-) delete mode 100644 libgloss/pru/Makefile.in create mode 100644 libgloss/pru/Makefile.inc create mode 100644 libgloss/pru/crt0-minrt.S diff --git a/libgloss/Makefile.am b/libgloss/Makefile.am index 0d4460b58..c45f0fa2e 100644 --- a/libgloss/Makefile.am +++ b/libgloss/Makefile.am @@ -93,6 +93,9 @@ endif if CONFIG_NIOS2 include nios2/Makefile.inc endif +if CONFIG_PRU +include pru/Makefile.inc +endif if CONFIG_RISCV include riscv/Makefile.inc endif diff --git a/libgloss/configure.ac b/libgloss/configure.ac index 268d86c51..695f37f15 100644 --- a/libgloss/configure.ac +++ b/libgloss/configure.ac @@ -238,8 +238,7 @@ case "${target}" in subdirs="$subdirs or1k" ;; pru-*-*) - AC_CONFIG_FILES([pru/Makefile]) - subdirs="$subdirs pru" + config_pru=true ;; nios2-*-*) config_nios2=true @@ -250,7 +249,7 @@ AC_SUBST(subdirs) dnl These subdirs have converted to non-recursive make. Hopefully someday all dnl the ports above will too! m4_foreach_w([SUBDIR], [ - aarch64 arc arm bfin csky d30v iq2000 libnosys lm32 nios2 riscv wince xtensa + aarch64 arc arm bfin csky d30v iq2000 libnosys lm32 nios2 pru riscv wince xtensa ], [dnl AM_CONDITIONAL([CONFIG_]m4_toupper(SUBDIR), [test x$config_]SUBDIR = xtrue) ]) diff --git a/libgloss/pru/Makefile.in b/libgloss/pru/Makefile.in deleted file mode 100644 index fc5905a5e..000000000 --- a/libgloss/pru/Makefile.in +++ /dev/null @@ -1,145 +0,0 @@ -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD -# -# Copyright 2018-2019 Dimitar Dimitrov <dimitar@dinux.eu> -# 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 AUTHOR ``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 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. - -VPATH = @srcdir@ @srcdir@/.. - -srcdir = @srcdir@ -objdir = . -srcroot = $(srcdir)/../.. -objroot = $(objdir)/../.. - -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -host_alias = @host_alias@ -target_alias = @target_alias@ - -bindir = @bindir@ -libdir = @libdir@ -includedir = @includedir@ -tooldir = $(exec_prefix)/$(target_alias) - -# Multilib support variables. -# TOP is used instead of MULTI{BUILD,SRC}TOP. -MULTIDIRS = -MULTISUBDIR = - -SHELL = /bin/sh - -mkinstalldirs = $(SHELL) $(srcroot)/mkinstalldirs - -CC = @CC@ - -AS = @AS@ - -AR = @AR@ - -LD = @LD@ - -RANLIB = @RANLIB@ - -OBJDUMP = `t='$(program_transform_name)'; echo objdump | sed -e $$t` -OBJCOPY = `t='$(program_transform_name)'; echo objcopy | sed -e $$t` - -# object files needed -OBJS = \ - do_global_dtors.o gettimeofday.o \ - isatty.o putnum.o raise.o \ - inbyte.o outbyte.o sbrk.o stat.o syscalls.o \ - do_global_dtors.o - -# Object files specific to particular targets. -EVALOBJS = ${OBJS} - -CRTOBJS = crt0.o crt0-minrt.o -OUTPUTS = libgloss.a $(CRTOBJS) - -INCLUDES = -I$(srcdir)/.. - -# Note that when building the library, ${MULTILIB} is not the way multilib -# options are passed; they're passed in $(CFLAGS). -CFLAGS_FOR_TARGET = ${MULTILIB} ${INCLUDES} -LDFLAGS_FOR_TARGET = ${MULTILIB} - -.c.o: - $(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $< - -.C.o: - $(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $< -.s.o: - $(AS) $(ASFLAGS_FOR_TARGET) $(ASFLAGS) -o $*.o $< - -# -# GCC knows to run the preprocessor on .S files before it assembles them. -# -.S.o: - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< - -all: ${OUTPUTS} - -# -# here's where we build the library for each target -# - -libgloss.a: $(EVALOBJS) - ${AR} ${ARFLAGS} $@ $(EVALOBJS) - ${RANLIB} $@ - -# C Runtime Library startup code. -crt0.o: $(srcdir)/crt0.S - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) $< -c -o $@ - -crt0-minrt.o: $(srcdir)/crt0.S - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -DMINRT $< -c -o $@ - -doc: - -clean mostlyclean: - rm -f $(OUTPUTS) *.i *~ *.o *-test *.srec *.dis *.map *.x - -distclean maintainer-clean realclean: clean - rm -f Makefile $(OUTPUTS) - -.PHONY: install info install-info clean-info -install: $(OUTPUTS) - for outputs in ${OUTPUTS}; do\ - ${INSTALL_DATA} $${outputs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$${outputs}; \ - done - for s in $(SCRIPTS); do \ - b=`basename $$s`; \ - ${INSTALL_DATA} $$s ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$$b ;\ - done - ${mkinstalldirs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/device-specs; \ - for s in ${srcdir}/device-specs/*; do \ - b=`basename $$s`; \ - $(INSTALL_DATA) $$s $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/device-specs/$$b ;\ - done - -info: -install-info: -clean-info: - -Makefile: $(srcdir)/Makefile.in ../config.status - cd .. && $(SHELL) config.status diff --git a/libgloss/pru/Makefile.inc b/libgloss/pru/Makefile.inc new file mode 100644 index 000000000..fbab7d8f9 --- /dev/null +++ b/libgloss/pru/Makefile.inc @@ -0,0 +1,19 @@ +multilibtool_DATA += \ + %D%/crt0.o \ + %D%/crt0-minrt.o + +pru_devicespecsdir = $(multilibtooldir)/device-specs +pru_devicespecs_DATA = %D%/device-specs/sim + +multilibtool_LIBRARIES += %D%/libgloss.a +%C%_libgloss_a_SOURCES = \ + %D%/do_global_dtors.c \ + %D%/gettimeofday.c \ + %D%/isatty.c \ + %D%/putnum.c \ + %D%/raise.c \ + %D%/inbyte.c \ + %D%/outbyte.c \ + %D%/sbrk.c \ + %D%/stat.c \ + %D%/syscalls.S diff --git a/libgloss/pru/crt0-minrt.S b/libgloss/pru/crt0-minrt.S new file mode 100644 index 000000000..60647d372 --- /dev/null +++ b/libgloss/pru/crt0-minrt.S @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * crt0-minrt.S -- Minimal PRU startup code + * + * Copyright (c) 2024 Dimitar Dimitrov <dimitar@dinux.eu> + * 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 AUTHOR ``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 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 "newlib.h" + + .extern main + + .text + .section .init0, "x" + .global _start +_start: + /* Initialize stack pointer. */ + ldi32 sp, _stack_top + + /* DATA and BSS are handled by the loader, so nothing to do here. */ + + /* Just in case main() tries to access argc, argv[] and envp. */ + zero r14, 3 * 4 + + /* Call main. */ + call main + + /* We should never reach here. */ +_crt_exit: + halt + jmp _crt_exit + + /* PRU obviously has no shared libraries, but dso_handle + helps to achieve better GCC test coverage. Besides, + it should be free with minrt. */ + .section .data + .global __dso_handle + .weak __dso_handle +__dso_handle: + .long 0 diff --git a/libgloss/pru/crt0.S b/libgloss/pru/crt0.S index b3f0d53a9..ad31cc9cc 100644 --- a/libgloss/pru/crt0.S +++ b/libgloss/pru/crt0.S @@ -39,7 +39,6 @@ _start: /* DATA and BSS are handled by the loader, so nothing to do here. */ -#if !defined(MINRT) .extern _do_global_dtors /* Ensure destructors get called. Call is per GNU ABI (i.e. 32-bit function pointers). But it is also compatible with the TI ABI @@ -60,27 +59,22 @@ ctors_loop: add r5, r5, 2 jmp ctors_loop ctors_done: -#endif /* Just in case main() tries to access argc, argv[] and envp. */ zero r14, 3 * 4 -#if !defined(MINRT) .weak __c_args__ ldi32 r5, __c_args__ qbeq __skip_c_args, r5, 0 lbbo r14, r5, 0, 4 /* argc */ add r15, r5, 4 /* argv */ __skip_c_args: -#endif /* Call main */ call main -#if !defined(MINRT) /* Call exit */ call exit -#endif /* We should never reach here. */ _crt_exit: -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] libgloss: pru: Trim crt0-minrt.o 2024-01-02 8:24 [PATCH 1/2] libgloss: merge pru into top-level Makefile Dimitar Dimitrov @ 2024-01-02 8:24 ` Dimitar Dimitrov 2024-01-02 13:15 ` [PATCH 1/2] libgloss: merge pru into top-level Makefile Mike Frysinger 2024-01-03 17:56 ` [PATCH v2 " Dimitar Dimitrov 2 siblings, 0 replies; 6+ messages in thread From: Dimitar Dimitrov @ 2024-01-02 8:24 UTC (permalink / raw) To: newlib; +Cc: Dimitar Dimitrov Strip a few more instructions from crt0-minrt.S: - Remove "halt" and rely on the infinite loop after main()'s return. - Remove main()'s argc and argv argument initialization. Host loader does not set them, and typical firmware does not use them, either. - Remove the __dso_handle symbol. This should be safe because the default crt0.S is fully standards compliant. Whereas crt0-minrt.S has been documented from the beginning to intentionally miss features in order to reduce firmware size, while still enabling typical PRU firmware to operate. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu> --- libgloss/pru/crt0-minrt.S | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/libgloss/pru/crt0-minrt.S b/libgloss/pru/crt0-minrt.S index 60647d372..fa5e80af4 100644 --- a/libgloss/pru/crt0-minrt.S +++ b/libgloss/pru/crt0-minrt.S @@ -38,22 +38,9 @@ _start: /* DATA and BSS are handled by the loader, so nothing to do here. */ - /* Just in case main() tries to access argc, argv[] and envp. */ - zero r14, 3 * 4 - - /* Call main. */ + /* Call main. Assume argc and argv are not used with -minrt! */ call main /* We should never reach here. */ _crt_exit: - halt jmp _crt_exit - - /* PRU obviously has no shared libraries, but dso_handle - helps to achieve better GCC test coverage. Besides, - it should be free with minrt. */ - .section .data - .global __dso_handle - .weak __dso_handle -__dso_handle: - .long 0 -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] libgloss: merge pru into top-level Makefile 2024-01-02 8:24 [PATCH 1/2] libgloss: merge pru into top-level Makefile Dimitar Dimitrov 2024-01-02 8:24 ` [PATCH 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov @ 2024-01-02 13:15 ` Mike Frysinger 2024-01-03 17:56 ` [PATCH v2 " Dimitar Dimitrov 2 siblings, 0 replies; 6+ messages in thread From: Mike Frysinger @ 2024-01-02 13:15 UTC (permalink / raw) To: Dimitar Dimitrov; +Cc: newlib [-- Attachment #1: Type: text/plain, Size: 1866 bytes --] On 02 Jan 2024 10:24, Dimitar Dimitrov wrote: > --- a/libgloss/pru/Makefile.in > +++ /dev/null > @@ -1,145 +0,0 @@ > -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD > -# > -# Copyright 2018-2019 Dimitar Dimitrov <dimitar@dinux.eu> > -# 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 AUTHOR ``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 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. please retain the license in the new file, but use ## as the comment marker > --- /dev/null > +++ b/libgloss/pru/Makefile.inc > @@ -0,0 +1,19 @@ > +multilibtool_DATA += \ > + %D%/crt0.o \ > + %D%/crt0-minrt.o add the .S files to libobjs_a_SOURCES so automake generates compile rules otherwise lgtm, thanks ! -mike [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] libgloss: merge pru into top-level Makefile @ 2024-01-03 17:56 ` Dimitar Dimitrov 2024-01-03 17:56 ` [PATCH v2 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov 2024-01-03 21:48 ` [PATCH v2 1/2] libgloss: merge pru into top-level Makefile Mike Frysinger 0 siblings, 2 replies; 6+ messages in thread From: Dimitar Dimitrov @ 2024-01-03 17:56 UTC (permalink / raw) To: newlib; +Cc: Dimitar Dimitrov Avoid a recursive make to speed things up a bit. This change was inspired by the recent similar patch for c6x: https://sourceware.org/pipermail/newlib/2023/020869.html While at it, fork crt0-minrt.S into a separate source file instead of relying on a predefined macro to generate two different object files. This improves clarity, simplifies the build rules, and would allow further optimization in crt0-minrt.S to be implemented more cleanly. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu> --- Changes since v1: - Retained copyright in pru/Makefile.inc. - Addec crt0*.s to libobjs_a_SOURCES. - Rebased. libgloss/Makefile.am | 3 + libgloss/configure.ac | 7 +- libgloss/pru/Makefile.in | 145 -------------------------------------- libgloss/pru/Makefile.inc | 48 +++++++++++++ libgloss/pru/crt0-minrt.S | 59 ++++++++++++++++ libgloss/pru/crt0.S | 6 -- 6 files changed, 113 insertions(+), 155 deletions(-) delete mode 100644 libgloss/pru/Makefile.in create mode 100644 libgloss/pru/Makefile.inc create mode 100644 libgloss/pru/crt0-minrt.S diff --git a/libgloss/Makefile.am b/libgloss/Makefile.am index a8a445b1d..6c8d551ab 100644 --- a/libgloss/Makefile.am +++ b/libgloss/Makefile.am @@ -99,6 +99,9 @@ endif if CONFIG_NIOS2 include nios2/Makefile.inc endif +if CONFIG_PRU +include pru/Makefile.inc +endif if CONFIG_RISCV include riscv/Makefile.inc endif diff --git a/libgloss/configure.ac b/libgloss/configure.ac index ec6dec0a0..b9240e1fd 100644 --- a/libgloss/configure.ac +++ b/libgloss/configure.ac @@ -235,8 +235,7 @@ case "${target}" in subdirs="$subdirs or1k" ;; pru-*-*) - AC_CONFIG_FILES([pru/Makefile]) - subdirs="$subdirs pru" + config_pru=true ;; nios2-*-*) config_nios2=true @@ -247,8 +246,8 @@ AC_SUBST(subdirs) dnl These subdirs have converted to non-recursive make. Hopefully someday all dnl the ports above will too! m4_foreach_w([SUBDIR], [ - aarch64 arc arm bfin csky d30v i960 iq2000 libnosys lm32 moxie nios2 riscv - v850 wince xtensa + aarch64 arc arm bfin csky d30v i960 iq2000 libnosys lm32 moxie nios2 pru + riscv v850 wince xtensa ], [dnl AM_CONDITIONAL([CONFIG_]m4_toupper(SUBDIR), [test x$config_]SUBDIR = xtrue) ]) diff --git a/libgloss/pru/Makefile.in b/libgloss/pru/Makefile.in deleted file mode 100644 index fc5905a5e..000000000 --- a/libgloss/pru/Makefile.in +++ /dev/null @@ -1,145 +0,0 @@ -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD -# -# Copyright 2018-2019 Dimitar Dimitrov <dimitar@dinux.eu> -# 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 AUTHOR ``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 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. - -VPATH = @srcdir@ @srcdir@/.. - -srcdir = @srcdir@ -objdir = . -srcroot = $(srcdir)/../.. -objroot = $(objdir)/../.. - -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -host_alias = @host_alias@ -target_alias = @target_alias@ - -bindir = @bindir@ -libdir = @libdir@ -includedir = @includedir@ -tooldir = $(exec_prefix)/$(target_alias) - -# Multilib support variables. -# TOP is used instead of MULTI{BUILD,SRC}TOP. -MULTIDIRS = -MULTISUBDIR = - -SHELL = /bin/sh - -mkinstalldirs = $(SHELL) $(srcroot)/mkinstalldirs - -CC = @CC@ - -AS = @AS@ - -AR = @AR@ - -LD = @LD@ - -RANLIB = @RANLIB@ - -OBJDUMP = `t='$(program_transform_name)'; echo objdump | sed -e $$t` -OBJCOPY = `t='$(program_transform_name)'; echo objcopy | sed -e $$t` - -# object files needed -OBJS = \ - do_global_dtors.o gettimeofday.o \ - isatty.o putnum.o raise.o \ - inbyte.o outbyte.o sbrk.o stat.o syscalls.o \ - do_global_dtors.o - -# Object files specific to particular targets. -EVALOBJS = ${OBJS} - -CRTOBJS = crt0.o crt0-minrt.o -OUTPUTS = libgloss.a $(CRTOBJS) - -INCLUDES = -I$(srcdir)/.. - -# Note that when building the library, ${MULTILIB} is not the way multilib -# options are passed; they're passed in $(CFLAGS). -CFLAGS_FOR_TARGET = ${MULTILIB} ${INCLUDES} -LDFLAGS_FOR_TARGET = ${MULTILIB} - -.c.o: - $(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $< - -.C.o: - $(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $< -.s.o: - $(AS) $(ASFLAGS_FOR_TARGET) $(ASFLAGS) -o $*.o $< - -# -# GCC knows to run the preprocessor on .S files before it assembles them. -# -.S.o: - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< - -all: ${OUTPUTS} - -# -# here's where we build the library for each target -# - -libgloss.a: $(EVALOBJS) - ${AR} ${ARFLAGS} $@ $(EVALOBJS) - ${RANLIB} $@ - -# C Runtime Library startup code. -crt0.o: $(srcdir)/crt0.S - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) $< -c -o $@ - -crt0-minrt.o: $(srcdir)/crt0.S - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -DMINRT $< -c -o $@ - -doc: - -clean mostlyclean: - rm -f $(OUTPUTS) *.i *~ *.o *-test *.srec *.dis *.map *.x - -distclean maintainer-clean realclean: clean - rm -f Makefile $(OUTPUTS) - -.PHONY: install info install-info clean-info -install: $(OUTPUTS) - for outputs in ${OUTPUTS}; do\ - ${INSTALL_DATA} $${outputs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$${outputs}; \ - done - for s in $(SCRIPTS); do \ - b=`basename $$s`; \ - ${INSTALL_DATA} $$s ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$$b ;\ - done - ${mkinstalldirs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/device-specs; \ - for s in ${srcdir}/device-specs/*; do \ - b=`basename $$s`; \ - $(INSTALL_DATA) $$s $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/device-specs/$$b ;\ - done - -info: -install-info: -clean-info: - -Makefile: $(srcdir)/Makefile.in ../config.status - cd .. && $(SHELL) config.status diff --git a/libgloss/pru/Makefile.inc b/libgloss/pru/Makefile.inc new file mode 100644 index 000000000..7c119dc67 --- /dev/null +++ b/libgloss/pru/Makefile.inc @@ -0,0 +1,48 @@ +## SPDX-License-Identifier: BSD-2-Clause-FreeBSD +## +## Copyright 2018-2024 Dimitar Dimitrov <dimitar@dinux.eu> +### 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 AUTHOR ``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 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. + +multilibtool_DATA += \ + %D%/crt0.o \ + %D%/crt0-minrt.o + +pru_devicespecsdir = $(multilibtooldir)/device-specs +pru_devicespecs_DATA = %D%/device-specs/sim + +libobjs_a_SOURCES += \ + %D%/crt0.S \ + %D%/crt0-minrt.S + +multilibtool_LIBRARIES += %D%/libgloss.a +%C%_libgloss_a_SOURCES = \ + %D%/do_global_dtors.c \ + %D%/gettimeofday.c \ + %D%/isatty.c \ + %D%/putnum.c \ + %D%/raise.c \ + %D%/inbyte.c \ + %D%/outbyte.c \ + %D%/sbrk.c \ + %D%/stat.c \ + %D%/syscalls.S diff --git a/libgloss/pru/crt0-minrt.S b/libgloss/pru/crt0-minrt.S new file mode 100644 index 000000000..60647d372 --- /dev/null +++ b/libgloss/pru/crt0-minrt.S @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * crt0-minrt.S -- Minimal PRU startup code + * + * Copyright (c) 2024 Dimitar Dimitrov <dimitar@dinux.eu> + * 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 AUTHOR ``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 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 "newlib.h" + + .extern main + + .text + .section .init0, "x" + .global _start +_start: + /* Initialize stack pointer. */ + ldi32 sp, _stack_top + + /* DATA and BSS are handled by the loader, so nothing to do here. */ + + /* Just in case main() tries to access argc, argv[] and envp. */ + zero r14, 3 * 4 + + /* Call main. */ + call main + + /* We should never reach here. */ +_crt_exit: + halt + jmp _crt_exit + + /* PRU obviously has no shared libraries, but dso_handle + helps to achieve better GCC test coverage. Besides, + it should be free with minrt. */ + .section .data + .global __dso_handle + .weak __dso_handle +__dso_handle: + .long 0 diff --git a/libgloss/pru/crt0.S b/libgloss/pru/crt0.S index b3f0d53a9..ad31cc9cc 100644 --- a/libgloss/pru/crt0.S +++ b/libgloss/pru/crt0.S @@ -39,7 +39,6 @@ _start: /* DATA and BSS are handled by the loader, so nothing to do here. */ -#if !defined(MINRT) .extern _do_global_dtors /* Ensure destructors get called. Call is per GNU ABI (i.e. 32-bit function pointers). But it is also compatible with the TI ABI @@ -60,27 +59,22 @@ ctors_loop: add r5, r5, 2 jmp ctors_loop ctors_done: -#endif /* Just in case main() tries to access argc, argv[] and envp. */ zero r14, 3 * 4 -#if !defined(MINRT) .weak __c_args__ ldi32 r5, __c_args__ qbeq __skip_c_args, r5, 0 lbbo r14, r5, 0, 4 /* argc */ add r15, r5, 4 /* argv */ __skip_c_args: -#endif /* Call main */ call main -#if !defined(MINRT) /* Call exit */ call exit -#endif /* We should never reach here. */ _crt_exit: -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] libgloss: pru: Trim crt0-minrt.o 2024-01-03 17:56 ` [PATCH v2 " Dimitar Dimitrov @ 2024-01-03 17:56 ` Dimitar Dimitrov 2024-01-03 21:48 ` [PATCH v2 1/2] libgloss: merge pru into top-level Makefile Mike Frysinger 1 sibling, 0 replies; 6+ messages in thread From: Dimitar Dimitrov @ 2024-01-03 17:56 UTC (permalink / raw) To: newlib; +Cc: Dimitar Dimitrov Strip a few more instructions from crt0-minrt.S: - Remove "halt" and rely on the infinite loop after main()'s return. - Remove main()'s argc and argv argument initialization. Host loader does not set them, and typical firmware does not use them, either. - Remove the __dso_handle symbol. This should be safe because the default crt0.S is fully standards compliant. Whereas crt0-minrt.S has been documented from the beginning to intentionally miss features in order to reduce firmware size, while still enabling typical PRU firmware to operate. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu> --- libgloss/pru/crt0-minrt.S | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/libgloss/pru/crt0-minrt.S b/libgloss/pru/crt0-minrt.S index 60647d372..fa5e80af4 100644 --- a/libgloss/pru/crt0-minrt.S +++ b/libgloss/pru/crt0-minrt.S @@ -38,22 +38,9 @@ _start: /* DATA and BSS are handled by the loader, so nothing to do here. */ - /* Just in case main() tries to access argc, argv[] and envp. */ - zero r14, 3 * 4 - - /* Call main. */ + /* Call main. Assume argc and argv are not used with -minrt! */ call main /* We should never reach here. */ _crt_exit: - halt jmp _crt_exit - - /* PRU obviously has no shared libraries, but dso_handle - helps to achieve better GCC test coverage. Besides, - it should be free with minrt. */ - .section .data - .global __dso_handle - .weak __dso_handle -__dso_handle: - .long 0 -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] libgloss: merge pru into top-level Makefile 2024-01-03 17:56 ` [PATCH v2 " Dimitar Dimitrov 2024-01-03 17:56 ` [PATCH v2 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov @ 2024-01-03 21:48 ` Mike Frysinger 1 sibling, 0 replies; 6+ messages in thread From: Mike Frysinger @ 2024-01-03 21:48 UTC (permalink / raw) To: Dimitar Dimitrov; +Cc: newlib [-- Attachment #1: Type: text/plain, Size: 638 bytes --] On 03 Jan 2024 19:56, Dimitar Dimitrov wrote: > --- /dev/null > +++ b/libgloss/pru/Makefile.inc > @@ -0,0 +1,48 @@ > +## SPDX-License-Identifier: BSD-2-Clause-FreeBSD > +## > +## Copyright 2018-2024 Dimitar Dimitrov <dimitar@dinux.eu> > +### All rights reserved. only need ## here, not ### > +multilibtool_DATA += \ > + %D%/crt0.o \ > + %D%/crt0-minrt.o > + > +pru_devicespecsdir = $(multilibtooldir)/device-specs > +pru_devicespecs_DATA = %D%/device-specs/sim > + > +libobjs_a_SOURCES += \ > + %D%/crt0.S \ > + %D%/crt0-minrt.S i've been grouping libobjs_a_SOURCES right after multilibtool_DATA so it's clear they're "together" -mike [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-01-03 21:48 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-01-02 8:24 [PATCH 1/2] libgloss: merge pru into top-level Makefile Dimitar Dimitrov 2024-01-02 8:24 ` [PATCH 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov 2024-01-02 13:15 ` [PATCH 1/2] libgloss: merge pru into top-level Makefile Mike Frysinger 2024-01-03 17:56 ` [PATCH v2 " Dimitar Dimitrov 2024-01-03 17:56 ` [PATCH v2 2/2] libgloss: pru: Trim crt0-minrt.o Dimitar Dimitrov 2024-01-03 21:48 ` [PATCH v2 1/2] libgloss: merge pru into top-level Makefile Mike Frysinger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).