summaryrefslogtreecommitdiff
path: root/lib/csu/sparc
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-08-11 22:58:07 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-08-11 22:58:07 +0000
commit704944d490274d2f942b4239951d409bbb3156af (patch)
tree9c7da466a7bbb6f8aab2a613e5a80b1f575c2763 /lib/csu/sparc
parentd0a15acf993ad0b1cfe959dfd6e56c6a3300e543 (diff)
Adapt sparc crt* to how things are done on our other ELF architectures.
Some parts of crt0.c are from NetBSD.
Diffstat (limited to 'lib/csu/sparc')
-rw-r--r--lib/csu/sparc/Makefile56
-rw-r--r--lib/csu/sparc/crt0.c194
2 files changed, 105 insertions, 145 deletions
diff --git a/lib/csu/sparc/Makefile b/lib/csu/sparc/Makefile
index 9d470afb158..35798c785af 100644
--- a/lib/csu/sparc/Makefile
+++ b/lib/csu/sparc/Makefile
@@ -1,42 +1,48 @@
-# $OpenBSD: Makefile,v 1.5 2001/03/24 18:40:21 tholo Exp $
+# $OpenBSD: Makefile,v 1.6 2002/08/11 22:58:06 art Exp $
# from: @(#)Makefile 5.5 (Berkeley) 5/21/91
CFLAGS+= -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
+
+.PATH: ${.CURDIR}/../common_elf
+CFLAGS+= -I${.CURDIR}/../common_elf
+
+PICFLAG?=-fPIC
all: ${OBJS}
-crt0.o: ${SRCS}
- @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}"
- @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o
- @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
+crt0.o: crt0.c
+ ${COMPILE.c} -DCRT0 ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+gcrt0.o: crt0.c
+ ${COMPILE.c} -DMCRT0 ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @rm -f ${.TARGET}.o
+
+crtbegin.o: crtbegin.c
+ ${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
+ @${LD} -x -r -o ${.TARGET} ${.TARGET}.o
+ @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
-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
+ ${COMPILE.c} ${.ALLSRC} -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
+ ${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)
-
.include <bsd.prog.mk>
diff --git a/lib/csu/sparc/crt0.c b/lib/csu/sparc/crt0.c
index 40d7833436d..3d5a004eb65 100644
--- a/lib/csu/sparc/crt0.c
+++ b/lib/csu/sparc/crt0.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: crt0.c,v 1.5 2002/07/22 19:15:40 art Exp $ */
-/* $NetBSD: crt0.c,v 1.15 1995/06/15 21:41:55 pk Exp $ */
+/* $NetBSD: crt0.c,v 1.9 2000/06/14 22:52:50 cgd Exp $ */
+
/*
- * Copyright (c) 1993 Paul Kranenburg
+ * 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:
@@ -14,10 +15,12 @@
* 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 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
- *
+ * 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.
@@ -28,132 +31,83 @@
* 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>>
*/
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: crt0.c,v 1.5 2002/07/22 19:15:40 art Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
#include <stdlib.h>
-#include "common.h"
-
-extern unsigned char etext;
-extern unsigned char eprol asm ("eprol");
-extern void start(void) asm("start");
-
-#undef mmap
-#define mmap(addr, len, prot, flags, fd, off) \
- __syscall2((quad_t)SYS_mmap, (addr), (len), (prot), (flags), \
- (fd), 0, (off_t)(off))
-extern int __syscall2(quad_t, ...);
+void ___start(int, char **, char **, void (*cleanup)(void), void *);
+
+__asm("
+ .text
+ .align 4
+ .global __start
+ .global _start
+__start:
+_start:
+ mov 0, %fp
+ ld [%sp + 64], %o0 ! get argc
+ add %sp, 68, %o1 ! get argv
+ sll %o0, 2, %o2 !
+ add %o2, 4, %o2 ! envp = argv + (argc << 2) + 4
+ add %o1, %o2, %o2 !
+ andn %sp, 7, %sp ! align
+ sub %sp, 24, %sp ! expand to standard stack frame size
+ mov %g3, %o3
+ mov %g2, %o4
+ call ___start
+ mov %g1, %o5
+");
+
+char **environ;
+char *__progname = "";
-asm (" .global start");
-asm (" .text");
-asm (" start:");
-
-/* Set up `argc', `argv', and `envp' into local registers (from GNU Emacs). */
-asm (" mov 0, %fp");
-asm (" ld [%sp + 64], %l0"); /* argc */
-asm (" add %sp, 68, %l1"); /* argv */
-asm (" sll %l0, 2, %l2"); /**/
-asm (" add %l2, 4, %l2"); /* envp = argv + (argc << 2) + 4 */
-asm (" add %l1, %l2, %l2"); /**/
-asm (" sethi %hi(_environ), %l3");
-asm (" st %l2, [%l3+%lo(_environ)]"); /* *environ = l2 */
-
-/* Finish diddling with stack. */
-asm (" andn %sp, 7, %sp");
-asm (" sub %sp, 24, %sp");
-
-/*
- * Set __progname:
- * if (argv[0])
- * if ((__progname = _strrchr(argv[0], '/')) == NULL)
- * __progname = argv[0];
- * else
- * ++__progname;
- */
-asm (" ld [%l1], %o0");
-asm (" cmp %o0, 0");
-asm (" mov %o0, %l6");
-asm (" be 1f");
-asm (" sethi %hi(___progname), %l7");
-#ifdef DYNAMIC
-asm (" call __strrchr");
-#else
-asm (" call _strrchr");
-#endif
-asm (" mov 47, %o1");
-asm (" cmp %o0, 0");
-asm (" be,a 1f");
-asm (" st %l6, [%l7+%lo(___progname)]");
-asm (" add %o0, 1, %o0");
-asm (" st %o0, [%l7+%lo(___progname)]");
-asm ("1:");
-
-#ifdef DYNAMIC
-/* Resolve symbols in dynamic libraries */
-asm (" sethi %hi(__DYNAMIC), %o0");
-asm (" orcc %o0, %lo(__DYNAMIC), %o0");
-asm (" be 1f");
-asm (" nop");
-asm (" call ___load_rtld");
-asm (" nop");
-asm ("1:");
-#endif
+#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),
+ void *obj)
+{
+ environ = envp;
+
+ if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
+ if ((__progname = _strrchr(__progname, '/')) == NULL)
+ __progname = argv[0];
+ else
+ __progname++;
+ }
-/* From here, all symbols should have been resolved, so we can use libc */
#ifdef MCRT0
-/*
- * atexit(_mcleanup);
- * monstartup((u_long)&eprol, (u_long)&etext);
- */
-asm (" sethi %hi(__mcleanup), %o0");
-asm (" call _atexit");
-asm (" or %o0, %lo(__mcleanup), %o0");
-asm (" sethi %hi(_eprol), %o0");
-asm (" or %o0, %lo(_eprol), %o0");
-asm (" sethi %hi(_etext), %o1");
-asm (" call _monstartup");
-asm (" or %o1, %lo(_etext), %o1");
+ atexit(_mcleanup);
+ monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
-/* Move `argc', `argv', and `envp' from locals to parameters for `main'. */
-asm (" mov %l0,%o0");
-asm (" mov %l1,%o1");
-asm ("__callmain:"); /* Defined for the benefit of debuggers */
-asm (" call _main");
-asm (" mov %l2,%o2");
+ __init();
-asm (" call _exit");
-asm (" nop");
+ exit(main(argc, argv, environ));
+}
-#ifdef DYNAMIC
-/* System call entry */
-asm(" .set SYSCALL_G2RFLAG, 0x400");
-asm(" .set SYS___syscall, 198");
-asm("___syscall2:");
-asm(" sethi %hi(SYS___syscall), %g1"); /* `SYS___syscall' */
-asm(" ba 1f");
-asm(" or %g1, %lo(SYS___syscall), %g1");
-asm("___syscall:");
-asm(" clr %g1"); /* `SYS_syscall' */
-asm("1:");
-asm(" or %g1, SYSCALL_G2RFLAG, %g1"); /* Use quick return */
-asm(" add %o7, 8, %g2");
-asm(" ta %g0");
-asm(" mov -0x1, %o0"); /* Note: no `errno' */
-asm(" jmp %o7 + 0x8");
-asm(" mov -0x1, %o1");
-#endif
+static char *
+_strrchr(const char *p, char ch)
+{
+ char *save;
-#include "common.c"
+ for (save = NULL;; ++p) {
+ if (*p == ch)
+ save = (char *)p;
+ if (!*p)
+ return(save);
+ }
+}
#ifdef MCRT0
-asm (" .text");
+asm (" .text");
asm ("_eprol:");
#endif