This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: reorganise SPU crt0 files


The following patch, written by Sa Liu (Cc'ed), reorganises the C
runtime files to move much of the code to libgloss.  I will be
submitting the corresponding patch to libgloss shortly and will not
commit either patch until they are approved by both projects to
minimise bother.  :-)

Okay for the trunk?  [I've just noticed that we need to update the
documentation, so I will work on that now while this patch is being
reviewed.]

Thanks,
Ben

2006-12-01  Sa Liu  <saliu@de.ibm.com>

        * config/spu/spu-elf.h (STARTFILE_SPEC): Update.
        (ENDFILE_SPEC): Likewise.
        (INIT_SECTION_ASM_OP): Define, if not already.
        (FINI_SECTION_ASM_OP): Likewise.
        * config/spu/spu.opt (mstdmain): New option.
        * config/spu/crti.asm: Remove.
        * config/spu/crtn.asm: Likewise.
        * config/spu/crt0.c: Likewise.
        * config/spu/crtend.c: Likewise.
        * config/spu/t-spu-elf (EXTRA_MULTILIB_PARTS): Remove crt0 files
        listed above.
        ($(T)crti.o, $(T)crtn.o, $(T)crt1.o, $(T)crtend1.o): Remove.

Index: crti.asm
===================================================================
--- crti.asm	(revision 119380)
+++ crti.asm	(working copy)
@@ -1,53 +0,0 @@
-#  Copyright (C) 2006 Free Software Foundation, Inc.
-#
-#  This file is free software; you can redistribute it and/or modify it under
-#  the terms of the GNU General Public License as published by the Free
-#  Software Foundation; either version 2 of the License, or (at your option) 
-#  any later version.
-#
-#  This file is distributed in the hope that it will be useful, but WITHOUT
-#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-#  for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this file; see the file COPYING.  If not, write to the Free
-#  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.  */
-# 
-#    As a special exception, if you link this library with files
-#    compiled with GCC to produce an executable, this does not cause
-#    the resulting executable to be covered by the GNU General Public License.
-#    This exception does not however invalidate any other reasons why
-#    the executable file might be covered by the GNU General Public License.
-# 
-
-# This file just make a stack frame for the contents of the .fini and
-# .init sections.  Users may put any desired instructions in those
-# sections.
-
-	# Note - this macro is complimented by the FUNC_END macro
-	# in crtn.asm.  If you change this macro you must also change
-	# that macro match.
-.macro FUNC_START
-	#  Create a stack frame and save any call-preserved registers
-	ai	$sp, $sp, -16
-	stqd	$lr, 0($sp)
-.endm
-		
-	.file		"crti.asm"
-
-	.section	".init"
-	.align 2
-	.global	_init
-_init:
-	FUNC_START
-	
-		
-	.section	".fini"
-	.align	2
-	.global	_fini
-_fini:
-	FUNC_START
-	
-# end of crti.asm
Index: crtn.asm
===================================================================
--- crtn.asm	(revision 119380)
+++ crtn.asm	(working copy)
@@ -1,54 +0,0 @@
-#  Copyright (C) 2006 Free Software Foundation, Inc.
-#
-#  This file is free software; you can redistribute it and/or modify it under
-#  the terms of the GNU General Public License as published by the Free
-#  Software Foundation; either version 2 of the License, or (at your option) 
-#  any later version.
-#
-#  This file is distributed in the hope that it will be useful, but WITHOUT
-#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-#  for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this file; see the file COPYING.  If not, write to the Free
-#  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.  */
-# 
-#    As a special exception, if you link this library with files
-#    compiled with GCC to produce an executable, this does not cause
-#    the resulting executable to be covered by the GNU General Public License.
-#    This exception does not however invalidate any other reasons why
-#    the executable file might be covered by the GNU General Public License.
-# 
-
-# This file just makes sure that the .fini and .init sections do in
-# fact return.  Users may put any desired instructions in those sections.
-# This file is the last thing linked into any executable.
-
-	# Note - this macro is complimented by the FUNC_START macro
-	# in crti.asm.  If you change this macro you must also change
-	# that macro match.
-	#
-	# Note - we do not try any fancy optimisations of the return
-	# sequences here, it is just not worth it.  Instead keep things
-	# simple.  Restore all the save resgisters, including the link
-	# register and then perform the correct function return instruction.
-.macro FUNC_END
-	lqd	$lr, 0($sp)
-	ai	$sp, $sp, 16
-	bi	$lr
-.endm
-		
-	
-	.file		"crtn.asm"
-
-	.section	".init"
-	;;
-	FUNC_END
-	
-	.section	".fini"
-	;;
-	FUNC_END
-	
-# end of crtn.asm
Index: crt0.c
===================================================================
--- crt0.c	(revision 119380)
+++ crt0.c	(working copy)
@@ -1,131 +0,0 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
-  
-   This file is free software; you can redistribute it and/or modify it under
-   the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2 of the License, or (at your option)
-   any later version.
-  
-   This file is distributed in the hope that it will be useful, but WITHOUT
-   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-   for more details.
-  
-   You should have received a copy of the GNU General Public License
-   along with this file; see the file COPYING.  If not, write to the Free
-   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.  */
-
-/* As a special exception, if you link this library with files compiled with
-   GCC to produce an executable, this does not cause the resulting executable
-   to be covered by the GNU General Public License.  The exception does not
-   however invalidate any other reasons why the executable file might be covered
-   by the GNU General Public License. */
-
-extern int main(int, unsigned long long, unsigned long long);
-void _start(int, unsigned long long, unsigned long long) __attribute__((__naked__));
-
-extern void exit(int);
-
-void _exit(int) __attribute__((__naked__));
-
-typedef void (*func_ptr) (void);
-typedef __attribute__ ((__vector_size__(16))) unsigned int vec_uint4;
-
-extern vec_uint4 __stack[];
-register vec_uint4 si_sp __asm__("$sp");
-register unsigned int si_r2 __asm__("$2");
-
-extern char _end[];
-
-/* If we want these aligned we need to do it in the linker script. */
-func_ptr __CTOR_LIST__[1]
-  __attribute__ ((__section__(".ctors"), __aligned__(4)))
-  = { (func_ptr) (-1) };
-
-static func_ptr __DTOR_LIST__[1]
-  __attribute__((__section__(".dtors"), __aligned__(4)))
-  = { (func_ptr) (-1) };
-
-void *__dso_handle = 0;
-
-/* According to the BE Linux ABI an SPU module is called with these
- * parameters.  Also, $2 is set to the Available Stack Size.  */
-void
-_start(int spu_id,
-       unsigned long long param,
-       unsigned long long env)
-{
-  unsigned int stack_size;
-  unsigned int sp = (unsigned int)(__stack - 2);
-
-  /* Initialize the stack.  __stack has been set to point to the top
-     quadword of the stack.  The ABI requires at least a NULL terminated
-     back chain and lr save area.  For example:
-         +----------------+
-	 | 0              |
-         +----------------+  <-  __stack (e.g., 0x3fff0)
-	 | space for $lr  |
-         +----------------+
-	 | back chain     |
-         +----------------+  <-  $sp  (e.g., __stack - 32, 0x3ffd0)
-  */
-  __stack[0] = (vec_uint4){0, 0, 0, 0};
-  __stack[-1] = (vec_uint4){0, 0, 0, 0};
-
-  /* Initialize the Available Stack Size word of the Stack Pointer
-   * information register.  The BE Linux ABI passes the stack size in
-   * $2, or use everything up to _end if $2 == 0. */
-  stack_size = si_r2 == 0 ? sp - (unsigned int)_end : si_r2;
-
-  __stack[-2] = (vec_uint4){(unsigned int)__stack, stack_size, 0, 0};
-
-  si_sp = (vec_uint4){sp, stack_size, 0, 0};
-
-
-  {
-    extern func_ptr __CTOR_END__[];
-    func_ptr *p;
-
-    /* The compiler assumes all symbols are 16 byte aligned, which is
-     * not the case for __CTOR_END__.  This inline assembly makes sure
-     * the address is loaded into a register for which the compiler does
-     * not assume anything about alignment. */
-    __asm__ ("\n" : "=r" (p) : "0" (__CTOR_END__ - 1));
-
-    for (; *p != (func_ptr) -1; p--)
-      (*p) ();
-  }
-
-  exit(main(spu_id, param, env));
-  __asm__ volatile ( "	stop	0x20ff");
-}
-
-/* C99 requires _Exit */
-void _Exit(int) __attribute__((__weak__, __alias__("_exit")));
-
-void
-_exit(int rc)
-{
-  {
-    static func_ptr *p = 0;
-    if (!p)
-      {
-	/* See comment for __CTOR_END__ above. */
-	__asm__ ("" : "=r" (p) : "0" (__DTOR_LIST__ + 1));
-	for (; *p; p++)
-	  (*p) ();
-      }
-  }
-  /* Some self modifying code to return 'rc' in the 'stop' insn. */
-  __asm__ volatile (
-    "	ori	$3, %0,0\n"
-    "	lqr	$4, 1f\n"
-    "	cbd	$5, 1f+3($sp)\n"
-    "	shufb	$0, %0, $4, $5\n"
-    "	stqr	$0, 1f\n"
-    "	sync\n"
-    "1:\n"
-    "	stop	0x2000\n"
-    : : "r" (rc) );
-}
-
Index: crtend.c
===================================================================
--- crtend.c	(revision 119380)
+++ crtend.c	(working copy)
@@ -1,32 +0,0 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
-
-   This file is free software; you can redistribute it and/or modify it under
-   the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2 of the License, or (at your option) 
-   any later version.
-
-   This file is distributed in the hope that it will be useful, but WITHOUT
-   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-   for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this file; see the file COPYING.  If not, write to the Free
-   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.  */
-
-/* As a special exception, if you link this library with files compiled with 
-   GCC to produce an executable, this does not cause the resulting executable 
-   to be covered by the GNU General Public License.  The exception does not 
-   however invalidate any other reasons why the executable file might be covered 
-   by the GNU General Public License. */
-
-typedef void (*func_ptr) (void);
-
-func_ptr __CTOR_END__[1]
-  __attribute__ ((section(".ctors"), aligned(sizeof(func_ptr))))
-  = { (func_ptr) (0) };
-
-func_ptr __DTOR_END__[1]
-  __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
-  = { (func_ptr) (0) };
Index: spu-elf.h
===================================================================
--- spu-elf.h	(revision 119380)
+++ spu-elf.h	(working copy)
@@ -25,11 +25,23 @@
             asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
 
 
