The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | # bionic/arch-x86/bionic/crtbegin_static.S |
| 2 | # |
| 3 | # Copyright 2006, The Android Open Source Project |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
| 7 | # * Redistributions of source code must retain the above copyright |
| 8 | # notice, this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer in the |
| 11 | # documentation and/or other materials provided with the distribution. |
| 12 | # * Neither the name of Google Inc. nor the names of its contributors may |
| 13 | # be used to endorse or promote products derived from this software |
| 14 | # without specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR |
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | # EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | .text |
| 28 | .align 4 |
| 29 | .type _start, @function |
| 30 | .globl _start |
| 31 | |
David 'Digit' Turner | 03eabfe | 2009-05-28 15:54:03 +0200 | [diff] [blame^] | 32 | # This is the small startup code that is first run when |
| 33 | # any static executable runs. A static executable is one |
| 34 | # that is started directly by the Linux kernel, not from |
| 35 | # the dynamic linker, it thus cannot depend on any shared |
| 36 | # library. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | # |
David 'Digit' Turner | 03eabfe | 2009-05-28 15:54:03 +0200 | [diff] [blame^] | 38 | # It's purpose is to call __libc_init as defined in |
| 39 | # bionic/libc_init_static.c with appropriate |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | # arguments, which are: |
| 41 | # |
| 42 | # - the address of the raw data block setup by the Linux |
| 43 | # kernel ELF loader |
| 44 | # |
David 'Digit' Turner | 03eabfe | 2009-05-28 15:54:03 +0200 | [diff] [blame^] | 45 | # - address of an "onexit" function (not used on any |
| 46 | # platform supported by Bionic). |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 47 | # |
David 'Digit' Turner | 03eabfe | 2009-05-28 15:54:03 +0200 | [diff] [blame^] | 48 | # - address of the "main" function of the program. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 49 | # |
David 'Digit' Turner | 03eabfe | 2009-05-28 15:54:03 +0200 | [diff] [blame^] | 50 | # - address of the constructors table, i.e. a table |
| 51 | # that points to various initialization and |
| 52 | # finalization sections for the program. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 53 | # |
| 54 | _start: |
| 55 | mov %esp, %eax |
| 56 | mov $1f, %edx |
| 57 | pushl %edx |
| 58 | mov $0f, %edx |
| 59 | pushl %edx |
| 60 | mov $0, %edx |
| 61 | pushl %edx |
| 62 | pushl %eax |
| 63 | call __libc_init |
| 64 | |
| 65 | 0: jmp main |
| 66 | |
| 67 | 1: .long __PREINIT_ARRAY__ |
| 68 | .long __INIT_ARRAY__ |
| 69 | .long __FINI_ARRAY__ |
| 70 | .long __CTOR_LIST__ |
| 71 | |
| 72 | # the .ctors section contains a list of pointers to "constructor" |
| 73 | # functions that need to be called in order during C library initialization, |
| 74 | # just before the program is being run. This is a C++ requirement |
| 75 | # |
| 76 | # the last entry shall be 0, and is defined in crtend.S |
| 77 | # |
| 78 | .section .preinit_array, "aw" |
| 79 | .globl __PREINIT_ARRAY__ |
| 80 | __PREINIT_ARRAY__: |
| 81 | .long -1 |
| 82 | |
| 83 | .section .init_array, "aw" |
| 84 | .globl __INIT_ARRAY__ |
| 85 | __INIT_ARRAY__: |
| 86 | .long -1 |
| 87 | |
| 88 | .section .fini_array, "aw" |
| 89 | .globl __FINI_ARRAY__ |
| 90 | __FINI_ARRAY__: |
| 91 | .long -1 |
| 92 | |
| 93 | .section .ctors, "aw" |
| 94 | .globl __CTOR_LIST__ |
| 95 | __CTOR_LIST__: |
| 96 | .long -1 |
| 97 | |