Subversion Repositories Kolibri OS

Rev

Rev 3593 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1693 serge 1
/*
2
 * crt1.c
3
 * This file has no copyright assigned and is placed in the Public Domain.
4
 * This file is a part of the mingw-runtime package.
5
 * No warranty is given; refer to the file DISCLAIMER within the package.
6
 *
7
 * Source code for the startup proceedures used by all programs. This code
8
 * is compiled to make crt1.o, which should be located in the library path.
9
 *
10
 */
11
 
12
/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to
13
   avoid problems with older GCC. */
14
 
15
#include 
16
#include 
17
#include 
18
#include 
1906 serge 19
#include 
20
#include 
21
 
1693 serge 22
#include "cpu_features.h"
23
 
24
 
25
/* NOTE: The code for initializing the _argv, _argc, and environ variables
26
 *       has been moved to a separate .c file which is included in both
27
 *       crt1.c and dllcrt1.c. This means changes in the code don't have to
28
 *       be manually synchronized, but it does lead to this not-generally-
29
 *       a-good-idea use of include. */
30
 
31
 
3805 Serge 32
extern char __cmdline[];
33
extern char __pgmname[];
1693 serge 34
 
35
extern int main (int, char **, char **);
36
 
37
int   _errno;
38
int   _fmode;
39
 
40
char  __appcwd[1024];
41
int   __appcwdlen;
42
 
43
int    _argc;
44
char **_argv;
45
 
46
static char *arg[2];
47
 
48
void   _exit(int __status) __attribute__((noreturn));
49
 
50
 
51
char * __libc_getenv(const char *name)
52
{
53
    return NULL;
54
}
55
 
56
void __main (){};
57
 
1906 serge 58
struct app_hdr
59
{
60
    char  banner[8];
61
    int   version;
62
    int   start;
63
    int   iend;
64
    int   memsize;
65
    int   stacktop;
66
    char  *cmdline;
67
    char  *path;
68
};
69
 
3593 Serge 70
typedef void (*ctp)();
71
static void __do_global_ctors ()
72
{
73
  extern int __CTOR_LIST__;
74
  int *c = &__CTOR_LIST__;
75
  c++;
76
  while (*c)
77
    {
78
      ctp d = (ctp)*c;
79
      (d)();
80
      c++;
81
    }
82
}
1906 serge 83
 
1693 serge 84
void  __attribute__((noreturn))
85
__crt_startup (void)
86
{
87
    int nRet;
1906 serge 88
    struct   app_hdr *header;
1693 serge 89
 
1906 serge 90
 
3065 serge 91
    init_global_reent();
1693 serge 92
 
93
  /*
94
   * Initialize floating point unit.
95
   */
96
    __cpu_features_init ();   /* Do we have SSE, etc.*/
97
//  _fpreset ();              /* Supplied by the runtime library. */
98
 
3593 Serge 99
    __do_global_ctors();
1693 serge 100
 
101
    __appcwdlen = strrchr(&__pgmname, '/') - &__pgmname + 1;
102
    __appcwdlen = __appcwdlen > 1023 ? 1023 : __appcwdlen;
1906 serge 103
    memcpy(__appcwd, &__pgmname, __appcwdlen);
1693 serge 104
    __appcwd[__appcwdlen] = 0;
105
 
1906 serge 106
    set_cwd(__appcwd);
107
 
1693 serge 108
    arg[0] = &__pgmname;
109
 
3805 Serge 110
    if( __cmdline[0] != 0)
1693 serge 111
    {
112
        _argc = 2;
113
        arg[1] = &__cmdline;
114
    } else _argc = 1;
115
 
116
    _argv = arg;
117
 
118
  /*
119
   * Sets the default file mode.
120
   * If _CRT_fmode is set, also set mode for stdin, stdout
121
   * and stderr, as well
122
   * NOTE: DLLs don't do this because that would be rude!
123
   */
124
//  _mingw32_init_fmode ();
125
 
1906 serge 126
 
1693 serge 127
    nRet = main (_argc, _argv, NULL);
128
 
129
  /*
130
   * Perform exit processing for the C library. This means
131
   * flushing output and calling 'atexit' registered functions.
132
   */
1906 serge 133
    exit (nRet);
1693 serge 134
}
135