Module Name:    src
Committed By:   matt
Date:           Sat Jun 22 02:37:09 UTC 2013

Modified Files:
        src/lib/csu/common: Makefile.inc
Added Files:
        src/lib/csu/arch/mips: Makefile.inc crt0.S crtbegin.h crtend.S crti.S
            crtn.S
        src/lib/csu/common: crtbegin.c

Log Message:
Add a common crtbegin.c file and use a machine dependent crtbegin.h to
fill in .init/.fini.
Add mips support for USE_COMPILERCRTSTUFF=no (compiled only)


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/csu/arch/mips/Makefile.inc \
    src/lib/csu/arch/mips/crt0.S src/lib/csu/arch/mips/crtbegin.h \
    src/lib/csu/arch/mips/crtend.S src/lib/csu/arch/mips/crti.S \
    src/lib/csu/arch/mips/crtn.S
cvs rdiff -u -r1.8 -r1.9 src/lib/csu/common/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/csu/common/crtbegin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/csu/common/Makefile.inc
diff -u src/lib/csu/common/Makefile.inc:1.8 src/lib/csu/common/Makefile.inc:1.9
--- src/lib/csu/common/Makefile.inc:1.8	Sat Jun 22 02:21:58 2013
+++ src/lib/csu/common/Makefile.inc	Sat Jun 22 02:37:09 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.8 2013/06/22 02:21:58 matt Exp $
+#	$NetBSD: Makefile.inc,v 1.9 2013/06/22 02:37:09 matt Exp $
 
 .include <bsd.own.mk>
 
@@ -12,10 +12,10 @@ OBJS+=		crtbegin.o crtbeginS.o crtend.o
 
 realall: ${OBJS}
 
