blob: b013641d65b88816dd7ac8b3f72e58be533e0783 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001# bionic/arch-x86/bionic/crtbegin_dynamic.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' Turner03eabfe2009-05-28 15:54:03 +020032# This is the small startup code that is called from
33# the dynamic linker to execute an executable once all
34# dependent shared libraries have been loaded and
35# initialized.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036#
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020037# It's purpose is to call __libc_init as defined in
38# bionic/libc_init_dynamic.c with appropriate
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039# arguments, which are:
40#
41# - the address of the raw data block setup by the Linux
42# kernel ELF loader
43#
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020044# - address of an "onexit" function (not used on any
45# platform supported by Bionic)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046#
47# - address of the "main" function of the program. We
48# can't hard-code it in the adr pseudo instruction
49# so we use a tiny trampoline that will get relocated
50# by the dynamic linker before this code runs
51#
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020052# - address of the constructors table, i.e. a table
53# that points to various initialization and
54# finalization sections for the program.
55#
56# NOTE: This code is currently placed in shared libraries
57# by the build system, but will be ignored.
58#
59# On the other hand, the arrays defined below are
60# required and will be parsed by the dynamic linker.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080061#
62_start:
63 mov %esp, %eax
64 mov $1f, %edx
65 pushl %edx
66 mov $0f, %edx
67 pushl %edx
68 mov $0, %edx
69 pushl %edx
70 pushl %eax
71 call __libc_init
72
730:
74 jmp main
75
761: .long __PREINIT_ARRAY__
77 .long __INIT_ARRAY__
78 .long __FINI_ARRAY__
79 .long __CTOR_LIST__
80
81# the .ctors section contains a list of pointers to "constructor"
82# functions that need to be called in order during C library initialization,
83# just before the program is being run. This is a C++ requirement
84#
85# the last entry shall be 0, and is defined in crtend.S
86#
87 .section .preinit_array, "aw"
88 .globl __PREINIT_ARRAY__
89__PREINIT_ARRAY__:
90 .long -1
91
92 .section .init_array, "aw"
93 .globl __INIT_ARRAY__
94__INIT_ARRAY__:
95 .long -1
96
97 .section .fini_array, "aw"
98 .globl __FINI_ARRAY__
99__FINI_ARRAY__:
100 .long -1
101
102 .section .ctors, "aw"
103 .globl __CTOR_LIST__
104__CTOR_LIST__:
105 .long -1
106