Back to index

glibc  2.9
start.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1992,1995,1996,1997,2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    In addition to the permissions in the GNU Lesser General Public
00010    License, the Free Software Foundation gives you unlimited
00011    permission to link the compiled version of this file with other
00012    programs, and to distribute those programs without any restriction
00013    coming from the use of this file. (The GNU Lesser General Public
00014    License restrictions do apply in other respects; for example, they
00015    cover modification of the file, and distribution when not linked
00016    into another program.)
00017 
00018    Note that people who make modified versions of this file are not
00019    obligated to grant this special exception for their modified
00020    versions; it is their choice whether to do so. The GNU Lesser
00021    General Public License gives permission to release a modified
00022    version without this exception; this exception also makes it
00023    possible to release a modified version which carries forward this
00024    exception.
00025 
00026    The GNU C Library is distributed in the hope that it will be useful,
00027    but WITHOUT ANY WARRANTY; without even the implied warranty of
00028    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00029    Lesser General Public License for more details.
00030 
00031    You should have received a copy of the GNU Lesser General Public
00032    License along with the GNU C Library; if not, write to the Free
00033    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00034    02111-1307 USA.  */
00035 
00036 #include <errno.h>
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 
00040 #ifndef       __GNUC__
00041   #error This file uses GNU C extensions; you must compile with GCC.
00042 #endif
00043 
00044 /* The first piece of initialized data.  */
00045 int __data_start = 0;
00046 
00047 extern void __libc_init (int argc, char **argv, char **envp);
00048 extern int main (int argc, char **argv, char **envp);
00049 
00050 /* Use the stack pointer to access the arguments.  This assumes that
00051    we can guess how big the frame will be.  */
00052 register long int sp asm("sp");
00053 #ifdef __OPTIMIZE__
00054 #define STACKSIZE 8
00055 #else
00056 #define STACKSIZE 10
00057 #endif
00058 
00059 void
00060 __start ()
00061 {
00062   int argc;
00063   char **argv, **envp;
00064 
00065   /* Set up the global pointer.  */
00066   asm volatile ("la $28,_gp");
00067   argc = ((int *) sp)[STACKSIZE];
00068   argv = (char **) &((int *) sp)[STACKSIZE + 1];
00069   envp = &argv[argc + 1];
00070   __environ = envp;
00071 
00072   __libc_init (argc, argv, envp);
00073   errno = 0;
00074   exit (main (argc, argv, envp));
00075 }