Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: src/untrusted/stubs/crt1_x86.S

Issue 7276050: Change startup ABI for untrusted code to be C-compatible (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: disable bogus stack_frame.cc test for now Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/untrusted/stubs/crt1_arm.S ('k') | src/untrusted/stubs/crt1_x86_32.S » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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.
18 *
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.
30 */
31
32 /* Native Client crt0 startup code */
33 /* FIXME(khim): split x86 and x86-64 version */
34
35 .data
36 .globl environ
37
38 .text
39 .p2align NACLENTRYALIGN,0xf4
40
41 .global _start
42 _start:
43 /*
44 * The i386 ELF ABI specifies that on entry the stack looks like:
45 * --------------------------------
46 * | Unspecified |
47 * --------------------------------
48 * | Information block, including |
49 * | argument strings, |
50 * | environment strings, |
51 * | auxiliary information |
52 * | ... |
53 * | (size varies) |
54 * --------------------------------
55 * | Unspecified |
56 * --------------------------------
57 * | Null auxiliary vector entry |
58 * --------------------------------
59 * | Auxiliary vector |
60 * | ... |
61 * | (2-word entries) |
62 * --------------------------------
63 * | 0 word |
64 * --------------------------------
65 * | Environment pointers |
66 * | ... |
67 * | (one word each) |
68 * --------------------------------
69 * | Argument pointers |
70 * | ... |
71 * 4(%esp) | (Argument count words) |
72 * --------------------------------
73 * 0(%esp) | Argument count |
74 * --------------------------------
75 * | Undefined |
76 * --------------------------------
77 * TODO(sehr): fix stack alignments of atexit, _init, _fini, and
78 * exit.
79 */
80
81 /*
82 * The ABI uses a null frame pointer to say when to stop backtracing.
83 * In x86-64 case we don't need this because RBP handling is special
84 * and so loader will load proper value in RBP.
85 */
86 #if !defined(__x86_64__)
87 xorl %ebp, %ebp
88 #endif
89
90 /*
91 * Because we are going to align the stack 0mod16 for SSE2,
92 * We need to gather the argc, argv, and envp pointers before
93 * moving esp.
94 */
95 #if defined(__x86_64__)
96 popq %rsi /* Remove argc from the top of the stack */
97 movq %rsp, %rcx /* Save the argv pointer */
98 #else
99 popl %esi /* Remove argc from the top of the stack */
100 movl %esp, %ecx /* Save the argv pointer */
101 #endif
102
103 /*
104 * Finding envp requires skipping over argc+1 words.
105 */
106 #if defined(__x86_64__)
107 /* NOTE(khim): we are using ILP32 model in x86-64 mode! */
108 leal 4(%rsp, %rsi, 4), %ebx
109 #else
110 leal 4(%esp, %esi, 4), %ebx
111 #endif
112
113 /*
114 * environ is initiallly set to point to the same location as envp.
115 * setenv, etc., may change this pointer later.
116 */
117 #if defined(__x86_64__)
118 movl %ebx, environ(%rip)
119 #else
120 movl %ebx, environ
121 #endif
122
123 /*
124 * Align the stack 0mod16, for SSE2
125 */
126 #if defined(__x86_64__)
127 andq $0xfffffffffffffff0, %rsp
128 #else
129 andl $0xfffffff0, %esp
130 #endif
131
132 #if defined(__x86_64__)
133 /*
134 *Save the arguments in spare registers.
135 */
136 movq %rsi, %r12
137 movq %rcx, %r13
138 movl %ebx, %r14d
139 #else
140 /*
141 * Push the arguments to main.
142 */
143 pushl %ebp /* Padding to maintain 0mod16 alignment */
144 pushl %ebx /* Push envp onto the stack */
145 pushl %ecx /* Push argv onto the stack */
146 pushl %esi /* Push argc back onto the stack */
147 #endif
148
149 /*
150 * Install the fini section for use at exit. The C++ static object
151 * destructors are invoked from here.
152 */
153 #if defined(__x86_64__)
154 /* TODO(eaeltsin): replace _fini with __libc_fini_array! */
155 leal _fini(%rip), %edi
156 call atexit
157 #else
158 subl $12, %esp /* Padding to maintain 0mod16 alignment */
159 /* TODO(eaeltsin): replace _fini with __libc_fini_array! */
160 pushl $_fini
161 call atexit
162 addl $16, %esp /* Pop parameter and padding */
163 #endif
164
165 /*
166 * Initialize the pthreads library. We need to do at least a minimal
167 * amount of initialization (e.g., set up gs) to allow thread local
168 * storage references to work. The default binding of the symbol
169 * is weak, replaced by the real pthread library initialization when
170 * present.
171 */
172 call __pthread_initialize
173
174 /*
175 * Install the pthread_shutdown call to be called at exit.
176 */
177 #if defined(__x86_64__)
178 leal __pthread_shutdown(%rip), %edi
179 call atexit
180 #else
181 subl $12, %esp /* Padding to maintain 0mod16 alignment */
182 pushl $__pthread_shutdown
183 call atexit
184 addl $16, %esp /* Pop parameter and padding */
185 #endif
186
187 /*
188 * Execute the init section before starting main. The C++ static
189 * object constructors are invoked from here.
190 */
191 /* TODO(eaeltsin): replace _init with __libc_init_array! */
192 call _init
193
194 /*
195 * Invoke main, the start of the user's code.
196 */
197 #if defined(__x86_64__)
198 movq %r12, %rdi
199 movq %r13, %rsi
200 movl %r14d, %edx
201 call main
202 movq %rax, %r12 /* Save return value for use by exit call. */
203 #else
204 call main
205 subl $12, %esp /* Make space for the return value */
206 pushl %eax /* Save return value for use by exit call. */
207 #endif
208
209 /*
210 * Call exit from the C library so atexit gets called, and the
211 * C++ destructors get run. This calls our exit routine below
212 * when it's done.
213 */
214 #if defined(__x86_64__)
215 movq %r12, %rdi
216 call exit
217 #else
218 call exit
219 addl $32, %esp /* Clean up all the arguments */
220 #endif
221
222 halt_loop:
223 hlt
224 jmp halt_loop
225
OLDNEW
« no previous file with comments | « src/untrusted/stubs/crt1_arm.S ('k') | src/untrusted/stubs/crt1_x86_32.S » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698