summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/Makefile.inc7
-rw-r--r--lib/csu/amd64/Makefile45
-rw-r--r--lib/csu/amd64/crt1.c81
-rw-r--r--lib/csu/amd64/crti.S43
-rw-r--r--lib/csu/amd64/crtn.S37
-rw-r--r--lib/csu/arm/Makefile44
-rw-r--r--lib/csu/arm/crt1.c125
-rw-r--r--lib/csu/arm/crti.S21
-rw-r--r--lib/csu/arm/crtn.S10
-rw-r--r--lib/csu/common/crtbrand.c66
-rw-r--r--lib/csu/common/ignore_init.c114
-rw-r--r--lib/csu/common/notes.h38
-rw-r--r--lib/csu/i386-elf/Makefile51
-rw-r--r--lib/csu/i386-elf/crt1_c.c83
-rw-r--r--lib/csu/i386-elf/crt1_s.S54
-rw-r--r--lib/csu/i386-elf/crti.S43
-rw-r--r--lib/csu/i386-elf/crtn.S37
-rw-r--r--lib/csu/ia64/Makefile62
-rw-r--r--lib/csu/ia64/crt1.S197
-rw-r--r--lib/csu/ia64/crti.S60
-rw-r--r--lib/csu/ia64/crtn.S44
-rw-r--r--lib/csu/mips/Makefile44
-rw-r--r--lib/csu/mips/crt1.c96
-rw-r--r--lib/csu/mips/crti.S50
-rw-r--r--lib/csu/mips/crtn.S24
-rw-r--r--lib/csu/powerpc/Makefile44
-rw-r--r--lib/csu/powerpc/crt1.c110
-rw-r--r--lib/csu/powerpc/crti.S51
-rw-r--r--lib/csu/powerpc/crtn.S46
-rw-r--r--lib/csu/powerpc64/Makefile45
-rw-r--r--lib/csu/powerpc64/crt1.c110
-rw-r--r--lib/csu/powerpc64/crti.S61
-rw-r--r--lib/csu/powerpc64/crtn.S42
-rw-r--r--lib/csu/sparc64/Makefile24
-rw-r--r--lib/csu/sparc64/crt1.c111
-rw-r--r--lib/csu/sparc64/crti.S57
-rw-r--r--lib/csu/sparc64/crtn.S42
37 files changed, 2219 insertions, 0 deletions
diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc
new file mode 100644
index 0000000..11ddc66
--- /dev/null
+++ b/lib/csu/Makefile.inc
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+SSP_CFLAGS=
+
+SED_FIX_NOTE = -i "" -e '/\.note\.tag/s/progbits/note/'
+
+.include "../Makefile.inc"
diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile
new file mode 100644
index 0000000..80d14a7
--- /dev/null
+++ b/lib/csu/amd64/Makefile
@@ -0,0 +1,45 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+CFLAGS+= -fno-omit-frame-pointer
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/amd64/crt1.c b/lib/csu/amd64/crt1.c
new file mode 100644
index 0000000..f33aad6
--- /dev/null
+++ b/lib/csu/amd64/crt1.c
@@ -0,0 +1,81 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 1996-1998 John D. Polstra.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+typedef void (*fptr)(void);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+void _start(char **, void (*)(void));
+
+/* The entry function. */
+void
+_start(char **ap, void (*cleanup)(void))
+{
+ int argc;
+ char **argv;
+ char **env;
+
+ argc = *(long *)(void *)ap;
+ argv = ap + 1;
+ env = ap + 2 + argc;
+ environ = env;
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+__asm__("eprol:");
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
diff --git a/lib/csu/amd64/crti.S b/lib/csu/amd64/crti.S
new file mode 100644
index 0000000..618dca1
--- /dev/null
+++ b/lib/csu/amd64/crti.S
@@ -0,0 +1,43 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ .align 4
+ .globl _init
+ .type _init,@function
+_init:
+ subq $8,%rsp
+
+ .section .fini,"ax",@progbits
+ .align 4
+ .globl _fini
+ .type _fini,@function
+_fini:
+ subq $8,%rsp
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/amd64/crtn.S b/lib/csu/amd64/crtn.S
new file mode 100644
index 0000000..c411f00
--- /dev/null
+++ b/lib/csu/amd64/crtn.S
@@ -0,0 +1,37 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ addq $8,%rsp
+ ret
+
+ .section .fini,"ax",@progbits
+ addq $8,%rsp
+ ret
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile
new file mode 100644
index 0000000..bf4c7b1
--- /dev/null
+++ b/lib/csu/arm/Makefile
@@ -0,0 +1,44 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/arm/crt1.c b/lib/csu/arm/crt1.c
new file mode 100644
index 0000000..127c28d
--- /dev/null
+++ b/lib/csu/arm/crt1.c
@@ -0,0 +1,125 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 2001 David E. O'Brien.
+ * All rights reserved.
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ * Copyright (c) 1997 Jason R. Thorpe.
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * FreeBSD Project. See http://www.freebsd.org/ for
+ * information about FreeBSD.
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.netbsd.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+extern void _start(int, char **, char **, const struct Struct_Obj_Entry *,
+ void (*)(void), struct ps_strings *);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+struct ps_strings *__ps_strings;
+
+void __start(int, char **, char **, struct ps_strings *,
+ const struct Struct_Obj_Entry *, void (*)(void));
+
+/* The entry function. */
+__asm(" .text \n"
+" .align 0 \n"
+" .globl _start \n"
+" _start: \n"
+" mov r5, r2 /* cleanup */ \n"
+" mov r4, r1 /* obj_main */ \n"
+" mov r3, r0 /* ps_strings */ \n"
+" /* Get argc, argv, and envp from stack */ \n"
+" ldr r0, [sp, #0x0000] \n"
+" add r1, sp, #0x0004 \n"
+" add r2, r1, r0, lsl #2 \n"
+" add r2, r2, #0x0004 \n"
+" /* Ensure the stack is properly aligned before calling C code. */\n"
+" bic sp, sp, #7 \n"
+" sub sp, sp, #8 \n"
+" str r5, [sp, #4] \n"
+" str r4, [sp, #0] \n"
+"\n"
+" b __start ");
+/* ARGSUSED */
+void
+__start(int argc, char **argv, char **env, struct ps_strings *ps_strings,
+ const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void))
+{
+
+ environ = env;
+
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (ps_strings != (struct ps_strings *)0)
+ __ps_strings = ps_strings;
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+#endif
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
diff --git a/lib/csu/arm/crti.S b/lib/csu/arm/crti.S
new file mode 100644
index 0000000..40e83bb
--- /dev/null
+++ b/lib/csu/arm/crti.S
@@ -0,0 +1,21 @@
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",%progbits
+ .align 4
+ .globl _init
+ .type _init,%function
+_init:
+ mov ip, sp
+ stmdb sp!, {fp, ip, lr, pc}
+ sub fp, ip, #4
+
+ .section .fini,"ax",%progbits
+ .align 4
+ .globl _fini
+ .type _fini,%function
+_fini:
+ mov ip, sp
+ stmdb sp!, {fp, ip, lr, pc}
+ sub fp, ip, #4
+
diff --git a/lib/csu/arm/crtn.S b/lib/csu/arm/crtn.S
new file mode 100644
index 0000000..962f0ed
--- /dev/null
+++ b/lib/csu/arm/crtn.S
@@ -0,0 +1,10 @@
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",%progbits
+ ldmea fp, {fp, sp, pc}
+ mov pc, lr
+
+ .section .fini,"ax",%progbits
+ ldmea fp, {fp, sp, pc}
+ mov pc, lr
diff --git a/lib/csu/common/crtbrand.c b/lib/csu/common/crtbrand.c
new file mode 100644
index 0000000..04df686
--- /dev/null
+++ b/lib/csu/common/crtbrand.c
@@ -0,0 +1,66 @@
+/*-
+ * Copyright 2000 David E. O'Brien, John D. Polstra.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include "notes.h"
+
+/*
+ * Special ".note" entry specifying the ABI version. See
+ * http://www.netbsd.org/Documentation/kernel/elf-notes.html
+ * for more information.
+ *
+ * For all arches except sparc, gcc emits the section directive for the
+ * following struct with a PROGBITS type. However, newer versions of binutils
+ * (after 2.16.90) require the section to be of NOTE type, to guarantee that the
+ * .note.ABI-tag section correctly ends up in the first page of the final
+ * executable.
+ *
+ * Unfortunately, there is no clean way to tell gcc to use another section type,
+ * so this C file (or the C file that includes it) must be compiled in multiple
+ * steps:
+ *
+ * - Compile the .c file to a .s file.
+ * - Edit the .s file to change the 'progbits' type to 'note', for the section
+ * directive that defines the .note.ABI-tag section.
+ * - Compile the .s file to an object file.
+ *
+ * These steps are done in the invididual Makefiles for each applicable arch.
+ */
+static const struct {
+ int32_t namesz;
+ int32_t descsz;
+ int32_t type;
+ char name[sizeof(NOTE_FREEBSD_VENDOR)];
+ int32_t desc;
+} abitag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = {
+ .namesz = sizeof(NOTE_FREEBSD_VENDOR),
+ .descsz = sizeof(int32_t),
+ .type = ABI_NOTETYPE,
+ .name = NOTE_FREEBSD_VENDOR,
+ .desc = __FreeBSD_version
+};
diff --git a/lib/csu/common/ignore_init.c b/lib/csu/common/ignore_init.c
new file mode 100644
index 0000000..e3d2441
--- /dev/null
+++ b/lib/csu/common/ignore_init.c
@@ -0,0 +1,114 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <kib@FreeBSD.org>
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "notes.h"
+
+extern int main(int, char **, char **);
+
+extern void (*__preinit_array_start[])(int, char **, char **) __hidden;
+extern void (*__preinit_array_end[])(int, char **, char **) __hidden;
+extern void (*__init_array_start[])(int, char **, char **) __hidden;
+extern void (*__init_array_end[])(int, char **, char **) __hidden;
+extern void (*__fini_array_start[])(void) __hidden;
+extern void (*__fini_array_end[])(void) __hidden;
+extern void _fini(void) __hidden;
+extern void _init(void) __hidden;
+
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
+char **environ;
+const char *__progname = "";
+
+static void
+finalizer(void)
+{
+ void (*fn)(void);
+ size_t array_size, n;
+
+ array_size = __fini_array_end - __fini_array_start;
+ for (n = array_size; n > 0; n--) {
+ fn = __fini_array_start[n - 1];
+ if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1)
+ (fn)();
+ }
+ _fini();
+}
+
+static inline void
+handle_static_init(int argc, char **argv, char **env)
+{
+ void (*fn)(int, char **, char **);
+ size_t array_size, n;
+
+ if (&_DYNAMIC != NULL)
+ return;
+
+ atexit(finalizer);
+
+ array_size = __preinit_array_end - __preinit_array_start;
+ for (n = 0; n < array_size; n++) {
+ fn = __preinit_array_start[n];
+ if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1)
+ fn(argc, argv, env);
+ }
+ _init();
+ array_size = __init_array_end - __init_array_start;
+ for (n = 0; n < array_size; n++) {
+ fn = __init_array_start[n];
+ if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1)
+ fn(argc, argv, env);
+ }
+}
+
+static inline void
+handle_progname(const char *v)
+{
+ const char *s;
+
+ __progname = v;
+ for (s = __progname; *s != '\0'; s++) {
+ if (*s == '/')
+ __progname = s + 1;
+ }
+}
+
+static const struct {
+ int32_t namesz;
+ int32_t descsz;
+ int32_t type;
+ char name[sizeof(NOTE_FREEBSD_VENDOR)];
+ uint32_t desc;
+} crt_noinit_tag __attribute__ ((section (NOTE_SECTION),
+ aligned(4))) __used = {
+ .namesz = sizeof(NOTE_FREEBSD_VENDOR),
+ .descsz = sizeof(uint32_t),
+ .type = CRT_NOINIT_NOTETYPE,
+ .name = NOTE_FREEBSD_VENDOR,
+ .desc = 0
+};
diff --git a/lib/csu/common/notes.h b/lib/csu/common/notes.h
new file mode 100644
index 0000000..fcc2b66
--- /dev/null
+++ b/lib/csu/common/notes.h
@@ -0,0 +1,38 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <kib@FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef CSU_COMMON_NOTES_H
+#define CSU_COMMON_NOTES_H
+
+#define NOTE_FREEBSD_VENDOR "FreeBSD"
+
+#define NOTE_SECTION ".note.tag"
+
+#define ABI_NOTETYPE 1
+#define CRT_NOINIT_NOTETYPE 2
+
+#endif
diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386-elf/Makefile
new file mode 100644
index 0000000..286c15c
--- /dev/null
+++ b/lib/csu/i386-elf/Makefile
@@ -0,0 +1,51 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crti.S crtn.S
+FILES= ${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o
+FILESOWN= ${LIBOWN}
+FILESGRP= ${LIBGRP}
+FILESMODE= ${LIBMODE}
+FILESDIR= ${LIBDIR}
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+CLEANFILES= ${FILES} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+CLEANFILES+= crt1_c.s gcrt1_c.s Scrt1_c.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1_c.c is not
+# directly compiled to .o files.
+
+gcrt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1_c.o: gcrt1_c.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1_c.s
+
+gcrt1.o: gcrt1_c.o crt1_s.o
+ ${LD} ${LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
+
+crt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1_c.o: crt1_c.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1_c.s
+
+crt1.o: crt1_c.o crt1_s.o
+ ${LD} ${LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
+ objcopy --localize-symbol _start1 crt1.o
+
+Scrt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1_c.o: Scrt1_c.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1_c.s
+
+Scrt1.o: Scrt1_c.o crt1_s.o
+ ${LD} ${LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
+ objcopy --localize-symbol _start1 Scrt1.o
+
+.include <bsd.prog.mk>
diff --git a/lib/csu/i386-elf/crt1_c.c b/lib/csu/i386-elf/crt1_c.c
new file mode 100644
index 0000000..3249069
--- /dev/null
+++ b/lib/csu/i386-elf/crt1_c.c
@@ -0,0 +1,83 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 1996-1998 John D. Polstra.
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+typedef void (*fptr)(void);
+
+extern void _start(char *, ...);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+void _start1(fptr, int, char *[]) __dead2;
+
+/* The entry function, C part. */
+void
+_start1(fptr cleanup, int argc, char *argv[])
+{
+ char **env;
+
+ env = argv + argc + 1;
+ environ = env;
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+__asm__("eprol:");
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+__asm(".hidden _start1");
diff --git a/lib/csu/i386-elf/crt1_s.S b/lib/csu/i386-elf/crt1_s.S
new file mode 100644
index 0000000..17ac0e3
--- /dev/null
+++ b/lib/csu/i386-elf/crt1_s.S
@@ -0,0 +1,54 @@
+/*-
+ * Copyright 2009 Konstantin Belousov.
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .text
+ .align 4
+ .globl _start
+ .type _start, @function
+_start:
+ .cfi_startproc
+ xorl %ebp,%ebp
+ pushl %ebp
+ .cfi_def_cfa_offset 4
+ movl %esp,%ebp
+ .cfi_offset %ebp,-8
+ .cfi_def_cfa_register %ebp
+ andl $0xfffffff0,%esp # align stack
+ leal 8(%ebp),%eax
+ subl $4,%esp
+ pushl %eax # argv
+ pushl 4(%ebp) # argc
+ pushl %edx # rtld cleanup
+ call _start1
+ int3
+ .cfi_endproc
+ .size _start, . - _start
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/i386-elf/crti.S b/lib/csu/i386-elf/crti.S
new file mode 100644
index 0000000..77e4e77
--- /dev/null
+++ b/lib/csu/i386-elf/crti.S
@@ -0,0 +1,43 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ .align 4
+ .globl _init
+ .type _init,@function
+_init:
+ sub $12,%esp /* re-align stack pointer */
+
+ .section .fini,"ax",@progbits
+ .align 4
+ .globl _fini
+ .type _fini,@function
+_fini:
+ sub $12,%esp /* re-align stack pointer */
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/i386-elf/crtn.S b/lib/csu/i386-elf/crtn.S
new file mode 100644
index 0000000..0264e22
--- /dev/null
+++ b/lib/csu/i386-elf/crtn.S
@@ -0,0 +1,37 @@
+/*-
+ * Copyright 1996, 1997, 1998, 2000 John D. Polstra.
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ add $12,%esp
+ ret
+
+ .section .fini,"ax",@progbits
+ add $12,%esp
+ ret
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/ia64/Makefile b/lib/csu/ia64/Makefile
new file mode 100644
index 0000000..b12e888
--- /dev/null
+++ b/lib/csu/ia64/Makefile
@@ -0,0 +1,62 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= crt1.o gcrt1.o Scrt1.o
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1_.o gcrt1_.o Scrt1_.o
+CLEANFILES+= crtbrand.o gcrtbrand.o Scrtbrand.o
+CLEANFILES+= crtbrand.s gcrtbrand.s Scrtbrand.s
+
+crt1_.o: crt1.S
+ ${CC} ${CFLAGS} -c -o ${.TARGET} ${.ALLSRC}
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crtbrand.c is not
+# directly compiled to .o files.
+
+crtbrand.s: crtbrand.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.ALLSRC}
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+crtbrand.o: crtbrand.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crtbrand.s
+
+crt1.o: crt1_.o crtbrand.o
+ ${LD} ${LDFLAGS} -r -o ${.TARGET} crt1_.o crtbrand.o
+
+gcrt1_.o: crt1.S
+ ${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.ALLSRC}
+
+gcrtbrand.s: crtbrand.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.ALLSRC}
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+gcrtbrand.o: gcrtbrand.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrtbrand.s
+
+gcrt1.o: gcrt1_.o gcrtbrand.o
+ ${LD} ${LDFLAGS} -r -o ${.TARGET} ${.ALLSRC}
+
+Scrt1_.o: crt1.S
+ ${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.ALLSRC}
+
+Scrtbrand.s: crtbrand.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.ALLSRC}
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrtbrand.o: Scrtbrand.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrtbrand.s
+
+Scrt1.o: Scrt1_.o Scrtbrand.o
+ ${LD} ${LDFLAGS} -r -o ${.TARGET} ${.ALLSRC}
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/ia64/crt1.S b/lib/csu/ia64/crt1.S
new file mode 100644
index 0000000..6ff9cd9
--- /dev/null
+++ b/lib/csu/ia64/crt1.S
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2003 Marcel Moolenaar
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .text
+
+/*
+ * void _start(char **ap, struct ps_strings *, void (*cleanup)(void));
+ */
+#define AP in0
+#define CLEANUP in2
+
+#define GP loc0
+#define ARGC loc1
+#define ARGV loc2
+#define ENVP loc3
+
+ .global _start
+ .type _start, @function
+ .proc _start
+_start:
+ .prologue
+ .save rp, r0
+ .body
+{ .mlx
+ alloc r14=ar.pfs,3,4,3,0
+ movl r15=@gprel(1f)
+}
+1:
+{ .mmi
+ ld4 ARGC=[AP]
+ adds ARGV=8,AP
+ mov r16=ip
+ ;;
+}
+{ .mmi
+ sub gp=r16,r15
+ sub GP=r16,r15
+ shladd r14=ARGC,3,AP
+ ;;
+}
+{ .mii
+ addl r15=@ltoff(environ),gp
+ cmp4.ge p6,p7=0,ARGC
+ adds ENVP=16,r14
+ ;;
+}
+{ .mmi
+ ld8 r14=[r15]
+(p7) ld8 r15=[ARGV]
+ addl r16=@gprel(__progname),gp
+ ;;
+}
+{ .mib
+ st8 [r14]=ENVP
+(p7) cmp.eq p6,p0=0,r15
+(p6) br.dpnt .L1
+ ;;
+}
+ /* Normalize __progname. */
+{ .mmi
+ st8 [r16]=r15
+ ld1 r14=[r15],1
+ nop 0
+ ;;
+}
+.L0:
+{ .mib
+ cmp4.eq p7,p0=0,r14
+ cmp4.eq p6,p0=0x2f,r14
+(p7) br.dptk .L1
+ ;;
+}
+{ .mmb
+(p6) st8 [r16]=r15
+ ld1 r14=[r15],1
+ br.dptk.many .L0
+}
+.L1:
+{ .mib
+ cmp.ne p7,p0=0,CLEANUP
+ mov out0=CLEANUP
+(p7) br.call.sptk b0=atexit
+ ;;
+}
+{ .mfb
+ mov gp=GP
+ nop 0
+ br.call.sptk b0=_init_tls
+}
+#ifdef GCRT
+{ .mmi
+ mov gp=GP
+ ;;
+ addl r14=@ltoff(@fptr(_mcleanup)),gp
+ nop 0
+ ;;
+}
+{ .mfb
+ ld8 out0=[r14]
+ nop 0
+ br.call.sptk b0=atexit
+ ;;
+}
+#endif
+{ .mmi
+ mov gp=GP
+ ;;
+ addl r14=@ltoff(@fptr(_fini)),gp
+ nop 0
+ ;;
+}
+{ .mfb
+ ld8 out0=[r14]
+ nop 0
+ br.call.sptk b0=atexit
+ ;;
+}
+#ifdef GCRT
+{ .mmi
+ mov gp=GP
+ ;;
+ addl r14=@ltoff(eprol),gp
+ addl r15=@ltoff(etext),gp
+ ;;
+}
+{ .mmb
+ ld8 out0=[r14]
+ ld8 out1=[r15]
+ br.call.sptk b0=monstartup
+ ;;
+}
+#endif
+{ .mfb
+ mov gp=GP
+ nop 0
+ br.call.sptk b0=_init
+ ;;
+}
+{ .mmi
+ mov gp=GP
+ mov out0=ARGC
+ mov out1=ARGV
+}
+{ .mfb
+ mov out2=ENVP
+ nop 0
+ br.call.sptk b0=main
+ ;;
+}
+{ .mib
+ mov gp=GP
+ mov out0=r8
+ br.call.sptk b0=exit
+ ;;
+}
+ .endp _start
+
+#ifdef GCRT
+eprol:
+#endif
+
+ .rodata
+.empty: stringz ""
+
+ .sdata
+ .global __progname
+ .size __progname,8
+ .type __progname,@object
+__progname: data8 .empty
+
+ .common environ,8,8
diff --git a/lib/csu/ia64/crti.S b/lib/csu/ia64/crti.S
new file mode 100644
index 0000000..66ef948
--- /dev/null
+++ b/lib/csu/ia64/crti.S
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2001 Peter Wemm <peter@FreeBSD.org>
+ * 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 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * This file (and its companion crtn.S) form the terminators of the
+ * .init and .fini sections.
+ */
+ .file "crti.S"
+
+ .section .init,"ax",@progbits
+ .global _init#
+ .proc _init#
+_init:
+ .regstk 0,2,0,0
+ .prologue 12,loc0
+ .save ar.pfs,loc1
+ alloc loc1=ar.pfs,0,2,0,0
+ mov loc0=b0 /* Save return addr */
+ .body
+ .endp _init#
+
+ .section .fini,"ax",@progbits
+ .global _fini#
+ .proc _fini#
+_fini:
+ .regstk 0,2,0,0
+ .prologue 12,loc0
+ .save ar.pfs,loc1
+ alloc loc1=ar.pfs,0,2,0,0
+ mov loc0=b0 /* Save return addr */
+ .body
+ .endp _fini#
diff --git a/lib/csu/ia64/crtn.S b/lib/csu/ia64/crtn.S
new file mode 100644
index 0000000..681fba3
--- /dev/null
+++ b/lib/csu/ia64/crtn.S
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2001 Peter Wemm <peter@FreeBSD.org>
+ * 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 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .file "crtn.S"
+
+ .section .init,"ax",@progbits
+ .regstk 0,2,0,0
+ mov b0=loc0 /* Recover return addr */
+ mov ar.pfs=loc1
+ br.ret.sptk.many b0
+
+ .section .fini,"ax",@progbits
+ .regstk 0,2,0,0
+ mov b0=loc0 /* Recover return addr */
+ mov ar.pfs=loc1
+ br.ret.sptk.many b0
diff --git a/lib/csu/mips/Makefile b/lib/csu/mips/Makefile
new file mode 100644
index 0000000..bf4c7b1
--- /dev/null
+++ b/lib/csu/mips/Makefile
@@ -0,0 +1,44 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/mips/crt1.c b/lib/csu/mips/crt1.c
new file mode 100644
index 0000000..1968f06
--- /dev/null
+++ b/lib/csu/mips/crt1.c
@@ -0,0 +1,96 @@
+/*-
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christopher G. Demetriou
+ * for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+
+#include <stdlib.h>
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+void __start(char **, void (*)(void), struct Struct_Obj_Entry *, struct ps_strings *);
+
+/* The entry function. */
+void
+__start(char **ap,
+ void (*cleanup)(void), /* from shared loader */
+ struct Struct_Obj_Entry *obj __unused, /* from shared loader */
+ struct ps_strings *ps_strings __unused)
+{
+ int argc;
+ char **argv;
+ char **env;
+
+ argc = * (long *) ap;
+ argv = ap + 1;
+ env = ap + 2 + argc;
+ environ = env;
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
diff --git a/lib/csu/mips/crti.S b/lib/csu/mips/crti.S
new file mode 100644
index 0000000..cada08d
--- /dev/null
+++ b/lib/csu/mips/crti.S
@@ -0,0 +1,50 @@
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",%progbits
+ .align 4
+ .globl _init
+ .type _init,%function
+_init:
+ .set noreorder
+#if defined(__ABICALLS__) && (defined(__mips_o32) || defined(__mips_o64))
+ SETUP_GP
+#endif
+ PTR_ADDU sp, sp, -CALLFRAME_SIZ
+ REG_S ra, CALLFRAME_RA(sp)
+#if defined(__ABICALLS__)
+#if defined(__mips_o32) || defined(__mips_o64)
+ SAVE_GP(CALLFRAME_GP)
+#else
+ SETUP_GP64(CALLFRAME_GP, _init)
+#endif
+#else /* __ABICALLS__ */
+#if defined(__mips_n32) || defined(__mips_n64)
+ REG_S gp, CALLFRAME_GP(sp)
+#endif
+#endif
+ .set reorder
+
+ .section .fini,"ax",%progbits
+ .align 4
+ .globl _fini
+ .type _fini,%function
+_fini:
+ .set noreorder
+#if defined(__ABICALLS__) && (defined(__mips_o32) || defined(__mips_o64))
+ SETUP_GP
+#endif
+ PTR_ADDU sp, sp, -CALLFRAME_SIZ
+ REG_S ra, CALLFRAME_RA(sp)
+#if defined(__ABICALLS__)
+#if defined(__mips_o32) || defined(__mips_o64)
+ SAVE_GP(CALLFRAME_GP)
+#else
+ SETUP_GP64(CALLFRAME_GP, _fini)
+#endif
+#else /* __ABICALLS__ */
+#if defined(__mips_n32) || defined(__mips_n64)
+ REG_S gp, CALLFRAME_GP(sp)
+#endif
+#endif
+ .set reorder
diff --git a/lib/csu/mips/crtn.S b/lib/csu/mips/crtn.S
new file mode 100644
index 0000000..8d190f8
--- /dev/null
+++ b/lib/csu/mips/crtn.S
@@ -0,0 +1,24 @@
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",%progbits
+ .align 4
+ .set noreorder
+#if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64))
+ REG_L gp, CALLFRAME_GP(sp)
+#endif
+ REG_L ra, CALLFRAME_RA(sp)
+ jr ra
+ PTR_ADDU sp, sp, CALLFRAME_SIZ
+ .set reorder
+
+ .section .fini,"ax",%progbits
+ .align 4
+ .set noreorder
+#if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64))
+ REG_L gp, CALLFRAME_GP(sp)
+#endif
+ REG_L ra, CALLFRAME_RA(sp)
+ jr ra
+ PTR_ADDU sp, sp, CALLFRAME_SIZ
+ .set reorder
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
new file mode 100644
index 0000000..bf4c7b1
--- /dev/null
+++ b/lib/csu/powerpc/Makefile
@@ -0,0 +1,44 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/powerpc/crt1.c b/lib/csu/powerpc/crt1.c
new file mode 100644
index 0000000..c3be90d
--- /dev/null
+++ b/lib/csu/powerpc/crt1.c
@@ -0,0 +1,110 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 2001 David E. O'Brien.
+ * All rights reserved.
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ * Copyright (c) 1997 Jason R. Thorpe.
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * FreeBSD Project. See http://www.freebsd.org/ for
+ * information about FreeBSD.
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.netbsd.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+struct ps_strings *__ps_strings;
+
+void _start(int, char **, char **, const struct Struct_Obj_Entry *,
+ void (*)(void), struct ps_strings *);
+
+/* The entry function. */
+/*
+ * First 5 arguments are specified by the PowerPC SVR4 ABI.
+ * The last argument, ps_strings, is a BSD extension.
+ */
+/* ARGSUSED */
+void
+_start(int argc, char **argv, char **env,
+ const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
+ struct ps_strings *ps_strings)
+{
+
+ environ = env;
+
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (ps_strings != (struct ps_strings *)0)
+ __ps_strings = ps_strings;
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
diff --git a/lib/csu/powerpc/crti.S b/lib/csu/powerpc/crti.S
new file mode 100644
index 0000000..da83d1d
--- /dev/null
+++ b/lib/csu/powerpc/crti.S
@@ -0,0 +1,51 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ .align 2
+ .globl _init
+ .type _init,@function
+_init:
+ stwu 1,-16(1)
+ mflr 0
+ stw 31,12(1)
+ stw 0,20(1)
+ mr 31,1
+
+
+ .section .fini,"ax",@progbits
+ .align 2
+ .globl _fini
+_fini:
+ stwu 1,-16(1)
+ mflr 0
+ stw 31,12(1)
+ stw 0,20(1)
+ mr 31,1
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/powerpc/crtn.S b/lib/csu/powerpc/crtn.S
new file mode 100644
index 0000000..7430118
--- /dev/null
+++ b/lib/csu/powerpc/crtn.S
@@ -0,0 +1,46 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ lwz 11,0(1)
+ lwz 0,4(11)
+ mtlr 0
+ lwz 31,-4(11)
+ mr 1,11
+ blr
+
+
+ .section .fini,"ax",@progbits
+ lwz 11,0(1)
+ lwz 0,4(11)
+ mtlr 0
+ lwz 31,-4(11)
+ mr 1,11
+ blr
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile
new file mode 100644
index 0000000..123391e
--- /dev/null
+++ b/lib/csu/powerpc64/Makefile
@@ -0,0 +1,45 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common \
+ -I${.CURDIR}/../../libc/include \
+ -mlongcall
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+CLEANFILES+= crt1.s gcrt1.s Scrt1.s
+
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+ sed ${SED_FIX_NOTE} ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/powerpc64/crt1.c b/lib/csu/powerpc64/crt1.c
new file mode 100644
index 0000000..a7c3581
--- /dev/null
+++ b/lib/csu/powerpc64/crt1.c
@@ -0,0 +1,110 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 2001 David E. O'Brien.
+ * All rights reserved.
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ * Copyright (c) 1997 Jason R. Thorpe.
+ * Copyright (c) 1995 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * FreeBSD Project. See http://www.freebsd.org/ for
+ * information about FreeBSD.
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.netbsd.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+extern void _start(int, char **, char **, const struct Struct_Obj_Entry *,
+ void (*)(void), struct ps_strings *);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+struct ps_strings *__ps_strings;
+
+/* The entry function. */
+/*
+ * First 5 arguments are specified by the PowerPC SVR4 ABI.
+ * The last argument, ps_strings, is a BSD extension.
+ */
+/* ARGSUSED */
+void
+_start(int argc, char **argv, char **env,
+ const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
+ struct ps_strings *ps_strings)
+{
+
+ environ = env;
+
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (ps_strings != (struct ps_strings *)0)
+ __ps_strings = ps_strings;
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else
+ _init_tls();
+
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
diff --git a/lib/csu/powerpc64/crti.S b/lib/csu/powerpc64/crti.S
new file mode 100644
index 0000000..767d920
--- /dev/null
+++ b/lib/csu/powerpc64/crti.S
@@ -0,0 +1,61 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ .align 2
+ .globl _init
+ .section ".opd","aw"
+ .align 3
+_init:
+ .quad .L._init,.TOC.@tocbase,0
+ .previous
+ .type _init,@function
+
+ .align 4
+.L._init:
+ stdu 1,-48(1)
+ mflr 0
+ std 0,64(1)
+
+ .section .fini,"ax",@progbits
+ .align 2
+ .globl _fini
+ .section ".opd","aw"
+ .align 3
+_fini:
+ .quad .L._fini,.TOC.@tocbase,0
+ .previous
+ .type _fini,@function
+
+ .align 4
+.L._fini:
+ stdu 1,-48(1)
+ mflr 0
+ std 0,64(1)
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/powerpc64/crtn.S b/lib/csu/powerpc64/crtn.S
new file mode 100644
index 0000000..39f21ae
--- /dev/null
+++ b/lib/csu/powerpc64/crtn.S
@@ -0,0 +1,42 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .section .init,"ax",@progbits
+ ld %r1,0(%r1)
+ ld 0,16(%r1)
+ mtlr 0
+ blr
+
+
+ .section .fini,"ax",@progbits
+ ld %r1,0(%r1)
+ ld 0,16(%r1)
+ mtlr 0
+ blr
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile
new file mode 100644
index 0000000..7f8dd7a
--- /dev/null
+++ b/lib/csu/sparc64/Makefile
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../common
+
+SRCS= crt1.c crti.S crtn.S
+OBJS= ${SRCS:N*.h:R:S/$/.o/g}
+OBJS+= Scrt1.o gcrt1.o
+CFLAGS+= -I${.CURDIR}/../common -I${.CURDIR}/../../libc/include
+
+all: ${OBJS}
+
+CLEANFILES= ${OBJS}
+
+gcrt1.o: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+
+Scrt1.o: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1.o ${.ALLSRC}
+
+realinstall:
+ ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${OBJS} ${DESTDIR}${LIBDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/csu/sparc64/crt1.c b/lib/csu/sparc64/crt1.c
new file mode 100644
index 0000000..3b3ecc2
--- /dev/null
+++ b/lib/csu/sparc64/crt1.c
@@ -0,0 +1,111 @@
+/* LINTLIBRARY */
+/*-
+ * Copyright 2001 David E. O'Brien.
+ * All rights reserved.
+ * Copyright (c) 1995, 1998 Berkeley Software Design, Inc.
+ * All rights reserved.
+ * Copyright 1996-1998 John D. Polstra.
+ * 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.
+ * 3. The name of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifndef lint
+#ifndef __GNUC__
+#error "GCC is needed to compile this file"
+#endif
+#endif /* lint */
+
+#include <stdlib.h>
+
+#include "libc_private.h"
+#include "crtbrand.c"
+#include "ignore_init.c"
+
+struct Struct_Obj_Entry;
+struct ps_strings;
+
+extern void __sparc_utrap_setup(void);
+
+#ifdef GCRT
+extern void _mcleanup(void);
+extern void monstartup(void *, void *);
+extern int eprol;
+extern int etext;
+#endif
+
+void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
+ struct ps_strings *);
+
+/* The entry function. */
+/*
+ * %o0 holds ps_strings pointer.
+ *
+ * Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1,
+ * but for now we do not use it here.
+ *
+ * The SPARC compliance definitions specifies that the kernel pass the
+ * address of a function to be executed on exit in %g1. We do not make
+ * use of it as it is quite broken, because gcc can use this register
+ * as a temporary, so it is not safe from C code. Its even more broken
+ * for dynamic executables since rtld runs first.
+ */
+/* ARGSUSED */
+void
+_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused,
+ struct ps_strings *ps_strings __unused)
+{
+ int argc;
+ char **argv;
+ char **env;
+
+ argc = *(long *)(void *)ap;
+ argv = ap + 1;
+ env = ap + 2 + argc;
+ environ = env;
+ if (argc > 0 && argv[0] != NULL)
+ handle_progname(argv[0]);
+
+ if (&_DYNAMIC != NULL)
+ atexit(cleanup);
+ else {
+ __sparc_utrap_setup();
+ _init_tls();
+ }
+#ifdef GCRT
+ atexit(_mcleanup);
+ monstartup(&eprol, &etext);
+#endif
+
+ handle_static_init(argc, argv, env);
+ exit(main(argc, argv, env));
+}
+
+#ifdef GCRT
+__asm__(".text");
+__asm__("eprol:");
+__asm__(".previous");
+#endif
diff --git a/lib/csu/sparc64/crti.S b/lib/csu/sparc64/crti.S
new file mode 100644
index 0000000..9e529a5
--- /dev/null
+++ b/lib/csu/sparc64/crti.S
@@ -0,0 +1,57 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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.
+ * 3. Neither the name of the author nor the names of additional contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .file "crti.S"
+
+ /* The minimum stack frame size (bytes) is:
+ * 16 extended words for saving the current register window,
+ * 1 extended word for "hidden parameter",
+ * 6 extended words in wihch a callee can store its arguments
+ * ("The SPARC Architecure Manual" by Weaver & Germond)
+ * This gives 184 bytes. However we must round up to an extended
+ * word boundary, thus 192 bytes.
+ * (if we weren't v9, it would be 96 bytes rather than 192)
+ */
+
+ .section .init,"ax",@progbits
+ .align 4
+ .globl _init
+ .type _init,#function
+_init:
+ save %sp,-192,%sp
+
+
+ .section .fini,"ax",@progbits
+ .globl _fini
+ .type _fini,#function
+ .align 4
+_fini:
+ save %sp,-192,%sp
diff --git a/lib/csu/sparc64/crtn.S b/lib/csu/sparc64/crtn.S
new file mode 100644
index 0000000..5b6d4a7
--- /dev/null
+++ b/lib/csu/sparc64/crtn.S
@@ -0,0 +1,42 @@
+/*-
+ * Copyright 2001 David E. O'Brien
+ * 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.
+ * 3. Neither the name of the author nor the names of additional contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * 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 <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ .file "crtn.S"
+
+ .section .init,"ax",@progbits
+ .align 4
+ ret
+ restore
+
+ .section .fini,"ax",@progbits
+ .align 4
+ ret
+ restore
OpenPOWER on IntegriCloud