home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / i386 / crt / gcrt0.S < prev    next >
Encoding:
Text File  |  1994-11-09  |  5.3 KB  |  203 lines

  1. /*
  2.  * Copyright (c) 1993 Eric Youngdale, Peter MacDonald, David Engel
  3.  * and Hongjiu Lu.
  4.  *
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. The name of the above contributors may not be
  13.  *    used to endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  17.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  20.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  */
  28.  
  29. /* Notice of general intent:
  30.  *
  31.  * The linux operating system generally contains large amounts of code
  32.  * that fall under the GNU General Public License, or GPL for short.
  33.  * This file contains source code that by it's very nature would always
  34.  * be linked with an application program, and because of this a GPL type
  35.  * of copyright on this file would place restrictions upon the
  36.  * distribution of binary-only commercial software.  Since the goal of the
  37.  * Linux project as a whole is not to discourage the development and
  38.  * distribution of commercial software for Linux, this file has been placed
  39.  * under a more relaxed BSD-style of copyright.
  40.  *
  41.  * It is the general understanding of the above contributors that a
  42.  * program executable linked to a library containing code that falls
  43.  * under the GPL or GLPL style of license is not subject to the terms of
  44.  * the GPL or GLPL license if the program executable(s) that are supplied
  45.  * are linked to a shared library form of the GPL or GLPL library, and as long
  46.  * as the form of the shared library is such that it is possible for
  47.  * the end user to modify and rebuild the library and use it in
  48.  * conjunction with the program executable.
  49.  */
  50.  
  51. #ifdef __ELF__
  52. #define MAIN main
  53. #define ATEXIT atexit
  54. #define EXIT exit
  55. #define LIBC_INIT __libc_init
  56. #define SETFPUCW __setfpucw
  57. #define FPU_CONTROL __fpu_control
  58. #define ENVIRON __environ
  59. #define BRK_ADDR ___brk_addr
  60. #define MONSTARTUP monstartup
  61. #define    V_ETEXT    $_etext
  62. #define    V_ENTRY    $_start
  63. #define V_MCLEANUP $_mcleanup
  64. #ifdef __i486__
  65. #define ALIGN_TEXT    .align    16,0x90
  66. #else
  67. #define ALIGN_TEXT    .align    4,0x90
  68. #endif
  69. #define ALIGN_DATA    .align    4
  70. #else
  71. #define MAIN _main
  72. #define ATEXIT _atexit
  73. #define EXIT _exit
  74. #define LIBC_INIT ___libc_init
  75. #define SETFPUCW ___setfpucw
  76. #define FPU_CONTROL ___fpu_control
  77. #define ENVIRON ___environ
  78. #define BRK_ADDR ____brk_addr
  79. #define MONSTARTUP _monstartup
  80. #define    V_ETEXT    $_etext
  81. #define    V_ENTRY    $__entry
  82. #define V_MCLEANUP $__mcleanup
  83. #ifdef __i486__
  84. #define ALIGN_TEXT    .align    4,0x90
  85. #else
  86. #define ALIGN_TEXT    .align    2,0x90
  87. #endif
  88. #define ALIGN_DATA    .align    2
  89. #endif
  90.  
  91.     .file "gcrt0.S"
  92.  
  93.     .text
  94.     ALIGN_TEXT
  95.     .globl    ___crt_dummy__
  96. ___crt_dummy__:
  97. #ifndef __ELF__
  98. __entry:
  99. /*
  100.  * The first thing we do is try to load the shared library. If that
  101.  * fails, it won't return.
  102.  */
  103.     call ___load_shared_libraries
  104. #else
  105. /* ELF stuff here */
  106. .globl _start
  107. .type _start,@function
  108. _start:
  109.     /* First locate the start of the environment variables */
  110.     popl %ecx
  111.     movl %esp,%ebx  /* Points to the arguments */
  112.     movl %esp,%eax /* Same here */
  113.     movl %ecx,%edx
  114.     addl %edx,%edx
  115.     addl %edx,%edx
  116.     addl %edx,%eax
  117.     addl $4,%eax    
  118.     pushl %eax  /* Environment pointer */
  119.     push %ebx   /* Argument pointer */
  120.     pushl %ecx /* And the argument count */
  121. /*
  122.  * Make sure we are not using iBCS2 personality. (i.e. force linux).
  123.  */
  124.     movl $136,%eax
  125.     movl $0,%ebx
  126.     int  $0x80
  127.  
  128. #endif
  129.  
  130. /*
  131.  *    This is important, and was missing from the new version...
  132.  */
  133.     movl $45,%eax
  134.     movl $0,%ebx
  135.     int  $0x80
  136.     movl %eax,BRK_ADDR
  137. /*
  138.  *    Setup profiling
  139.  */
  140.     pushl V_MCLEANUP
  141.     call ATEXIT
  142.     addl $4,%esp
  143.     pushl V_ETEXT
  144.     pushl V_ENTRY
  145.     call MONSTARTUP
  146.     addl $8,%esp
  147. /*
  148.  *    ok, set up the  ___environ and call _main
  149.  */    
  150.     movl 8(%esp),%eax
  151.     movl %eax,ENVIRON
  152.     movzwl FPU_CONTROL,%eax
  153.     pushl %eax
  154.     call SETFPUCW
  155.     addl $4,%esp
  156. /* Some functions may be needed. */
  157.     call LIBC_INIT
  158. #ifdef ELF_INIT_FINI
  159.     pushl $_fini
  160.     call atexit
  161.     addl $4,%esp
  162.     call _init
  163. #endif
  164.     call MAIN
  165.     pushl %eax
  166.     call EXIT
  167. /*
  168.  *    Just in case _exit fails... We use int $0x80 for __exit().
  169.  */
  170.     popl %ebx
  171.     ALIGN_TEXT
  172. done:
  173.     movl $1,%eax
  174.     int $0x80
  175.     jmp done
  176.     ALIGN_TEXT
  177.  
  178. #ifdef __ELF__
  179.     .size    _start,.-_start
  180.         .globl __environ
  181.     .data   
  182.     .type __environ,@object
  183.     ALIGN_DATA
  184. __environ:
  185.     .long 0 
  186.     .size __environ,4
  187.     .weak environ
  188.     environ = __environ
  189. #else
  190.     ALIGN_TEXT
  191. ___shared_dummy__:
  192.     .asciz ""
  193.     .stabs "___SHARED_LIBRARIES__",25,0,0,___shared_dummy__
  194.  
  195.     .data
  196.     ALIGN_TEXT
  197. ___shared_dummy1__:
  198.     .long 0xfeeb1ed3  /* Magic number used by DLL code to make sure this
  199.                  is a real list */
  200.  
  201.     .stabs "__SHARABLE_CONFLICTS__",25,0,0,___shared_dummy1__
  202. #endif
  203.