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 / crt0.S < prev    next >
Encoding:
Text File  |  1994-11-09  |  4.9 KB  |  184 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 EXIT exit
  54. #define LIBC_INIT __libc_init
  55. #define SETFPUCW __setfpucw
  56. #define FPU_CONTROL __fpu_control
  57. #define ENVIRON __environ
  58. #define BRK_ADDR ___brk_addr
  59. #ifdef __i486__
  60. #define ALIGN_TEXT    .align    16,0x90
  61. #else
  62. #define ALIGN_TEXT    .align    4,0x90
  63. #endif
  64. #define ALIGN_DATA    .align    4
  65. #else
  66. #define MAIN _main
  67. #define EXIT _exit
  68. #define LIBC_INIT ___libc_init
  69. #define SETFPUCW ___setfpucw
  70. #define FPU_CONTROL ___fpu_control
  71. #define ENVIRON ___environ
  72. #define BRK_ADDR ____brk_addr
  73. #ifdef __i486__
  74. #define ALIGN_TEXT    .align    4,0x90
  75. #else
  76. #define ALIGN_TEXT    .align    2,0x90
  77. #endif
  78. #define ALIGN_DATA    .align    2
  79. #endif
  80.  
  81.     .file "crt0.S"
  82.  
  83.     .text
  84.     ALIGN_TEXT
  85.     .globl    ___crt_dummy__
  86. ___crt_dummy__:
  87. #ifndef __ELF__
  88. __entry:
  89. /*
  90.  * The first thing we do is try to load the shared library. If that
  91.  * fails, it won't return.
  92.  */
  93.     call ___load_shared_libraries
  94. #else
  95. /* ELF stuff here */
  96. .globl _start
  97. .type _start,@function
  98. _start:
  99.     /* First locate the start of the environment variables */
  100.     popl %ecx
  101.     movl %esp,%ebx  /* Points to the arguments */
  102.     movl %esp,%eax /* Same here */
  103.     movl %ecx,%edx
  104.     addl %edx,%edx
  105.     addl %edx,%edx
  106.     addl %edx,%eax
  107.     addl $4,%eax    
  108.     pushl %eax  /* Environment pointer */
  109.     push %ebx   /* Argument pointer */
  110.     pushl %ecx /* And the argument count */
  111. /*
  112.  * Make sure we are not using iBCS2 personality. (i.e. force linux).
  113.  */
  114.     movl $136,%eax
  115.     movl $0,%ebx
  116.     int  $0x80
  117.  
  118. #endif
  119.  
  120. /*
  121.  *    This is important, and was missing from the new version...
  122.  */
  123.     movl $45,%eax
  124.     movl $0,%ebx
  125.     int  $0x80
  126.     movl %eax,BRK_ADDR
  127. /*
  128.  *    ok, set up the  ___environ and call _main
  129.  */    
  130.     movl 8(%esp),%eax
  131.     movl %eax,ENVIRON
  132.     movzwl FPU_CONTROL,%eax
  133.     pushl %eax
  134.     call SETFPUCW
  135.     addl $4,%esp
  136. /* Some functions may be needed. */
  137.     call LIBC_INIT
  138. #ifdef ELF_INIT_FINI
  139.     pushl $_fini
  140.     call atexit
  141.     addl $4,%esp
  142.     call _init
  143. #endif
  144.     call MAIN
  145.     pushl %eax
  146.     call EXIT
  147. /*
  148.  *    Just in case _exit fails... We use int $0x80 for __exit().
  149.  */
  150.     popl %ebx
  151.     ALIGN_TEXT
  152. done:
  153.     movl $1,%eax
  154.     int $0x80
  155.     jmp done
  156.     ALIGN_TEXT
  157.  
  158. #ifdef __ELF__
  159.     .size    _start,.-_start
  160.     .globl __environ
  161.     .data
  162.     .type __environ,@object
  163.     ALIGN_DATA
  164. __environ:
  165.     .long 0
  166.     .size __environ,4
  167.     .weak environ
  168.     environ = __environ
  169. #else
  170.     .text
  171.     ALIGN_TEXT
  172. ___shared_dummy__:
  173.     .asciz ""
  174.     .stabs "___SHARED_LIBRARIES__",25,0,0,___shared_dummy__
  175.  
  176.     .data
  177.     ALIGN_DATA
  178. ___shared_dummy1__:
  179.     .long 0xfeeb1ed3  /* Magic number used by DLL code to make sure this
  180.                  is a real list */
  181.  
  182.     .stabs "__SHARABLE_CONFLICTS__",25,0,0,___shared_dummy1__
  183. #endif
  184.