summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-04-17 03:45:00 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-04-17 03:45:00 +0000
commitc6d530942182c9f5f1f8402bf432fe302e0e043f (patch)
tree3bc8ad647c9aafd5c5e5a9500133031f4bb2dac3 /lib
parent8d448c84f4408180c1dc578461dc115e26727b44 (diff)
i386 startup code for ELF. based on newer version of NetBSD code.
Diffstat (limited to 'lib')
-rw-r--r--lib/csu/i386/Makefile50
-rw-r--r--lib/csu/i386/crt0.c132
2 files changed, 98 insertions, 84 deletions
diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile
index 0682fb99a71..6e776e3f6f2 100644
--- a/lib/csu/i386/Makefile
+++ b/lib/csu/i386/Makefile
@@ -1,42 +1,50 @@
-# $OpenBSD: Makefile,v 1.6 2001/03/24 18:40:20 tholo Exp $
+# $OpenBSD: Makefile,v 1.7 2003/04/17 03:44:59 drahn Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -fno-omit-frame-pointer -DLIBC_SCCS -I${.CURDIR}/..
-OBJS= crt0.o gcrt0.o scrt0.o
-SRCS= crt0.c
+OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
+
+PICFLAG?=-fpic
+
+.PATH: ${.CURDIR}/../common_elf
+CFLAGS+= -I${.CURDIR}/../common_elf
all: ${OBJS}
-crt0.o: ${SRCS}
- @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o
+crt0.o: crt0.c
+ ${COMPILE.c} -DCRT0 ${.ALLSRC} -o ${.TARGET}.o
@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
-gcrt0.o: ${SRCS}
- @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o
+gcrt0.o: crt0.c
+ ${COMPILE.c} -DMCRT0 ${.ALLSRC} -o ${.TARGET}.o
@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
-scrt0.o: ${SRCS}
- @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o
+crtbegin.o: crtbegin.c
+ ${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
@rm -f ${.TARGET}.o
+crtbeginS.o: crtbeginS.c
+ ${COMPILE.c} ${PICFLAG} ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+crtend.o: crtend.c
+ ${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+crtendS.o: crtendS.c
+ ${COMPILE.c} ${PICFLAG} ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
realinstall:
${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
${DESTDIR}/usr/lib
-.if make(depend)
-CPPFLAGS+= -DDYNAMIC
-.endif
-
-afterdepend: .depend
- @(TMP=/tmp/_depend$$$$; \
- sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \
- < .depend > $$TMP; \
- mv $$TMP .depend)
+depend:
.include <bsd.prog.mk>
diff --git a/lib/csu/i386/crt0.c b/lib/csu/i386/crt0.c
index 22bbfddf5e7..350e237524e 100644
--- a/lib/csu/i386/crt0.c
+++ b/lib/csu/i386/crt0.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: crt0.c,v 1.9 2003/02/28 18:05:51 deraadt Exp $ */
+/* $OpenBSD: crt0.c,v 1.10 2003/04/17 03:44:59 drahn Exp $ */
/* $NetBSD: crt0.c,v 1.20 1995/06/03 13:16:08 pk Exp $ */
/*
- * Copyright (c) 1993 Paul Kranenburg
+ * Copyright (c) 1995 Christopher G. Demetriou
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,8 @@
* 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.
+ * 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
*
@@ -29,50 +30,66 @@
* 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.
- *
*/
-
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: crt0.c,v 1.9 2003/02/28 18:05:51 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: crt0.c,v 1.10 2003/04/17 03:44:59 drahn Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <stdlib.h>
-#include "common.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 */
+
-extern void start(void) asm("start");
+__asm("
+ .text
+ .align 4
+ .globl __start
+ .globl _start
+_start:
+__start:
+ pushl %ebx #ps_strings
+ pushl %ecx # obj
+ pushl %edx # cleanup
+ movl 12(%esp),%eax
+ leal 20(%esp,%eax,4),%ecx
+ leal 16(%esp),%edx
+ pushl %ecx
+ pushl %edx
+ pushl %eax
+ call ___start
+");
void
-start()
+___start(argc, argv, envp, cleanup, obj, ps_strings)
+ int argc;
+ char **argv;
+ char ** envp;
+ void (*cleanup)(void); /* from shared loader */
+ const void *obj; /* from shared loader */
+ struct ps_strings *ps_strings;
{
- struct kframe {
- int kargc;
- char *kargv[1]; /* size depends on kargc */
- char kargstr[1]; /* size varies */
- char kenvstr[1]; /* size varies */
- };
- /*
- * ALL REGISTER VARIABLES!!!
- */
+ char *namep;
register struct kframe *kfp;
- register char **argv, *ap;
char *s;
-#ifdef lint
- kfp = 0;
- initcode = initcode = 0;
-#else /* not lint */
- /* just above the saved frame pointer */
- asm ("lea 4(%%ebp), %0" : "=r" (kfp) );
-#endif /* not lint */
- argv = &kfp->kargv[0];
- environ = argv + kfp->kargc + 1;
-
- if ((ap = argv[0])) {
- if ((__progname = _strrchr(ap, '/')) == NULL)
- __progname = ap;
+ 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 &&
@@ -82,45 +99,34 @@ start()
__progname = __progname_storage;
}
-#ifdef DYNAMIC
- /* ld(1) convention: if DYNAMIC = 0 then statically linked */
-#ifdef stupid_gcc
- if (&_DYNAMIC)
-#else
- if ( ({volatile caddr_t x = (caddr_t)&_DYNAMIC; x; }) )
-#endif
- __load_rtld(&_DYNAMIC);
-#endif /* DYNAMIC */
-
-asm("eprol:");
-
#ifdef MCRT0
atexit(_mcleanup);
- monstartup((u_long)&eprol, (u_long)&etext);
-#endif /* MCRT0 */
+ monstartup((u_long)&_eprol, (u_long)&_etext);
+#endif
+
+ __init();
-asm ("__callmain:"); /* Defined for the benefit of debuggers */
- exit(main(kfp->kargc, argv, environ));
+ exit(main(argc, argv, environ));
}
-#ifdef DYNAMIC
- asm(" ___syscall:");
- asm(" popl %ecx");
- asm(" popl %eax");
- asm(" pushl %ecx");
- asm(" int $0x80");
- asm(" pushl %ecx");
- asm(" jc 1f");
- asm(" ret");
- asm(" 1:");
- asm(" movl $-1,%eax");
- asm(" ret");
-#endif /* DYNAMIC */
+static char *
+_strrchr(p, ch)
+register char *p, ch;
+{
+ register char *save;
-#include "common.c"
+ for (save = NULL;; ++p) {
+ if (*p == ch)
+ save = (char *)p;
+ if (!*p)
+ return(save);
+ }
+/* NOTREACHED */
+}
#ifdef MCRT0
-asm (" .text");
+asm (" .text");
asm ("_eprol:");
#endif
+