-#undef  STARTFILE_SPEC
-#define STARTFILE_SPEC	"crt1%O%s"
+
+/* Provide a STARTFILE_SPEC appropriate for GNU/Linux.  Here we add
+   the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
+   provides part of the support for getting C++ file-scope static
+   object constructed before entering `main'.  */
+
+#undef  STARTFILE_SPEC 
+#define STARTFILE_SPEC "%{mstdmain: crt2.o%s} %{!mstdmain: crt1.o%s} \
+			crti.o%s crtbegin.o%s"
 
 #undef  ENDFILE_SPEC
-#define ENDFILE_SPEC	"crtend1%O%s"
+#define ENDFILE_SPEC   "crtend.o%s crtn.o%s"
+
+#undef INIT_SECTION_ASM_OP
+#define INIT_SECTION_ASM_OP     "\t.section\t\".init\""
+#undef FINI_SECTION_ASM_OP
+#define FINI_SECTION_ASM_OP     "\t.section\t\".fini\""
 
 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
 
Index: spu.opt
===================================================================
--- spu.opt	(revision 119380)
+++ spu.opt	(working copy)
@@ -36,6 +36,10 @@ munsafe-dma
 Target Report RejectNegative InverseMask(SAFE_DMA)
 volatile must be specified on any memory that is effected by DMA
 
