Subversion Repositories Kolibri OS

Rev

Rev 4874 | Rev 6068 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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 <newlib.h>
  16. #include <stdint.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <sys/kos_io.h>
  21.  
  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.  
  32. extern char __cmdline[];
  33. extern char __pgmname[];
  34.  
  35. extern int main (int, char **, char **);
  36.  
  37. int   _errno;
  38. int   _fmode;
  39.  
  40. int    _argc;
  41. char **_argv;
  42.  
  43. static char *arg[2];
  44.  
  45. void   _exit(int __status) __attribute__((noreturn));
  46.  
  47.  
  48. char * __libc_getenv(const char *name)
  49. {
  50.     return NULL;
  51. }
  52.  
  53. void __main (){};
  54.  
  55. struct app_hdr
  56. {
  57.     char  banner[8];
  58.     int   version;
  59.     int   start;
  60.     int   iend;
  61.     int   memsize;
  62.     int   stacktop;
  63.     char  *cmdline;
  64.     char  *path;
  65. };
  66.  
  67. typedef void (*ctp)();
  68. static void __do_global_ctors ()
  69. {
  70.   extern int __CTOR_LIST__;
  71.   int *c = &__CTOR_LIST__;
  72.   c++;
  73.   while (*c)
  74.     {
  75.       ctp d = (ctp)*c;
  76.       (d)();
  77.       c++;
  78.     }
  79. }
  80.  
  81. void  __attribute__((noreturn))
  82. __crt_startup (void)
  83. {
  84.     int nRet;
  85.     struct   app_hdr *header;
  86.  
  87.  
  88.     init_global_reent();
  89.  
  90.   /*
  91.    * Initialize floating point unit.
  92.    */
  93.     __cpu_features_init ();   /* Do we have SSE, etc.*/
  94. //  _fpreset ();              /* Supplied by the runtime library. */
  95.  
  96.     __do_global_ctors();
  97.  
  98.     arg[0] = &__pgmname[0];
  99.  
  100.     if( __cmdline[0] != 0)
  101.     {
  102.         _argc = 2;
  103.         arg[1] = &__cmdline[0];
  104.     } else _argc = 1;
  105.  
  106.     _argv = arg;
  107.  
  108.   /*
  109.    * Sets the default file mode.
  110.    * If _CRT_fmode is set, also set mode for stdin, stdout
  111.    * and stderr, as well
  112.    * NOTE: DLLs don't do this because that would be rude!
  113.    */
  114. //  _mingw32_init_fmode ();
  115.  
  116.  
  117.     nRet = main (_argc, _argv, NULL);
  118.  
  119.   /*
  120.    * Perform exit processing for the C library. This means
  121.    * flushing output and calling 'atexit' registered functions.
  122.    */
  123.     exit (nRet);
  124. }
  125.  
  126.  
  127.  
  128.