2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 /* Native Client crt0 startup code */
38 .p2align NACLENTRYALIGN,0xf4,
43 * The i386 ELF ABI specifies that on entry the stack looks like:
44 * --------------------------------
46 * --------------------------------
47 * | Information block, including |
48 * | argument strings, |
49 * | environment strings, |
50 * | auxiliary information |
53 * --------------------------------
55 * --------------------------------
56 * | Null auxiliary vector entry |
57 * --------------------------------
58 * | Auxiliary vector |
60 * | (2-word entries) |
61 * --------------------------------
63 * --------------------------------
64 * | Environment pointers |
67 * --------------------------------
68 * | Argument pointers |
70 * 4(%esp) | (Argument count words) |
71 * --------------------------------
72 * 0(%esp) | Argument count |
73 * --------------------------------
75 * --------------------------------
76 * TODO: fix stack alignments of atexit, _init, _fini, and
81 * The ABI uses a null frame pointer to say when to stop backtracing.
86 * Because we are going to align the stack 0mod16 for SSE2,
87 * We need to gather the argc, argv, and envp pointers before
90 popl %esi /* Remove argc from the top of the stack */
91 movl %esp, %ecx /* Save the argv pointer */
94 * Finding envp requires skipping over argc+1 words.
96 leal 4(%esp, %esi, 4), %ebx
99 * environ is initiallly set to point to the same location as envp.
100 * setenv, etc., may change this pointer later.
105 * Align the stack 0mod16, for SSE2
107 andl $0xfffffff0, %esp
110 * Push the arguments to main.
112 pushl %ebp /* Padding to maintain 0mod16 alignment */
113 pushl %ebx /* Push envp onto the stack */
114 pushl %ecx /* Push argv onto the stack */
115 pushl %esi /* Push argc back onto the stack */
118 * Install the fini section for use at exit. The C++ static object
119 * destructors are invoked from here.
121 subl $12, %esp /* Padding to maintain 0mod16 alignment */
124 addl $16, %esp /* Pop parameter and padding */
127 * Initialize the pthreads library. We need to do at least a minimal
128 * amount of initialization (e.g., set up gs) to allow thread local
129 * storage references to work. The default binding of the symbol
130 * is weak, replaced by the real pthread library initialization when
133 call __pthread_initialize
136 * Install the pthread_shutdown call to be called at exit.
138 subl $12, %esp /* Padding to maintain 0mod16 alignment */
139 pushl $__pthread_shutdown
141 addl $16, %esp /* Pop parameter and padding */
144 * Execute the init section before starting main. The C++ static
145 * object constructors are invoked from here.
150 * Invoke main, the start of the user's code.
153 subl $12, %esp /* Make space for the return value */
156 * Call exit from the C library so atexit gets called, and the
157 * C++ destructors get run. This calls our exit routine below
162 addl $32, %esp /* Clean up all the arguments */