Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / csu / alpha / crt1.c
1 /*
2  * Copyright 2001 David E. O'Brien
3  * All rights reserved.
4  * Copyright 1996-1998 John D. Polstra.
5  * All rights reserved.
6  * Copyright (c) 1995 Christopher G. Demetriou
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *          This product includes software developed for the FreeBSD Project.
20  *          See http://www.freebsd.org/ for information about FreeBSD.
21  *      This product includes software developed by Christopher G. Demetriou
22  *    for the NetBSD Project.
23  * 4. The name of the author may not be used to endorse or promote products
24  *    derived from this software without specific prior written permission
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $FreeBSD: src/lib/csu/alpha/crt1.c,v 1.7.2.2 2001/08/01 09:30:36 obrien Exp $
38  * $DragonFly: src/lib/csu/alpha/Attic/crt1.c,v 1.2 2003/06/17 04:26:41 dillon Exp $
39  */
40
41 #ifndef __GNUC__
42 #error "GCC is needed to compile this file"
43 #endif
44
45 #include <stdlib.h>
46 #include "crtbrand.c"
47
48 struct Struct_Obj_Entry;
49 struct ps_strings;
50
51 #pragma weak _DYNAMIC
52 extern int _DYNAMIC;
53
54 extern void _init(void);
55 extern void _fini(void);
56 extern int main(int, char **, char **);
57
58 #ifdef GCRT
59 extern void _mcleanup(void);
60 extern void monstartup(void *, void *);
61 extern int eprol;
62 extern int etext;
63 #endif
64
65 char **environ;
66 char *__progname = "";
67
68 /* The entry function. */
69 void
70 _start(char **ap,
71         void (*cleanup)(void),                  /* from shared loader */
72         struct Struct_Obj_Entry *obj,           /* from shared loader */
73         struct ps_strings *ps_strings)
74 {
75         int argc;
76         char **argv;
77         char **env;
78
79         argc = * (long *) ap;
80         argv = ap + 1;
81         env  = ap + 2 + argc;
82         environ = env;
83         if(argc > 0 && argv[0] != NULL) {
84                 char *s;
85                 __progname = argv[0];
86                 for (s = __progname; *s != '\0'; s++)
87                         if (*s == '/')
88                                 __progname = s + 1;
89         }
90
91         if (&_DYNAMIC != NULL)
92                 atexit(cleanup);
93
94 #ifdef GCRT
95         atexit(_mcleanup);
96 #endif
97         atexit(_fini);
98 #ifdef GCRT
99         monstartup(&eprol, &etext);
100 #endif
101         _init();
102         exit( main(argc, argv, env) );
103 }
104
105 #ifdef GCRT
106 __asm__(".text");
107 __asm__("eprol:");
108 __asm__(".previous");
109 #endif
110
111 /*
112  * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
113  */