summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2002-07-16 12:28:50 +0000
committermarkm <markm@FreeBSD.org>2002-07-16 12:28:50 +0000
commitbedd05ccecbd002c4865f3dff35af258f0e5dd94 (patch)
tree4dcd84e724c9495af7116ae6dbbcee1b0420fb84 /lib/csu
parent4de6bef14519eb23505d35e15226e5711028252c (diff)
downloadFreeBSD-src-bedd05ccecbd002c4865f3dff35af258f0e5dd94.zip
FreeBSD-src-bedd05ccecbd002c4865f3dff35af258f0e5dd94.tar.gz
The main reason for this is to reduce diffs between all the crt1.c's.
Assembler macros are tidied up and made as similar as sanely possible. The macros are translated into C (__inline static) functions for lint. Declaration orders are made the same. Declarations are all ISOfied and tidied up. Comment contents have gratuitous diffs removed. The net result is a bunch of crt1.c's that are 90% the same. It may be possible to now encapsulate the differences in one MD header, and have only one MI crt1.c file (although the macros to do this may be ugly). Helpful comments by: obrien, bde Alpha tested by: des i386-elf tested by: markm
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/alpha/crt1.c20
-rw-r--r--lib/csu/amd64/crt1.c43
-rw-r--r--lib/csu/i386-elf/crt1.c43
-rw-r--r--lib/csu/ia64/crt1.c34
-rw-r--r--lib/csu/powerpc/crt1.c28
-rw-r--r--lib/csu/sparc64/crt1.c63
6 files changed, 140 insertions, 91 deletions
diff --git a/lib/csu/alpha/crt1.c b/lib/csu/alpha/crt1.c
index a173842..e871ab6 100644
--- a/lib/csu/alpha/crt1.c
+++ b/lib/csu/alpha/crt1.c
@@ -1,5 +1,5 @@
-/*
- * Copyright 2001 David E. O'Brien
+/*-
+ * Copyright 2001 David E. O'Brien.
* All rights reserved.
* Copyright 1996-1998 John D. Polstra.
* All rights reserved.
@@ -35,22 +35,25 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
#include <stdlib.h>
+
#include "libc_private.h"
#include "crtbrand.c"
struct Struct_Obj_Entry;
struct ps_strings;
-#pragma weak _DYNAMIC
extern int _DYNAMIC;
+#pragma weak _DYNAMIC
-extern void _init(void);
extern void _fini(void);
+extern void _init(void);
extern int main(int, char **, char **);
extern void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
struct ps_strings *);
@@ -66,18 +69,17 @@ char **environ;
const char *__progname = "";
/* The entry function. */
+/* ARGSUSED */
void
-_start(char **ap,
- void (*cleanup)(void), /* from shared loader */
- struct Struct_Obj_Entry *obj __unused, /* from shared loader */
- struct ps_strings *ps_strings __unused)
+_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused,
+ struct ps_strings *ps_strings __unused)
{
int argc;
char **argv;
char **env;
const char *s;
- argc = * (long *) ap;
+ argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
environ = env;
diff --git a/lib/csu/amd64/crt1.c b/lib/csu/amd64/crt1.c
index 5df6e11..a9caf9e 100644
--- a/lib/csu/amd64/crt1.c
+++ b/lib/csu/amd64/crt1.c
@@ -23,21 +23,26 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
-#include <stddef.h>
#include <stdlib.h>
#include "libc_private.h"
#include "crtbrand.c"
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
typedef void (*fptr)(void);
extern void _fini(void);
extern void _init(void);
extern int main(int, char **, char **);
+extern void _start(char *, ...);
#ifdef GCRT
extern void _mcleanup(void);
@@ -46,33 +51,35 @@ extern int eprol;
extern int etext;
#endif
-extern int _DYNAMIC;
-#pragma weak _DYNAMIC
+char **environ;
+const char *__progname = "";
-#ifdef __i386__
-#define get_rtld_cleanup() \
- ({ fptr __value; \
- __asm__("movl %%edx,%0" : "=rm"(__value)); \
- __value; })
+static __inline fptr
+get_rtld_cleanup(void)
+{
+ fptr retval;
+
+#ifdef __GNUC__
+ __asm__("movl %%edx,%0" : "=rm"(retval));
#else
-#error "This file only supports the i386 architecture"
+ retval = (fptr)0; /* XXXX Fix this for other compilers */
#endif
+ return(retval);
+}
-char **environ;
-const char *__progname = "";
-
+/* The entry function. */
void
-_start(char *arguments, ...)
+_start(char *ap, ...)
{
- fptr rtld_cleanup;
+ fptr cleanup;
int argc;
char **argv;
char **env;
const char *s;
- rtld_cleanup = get_rtld_cleanup();
- argv = &arguments;
- argc = * (int *) (argv - 1);
+ cleanup = get_rtld_cleanup();
+ argv = &ap;
+ argc = *(long *)(void *)(argv - 1);
env = argv + argc + 1;
environ = env;
if (argc > 0 && argv[0] != NULL) {
@@ -83,7 +90,7 @@ _start(char *arguments, ...)
}
if (&_DYNAMIC != NULL)
- atexit(rtld_cleanup);
+ atexit(cleanup);
#ifdef GCRT
atexit(_mcleanup);
diff --git a/lib/csu/i386-elf/crt1.c b/lib/csu/i386-elf/crt1.c
index 5df6e11..a9caf9e 100644
--- a/lib/csu/i386-elf/crt1.c
+++ b/lib/csu/i386-elf/crt1.c
@@ -23,21 +23,26 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
-#include <stddef.h>
#include <stdlib.h>
#include "libc_private.h"
#include "crtbrand.c"
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
typedef void (*fptr)(void);
extern void _fini(void);
extern void _init(void);
extern int main(int, char **, char **);
+extern void _start(char *, ...);
#ifdef GCRT
extern void _mcleanup(void);
@@ -46,33 +51,35 @@ extern int eprol;
extern int etext;
#endif
-extern int _DYNAMIC;
-#pragma weak _DYNAMIC
+char **environ;
+const char *__progname = "";
-#ifdef __i386__
-#define get_rtld_cleanup() \
- ({ fptr __value; \
- __asm__("movl %%edx,%0" : "=rm"(__value)); \
- __value; })
+static __inline fptr
+get_rtld_cleanup(void)
+{
+ fptr retval;
+
+#ifdef __GNUC__
+ __asm__("movl %%edx,%0" : "=rm"(retval));
#else
-#error "This file only supports the i386 architecture"
+ retval = (fptr)0; /* XXXX Fix this for other compilers */
#endif
+ return(retval);
+}
-char **environ;
-const char *__progname = "";
-
+/* The entry function. */
void
-_start(char *arguments, ...)
+_start(char *ap, ...)
{
- fptr rtld_cleanup;
+ fptr cleanup;
int argc;
char **argv;
char **env;
const char *s;
- rtld_cleanup = get_rtld_cleanup();
- argv = &arguments;
- argc = * (int *) (argv - 1);
+ cleanup = get_rtld_cleanup();
+ argv = &ap;
+ argc = *(long *)(void *)(argv - 1);
env = argv + argc + 1;
environ = env;
if (argc > 0 && argv[0] != NULL) {
@@ -83,7 +90,7 @@ _start(char *arguments, ...)
}
if (&_DYNAMIC != NULL)
- atexit(rtld_cleanup);
+ atexit(cleanup);
#ifdef GCRT
atexit(_mcleanup);
diff --git a/lib/csu/ia64/crt1.c b/lib/csu/ia64/crt1.c
index 4320b7b..392fd55 100644
--- a/lib/csu/ia64/crt1.c
+++ b/lib/csu/ia64/crt1.c
@@ -31,11 +31,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
#include <stdlib.h>
+
#include "libc_private.h"
#include "crtbrand.c"
@@ -45,9 +48,10 @@ struct ps_strings;
#pragma weak _DYNAMIC
extern int _DYNAMIC;
-extern void _init(void);
extern void _fini(void);
+extern void _init(void);
extern int main(int, char **, char **);
+extern void _start(char **, struct ps_strings *, void (*)(void));
#ifdef GCRT
extern void _mcleanup(void);
@@ -59,17 +63,10 @@ extern int etext;
char **environ;
const char *__progname = "";
-/* The entry function. */
-void
-_start(char **ap,
- struct ps_strings *ps_strings,
- void (*cleanup)(void))
+static __inline void
+fix_gp(void)
{
- int argc;
- char **argv;
- char **env;
- const char *s;
-
+#ifdef __GNUC__
/* Calculate gp */
__asm __volatile(" \
movl gp=@gprel(1f) ; \
@@ -78,8 +75,21 @@ _start(char **ap,
;; ; \
sub gp=r14,gp ; \
;; ");
+#endif
+}
+
+/* The entry function. */
+/* ARGSUSED */
+void
+_start(char **ap, struct ps_strings *ps_strings __unused, void (*cleanup)(void))
+{
+ int argc;
+ char **argv;
+ char **env;
+ const char *s;
- argc = * (long *) ap;
+ fix_gp();
+ argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
environ = env;
diff --git a/lib/csu/powerpc/crt1.c b/lib/csu/powerpc/crt1.c
index 46156eb..4206754 100644
--- a/lib/csu/powerpc/crt1.c
+++ b/lib/csu/powerpc/crt1.c
@@ -38,23 +38,28 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
#include <stdlib.h>
+
#include "libc_private.h"
#include "crtbrand.c"
struct Struct_Obj_Entry;
struct ps_strings;
-#pragma weak _DYNAMIC
extern int _DYNAMIC;
+#pragma weak _DYNAMIC
-extern void _init(void);
extern void _fini(void);
+extern void _init(void);
extern int main(int, char **, char **);
+extern void _start(int, char **, char **, const struct Struct_Obj_Entry *,
+ void (*)(void), struct ps_strings *);
#ifdef GCRT
extern void _mcleanup(void);
@@ -67,23 +72,20 @@ char **environ;
const char *__progname = "";
struct ps_strings *__ps_strings;
-/* The entry function.
- *
+/* The entry function. */
+/*
* First 5 arguments are specified by the PowerPC SVR4 ABI.
* The last argument, ps_strings, is a BSD extension.
*/
+/* ARGSUSED */
void
-_start(argc, argv, envp, obj, cleanup, ps_strings)
- int argc;
- char **argv, **envp;
- const struct Struct_Obj_Entry *obj; /* from shared loader */
- void (*cleanup)(void); /* from shared loader */
- struct ps_strings *ps_strings; /* BSD extension */
+_start(int argc, char **argv, char **env,
+ const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
+ struct ps_strings *ps_strings)
{
- char *namep;
const char *s;
- environ = envp;
+ environ = env;
if (argc > 0 && argv[0] != NULL) {
__progname = argv[0];
@@ -106,7 +108,7 @@ _start(argc, argv, envp, obj, cleanup, ps_strings)
monstartup(&eprol, &etext);
#endif
_init();
- exit( main(argc, argv, envp) );
+ exit( main(argc, argv, env) );
}
#ifdef GCRT
diff --git a/lib/csu/sparc64/crt1.c b/lib/csu/sparc64/crt1.c
index cd684f3..4bde8dc 100644
--- a/lib/csu/sparc64/crt1.c
+++ b/lib/csu/sparc64/crt1.c
@@ -1,5 +1,5 @@
-/*
- * Copyright 2001 David E. O'Brien
+/*-
+ * Copyright 2001 David E. O'Brien.
* All rights reserved.
* Copyright (c) 1995, 1998 Berkeley Software Design, Inc.
* All rights reserved.
@@ -29,25 +29,32 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#endif /* lint */
#include <stdlib.h>
+
#include "libc_private.h"
#include "crtbrand.c"
struct Struct_Obj_Entry;
struct ps_strings;
-#pragma weak _DYNAMIC
extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
+typedef void (*fptr)(void);
-extern void _init(void);
extern void _fini(void);
+extern void _init(void);
extern int main(int, char **, char **);
-extern void __sparc64_sigtramp_setup(void);
-extern void __sparc64_utrap_setup(void);
+extern void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
+ struct ps_strings *);
+extern void __sparc_sigtramp_setup(void);
+extern void __sparc_utrap_setup(void);
#ifdef GCRT
extern void _mcleanup(void);
@@ -59,9 +66,30 @@ extern int etext;
char **environ;
const char *__progname = "";
+/*
+ * Grab %g1 before it gets used for anything by the compiler.
+ * Sparc ELF psABI specifies a termination routine (if any) will be in
+ * %g1
+ */
+static __inline fptr
+get_term(void)
+{
+ fptr retval;
+
+#if 0
+#ifdef __GNUC__
+ __asm__ volatile("mov %%g1,%0" : "=r"(retval));
+#else
+ retval = (fptr)0; /* XXXX Fix this for other compilers */
+#endif
+#else
+ retval = (fptr)0; /* XXXX temporary */
+#endif
+ return(retval);
+}
+
/* The entry function. */
/*
- *
* %o0 holds ps_strings pointer. For Solaris compat and/or shared
* libraries, if %g1 is not 0, it is a routine to pass to atexit().
* (By passing the pointer in the usual argument register, we avoid
@@ -70,26 +98,20 @@ const char *__progname = "";
* Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1,
* but for now we do not use it here.
*/
+/* ARGSUSED */
void
-_start(char **ap,
- void (*cleanup)(void), /* from shared loader */
- struct Struct_Obj_Entry *obj, /* from shared loader */
- struct ps_strings *ps_strings)
+_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused,
+ struct ps_strings *ps_strings __unused)
{
+ void (*term)(void);
int argc;
char **argv;
char **env;
const char *s;
-#if 0
- void (*term)(void);
- /* Grab %g1 before it gets used for anything by the compiler. */
- /* Sparc ELF psABI specifies a termination routine (if any) will be in
- %g1 */
- __asm__ volatile("mov %%g1,%0" : "=r"(term));
-#endif
+ term = get_term();
- argc = * (long *) ap;
+ argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
environ = env;
@@ -102,14 +124,13 @@ _start(char **ap,
__sparc_sigtramp_setup();
__sparc_utrap_setup();
-#if 0
+
/*
* If the kernel or a shared library wants us to call
* a termination function, arrange to do so.
*/
if (term)
atexit(term);
-#endif
if (&_DYNAMIC != NULL)
atexit(cleanup);
OpenPOWER on IntegriCloud