home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / mach / i386 / start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-17  |  2.2 KB  |  81 lines

  1. /* Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <stddef.h>
  21. #include <stdlib.h>
  22. #include <errno.h>
  23. #include <unistd.h>
  24.  
  25. #ifndef    __GNUC__
  26.   #error This file uses GNU C extensions; you must compile with GCC.
  27. #endif
  28.  
  29. /* The first piece of initialized data.  */
  30. int __data_start = 0;
  31.  
  32. volatile int errno;
  33.  
  34. #ifndef    HAVE_GNU_LD
  35. #define    __environ    environ
  36. #endif
  37. char **__environ;
  38.  
  39. extern void EXFUN(__mach_init, (NOARGS));
  40. extern void EXFUN(__libc_init, (int argc, char **argv, char **envp));
  41. extern int EXFUN(main, (int argc, char **argv, char **envp));
  42.  
  43. /* These are uninitialized common definitions so they will be zero
  44.    by default.  If the user links in C threads, that will provide initialized
  45.    definitions that override these.  */
  46. void *(*_cthread_init_routine) (void); /* Returns new SP to use.  */
  47. void (*_cthread_exit_routine) (int status);
  48.  
  49. void
  50. _start (void)
  51. {
  52.   int *entry_sp;
  53.   register int argc;
  54.   register char **argv, **p;
  55.  
  56.   asm ("leal 4(%%ebp), %0" : "=r" (entry_sp));
  57.  
  58.   argc = *entry_sp;
  59.   argv = (char **) (entry_sp + 1);
  60.   p = argv;
  61.   while (*p++ != NULL)
  62.     ;
  63.   if (p >= (char **) argv[0])
  64.     --p;
  65.   __environ = p;
  66.  
  67.   __mach_init ();
  68.  
  69.   if (_cthread_init_routine != NULL)
  70.     asm volatile ("movl %0, %%esp" : /* No outputs.  */ :
  71.           "g" ((*_cthread_init_routine) ()));
  72.  
  73.   __libc_init (argc, argv, __environ);
  74.  
  75.   (_cthread_exit_routine != NULL ? *_cthread_exit_routine : exit)
  76.     (main (argc, argv, __environ));
  77.  
  78.   /* Should never get here.  */
  79.   _exit (-1);
  80. }
  81.