-.if exists(${ARCHDIR}/crtbegin.c)
+.if !exists(${ARCHDIR}/crtbegin.S)
 crtbegin.o: crtbegin.c
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} ${ARCHDIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .else
 crtbegin.o: crtbegin.S
 	${_MKTARGET_COMPILE}
@@ -27,10 +27,10 @@ crtbegin.o: crtbegin.S
 	${OBJCOPY} -R .ident ${.TARGET}
 .endif
 
-.if exists(${ARCHDIR}/crtbegin.c)
+.if !exists(${ARCHDIR}/crtbegin.S)
 crtbeginS.o: crtbegin.c
 	${_MKTARGET_COMPILE}
-	${COMPILE.c} -DPIC -DSHARED ${ARCHDIR}/crtbegin.c -o ${.TARGET}.o
+	${COMPILE.c} -DPIC -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .else
 crtbeginS.o: crtbegin.S
 	${_MKTARGET_COMPILE}

Added files:

Index: src/lib/csu/arch/mips/Makefile.inc
diff -u /dev/null src/lib/csu/arch/mips/Makefile.inc:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/Makefile.inc	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,3 @@
+#	$NetBSD: Makefile.inc,v 1.1 2013/06/22 02:37:09 matt Exp $
+
+CPPFLAGS+=	-I${ARCHDIR}
Index: src/lib/csu/arch/mips/crt0.S
diff -u /dev/null src/lib/csu/arch/mips/crt0.S:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/crt0.S	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,56 @@
+/* $NetBSD: crt0.S,v 1.1 2013/06/22 02:37:09 matt Exp $ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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 <mips/asm.h>
+
+RCSID("$NetBSD: crt0.S,v 1.1 2013/06/22 02:37:09 matt Exp $")
+
+STRONG_ALIAS(_start,__start)
+
+/*
+ *	Assumes kernel (or ld_elf.so) passes the following parameters to
+ *	user-space in registers:
+ *
+ *	a0      stack pointer (0 if setregs didn't fill this in)
+ *	a1      cleanup
+ *	a2      Obj_Entry
+ *	a3      ps_strings
+ *
+ *      XXX Does this violate the ABI?
+ *      as well as the usual registers (pc, sp, and t9 == pc for ABI).
+ */
+
+NESTED_NOPROFILE(__start, CALLFRAME_SIZ, ra)
+	move	a0, a1		/* cleanup */
+	move	a1, a2		/* Obj_Entry */
+	move	a2, a3		/* ps_strings */
+	j	_C_LABEL(___start)
+END(__start)
Index: src/lib/csu/arch/mips/crtbegin.h
diff -u /dev/null src/lib/csu/arch/mips/crtbegin.h:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/crtbegin.h	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+__asm(	"\n\t"
+	".pushsection .init, \"ax\", @progbits" "\n\t"
+	"jal	__do_global_ctors_aux"		"\n\t"
+	".popsection");
+__asm(	"\n\t"
+	".pushsection .fini, \"ax\", @progbits" "\n\t"
+	"jal	__do_global_dtors_aux"		"\n\t"
+	".popsection");
Index: src/lib/csu/arch/mips/crtend.S
diff -u /dev/null src/lib/csu/arch/mips/crtend.S:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/crtend.S	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,55 @@
+/*	$NetBSD: crtend.S,v 1.1 2013/06/22 02:37:09 matt Exp $	*/
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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 <mips/asm.h>
+
+RCSID("$NetBSD: crtend.S,v 1.1 2013/06/22 02:37:09 matt Exp $")
+
+	.section	.ctors, "aw", @progbits
+	.p2align 2
+	.global		__CTOR_LIST_END__
+	.hidden 	__CTOR_LIST_END__
+__CTOR_LIST_END__:
+	.word		0
+
+	.section	.dtors, "aw", @progbits
+	.p2align 2
+	.global		__DTOR_LIST_END__
+	.hidden 	__DTOR_LIST_END__
+__DTOR_LIST_END__:
+	.word		0
+
+	.section	.eh_frame, "a", @progbits
+	.p2align 2
+	.space	4
+
+	.section	.jcr, "aw", @progbits
+	.p2align 2
+	.space	4
Index: src/lib/csu/arch/mips/crti.S
diff -u /dev/null src/lib/csu/arch/mips/crti.S:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/crti.S	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,54 @@
+/* $NetBSD: crti.S,v 1.1 2013/06/22 02:37:09 matt Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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 <mips/asm.h>
+
+RCSID("$NetBSD: crti.S,v 1.1 2013/06/22 02:37:09 matt Exp $")
+
+#include "sysident.S"
+
+	.section ".init", "ax", @progbits
+NESTED_NOPROFILE(_init, CALLFRAME_SIZ, ra)
+        SETUP_GP
+        PTR_SUBU sp, sp, CALLFRAME_SIZ	# allocate stack frame
+        SAVE_GP(CALLFRAME_GP)
+        SETUP_GP64(CALLFRAME_GP, _init)
+	REG_S	ra, CALLFRAME_RA(sp)	# save RA
+END(_init)
+
+	.section ".fini", "ax", @progbits
+NESTED_NOPROFILE(_fini, CALLFRAME_SIZ, ra)
+        SETUP_GP
+        PTR_SUBU sp, sp, CALLFRAME_SIZ	# allocate stack frame
+        SAVE_GP(CALLFRAME_GP)
+        SETUP_GP64(CALLFRAME_GP, _fini)
+	REG_S	ra, CALLFRAME_RA(sp)	# save RA
+END(_fini)
Index: src/lib/csu/arch/mips/crtn.S
diff -u /dev/null src/lib/csu/arch/mips/crtn.S:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/arch/mips/crtn.S	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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 <mips/asm.h>
+
+RCSID("$NetBSD: crtn.S,v 1.1 2013/06/22 02:37:09 matt Exp $")
+
+	.section ".init", "ax", @progbits
+	RESTORE_GP64
+	REG_L	ra, CALLFRAME_RA(sp)
+	PTR_ADDU sp, sp, CALLFRAME_SIZ
+	jr	ra
+
+	.section ".fini", "ax", @progbits
+	RESTORE_GP64
+	REG_L	ra, CALLFRAME_RA(sp)
+	PTR_ADDU sp, sp, CALLFRAME_SIZ
+	jr	ra

Index: src/lib/csu/common/crtbegin.c
diff -u /dev/null src/lib/csu/common/crtbegin.c:1.1
--- /dev/null	Sat Jun 22 02:37:09 2013
+++ src/lib/csu/common/crtbegin.c	Sat Jun 22 02:37:09 2013
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
+ * 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/cdefs.h>
+__RCSID("$NetBSD: crtbegin.c,v 1.1 2013/06/22 02:37:09 matt Exp $");
+
+typedef void (*fptr_t)(void);
+
+__dso_hidden const fptr_t __JCR_LIST__[0] __section(".jcr");
+__dso_hidden const long __EH_FRAME_LIST__[0] __section(".eh_frame");
+__dso_hidden const fptr_t __CTOR_LIST__[] __section(".ctors") = {
+	(fptr_t) -1,
+};
+__dso_hidden extern const fptr_t __CTOR_LIST_END__[];
+__dso_hidden const fptr_t __DTOR_LIST__[] __section(".dtors") = {
+	(fptr_t) -1,
+};
+__dso_hidden extern const fptr_t __DTOR_LIST_END__[];
+
+#ifdef SHARED
+__dso_hidden void *__dso_handle = &__dso_handle;
+#else
+__dso_hidden void *__dso_handle;
+#endif
+
+__weakref_visible void cxa_finalize(void *)
+	__weak_reference(__cxa_finalize);
+__weakref_visible void Jv_RegisterClasses(const fptr_t *)
+	__weak_reference(_Jv_RegisterClasses);
+__weakref_visible void register_frame_info(const void *, const void *)
+	__weak_reference(__register_frame_info);
+__weakref_visible void deregister_frame_info(const void *)
+	__weak_reference(__deregister_frame_info);
+
+static long dwarf_eh_object[6];
+static unsigned char __initialized;
+static unsigned char __finished;
+
+static void __do_global_ctors_aux(void) __used;
+static void __do_global_dtors_aux(void) __used;
+
+static void
+__do_global_ctors_aux(void)
+{
+	if (__initialized)
+		return;
+
+	__initialized = 1;
+
+	if (register_frame_info)
+		register_frame_info(__EH_FRAME_LIST__, &dwarf_eh_object);
+
+	if (Jv_RegisterClasses && __JCR_LIST__[0] != 0)
+		Jv_RegisterClasses(__JCR_LIST__);
+
+	for (const fptr_t *p = __CTOR_LIST_END__; p > __CTOR_LIST__ + 1; ) {
+		(*(*--p))();
+	}
+}
+
+static void
+__do_global_dtors_aux(void)
+{
+	if (__finished)
+		return;
+
+	__finished = 1;
+
+	if (cxa_finalize)
+		cxa_finalize(__dso_handle);
+	
+	for (const fptr_t *p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__; ) {
+		(*(*p++))();
+	}
+
+	if (deregister_frame_info)
+		deregister_frame_info(__EH_FRAME_LIST__);
+}
+
+#include "crtbegin.h"

Reply via email to