summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-12-03 06:21:42 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-12-03 06:21:42 +0000
commitd2691ac140877e978fb1760a3b8839703bec2157 (patch)
tree1eb3ea9b962bb8302d7906e09e3f99eda594ab9a /lib
parent6999064a0775fb0dba819e0c6b3d16259508940e (diff)
Merge the per-arch crt0.c files into common_elf/crt0.c, with MD macros in
the md_init.h files. Worked out with and ok miod@; ok matthew@
Diffstat (limited to 'lib')
-rw-r--r--lib/csu/alpha/Makefile10
-rw-r--r--lib/csu/alpha/crt0.c108
-rw-r--r--lib/csu/alpha/md_init.h19
-rw-r--r--lib/csu/amd64/Makefile10
-rw-r--r--lib/csu/amd64/crt0.c118
-rw-r--r--lib/csu/amd64/md_init.h21
-rw-r--r--lib/csu/arm/Makefile10
-rw-r--r--lib/csu/arm/crt0.c130
-rw-r--r--lib/csu/arm/md_init.h32
-rw-r--r--lib/csu/common_elf/crt0.c (renamed from lib/csu/sparc64/crt0.c)73
-rw-r--r--lib/csu/hppa/Makefile10
-rw-r--r--lib/csu/hppa/crt0.c135
-rw-r--r--lib/csu/hppa/md_init.h38
-rw-r--r--lib/csu/hppa64/Makefile10
-rw-r--r--lib/csu/hppa64/crt0.c134
-rw-r--r--lib/csu/hppa64/md_init.h40
-rw-r--r--lib/csu/i386/Makefile10
-rw-r--r--lib/csu/i386/crt0.c124
-rw-r--r--lib/csu/i386/md_init.h24
-rw-r--r--lib/csu/m68k/Makefile10
-rw-r--r--lib/csu/m68k/crt0.c120
-rw-r--r--lib/csu/m68k/md_init.h18
-rw-r--r--lib/csu/m88k/Makefile10
-rw-r--r--lib/csu/m88k/crt0.c119
-rw-r--r--lib/csu/m88k/md_init.h29
-rw-r--r--lib/csu/mips64/Makefile10
-rw-r--r--lib/csu/mips64/crt0.c207
-rw-r--r--lib/csu/mips64/md_init.h50
-rw-r--r--lib/csu/powerpc/Makefile10
-rw-r--r--lib/csu/powerpc/crt0.c181
-rw-r--r--lib/csu/powerpc/md_init.h90
-rw-r--r--lib/csu/sh/Makefile10
-rw-r--r--lib/csu/sh/crt0.c119
-rw-r--r--lib/csu/sh/md_init.h22
-rw-r--r--lib/csu/sparc/Makefile10
-rw-r--r--lib/csu/sparc/crt0.c122
-rw-r--r--lib/csu/sparc/md_init.h23
-rw-r--r--lib/csu/sparc64/Makefile10
-rw-r--r--lib/csu/sparc64/md_init.h26
-rw-r--r--lib/csu/vax/Makefile10
-rw-r--r--lib/csu/vax/crt0.c120
-rw-r--r--lib/csu/vax/md_init.h39
42 files changed, 565 insertions, 1856 deletions
diff --git a/lib/csu/alpha/Makefile b/lib/csu/alpha/Makefile
index 1c688ccf8de..f668d772d21 100644
--- a/lib/csu/alpha/Makefile
+++ b/lib/csu/alpha/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.20 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.21 2013/12/03 06:21:40 guenther Exp $
# $NetBSD: Makefile,v 1.6 1996/10/18 05:27:38 thorpej Exp $
CFLAGS+= -DELFSIZE=64
@@ -12,14 +12,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fPIE ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fPIE ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fPIE ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fPIE ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/alpha/crt0.c b/lib/csu/alpha/crt0.c
deleted file mode 100644
index 28873820552..00000000000
--- a/lib/csu/alpha/crt0.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.10 2005/08/04 16:33:04 espie Exp $ */
-/* $NetBSD: crt0.c,v 1.1 1996/09/12 16:59:02 cgd Exp $ */
-/*
- * 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.
- */
-
-#include <stdlib.h>
-#include <limits.h>
-
-static char *_strrchr(char *, char);
-
-char **environ;
-char *__progname = "";
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-__asm(".globl _start");
-__asm(".type _start@function");
-__asm("_start = __start");
-void
-__start(sp, cleanup, obj)
- char **sp;
- void (*cleanup)(void); /* from shared loader */
- const void *obj; /* from shared loader */
-{
- long argc;
- char **argv, *namep;
- char *s;
-
- argc = *(long *)sp;
- argv = sp + 1;
- environ = sp + 2 + argc; /* 2: argc + NULL ending argv */
-
- if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(namep, '/')) == NULL)
- __progname = namep;
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-
-static char *
-_strrchr(p, ch)
-register char *p, ch;
-{
- register char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-/* NOTREACHED */
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
-
diff --git a/lib/csu/alpha/md_init.h b/lib/csu/alpha/md_init.h
index 020b05c3bff..04a726860ab 100644
--- a/lib/csu/alpha/md_init.h
+++ b/lib/csu/alpha/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:40 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* All rights reserved.
@@ -61,3 +61,20 @@
" lda $30, 16($30) \n" \
" ret \n" \
" .previous")
+
+/* XXX this should not be necessary: ld should use __start */
+#define MD_CRT0_START \
+ __asm ( \
+ ".globl _start \n" \
+ ".type _start@function \n" \
+ "_start = __start")
+
+#define MD_START __start
+#define MD_START_ARGS char **sp, void (*cleanup)(void)
+#define MD_START_SETUP \
+ char **argv, **envp; \
+ long argc; \
+ \
+ argc = *(long *)sp; \
+ argv = sp + 1; \
+ environ = envp = sp + 2 + argc; /* 2: argc + NULL ending argv */
diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile
index c4f7c12159b..1ac2bbc2fe9 100644
--- a/lib/csu/amd64/Makefile
+++ b/lib/csu/amd64/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.8 2013/12/03 06:21:40 guenther Exp $
CFLAGS+= -fno-omit-frame-pointer
OBJS= crt0.o gcrt0.o
@@ -13,14 +13,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/amd64/crt0.c b/lib/csu/amd64/crt0.c
deleted file mode 100644
index 3932f34b663..00000000000
--- a/lib/csu/amd64/crt0.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.4 2013/11/10 18:49:34 guenther Exp $ */
-/*
- * 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.
- */
-
-#include <stdlib.h>
-#include <limits.h>
-
-static char *_strrchr(char *, char);
-
-char **environ;
-char *__progname = "";
-
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-__asm(" .text ;\
- .align 8 ;\
- .globl __start ;\
- .globl _start ;\
-_start: ;\
-__start: ;\
- movq %rdx,%rcx ;\
- movq (%rsp),%rdi ;\
- leaq 16(%rsp,%rdi,8),%rdx ;\
- leaq 8(%rsp),%rsi ;\
- subq $8,%rsp ;\
- andq $~15,%rsp ;\
- addq $8,%rsp ;\
- jmp ___start ;\
-");
-
-void
-___start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *namep;
- char *s;
-
- environ = envp;
-
- if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(namep, '/')) == NULL)
- __progname = namep;
- else
- ++__progname;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-
-static char *
-_strrchr(p, ch)
-register char *p, ch;
-{
- register char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-/* NOTREACHED */
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
-
diff --git a/lib/csu/amd64/md_init.h b/lib/csu/amd64/md_init.h
index d923b5f7896..c95a7f34171 100644
--- a/lib/csu/amd64/md_init.h
+++ b/lib/csu/amd64/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.2 2011/03/30 19:15:03 kettenis Exp $ */
+/* $OpenBSD: md_init.h,v 1.3 2013/12/03 06:21:40 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -60,3 +60,22 @@
" addq $8,%rsp \n" \
" ret \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 8 \n" \
+ " .globl __start \n" \
+ " .globl _start \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " movq %rdx,%rcx \n" \
+ " movq (%rsp),%rdi \n" \
+ " leaq 16(%rsp,%rdi,8),%rdx \n" \
+ " leaq 8(%rsp),%rsi \n" \
+ " subq $8,%rsp \n" \
+ " andq $~15,%rsp \n" \
+ " addq $8,%rsp \n" \
+ " jmp ___start \n" \
+ " .previous")
diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile
index 6c6da2a2dbf..8e047967ebf 100644
--- a/lib/csu/arm/Makefile
+++ b/lib/csu/arm/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.8 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.9 2013/12/03 06:21:40 guenther Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -11,14 +11,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fpie -DPIC ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fpie -DPIC ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fpie -DPIC ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fpie -DPIC ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/arm/crt0.c b/lib/csu/arm/crt0.c
deleted file mode 100644
index c66511a202c..00000000000
--- a/lib/csu/arm/crt0.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.5 2013/12/01 17:18:30 guenther Exp $ */
-/* $NetBSD: crt0.c,v 1.6 2002/01/01 01:31:06 thorpej Exp $ */
-
-/*
- * Copyright (C) 1997 Mark Brinicombe
- * Copyright (C) 1995 Wolfgang Solfrank.
- * Copyright (C) 1995 TooLs GmbH.
- * 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 TooLs GmbH.
- * 4. The name of TooLs GmbH may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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/param.h>
-
-#include <machine/asm.h>
-#include <stdlib.h>
-
-static char *_strrchr(const char *, char);
-
-char **environ;
-
-char * __progname = "";
-
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-extern void _start(void);
-void ___start(int, char *[], char *[], void (*)(void));
-
-__asm(" .text \n"
-" .align 0 \n"
-" .globl _start \n"
-" .globl __start \n"
-"_start: \n"
-"__start: \n"
-" mov r3, r0 /* cleanup */ \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"
-"\n"
-" /* Ensure the stack is properly aligned before calling C code. */\n"
-#if 1
-" bic sp, sp, #7" /*__STRING(STACKALIGNBYTES)*/ " \n"
-#endif
-" sub sp, sp, #8 \n"
-" str r5, [sp, #4] \n"
-" str r4, [sp, #0] \n"
-"\n"
-" b " __STRING(___start) " ");
-/*
-" b " __STRING(_C_LABEL(___start)) " ");
-*/
-
-void
-___start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *s;
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif /* MCRT0 */
-
- __init();
-
-__asm("__callmain:"); /* Defined for the benefit of debuggers */
- exit(main(argc, argv, envp));
-}
-
-static char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
- /* NOTREACHED */
-}
-asm (" .section \".text\" \n_eprol:");
-
diff --git a/lib/csu/arm/md_init.h b/lib/csu/arm/md_init.h
index 1085a81b6cf..e7ea1499315 100644
--- a/lib/csu/arm/md_init.h
+++ b/lib/csu/arm/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.3 2012/08/22 17:19:34 pascal Exp $ */
+/* $OpenBSD: md_init.h,v 1.4 2013/12/03 06:21:40 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -70,3 +70,33 @@
".section "#sect",\"ax\",%progbits \n" \
" ldmea fp, {fp, sp, pc} \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 0 \n" \
+ " .globl _start \n" \
+ " .globl __start \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " mov r3, r0 /* cleanup */ \n" \
+ "/* Get argc/argv/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" \
+ " \n" \
+ "/* \n" \
+ " * Ensure the stack is properly \n" \
+ " * aligned before calling C code. \n" \
+ " */ \n" \
+ /* #if 1 */ \
+ " bic sp, sp, #7" /*__STRING(STACKALIGNBYTES)*/ " \n" \
+ /* #endif */ \
+ " sub sp, sp, #8 \n" \
+ " str r5, [sp, #4] \n" \
+ " str r4, [sp, #0] \n" \
+ " \n" \
+ " b ___start \n" \
+ ".previous");
diff --git a/lib/csu/sparc64/crt0.c b/lib/csu/common_elf/crt0.c
index 0146e27ca5f..32cbe4c1f87 100644
--- a/lib/csu/sparc64/crt0.c
+++ b/lib/csu/common_elf/crt0.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crt0.c,v 1.9 2012/12/23 12:24:13 kettenis Exp $ */
+/* $OpenBSD: crt0.c,v 1.1 2013/12/03 06:21:40 guenther Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -34,6 +34,22 @@
#include <stdlib.h>
#include <limits.h>
+#include "md_init.h"
+
+/* some defaults */
+#ifndef MD_START_ARGS
+#define MD_START_ARGS \
+ int argc, char **argv, char **envp, void (*cleanup)(void)
+#endif
+#ifndef MD_START
+#define MD_START ___start
+static void ___start(MD_START_ARGS) __used;
+#endif
+#ifndef MD_EPROL_LABEL
+#define MD_EPROL_LABEL __asm(" .text\n_eprol:")
+#endif
+
+
static char *_strrchr(char *, char);
char **environ;
@@ -46,29 +62,19 @@ extern void _mcleanup(void);
extern unsigned char _etext, _eprol;
#endif /* MCRT0 */
-__asm__(".text\n"
-" .align 4\n"
-" .global _start\n" /* NetBSD compat */
-" .global __start\n"
-"_start:\n"
-"__start:\n"
-" clr %fp\n"
-" add %sp, 2175, %o0\n" /* stack */
-" ba,pt %icc, ___start\n"
-" mov %g1, %o1");
-
-static void ___start(char **, void (*)(void)) __used;
-
-static void
-___start(char **sp, void (*cleanup)(void))
+#ifdef MD_CRT0_START
+MD_CRT0_START;
+#endif
+
+void
+MD_START(MD_START_ARGS)
{
- long argc;
- char **argv, *namep;
- char *s;
+ char *namep, *s;
+#ifdef MD_START_SETUP
+ MD_START_SETUP
+#endif
- argc = *(long *)sp;
- argv = sp + 1;
- environ = sp + 2 + argc; /* 2: argc + NULL ending argv */
+ environ = envp;
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
@@ -82,8 +88,10 @@ ___start(char **sp, void (*cleanup)(void))
__progname = __progname_storage;
}
- if (cleanup)
+#ifndef MD_NO_CLEANUP
+ if (cleanup != NULL)
atexit(cleanup);
+#endif
#ifdef MCRT0
atexit(_mcleanup);
@@ -92,27 +100,22 @@ ___start(char **sp, void (*cleanup)(void))
__init();
- exit(main(argc, argv, environ));
+ exit(main(argc, argv, envp));
}
-
static char *
-_strrchr(p, ch)
-register char *p, ch;
+_strrchr(char *p, char ch)
{
- register char *save;
+ char *save;
for (save = NULL;; ++p) {
if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
+ save = p;
+ if (*p == '\0')
+ return (save);
}
-/* NOTREACHED */
}
#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
+MD_EPROL_LABEL;
#endif
-
diff --git a/lib/csu/hppa/Makefile b/lib/csu/hppa/Makefile
index 110a4b01465..f3dcbbaea5d 100644
--- a/lib/csu/hppa/Makefile
+++ b/lib/csu/hppa/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.9 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.10 2013/12/03 06:21:40 guenther Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -11,14 +11,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/hppa/crt0.c b/lib/csu/hppa/crt0.c
deleted file mode 100644
index 69d2379b6d4..00000000000
--- a/lib/csu/hppa/crt0.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.13 2012/12/22 12:14:32 kettenis Exp $ */
-
-/*
- * Copyright (c) 2001 Michael Shalayeff
- * 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 OR HIS RELATIVES 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 MIND, 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.
- */
-
-int global __asm ("$global$") = 0;
-
-#include <sys/param.h>
-#include <sys/syscall.h>
-#include <sys/fcntl.h>
-#include <sys/exec.h>
-#include <stdlib.h>
-#include <paths.h>
-
-typedef char Obj_Entry;
-
-/*
- * Lots of the chunks of this file cobbled together from pieces of
- * other OpenBSD crt files, including the common code.
- */
-
-char **environ;
-
-extern void __init(void);
-extern void __fini(void);
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char etext, eprol;
-#endif /* MCRT0 */
-
-static char *__strrchr(const char *p, char ch);
-
-char *__progname = "";
-char __progname_storage[NAME_MAX+1];
-
-void ___start(struct ps_strings *arginfo, void (*cleanup)(void));
-
-__asm(
- ".import $global$, data\n\t"
- ".import ___start, code\n\t"
- ".text\n\t"
- ".align 4\n\t"
- ".export _start, entry\n\t"
- ".export __start, entry\n\t"
- ".type _start,@function\n\t"
- ".type __start,@function\n\t"
- ".label _start\n\t"
- ".label __start\n\t"
- ".proc\n\t"
- ".callinfo frame=0, calls\n\t"
- ".entry\n\t"
- "bl L$lpc, %r27\n\t"
- "depi 0, 31, 2, %r27\n\t"
-"L$lpc: addil L'$global$ - ($PIC_pcrel$0 - 8), %r27\n\t"
- "ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27\n\t"
- ".call\n\t"
- "b ___start\n\t"
- "copy %r27, %r19\n\t"
- ".exit\n\t"
- ".procend\n\t");
-
-void
-___start(struct ps_strings *arginfo, void (*cleanup)(void))
-{
- char **argv, *namep;
- char *s;
-
- argv = arginfo->ps_argvstr;
- environ = arginfo->ps_envstr;
- if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = __strrchr(namep, '/')) == NULL)
- __progname = namep;
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&eprol, (u_long)&etext);
-#endif
-
- __init();
-
- exit(main(arginfo->ps_nargvstr, argv, environ));
-}
-
-static char *
-__strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-}
-
-#ifdef MCRT0
-__asm (".export eprol, entry\n\t.label eprol");
-#endif
diff --git a/lib/csu/hppa/md_init.h b/lib/csu/hppa/md_init.h
index 732605ed263..ddd9e8769d2 100644
--- a/lib/csu/hppa/md_init.h
+++ b/lib/csu/hppa/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.3 2012/08/22 17:19:34 pascal Exp $ */
+/* $OpenBSD: md_init.h,v 1.4 2013/12/03 06:21:40 guenther Exp $ */
/*
* Copyright (c) 2003 Dale Rahn. All rights reserved.
@@ -66,3 +66,39 @@
" bv %r0(%r2) \n" \
" ldo -64(%r30),%r30 \n" \
" .previous")
+
+
+#include <sys/exec.h> /* for struct psstrings */
+
+#define MD_CRT0_START \
+ __asm( \
+ ".import $global$, data \n" \
+ " .import ___start, code \n" \
+ " .text \n" \
+ " .align 4 \n" \
+ " .export __start, entry \n" \
+ " .type __start,@function \n" \
+ " .label __start \n" \
+ " .proc \n" \
+ " .callinfo frame=0, calls \n" \
+ " .entry \n" \
+ " bl L$lpc, %r27 \n" \
+ " depi 0, 31, 2, %r27 \n" \
+ "L$lpc: addil L'$global$ - ($PIC_pcrel$0 - 8), %r27 \n" \
+ " ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27 \n" \
+ " .call \n" \
+ " b ___start \n" \
+ " copy %r27, %r19 \n" \
+ " .exit \n" \
+ " .procend")
+
+#define MD_START_ARGS struct ps_strings *arginfo, void (*cleanup)(void)
+#define MD_START_SETUP \
+ char **argv, **envp; \
+ int argc; \
+ \
+ argv = arginfo->ps_argvstr; \
+ argc = arginfo->ps_nargvstr; \
+ environ = envp = arginfo->ps_envstr;
+
+#define MD_EPROL_LABEL __asm (".export _eprol, entry\n\t.label _eprol")
diff --git a/lib/csu/hppa64/Makefile b/lib/csu/hppa64/Makefile
index 8dfda6a36bb..b86144e75ed 100644
--- a/lib/csu/hppa64/Makefile
+++ b/lib/csu/hppa64/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.4 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.5 2013/12/03 06:21:40 guenther Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -11,14 +11,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/hppa64/crt0.c b/lib/csu/hppa64/crt0.c
deleted file mode 100644
index 686d4612407..00000000000
--- a/lib/csu/hppa64/crt0.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.3 2011/07/09 00:12:56 kettenis Exp $ */
-
-/*
- * Copyright (c) 2001 Michael Shalayeff
- * 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 OR HIS RELATIVES 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 MIND, 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.
- */
-
-int global __asm ("$global$") = 0;
-
-#include <sys/param.h>
-#include <sys/syscall.h>
-#include <sys/fcntl.h>
-#include <sys/exec.h>
-#include <stdlib.h>
-#include <paths.h>
-
-typedef char Obj_Entry;
-
-/*
- * Lots of the chunks of this file cobbled together from pieces of
- * other OpenBSD crt files, including the common code.
- */
-
-char **environ;
-
-extern void __init(void);
-extern void __fini(void);
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char etext, eprol;
-#endif /* MCRT0 */
-
-void __start(char **, void (*)(void), const Obj_Entry *);
-static char *__strrchr(const char *p, char ch);
-
-char *__progname = "";
-char __progname_storage[NAME_MAX+1];
-
-void __start(char **sp, void (*cleanup)(void), const Obj_Entry *obj);
-
-__asm(
- ".import $global$, data\n\t"
- ".import ___start, code\n\t"
- ".text\n\t"
- ".align 4\n\t"
- ".export _start, entry\n\t"
- ".export __start, entry\n\t"
- ".type _start,@function\n\t"
- ".type __start,@function\n\t"
- ".label _start\n\t"
- ".label __start\n\t"
- ".proc\n\t"
- ".callinfo frame=0, calls\n\t"
- ".entry\n\t"
- "ldil L%__gp, %r27\n\t"
- ".call\n\t"
- "b ___start\n\t"
- "ldo R%__gp(%r27), %r27\n\t"
- ".exit\n\t"
- ".procend\n\t");
-
-void
-___start(sp, cleanup, obj)
- char **sp;
- void (*cleanup)(void); /* from shared loader */
- const Obj_Entry *obj; /* from shared loader */
-{
- struct ps_strings *arginfo = (struct ps_strings *)sp;
- char **argv, *namep;
- char *s;
-
- argv = arginfo->ps_argvstr;
- environ = arginfo->ps_envstr;
- if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = __strrchr(namep, '/')) == NULL)
- __progname = namep;
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&eprol, (u_long)&etext);
-#endif
-
- __init();
-
- exit(main(arginfo->ps_nargvstr, argv, environ));
-}
-
-static char *
-__strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-}
-
-#ifdef MCRT0
-__asm (".export eprol, entry\n\t.label eprol");
-#endif
diff --git a/lib/csu/hppa64/md_init.h b/lib/csu/hppa64/md_init.h
index 0cbb0b7464d..e7a12034b60 100644
--- a/lib/csu/hppa64/md_init.h
+++ b/lib/csu/hppa64/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.3 2011/09/19 21:05:29 kettenis Exp $ */
+/* $OpenBSD: md_init.h,v 1.4 2013/12/03 06:21:41 guenther Exp $ */
/*
* Copyright (c) 2003 Dale Rahn. All rights reserved.
@@ -58,3 +58,41 @@
" bv %r0(%rp) \n" \
" ldo -128(%sp),%sp \n" \
" .previous")
+
+#include <sys/exec.h> /* for struct psstrings */
+
+/* XXX no cleanup() callback passed to __start yet? */
+#define MD_NO_CLEANUP
+
+#define MD_CRT0_START \
+ __asm( \
+ ".import $global$, data \n" \
+ " .import ___start, code \n" \
+ " .text \n" \
+ " .align 4 \n" \
+ " .export _start, entry \n" \
+ " .export __start, entry \n" \
+ " .type _start,@function \n" \
+ " .type __start,@function \n" \
+ " .label _start \n" \
+ " .label __start \n" \
+ " .proc \n" \
+ " .callin_fo frame=0, calls \n" \
+ " .entry \n" \
+ " ldil L%__gp, %r27 \n" \
+ " .call \n" \
+ " b ___start \n" \
+ " ldo R%__gp(%r27), %r27 \n" \
+ " .exit \n" \
+ " .procend")
+
+#define MD_START_ARGS struct ps_strings *arginfo, void (*cleanup)(void)
+#define MD_START_SETUP \
+ char **argv, **envp; \
+ int argc; \
+ \
+ argv = arginfo->ps_argvstr; \
+ argc = arginfo->ps_nargvstr; \
+ environ = envp = arginfo->ps_envstr;
+
+#define MD_EPROL_LABEL __asm (".export _eprol, entry\n\t.label _eprol")
diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile
index af5594f0f8b..9c38e9b084e 100644
--- a/lib/csu/i386/Makefile
+++ b/lib/csu/i386/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.15 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.16 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -fno-omit-frame-pointer
@@ -14,14 +14,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fpie ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fpie ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/i386/crt0.c b/lib/csu/i386/crt0.c
deleted file mode 100644
index 4760785fb7b..00000000000
--- a/lib/csu/i386/crt0.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.15 2012/12/24 19:28:10 kettenis Exp $ */
-/* $NetBSD: crt0.c,v 1.20 1995/06/03 13:16:08 pk Exp $ */
-
-/*
- * 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.
- */
-
-#include <sys/param.h>
-#include <sys/exec.h>
-#include <stdlib.h>
-
-static char *_strrchr(char *, char);
-
-char **environ;
-char *__progname = "";
-
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-
-__asm(".text\n"
-" .align 4\n"
-" .globl __start\n"
-" .globl _start\n"
-"_start:\n"
-"__start:\n"
-" movl %esp,%ebp\n"
-" andl $~15,%esp # align stack\n"
-" pushl %edx # cleanup\n"
-" movl 0(%ebp),%eax\n"
-" leal 8(%ebp,%eax,4),%ecx\n"
-" leal 4(%ebp),%edx\n"
-" pushl %ecx\n"
-" pushl %edx\n"
-" pushl %eax\n"
-" xorl %ebp,%ebp # mark deepest stack frame\n"
-" call ___start ");
-
-void
-___start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *namep;
- char *s;
-
- environ = envp;
-
- if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(namep, '/')) == NULL)
- __progname = namep;
- else
- ++__progname;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-
-static char *
-_strrchr(p, ch)
-register char *p, ch;
-{
- register char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-/* NOTREACHED */
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
-
diff --git a/lib/csu/i386/md_init.h b/lib/csu/i386/md_init.h
index 5423e02ecd9..584af51599d 100644
--- a/lib/csu/i386/md_init.h
+++ b/lib/csu/i386/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.3 2012/12/23 12:00:48 kettenis Exp $ */
+/* $OpenBSD: md_init.h,v 1.4 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -62,3 +62,25 @@
" leave \n" \
" ret \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 4 \n" \
+ " .globl __start \n" \
+ " .globl _start \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " movl %esp,%ebp \n" \
+ " andl $~15,%esp # align stack\n" \
+ " pushl %edx # cleanup\n" \
+ " movl 0(%ebp),%eax \n" \
+ " leal 8(%ebp,%eax,4),%ecx \n" \
+ " leal 4(%ebp),%edx \n" \
+ " pushl %ecx \n" \
+ " pushl %edx \n" \
+ " pushl %eax \n" \
+ " xorl %ebp,%ebp # mark deepest stack frame\n" \
+ " call ___start \n" \
+ " .previous")
diff --git a/lib/csu/m68k/Makefile b/lib/csu/m68k/Makefile
index 1d3f71d90c6..6a9676e6454 100644
--- a/lib/csu/m68k/Makefile
+++ b/lib/csu/m68k/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.8 2013/02/02 13:29:14 miod Exp $
+# $OpenBSD: Makefile,v 1.9 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -13,14 +13,14 @@ PICFLAG= -fpic
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/m68k/crt0.c b/lib/csu/m68k/crt0.c
deleted file mode 100644
index d1e9a104a42..00000000000
--- a/lib/csu/m68k/crt0.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.10 2013/02/02 13:29:14 miod Exp $ */
-/* $NetBSD: crt0.c,v 1.13 2011/03/07 05:09:10 joerg Exp $ */
-
-/*
- * Copyright (c) 1999 Klaus Klein
- * 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
- * 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.
- *
- * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
- */
-
-#include <stdlib.h>
-#include <limits.h>
-
-static char *_strrchr(char *, char);
-
-char **environ;
-char *__progname = "";
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-static void ___start(int, char **, char **, void (*)(void)) __used;
-
-__asm("\n"
-" .text \n"
-" .align 2 \n"
-" .globl __start \n"
-"__start: \n"
-" movl %sp,%a0 \n"
-" movl (%a0)+,%d0 | argc\n"
-" movl %a1,-(%sp) | cleanup\n"
-" pea 4(%a0,%d0.l*4) | envp\n"
-" movl %a0,-(%sp) | argv\n"
-" movl %d0,-(%sp) | argc\n"
-" jsr ___start");
-
-void
-___start(int argc, char **argv, char **envp,
- void (*cleanup)(void))
-{
- char *s;
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-static char *
-_strrchr(p, ch)
-register char *p, ch;
-{
- register char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-/* NOTREACHED */
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
diff --git a/lib/csu/m68k/md_init.h b/lib/csu/m68k/md_init.h
index 65dcb141f0e..cb1637a4440 100644
--- a/lib/csu/m68k/md_init.h
+++ b/lib/csu/m68k/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2013/02/02 13:29:14 miod Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -53,3 +53,19 @@
".section "#sect",\"ax\",@progbits \n" \
" rts \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 2 \n" \
+ " .globl __start \n" \
+ "__start: \n" \
+ " movl %sp,%a0 \n" \
+ " movl (%a0)+,%d0 | argc \n" \
+ " movl %a1,-(%sp) | cleanup \n" \
+ " pea 4(%a0,%d0.l*4) | envp \n" \
+ " movl %a0,-(%sp) | argv \n" \
+ " movl %d0,-(%sp) | argc \n" \
+ " jsr ___start \n" \
+ ".previous")
diff --git a/lib/csu/m88k/Makefile b/lib/csu/m88k/Makefile
index d186fbdc8d3..c508cd295ff 100644
--- a/lib/csu/m88k/Makefile
+++ b/lib/csu/m88k/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.5 2013/01/15 19:37:08 miod Exp $
+# $OpenBSD: Makefile,v 1.6 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
OBJS= crt0.o gcrt0.o
@@ -16,14 +16,14 @@ PICFLAG= -fpic
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/m88k/crt0.c b/lib/csu/m88k/crt0.c
deleted file mode 100644
index d971a1c521e..00000000000
--- a/lib/csu/m88k/crt0.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.11 2013/05/08 16:06:45 miod Exp $ */
-
-/*
- * Mach Operating System
- * Copyright (c) 1991, 1992 Carnegie Mellon University
- * Copyright (c) 1991, 1992 Omron Corporation
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
-
-/*
- * When a program begins, r31 points to a structure passed by the kernel.
- *
- * This structure contains argc, the argv[] NULL-terminated array, and
- * the envp[] NULL-terminated array.
- */
-
-#include <sys/param.h>
-#include <stdlib.h>
-
-char **environ;
-char *__progname = "";
-
-char __progname_storage[NAME_MAX + 1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-static inline char *_strrchr(const char *p, char ch);
-
-__asm__ (
-" .text\n"
-" .align 3\n"
-" .globl __start\n"
-" .globl _start\n"
-"__start:\n"
-"_start:\n"
-" or %r0, %r0, %r0\n" /* two nop because execution may */
-" or %r0, %r0, %r0\n" /* skip up to two instructions */
- /* see setregs() in the kernel */
- /* for details. */
-" ld %r2, %r31, 0\n" /* argc */
-" addu %r3, %r31, 4\n" /* argv */
-" lda %r4, %r3[%r2]\n"
-" br.n ___start\n"
-" addu %r4, %r4, 4\n" /* envp = argv + argc + 1 */
-/* cleanup is %r5, zeroed in setregs() at the moment */
-);
-
-void
-___start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *s;
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-static char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-}
-
-#ifdef MCRT0
-asm("\t.text\n_eprol:\n");
-#endif
diff --git a/lib/csu/m88k/md_init.h b/lib/csu/m88k/md_init.h
index 76a4e2c9cf2..09bced2614b 100644
--- a/lib/csu/m88k/md_init.h
+++ b/lib/csu/m88k/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2013/01/05 11:20:55 miod Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*
* Copyright (c) 2012 Miodrag Vallat.
@@ -37,3 +37,30 @@
"\tjmp.n\t%r1\n" \
"\taddu\t%r31, %r31, 16\n" \
"\t.previous")
+
+/*
+ * When a program begins, r31 points to a structure passed by the kernel.
+ *
+ * This structure contains argc, the argv[] NULL-terminated array, and
+ * the envp[] NULL-terminated array.
+ *
+ * Our start code starts with two nops because execution may skip up to
+ * two instructions; see setregs() in the kernel for details.
+ */
+#define MD_CRT0_START \
+ __asm( \
+ " .text \n" \
+ " .align 3 \n" \
+ " .globl __start \n" \
+ " .globl _start \n" \
+ "__start: \n" \
+ "_start: \n" \
+ " or %r0, %r0, %r0 \n" \
+ " or %r0, %r0, %r0 \n" \
+ " ld %r2, %r31, 0 /* argc */ \n" \
+ " addu %r3, %r31, 4 /* argv */ \n" \
+ " lda %r4, %r3[%r2] \n" \
+ " br.n ___start \n" \
+ " addu %r4, %r4, 4 \n" \
+ " /* envp = argv + argc + 1 */ \n" \
+ " .previous");
diff --git a/lib/csu/mips64/Makefile b/lib/csu/mips64/Makefile
index 4af9c83fa2d..a77ef54e8d1 100644
--- a/lib/csu/mips64/Makefile
+++ b/lib/csu/mips64/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.4 2013/12/01 17:18:31 guenther Exp $
+# $OpenBSD: Makefile,v 1.5 2013/12/03 06:21:41 guenther Exp $
#CFLAGS+= -I${.CURDIR} -mips2
CFLAGS+= -I${.CURDIR}
@@ -9,14 +9,14 @@ OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
all: ${OBJS}
crt0.o: crt0.c ${DEPS}
- @echo "${CC} -DCRT0 -c ${.ALLSRC} -o ${.TARGET}"
- @${CC} -DCRT0 -c ${.ALLSRC} -o ${.TARGET}.o
+ @echo "${COMPILE.c} -DCRT0 -c ${.ALLSRC} -o ${.TARGET}"
+ @${COMPILE.c} -DCRT0 -c ${.ALLSRC} -o ${.TARGET}.o
@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c ${DEPS}
- @echo "${CC} -DMCRT0 -c ${.ALLSRC} -o ${.TARGET}"
- @${CC} -DMCRT0 -c ${.ALLSRC} -o ${.TARGET}.o
+ @echo "${COMPILE.c} -DMCRT0 -c ${.ALLSRC} -o ${.TARGET}"
+ @${COMPILE.c} -DMCRT0 -c ${.ALLSRC} -o ${.TARGET}.o
@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
diff --git a/lib/csu/mips64/crt0.c b/lib/csu/mips64/crt0.c
deleted file mode 100644
index 409227b122a..00000000000
--- a/lib/csu/mips64/crt0.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.6 2010/09/12 12:13:51 kettenis Exp $ */
-/* $NetBSD: crt0.c,v 1.7 1995/06/03 13:16:15 pk Exp $ */
-/*
- * Copyright (c) 1993 Paul Kranenburg
- * 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 Paul Kranenburg.
- * 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/param.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-extern void __init __P((void));
-extern void _mcleanup __P((void));
-extern unsigned char eprol asm ("eprol");
-extern unsigned char etext;
-
-char **environ;
-static char empty[1];
-char *__progname = empty;
-void __perf_init __P((void));
-
-static inline int
-_perfcall(int func, void *arg)
-{
- int status = 0;
-#if 0
- __asm__ volatile ( "move $4, %1\n\t"
- "move $5, %2\n\t"
- "teqi $0, 0\n\t"
- "move %0, $2"
- : "=r" (status)
- : "r" (func), "r" (arg)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10",
- "$11", "$12","$13","$14","$15","$24","$25", "memory");
-#endif
- return(status);
-}
-
-void
-__start()
-{
- struct kframe {
- long kargc;
- char *kargv[1]; /* size depends on kargc */
- char kargstr[1]; /* size varies */
- char kenvstr[1]; /* size varies */
- };
-
- register struct kframe *kfp;
- register char **argv, *ap;
-
-/*
- * Do GP register setup. Differs depending on shared lib stuff or not.
- */
-#if defined(_NO_ABICALLS)
- asm(" dla $28,_gp");
- asm(" daddiu %0,$29,32" : "=r" (kfp));
-#else
-#if defined(__GNUC__) && __GNUC__ > 3
- asm(" daddiu %0,$29,64" : "=r" (kfp));
-#else
- asm(" daddiu %0,$29,80" : "=r" (kfp));
-#endif
-#endif
- /* just above the saved frame pointer
- kfp = (struct kframe *) (&param-1);*/
- argv = &kfp->kargv[0];
- environ = argv + kfp->kargc + 1;
-
- if (ap = argv[0])
- if ((__progname = strrchr(ap, '/')) == NULL)
- __progname = ap;
- else
- ++__progname;
-
-asm("eprol:");
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&eprol, (u_long)&etext);
-#endif /*MCRT0*/
-
- __init();
- __perf_init();
-
-asm ("_callmain:"); /* Defined for the benefit of debuggers */
- exit(main(kfp->kargc, argv, environ));
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
-
-/************/
-#include <stdio.h>
-
-void _perf_cleanup __P((void));
-
-#define PCNT_CE 0x0400 /* Count enable */
-#define PCNT_UM 0x0200 /* Count in User mode */
-#define PCNT_KM 0x0100 /* Count in kernel mode */
-
-#define PCNT_FNC_SELECT 0x0001 /* Select counter source */
-#define PCNT_FNC_READ 0x0002 /* Read current value of counter */
-
-struct cname {
- char *name;
- int cval;
-} cn_tab[] = {
- { "CLOCKS", 0x00 },
- { "INSTR", 0x01 },
- { "FPINSTR", 0x02 },
- { "IINSTR", 0x03 },
- { "LOAD", 0x04 },
- { "STORE", 0x05 },
- { "DUAL", 0x06 },
- { "BRPREF", 0x07 },
- { "EXTMISS", 0x08 },
- { "STALL", 0x09 },
- { "SECMISS", 0x0a },
- { "INSMISS", 0x0b },
- { "DTAMISS", 0x0c },
- { "DTLBMISS", 0x0d },
- { "ITLBMISS", 0x0e },
- { "JTLBIMISS", 0x0f },
- { "JTLBDMISS", 0x10 },
- { "BRTAKEN", 0x11 },
- { "BRISSUED", 0x12 },
- { "SECWBACK", 0x13 },
- { "PRIWBACK", 0x14 },
- { "DCSTALL", 0x15 },
- { "MISS", 0x16 },
- { "FPEXC", 0x17 },
- { "MULSLIP", 0x18 },
- { "CP0SLIP", 0x19 },
- { "LDSLIP", 0x1a },
- { "WBFULL", 0x1b },
- { "CISTALL", 0x1c },
- { "MULSTALL", 0x1d },
- { "ELDSTALL", 0x1e },
-};
-#define NCNTAB (sizeof(cn_tab) / sizeof(struct cname))
-
-void
-__perf_init()
-{
- long pselect;
- char *cn;
-
- if((cn = getenv("__PERF_SELECT")) == NULL) {
- return;
- }
-
- for(pselect = 0; pselect < NCNTAB; pselect++) {
- if(strcmp(cn, cn_tab[pselect].name) == 0) {
- pselect = cn_tab[pselect].cval;
- break;
- }
- }
- if(pselect >= NCNTAB) {
- fprintf(stderr, "!! Invalid __PERF_SELECT !!\n");
- exit(255);
- }
- _perfcall(PCNT_FNC_SELECT, (void *)(PCNT_CE|PCNT_UM|pselect)); /*XXX*/
- atexit(_perf_cleanup);
-
- if((cn = getenv("__PERF_START")) == NULL) {
- return;
- }
-}
-
-void
-_perf_cleanup()
-{
- quad_t countvalue;
-
- _perfcall(PCNT_FNC_READ, &countvalue);
- printf("\ncount = %qd.\n", countvalue);
-}
diff --git a/lib/csu/mips64/md_init.h b/lib/csu/mips64/md_init.h
index 3270bbd6932..51a6d0b33ed 100644
--- a/lib/csu/mips64/md_init.h
+++ b/lib/csu/mips64/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.2 2004/09/09 17:45:26 pefo Exp $ */
+/* $OpenBSD: md_init.h,v 1.3 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -87,3 +87,51 @@
" jal " #func " \n" \
".previous")
+
+struct kframe {
+ int kargc;
+ char *kargv[1]; /* size depends on kargc */
+ char kargstr[1]; /* size varies */
+ char kenvstr[1]; /* size varies */
+};
+
+#define MD_START __start
+#define MD_START_ARGS void
+
+/*
+ * XXX no cleanup() callback passed to __start yet. Need to pull
+ * it from v0 in ASM?
+ */
+#define MD_NO_CLEANUP
+
+
+/*
+ * Do GP register setup and find the kframe struct. Differs depending
+ * on shared lib stuff or not.
+ * XXX just above the saved frame pointer?
+ * kfp = (struct kframe *) (&param-1);
+ */
+#if defined(_NO_ABICALLS)
+#define SETUP_KFP(kfp) \
+ asm(" dla $28,_gp \n" \
+ " daddiu %0,$29,32" : "=r" (kfp))
+#else
+#if defined(__GNUC__) && __GNUC__ > 3
+#define SETUP_KFP(kfp) \
+ asm(" daddiu %0,$29,64" : "=r" (kfp))
+#else
+#define SETUP_KFP(kfp) \
+ asm(" daddiu %0,$29,80" : "=r" (kfp))
+#endif
+#endif
+
+
+#define MD_START_SETUP \
+ struct kframe *kfp; \
+ char **argv, **envp; \
+ int argc; \
+ \
+ SETUP_KFP(kfp); \
+ argc = kfp->kargc; \
+ argv = &kfp->kargv[0]; \
+ environ = envp = argv + argc + 1;
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
index 2d275d3e91f..7168c8fd398 100644
--- a/lib/csu/powerpc/Makefile
+++ b/lib/csu/powerpc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.22 2012/12/19 20:26:52 kettenis Exp $
+# $OpenBSD: Makefile,v 1.23 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
OBJS= crt0.o gcrt0.o
@@ -15,14 +15,14 @@ PICFLAG= -fPIC
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -fpie -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -fpie -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -fpie -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -fpie -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/powerpc/crt0.c b/lib/csu/powerpc/crt0.c
deleted file mode 100644
index a1fcde53b89..00000000000
--- a/lib/csu/powerpc/crt0.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.8 2013/12/01 17:18:31 guenther Exp $ */
-/* $NetBSD: crt0.c,v 1.1 1996/09/12 16:59:02 cgd Exp $ */
-/*
- * 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.
- */
-#include <sys/param.h>
-#include <stdlib.h>
-#include <sys/syscall.h>
-
-char **environ;
-char * __progname = "";
-
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-static inline char * _strrchr(const char *p, char ch);
-
-#define STR(x) __STRING(x)
-__asm(
-" .text \n"
-" .section \".text\" \n"
-" .align 2 \n"
-" .size __got_start, 0 \n"
-" .type __got_start, @object \n"
-" .size __got_end, 0 \n"
-" .type __got_end, @object \n"
-" .weak __got_start \n"
-" .weak __got_end \n"
-" .globl _start \n"
-" .type _start, @function \n"
-" .globl __start \n"
-" .type __start, @function \n"
-"_start: \n"
-"__start: \n"
-" # move argument registers to saved registers for startup flush \n"
-" mr %r26, %r3 \n"
-" mr %r25, %r4 \n"
-" mr %r24, %r5 \n"
-" mr %r23, %r6 \n"
-" mr %r22, %r7 \n"
-" mflr %r27 /* save off old link register */ \n"
-" bl 1f \n"
-" # this instruction never gets executed but can be used \n"
-" # to find the virtual address where the page is loaded. \n"
-" bl _GLOBAL_OFFSET_TABLE_@local-4 \n"
-"1: \n"
-" mflr %r6 # this stores where we are (+4) \n"
-" lwz %r18, 0(%r6) # load the instruction at offset_sym \n"
-" # it contains an offset to the location \n"
-" # of the GOT. \n"
-" \n"
-" rlwinm %r18,%r18,0,8,30 # mask off the offset portion of the instr. \n"
-" \n"
-" /* \n"
-" * these adds effectively calculate the value the \n"
-" * bl _GLOBAL_OFFSET_TABLE_@local-4 \n"
-" * operation that would be below would calculate. \n"
-" */ \n"
-" add %r28, %r18, %r6 \n"
-" \n"
-" addi %r3,%r28,4 # calculate the actual got addr \n"
-" lwz %r0,__got_start@got(%r3) \n"
-" cmpwi %r0,0 \n"
-" beq 4f \n"
-" cmpw %r0,%r28 \n"
-" bne 4f \n"
-" lwz %r4,__got_end@got(%r3) \n"
-" cmpwi %r4,0 \n"
-" beq 2f \n"
-" \n"
-" sub %r4, %r4, %r0 \n"
-" b 3f \n"
-"2: \n"
-" li %r4, 4 \n"
-"3: \n"
-" \n"
-" /* mprotect GOT to eliminate W+X regions in static binaries */ \n"
-" li %r0, " STR(SYS_mprotect) " \n"
-" mr %r3, %r28 \n"
-" li %r5, 5 /* (PROT_READ|PROT_EXEC) */ \n"
-" sc \n"
-" \n"
-"4: \n"
-" li %r0, 0 \n"
-" # flush the blrl instruction out of the data cache \n"
-" dcbf %r6, %r18 \n"
-" sync \n"
-" isync \n"
-" # make certain that the got table addr is not in the icache \n"
-" icbi %r6, %r18 \n"
-" sync \n"
-" isync \n"
-" mtlr %r27 \n"
-" # move argument registers back from saved registers \n"
-" mr %r3, %r26 \n"
-" mr %r4, %r25 \n"
-" mr %r5, %r24 \n"
-" mr %r6, %r23 \n"
-" mr %r7, %r22 \n"
-" b ___start \n"
-);
-
-void
-___start(int argc, char **argv, char **envp, void *aux, void (*cleanup)(void))
-{
- char *s;
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-static inline char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-/* NOTREACHED */
-}
-asm (" .section \".text\" \n_eprol:");
-
diff --git a/lib/csu/powerpc/md_init.h b/lib/csu/powerpc/md_init.h
index c7953143668..3fab44b9a98 100644
--- a/lib/csu/powerpc/md_init.h
+++ b/lib/csu/powerpc/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -60,3 +60,91 @@
" addi %r1,%r1,16 \n" \
" blr \n" \
" .previous")
+
+#include <sys/syscall.h> /* for SYS_mprotect */
+
+#define STR(x) __STRING(x)
+#define MD_CRT0_START \
+__asm( \
+" .text \n" \
+" .section \".text\" \n" \
+" .align 2 \n" \
+" .size __got_start, 0 \n" \
+" .type __got_start, @object \n" \
+" .size __got_end, 0 \n" \
+" .type __got_end, @object \n" \
+" .weak __got_start \n" \
+" .weak __got_end \n" \
+" .globl _start \n" \
+" .type _start, @function \n" \
+" .globl __start \n" \
+" .type __start, @function \n" \
+"_start: \n" \
+"__start: \n" \
+" # move argument registers to saved registers for startup flush \n" \
+" # ...except r6 (auxv) as ___start() doesn't need it \n" \
+" mr %r25, %r3 \n" \
+" mr %r24, %r4 \n" \
+" mr %r23, %r5 \n" \
+" mr %r22, %r7 \n" \
+" mflr %r27 /* save off old link register */ \n" \
+" bl 1f \n" \
+" # this instruction never gets executed but can be used \n" \
+" # to find the virtual address where the page is loaded. \n" \
+" bl _GLOBAL_OFFSET_TABLE_@local-4 \n" \
+"1: \n" \
+" mflr %r6 # this stores where we are (+4) \n" \
+" lwz %r18, 0(%r6) # load the instruction at offset_sym \n" \
+" # it contains an offset to the location \n" \
+" # of the GOT. \n" \
+" \n" \
+" rlwinm %r18,%r18,0,8,30 # mask off the offset portion of the instr. \n" \
+" \n" \
+" /* \n" \
+" * these adds effectively calculate the value the \n" \
+" * bl _GLOBAL_OFFSET_TABLE_@local-4 \n" \
+" * operation that would be below would calculate. \n" \
+" */ \n" \
+" add %r28, %r18, %r6 \n" \
+" \n" \
+" addi %r3,%r28,4 # calculate the actual got addr \n" \
+" lwz %r0,__got_start@got(%r3) \n" \
+" cmpwi %r0,0 \n" \
+" beq 4f \n" \
+" cmpw %r0,%r28 \n" \
+" bne 4f \n" \
+" lwz %r4,__got_end@got(%r3) \n" \
+" cmpwi %r4,0 \n" \
+" beq 2f \n" \
+" \n" \
+" sub %r4, %r4, %r0 \n" \
+" b 3f \n" \
+"2: \n" \
+" li %r4, 4 \n" \
+"3: \n" \
+" \n" \
+" /* mprotect GOT to eliminate W+X regions in static binaries */ \n" \
+" li %r0, " STR(SYS_mprotect) " \n" \
+" mr %r3, %r28 \n" \
+" li %r5, 5 /* (PROT_READ|PROT_EXEC) */ \n" \
+" sc \n" \
+" \n" \
+"4: \n" \
+" li %r0, 0 \n" \
+" # flush the blrl instruction out of the data cache \n" \
+" dcbf %r6, %r18 \n" \
+" sync \n" \
+" isync \n" \
+" # make certain that the got table addr is not in the icache \n" \
+" icbi %r6, %r18 \n" \
+" sync \n" \
+" isync \n" \
+" mtlr %r27 \n" \
+" # move argument registers back from saved registers \n" \
+" # putting cleanup in r6 instead of r7 \n" \
+" mr %r3, %r25 \n" \
+" mr %r4, %r24 \n" \
+" mr %r5, %r23 \n" \
+" mr %r6, %r22 \n" \
+" b ___start \n" \
+)
diff --git a/lib/csu/sh/Makefile b/lib/csu/sh/Makefile
index d5e2faa724c..2e59cd613c1 100644
--- a/lib/csu/sh/Makefile
+++ b/lib/csu/sh/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.5 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.6 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -11,14 +11,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fpie -DPIC ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fpie -DPIC ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fpie -DPIC ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fpie -DPIC ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/sh/crt0.c b/lib/csu/sh/crt0.c
deleted file mode 100644
index 0f547a3a1d0..00000000000
--- a/lib/csu/sh/crt0.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.7 2013/12/01 17:18:31 guenther Exp $ */
-/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $ */
-
-/*
- * Copyright (c) 1998 Christos Zoulas
- * 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
- * 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.
- *
- * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
- */
-
-#include <sys/param.h>
-
-#include <machine/asm.h>
-#include <machine/fpu.h>
-#include <stdlib.h>
-
-static char *_strrchr(const char *, char);
-
-char **environ;
-
-char * __progname = "";
-
-char __progname_storage[NAME_MAX+1];
-
-#if defined(__SH4__) && !defined(__SH4_NOFPU__)
-unsigned int __fpscr_values[2];
-#endif
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-void __start(int, char *[], char *[], void (*)(void));
-
-void
-__start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *s;
-
-#if defined(__SH4__) && !defined(__SH4_NOFPU__)
- extern void __set_fpscr(unsigned int);
-
- __set_fpscr(0);
- __fpscr_values[0] |= FPSCR_DN;
- __fpscr_values[1] |= FPSCR_DN;
- __asm__ __volatile__ ("lds %0, fpscr" : : "r" (__fpscr_values[1]));
-#endif
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif /* MCRT0 */
-
- __init();
-
-__asm("__callmain:"); /* Defined for the benefit of debuggers */
- exit(main(argc, argv, envp));
-}
-
-static char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
- /* NOTREACHED */
-}
-asm (" .section \".text\" \n_eprol:");
diff --git a/lib/csu/sh/md_init.h b/lib/csu/sh/md_init.h
index c3885ad22a5..2d600e25dee 100644
--- a/lib/csu/sh/md_init.h
+++ b/lib/csu/sh/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2006/10/10 22:07:10 miod Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/* $NetBSD: dot_init.h,v 1.3 2005/12/24 22:02:10 perry Exp $ */
/*-
@@ -66,3 +66,23 @@ __asm(".section " #section "\n" \
"0: .p2align 2 \n" \
"1: .long " #func " - 0b \n" \
"2: .previous");
+
+
+/* no ASM stub for __start; the C routine can be called directly */
+#define MD_START __start
+
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+#include <machine/fpu.h>
+
+#define MD_CRT0_START \
+ void __set_fpscr(unsigned int); \
+ unsigned int __fpscr_values[2]
+
+#define MD_START_SETUP \
+ __set_fpscr(0); \
+ __fpscr_values[0] |= FPSCR_DN; \
+ __fpscr_values[1] |= FPSCR_DN; \
+ __asm __volatile__ ("lds %0, fpscr" \
+ : : "r" (__fpscr_values[1]));
+#endif /* defined(__SH4__) && !defined(__SH4_NOFPU__) */
+
diff --git a/lib/csu/sparc/Makefile b/lib/csu/sparc/Makefile
index 0d16180a4ce..83ca2230804 100644
--- a/lib/csu/sparc/Makefile
+++ b/lib/csu/sparc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.12 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.13 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -13,14 +13,14 @@ PICFLAG= -fPIC
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/sparc/crt0.c b/lib/csu/sparc/crt0.c
deleted file mode 100644
index 43cc5ac5301..00000000000
--- a/lib/csu/sparc/crt0.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/* $NetBSD: crt0.c,v 1.9 2000/06/14 22:52:50 cgd Exp $ */
-
-/*
- * Copyright (c) 1998 Christos Zoulas
- * 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
- * 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.
- *
- * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
- */
-
-#include <stdlib.h>
-#include <limits.h>
-
-void ___start(int, char **, char **, void (*cleanup)(void));
-
-__asm(
-" .text\n"
-" .align 4\n"
-" .global __start\n"
-" .global _start\n"
-"__start:\n"
-"_start:\n"
-" mov 0, %fp\n"
-" ld [%sp + 64], %o0 ! get argc\n"
-" add %sp, 68, %o1 ! get argv\n"
-" sll %o0, 2, %o2\n"
-" add %o2, 4, %o2 ! envp = argv + (argc << 2) + 4\n"
-" add %o1, %o2, %o2\n"
-" andn %sp, 7, %sp ! align\n"
-" sub %sp, 24, %sp ! expand to standard stack frame size\n"
-" call ___start\n"
-" mov %g1, %o3\n"
-);
-
-char **environ;
-char *__progname = "";
-char __progname_storage[NAME_MAX+1];
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif /* MCRT0 */
-
-static char *_strrchr(const char *, char);
-
-void
-___start(int argc, char **argv, char **envp, void (*cleanup)(void))
-{
- char *s;
-
- environ = envp;
-
- if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
- if (cleanup)
- atexit(cleanup);
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif
-
- __init();
-
- exit(main(argc, argv, environ));
-}
-
-static char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL;; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (!*p)
- return(save);
- }
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
diff --git a/lib/csu/sparc/md_init.h b/lib/csu/sparc/md_init.h
index 30c0116ede0..cf102f4dd64 100644
--- a/lib/csu/sparc/md_init.h
+++ b/lib/csu/sparc/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -57,3 +57,24 @@
" ret \n" \
" restore \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 4 \n" \
+ " .global __start \n" \
+ " .global _start \n" \
+ "__start: \n" \
+ "_start: \n" \
+ " mov 0, %fp \n" \
+ " ld [%sp + 64], %o0 ! get argc\n" \
+ " add %sp, 68, %o1 ! get argv\n" \
+ " sll %o0, 2, %o2 \n" \
+ " add %o2, 4, %o2 ! envp = argv + (argc << 2) + 4\n" \
+ " add %o1, %o2, %o2 \n" \
+ " andn %sp, 7, %sp ! align \n" \
+ " sub %sp, 24, %sp ! expand to standard frame size\n" \
+ " call ___start \n" \
+ " mov %g1, %o3 \n" \
+ " .previous")
diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile
index ad86dbe40be..1cb19d20c04 100644
--- a/lib/csu/sparc64/Makefile
+++ b/lib/csu/sparc64/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.9 2011/11/08 10:37:09 guenther Exp $
+# $OpenBSD: Makefile,v 1.10 2013/12/03 06:21:41 guenther Exp $
# $NetBSD: Makefile,v 1.6 1996/10/18 05:27:38 thorpej Exp $
CFLAGS+= -DELFSIZE=64
@@ -14,14 +14,14 @@ CFLAGS+= -I${ELFDIR} -I${.CURDIR}
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 -fPIC ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 -fPIC ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 -fPIC ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 -fPIC ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/sparc64/md_init.h b/lib/csu/sparc64/md_init.h
index 045199de0b9..4120c590320 100644
--- a/lib/csu/sparc64/md_init.h
+++ b/lib/csu/sparc64/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2004/01/08 14:59:15 drahn Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@@ -57,3 +57,27 @@
" ret \n" \
" restore \n" \
" .previous")
+
+
+#define MD_CRT0_START \
+ __asm__( \
+ ".text \n" \
+ " .align 4 \n" \
+ " .global _start \n" \
+ " .global __start \n" \
+ "_start: \n" \
+ "__start: \n" \
+ " clr %fp \n" \
+ " add %sp, 2175, %o0 /* stack */\n" \
+ " ba,pt %icc, ___start \n" \
+ " mov %g1, %o1 \n" \
+ " .previous")
+
+#define MD_START_ARGS char **sp, void (*cleanup)(void)
+#define MD_START_SETUP \
+ char **argv, **envp; \
+ long argc; \
+ \
+ argc = *(long *)sp; \
+ argv = sp + 1; \
+ environ = envp = sp + 2 + argc; /* 2: argc + NULL ending argv */
diff --git a/lib/csu/vax/Makefile b/lib/csu/vax/Makefile
index bc0a4d57364..dceeb1e039c 100644
--- a/lib/csu/vax/Makefile
+++ b/lib/csu/vax/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.9 2013/07/05 21:10:50 miod Exp $
+# $OpenBSD: Makefile,v 1.10 2013/12/03 06:21:41 guenther Exp $
# from: @(#)Makefile 5.6 (Berkeley) 5/22/91
OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
@@ -14,14 +14,14 @@ PICFLAG=
all: ${OBJS}
crt0.o: crt0.c
- @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
gcrt0.o: crt0.c
- @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
+ @echo ${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DMCRT0 ${ELFDIR}/crt0.c -o ${.TARGET}.o
@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
diff --git a/lib/csu/vax/crt0.c b/lib/csu/vax/crt0.c
deleted file mode 100644
index b30622053e1..00000000000
--- a/lib/csu/vax/crt0.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/* $OpenBSD: crt0.c,v 1.10 2013/07/05 21:10:50 miod Exp $ */
-/* $NetBSD: crt0.c,v 1.14 2002/05/16 19:38:21 wiz Exp $ */
-
-/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Paul Kranenburg.
- *
- * 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 the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 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 <stdlib.h>
-#include <limits.h>
-
-#ifdef MCRT0
-extern void monstartup(u_long, u_long);
-extern void _mcleanup(void);
-extern unsigned char _etext, _eprol;
-#endif
-
-char **environ;
-char *__progname = "";
-char __progname_storage[1 + NAME_MAX];
-
-static char *_strrchr(const char *, char);
-
-struct kframe {
- int kargc;
- char *kargv[1]; /* size depends on kargc */
- char kargstr[1]; /* size varies */
- char kenvstr[1]; /* size varies */
-};
-
- asm(" .text");
- asm(" .align 2");
- asm(" .globl _start");
- asm(" .type _start,@function");
- asm(" _start:");
- asm(" .word 0x0101"); /* two nops just in case */
- asm(" pushl %sp"); /* no registers to save */
- asm(" calls $1,__start"); /* do the real start */
- asm(" halt");
-
-void
-__start(struct kframe *kfp)
-{
- char **argv, *ap;
- char *s;
-
- argv = &kfp->kargv[0];
- environ = argv + kfp->kargc + 1;
-
- if ((__progname = argv[0]) != NULL) {
- if ((__progname = _strrchr(__progname, '/')) == NULL)
- __progname = argv[0];
- else
- __progname++;
- for (s = __progname_storage; *__progname &&
- s < &__progname_storage[sizeof __progname_storage - 1]; )
- *s++ = *__progname++;
- *s = '\0';
- __progname = __progname_storage;
- }
-
-#ifdef MCRT0
- atexit(_mcleanup);
- monstartup((u_long)&_eprol, (u_long)&_etext);
-#endif /* MCRT0 */
-
- __init();
-
-asm ("__callmain:"); /* Defined for the benefit of debuggers */
- exit(main(kfp->kargc, argv, environ));
-}
-
-static char *
-_strrchr(const char *p, char ch)
-{
- char *save;
-
- for (save = NULL; ; ++p) {
- if (*p == ch)
- save = (char *)p;
- if (*p == '\0')
- return (save);
- }
-}
-
-#ifdef MCRT0
-asm (" .text");
-asm ("_eprol:");
-#endif
diff --git a/lib/csu/vax/md_init.h b/lib/csu/vax/md_init.h
index 335c51fb5f5..cad67623fad 100644
--- a/lib/csu/vax/md_init.h
+++ b/lib/csu/vax/md_init.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: md_init.h,v 1.1 2013/07/05 21:10:50 miod Exp $ */
+/* $OpenBSD: md_init.h,v 1.2 2013/12/03 06:21:41 guenther Exp $ */
/*
* Copyright (c) 2008 Miodrag Vallat.
@@ -34,3 +34,40 @@
"\t.section\t" #section ",\"ax\",@progbits\n" \
"\tret\n" \
"\t.previous")
+
+/*
+ * _start has no registers to save before calling the real start.
+ * _start has two nops, just in case (c.f. m88k?).
+ */
+#define MD_CRT0_START \
+ __asm( \
+ ".text \n" \
+ " .align 2 \n" \
+ " .globl _start \n" \
+ " .type _start,@function \n" \
+ "_start: \n" \
+ " .word 0x0101 \n" \
+ " pushl %sp \n" \
+ " calls $1,___start \n" \
+ " halt \n" \
+ " .previous")
+
+struct kframe {
+ int kargc;
+ char *kargv[1]; /* size depends on kargc */
+ char kargstr[1]; /* size varies */
+ char kenvstr[1]; /* size varies */
+};
+
+/* no cleanup() callback passed to ___start, because no ld.so */
+#define MD_NO_CLEANUP
+
+#define MD_START_ARGS struct kframe *kfp
+#define MD_START_SETUP \
+ char **argv, **envp; \
+ int argc; \
+ \
+ argc = kfp->kargc; \
+ argv = &kfp->kargv[0]; \
+ environ = envp = argv + argc + 1;
+