summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2013-01-05 11:20:52 +0000
committermiod <miod@openbsd.org>2013-01-05 11:20:52 +0000
commit0b514a0798ffc86c581fc3611e7adb25cce99305 (patch)
tree2b36cbda37a019f9cf96e473dab56a2daf9a1761 /lib/csu
parentif defined(NOPIC), do not attempt to .include arch/Makefile.inc for it may (diff)
downloadwireguard-openbsd-0b514a0798ffc86c581fc3611e7adb25cce99305.tar.xz
wireguard-openbsd-0b514a0798ffc86c581fc3611e7adb25cce99305.zip
Switch m88k ports to ELF.
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/m88k/Makefile72
-rw-r--r--lib/csu/m88k/crt0.c83
-rw-r--r--lib/csu/m88k/md_init.h39
3 files changed, 138 insertions, 56 deletions
diff --git a/lib/csu/m88k/Makefile b/lib/csu/m88k/Makefile
index d6cac6be23c..67a803909ea 100644
--- a/lib/csu/m88k/Makefile
+++ b/lib/csu/m88k/Makefile
@@ -1,46 +1,64 @@
-# $OpenBSD: Makefile,v 1.3 2011/11/08 10:37:09 guenther Exp $
-# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
+# $OpenBSD: Makefile,v 1.4 2013/01/05 11:20:55 miod Exp $
+# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
-CFLAGS+= -I${.CURDIR}/..
-OBJS= crt0.o gcrt0.o scrt0.o
-SRCS= crt0.c
+OBJS= crt0.o gcrt0.o
+OBJS+= crtbegin.o crtend.o
+OBJS+= crtbeginS.o crtendS.o
+SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
-.if !defined(NOPIC)
-DYNAMIC = -DDYNAMIC
-.endif
+ELFDIR= ${.CURDIR}/../common_elf
+.PATH: ${ELFDIR}
+CFLAGS+= -I${ELFDIR} -I${.CURDIR}
+
+#PICFLAG= -fpic
+PICFLAG=
all: ${OBJS}
-crt0.o: ${SRCS}
- @echo "${COMPILE.c} -DCRT0 ${DYNAMIC} ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o
- @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
+crt0.o: crt0.c
+ @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
+ @${COMPILE.c} -DCRT0 ${.CURDIR}/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
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+crtbegin.o: crtbegin.c
+ @echo ${COMPILE.c} ${ELFDIR}/crtbegin.c -o ${.TARGET}
+ @${COMPILE.c} ${ELFDIR}/crtbegin.c -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+crtbeginS.o: crtbeginS.c
+ @echo ${COMPILE.c} ${PICFLAG} ${ELFDIR}/crtbeginS.c -o ${.TARGET}
+ @${COMPILE.c} ${PICFLAG} ${ELFDIR}/crtbeginS.c -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
-gcrt0.o: ${SRCS}
- @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o
- @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
+crtend.o: crtend.c
+ @echo ${COMPILE.c} ${ELFDIR}/crtend.c -o ${.TARGET}
+ @${COMPILE.c} ${ELFDIR}/crtend.c -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
-scrt0.o: ${SRCS}
- @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o
- @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
+crtendS.o: crtendS.c
+ @echo ${COMPILE.c} ${PICFLAG} ${ELFDIR}/crtendS.c -o ${.TARGET}
+ @${COMPILE.c} ${PICFLAG} ${ELFDIR}/crtendS.c -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
realinstall:
${INSTALL} ${INSTALL_COPY} -S -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
${DESTDIR}/usr/lib
-.if make(depend)
-CPPFLAGS+= -DDYNAMIC
-.endif
-
-afterdepend: .depend
+afterdepend:: .depend
@(TMP=/tmp/_depend$$$$; \
- sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \
- < .depend > $$TMP; \
+ sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o:/' \
+ < .depend > $$TMP; \
mv $$TMP .depend)
.include <bsd.prog.mk>
diff --git a/lib/csu/m88k/crt0.c b/lib/csu/m88k/crt0.c
index fc4cc1ab4aa..58c42ed4fd1 100644
--- a/lib/csu/m88k/crt0.c
+++ b/lib/csu/m88k/crt0.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crt0.c,v 1.9 2005/08/04 16:33:05 espie Exp $ */
+/* $OpenBSD: crt0.c,v 1.10 2013/01/05 11:20:55 miod Exp $ */
/*
* Mach Operating System
@@ -34,37 +34,53 @@
* the envp[] NULL-terminated array.
*/
+#include <sys/param.h>
#include <stdlib.h>
-#include "common.h"
+char **environ;
+char *__progname = "";
-struct kframe {
- int argc;
- char *argv[0];
-};
+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 8\n"
-" .globl start\n"
-"start:\n"
-" br.n _start\n"
-" or r2, r31, r0\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 */
);
static void
-start(struct kframe *kfp)
+___start(int argc, char **argv, char **envp, void (*cleanup)(void))
{
- char **argv, *ap, *s;
+ char *s;
- argv = &kfp->argv[0];
- environ = argv + kfp->argc + 1;
+ environ = envp;
- if (ap = argv[0]) {
- if ((__progname = _strrchr(ap, '/')) == NULL)
- __progname = ap;
+ if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
+ if ((__progname = _strrchr(__progname, '/')) == NULL)
+ __progname = argv[0];
else
- ++__progname;
+ __progname++;
for (s = __progname_storage; *__progname &&
s < &__progname_storage[sizeof __progname_storage - 1]; )
*s++ = *__progname++;
@@ -72,23 +88,32 @@ start(struct kframe *kfp)
__progname = __progname_storage;
}
-__asm__ ("eprol:");
+ if (cleanup)
+ atexit(cleanup);
#ifdef MCRT0
atexit(_mcleanup);
- monstartup((u_long)&eprol, (u_long)&etext);
+ monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
-__asm__ ("__callmain:"); /* Defined for the benefit of debuggers */
- exit(main(kfp->argc, argv, environ));
+ __init();
+
+ exit(main(argc, argv, environ));
}
-#include "common.c"
+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\n\
- global _eprol\n\
-_eprol:\n\
-");
+asm("\t.text\n_eprol:\n");
#endif
diff --git a/lib/csu/m88k/md_init.h b/lib/csu/m88k/md_init.h
new file mode 100644
index 00000000000..76a4e2c9cf2
--- /dev/null
+++ b/lib/csu/m88k/md_init.h
@@ -0,0 +1,39 @@
+/* $OpenBSD: md_init.h,v 1.1 2013/01/05 11:20:55 miod Exp $ */
+
+/*
+ * Copyright (c) 2012 Miodrag Vallat.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define MD_SECT_CALL_FUNC(section, func) __asm ( \
+ "\t.section\t" #section ",\"ax\",@progbits\n" \
+ "\tbsr\t" #func "\n" \
+ "\t.previous")
+
+#define MD_SECTION_PROLOGUE(section, entry) __asm ( \
+ "\t.section\t" #section ",\"ax\",@progbits\n" \
+ "\t.globl\t" #entry "\n" \
+ "\t.type\t" #entry ",@function\n" \
+ "\t.align\t2\n" \
+ #entry ":\n" \
+ "\tsubu\t%r31, %r31, 16\n" \
+ "\tst\t%r1, %r31, 0\n" \
+ "\t.previous")
+
+#define MD_SECTION_EPILOGUE(section) __asm( \
+ "\t.section\t" #section ",\"ax\",@progbits\n" \
+ "\tld\t%r1, %r31, 0\n" \
+ "\tjmp.n\t%r1\n" \
+ "\taddu\t%r31, %r31, 16\n" \
+ "\t.previous")