summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-02-26 18:50:36 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-02-26 18:50:36 +0000
commitdec61d55bcdf2e962ba643e7bbfb3d1a54d18507 (patch)
treefd2719fb4c2d09f661602eb398d9b205558642b6
parentf48fd959f08ee5e49ec98a232e0d8cf13f01fa44 (diff)
Switch to a C version of powerpc crt0 file. easier to read. moves
_progname storage into data instead of stack.
-rw-r--r--lib/csu/powerpc/Makefile14
-rw-r--r--lib/csu/powerpc/crt0.c96
-rw-r--r--lib/csu/powerpc/crt0.s83
3 files changed, 103 insertions, 90 deletions
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
index d6621620630..9766689394d 100644
--- a/lib/csu/powerpc/Makefile
+++ b/lib/csu/powerpc/Makefile
@@ -1,7 +1,7 @@
# $OpenBSDe Makefile,v 1.6 2000/06/28 04:56:44 rahnds Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/1/93
-CFLAGS= -DLIBC_SCCS
+CFLAGS+= -DLIBC_SCCS
OBJS= crt0.o gcrt0.o scrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o
PICFLAG?=-fpic
@@ -10,18 +10,18 @@ CLEANFILES+= core a.out
all: ${OBJS}
-crt0.o: crt0.s
- ${CPP} -DCRT0 ${.ALLSRC} | ${AS} -o $@
+crt0.o: crt0.c
+ ${CC} ${CFLAGS} -c -DCRT0 ${.ALLSRC} -o $@
@${LD} -x -r ${.TARGET}
@mv a.out ${.TARGET}
-gcrt0.o: crt0.s
- ${CPP} -DMCRT0 ${.ALLSRC} | ${AS} -o $@
+gcrt0.o: crt0.c
+ ${CC} ${CFLAGS} -c -DMCRT0 ${.ALLSRC} -o $@
@${LD} -x -r ${.TARGET}
@mv a.out ${.TARGET}
-scrt0.o: crt0.s
- ${CPP} -DSCRT0 ${.ALLSRC} | ${AS} -o $@
+scrt0.o: crt0.c
+ ${CC} ${CFLAGS} -c -DSRT0 ${.ALLSRC} -o $@
@${LD} -x -r ${.TARGET}
@mv a.out ${.TARGET}
diff --git a/lib/csu/powerpc/crt0.c b/lib/csu/powerpc/crt0.c
new file mode 100644
index 00000000000..6491ab65ade
--- /dev/null
+++ b/lib/csu/powerpc/crt0.c
@@ -0,0 +1,96 @@
+/* $OpenBSD: crt0.c,v 1.1 2003/02/26 18:50:35 drahn 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>
+
+char **environ;
+char * __progname = "";
+
+char __progname_storage[MAXPATHLEN];
+
+#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);
+
+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 0
+ atexit(cleanup);
+#endif
+#ifdef MCRT0
+ atexit(_mcleanup);
+ monstartup((u_long)&_eprol, (u_long)&_etext);
+#endif
+
+#ifndef SCRT0
+ __init();
+#endif
+
+ 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/crt0.s b/lib/csu/powerpc/crt0.s
deleted file mode 100644
index de7a10bfac8..00000000000
--- a/lib/csu/powerpc/crt0.s
+++ /dev/null
@@ -1,83 +0,0 @@
-# $OpenBSD: crt0.s,v 1.7 2000/06/28 04:56:44 rahnds Exp $
-
- .section ".data"
- .comm environ, 4
- .globl __progname
-__progname:
- .long L1
-L1: .long 0 # null string plus padding
-
-
-
- .section ".text"
- .globl _start
- .type _start,@function
-_start:
-
- # squirrel away the arguments for main
- mr 13, 3
- mr 14, 4
- mr 15, 5
- mr 16, 6
-
- # make certain space exists on the stack for the
- # 'stw X, 4(1)' at the beginning of functions.
- subi 1, 1, 16
- li 0, 0
- stw 0, 0(1)
-
- # determine the program name (__progname)
- mr 4, 14
- lwz 28, 0(4) # r28 = argv[0] (program name)
- cmpwi 28, 0 # argv[0] == NULL?
- beq call_main # yep forget setup of progname
- mr 3, 28 # r3 = argv[0]
- li 4, '/' # r4 = '/'
- .extern strrchr
- bl strrchr # strrchr(argv[0], '/')
- cmpwi 3, 0 # == 0?
- beq no_slash_found # not found, use argv[0] still in r28
- addi 28, 3, 1 # was found, point at char after '/'
-no_slash_found:
- # store the address of the basename found in argv[0]
- lis 31, __progname@HA
- stw 28, __progname@L(31)
-
- lis 26, environ@HA
- stw 15, environ@L(26)
-
-call_main:
-#ifdef MCRT0
- lis 3, _mcleanup@ha
- addi 3, 3, _mcleanup@l
- bl atexit
- lis 3, eprol@ha
- addi 3, 3, eprol@l
- lis 4, _etext@ha
- addi 4, 4, _etext@l
- bl monstartup
-#endif
-#ifndef SCRT0
- .globl __init
- bl __init
-#endif
- # recover those saved registers
- mr 3, 13
- mr 4, 14
- mr 5, 15
- mr 6, 16
-
- bl main
- .extern exit
- bl exit
-
-eprol:
-#if 0
- .globl __main
-__main:
-#endif
- .globl __eabi
- .type __eabi,@function
-__eabi:
- blr
-