+mstdmain
+Target Report Mask(STD_MAIN)
+Use standard main function as entry for startup
+
 mbranch-hints
 Target Report Mask(BRANCH_HINTS)
 Generate branch hints for branches
Index: t-spu-elf
===================================================================
--- t-spu-elf	(revision 119380)
+++ t-spu-elf	(working copy)
@@ -54,31 +54,11 @@ CRTSTUFF_T_CFLAGS =
 # Neither gcc or newlib seem to have a standard way to generate multiple
 # crt*.o files.  So we don't use the standard crt0.o name anymore.
 
-EXTRA_MULTILIB_PARTS = crtbegin.o crtend.o crti.o crtn.o crt1.o crtend1.o
+EXTRA_MULTILIB_PARTS = crtbegin.o crtend.o
 
 LIBGCC = stmp-multilib
 INSTALL_LIBGCC = install-multilib
 
-# Assemble startup files.
-$(T)crti.o: $(srcdir)/config/spu/crti.asm $(GCC_PASSES)
-	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-	-c -o $(T)crti.o -x assembler-with-cpp $(srcdir)/config/spu/crti.asm
-
-$(T)crtn.o: $(srcdir)/config/spu/crtn.asm $(GCC_PASSES)
-	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-	-c -o $(T)crtn.o -x assembler-with-cpp $(srcdir)/config/spu/crtn.asm
-
-$(T)crt1.o: $(srcdir)/config/spu/crt0.c $(GCC_PASSES)
-	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-	-O2 \
-	-c -o $(T)crt1.o $(srcdir)/config/spu/crt0.c
-
-$(T)crtend1.o: $(srcdir)/config/spu/crtend.c $(GCC_PASSES)
-	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-	-O2 \
-	-c -o $(T)crtend1.o $(srcdir)/config/spu/crtend.c
-
-
 spu.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
   $(RTL_H) $(REGS_H) hard-reg-set.h \
   real.h insn-config.h conditions.h insn-attr.h flags.h $(RECOG_H) \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]