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
This commit is contained in:
parent
c0cb106043
commit
828191256b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=100167
@ -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;
|
||||
|
@ -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
|
||||
|
||||
#ifdef __i386__
|
||||
#define get_rtld_cleanup() \
|
||||
({ fptr __value; \
|
||||
__asm__("movl %%edx,%0" : "=rm"(__value)); \
|
||||
__value; })
|
||||
#else
|
||||
#error "This file only supports the i386 architecture"
|
||||
#endif
|
||||
|
||||
char **environ;
|
||||
const char *__progname = "";
|
||||
|
||||
void
|
||||
_start(char *arguments, ...)
|
||||
static __inline fptr
|
||||
get_rtld_cleanup(void)
|
||||
{
|
||||
fptr rtld_cleanup;
|
||||
fptr retval;
|
||||
|
||||
#ifdef __GNUC__
|
||||
__asm__("movl %%edx,%0" : "=rm"(retval));
|
||||
#else
|
||||
retval = (fptr)0; /* XXXX Fix this for other compilers */
|
||||
#endif
|
||||
return(retval);
|
||||
}
|
||||
|
||||
/* The entry function. */
|
||||
void
|
||||
_start(char *ap, ...)
|
||||
{
|
||||
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 = ≈
|
||||
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);
|
||||
|
@ -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
|
||||
|
||||
#ifdef __i386__
|
||||
#define get_rtld_cleanup() \
|
||||
({ fptr __value; \
|
||||
__asm__("movl %%edx,%0" : "=rm"(__value)); \
|
||||
__value; })
|
||||
#else
|
||||
#error "This file only supports the i386 architecture"
|
||||
#endif
|
||||
|
||||
char **environ;
|
||||
const char *__progname = "";
|
||||
|
||||
void
|
||||
_start(char *arguments, ...)
|
||||
static __inline fptr
|
||||
get_rtld_cleanup(void)
|
||||
{
|
||||
fptr rtld_cleanup;
|
||||
fptr retval;
|
||||
|
||||
#ifdef __GNUC__
|
||||
__asm__("movl %%edx,%0" : "=rm"(retval));
|
||||
#else
|
||||
retval = (fptr)0; /* XXXX Fix this for other compilers */
|
||||
#endif
|
||||
return(retval);
|
||||
}
|
||||
|
||||
/* The entry function. */
|
||||
void
|
||||
_start(char *ap, ...)
|
||||
{
|
||||
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 = ≈
|
||||
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);
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
argc = * (long *) ap;
|
||||
/* 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;
|
||||
|
||||
fix_gp();
|
||||
argc = *(long *)(void *)ap;
|
||||
argv = ap + 1;
|
||||
env = ap + 2 + argc;
|
||||
environ = env;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user