Home | History | Annotate | Line # | Download | only in i386
      1 /*	$NetBSD: crtbegin.S,v 1.1 2010/08/07 18:01:33 joerg Exp $	*/
      2 /*-
      3  * Copyright (c) 2010 Joerg Sonnenberger <joerg (at) NetBSD.org>
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  *
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in
     14  *    the documentation and/or other materials provided with the
     15  *    distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     21  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     27  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 #include <machine/asm.h>
     32 
     33 RCSID("$NetBSD: crtbegin.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
     34 
     35 	.section	.ctors, "aw", @progbits
     36 	.align 4
     37 __CTOR_LIST__:
     38 	.long -1
     39 
     40 	.section	.dtors, "aw", @progbits
     41 	.align 4
     42 __DTOR_LIST__:
     43 	.long -1
     44 
     45 	.section	.eh_frame, "a", @progbits
     46 	.align 4
     47 __EH_FRAME_LIST__:
     48 
     49 	.section	.jcr, "aw", @progbits
     50 	.align 4
     51 __JCR_LIST__:
     52 
     53 	.section	.data.rel, "aw", @progbits
     54 	.align 4
     55 	.type	__dso_handle, @object
     56 	.size	__dso_handle, 4
     57 	.globl	__dso_handle
     58 	.hidden	__dso_handle
     59 __dso_handle:
     60 #ifdef SHARED
     61 	.long	__dso_handle
     62 #else
     63 	.long	0
     64 #endif
     65 
     66 __dwarf_eh_object:
     67 	.zero	32
     68 
     69 __initialized:
     70 	.zero	1
     71 __finished:
     72 	.zero	1
     73 
     74 	.text
     75 	.weak	__cxa_finalize
     76 	.weak	__deregister_frame_info
     77 	.weak	__register_frame_info
     78 	.weak	_Jv_RegisterClasses
     79 
     80 __get_thunk:
     81 	movl	(%esp), %ebx
     82 	ret
     83 
     84 __do_global_dtors_aux:
     85 	pushl	%ebx
     86 	pushl	%edi
     87 	subl	$8, %esp
     88 	call	__get_thunk
     89 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
     90 
     91 	cmpb	$0, __finished@GOTOFF(%ebx)
     92 	jne	4f
     93 	movb	$1, __finished@GOTOFF(%ebx)
     94 
     95 #ifdef SHARED
     96 	cmpl	$0, __cxa_finalize@GOT(%ebx)
     97 	je	1f
     98 	movl	__dso_handle@GOTOFF(%ebx), %eax
     99 	movl	%eax, (%esp)
    100 	call	__cxa_finalize@PLT
    101 1:
    102 #endif
    103 
    104 	leal	4+__DTOR_LIST__@GOTOFF(%ebx), %edi
    105 2:
    106 	movl	(%edi), %eax
    107 	testl	%eax, %eax
    108 	je	3f
    109 	call	*%eax
    110 	addl	$8, %edi
    111 	jmp	2b
    112 3:
    113 
    114 	cmpl	$0, __deregister_frame_info@GOT(%ebx)
    115 	je	4f
    116 	leal	__EH_FRAME_LIST__@GOTOFF(%ebx), %eax
    117 	movl	%eax, (%esp)
    118 	call	__deregister_frame_info@PLT
    119 4:
    120 	addl	$8, %esp
    121 	popl	%edi
    122 	popl	%ebx
    123 	ret
    124 
    125 
    126 __do_global_ctors_aux:
    127 	pushl	%ebx
    128 	pushl	%edi
    129 	subl	$8, %esp
    130 	call	__get_thunk
    131 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
    132 
    133 	cmpb	$0, __initialized@GOTOFF(%ebx)
    134 	jne	4f
    135 	movb	$1, __initialized@GOTOFF(%ebx)
    136 
    137 	cmpl	$0, __register_frame_info@GOT(%ebx)
    138 	je	1f
    139 	leal	__dwarf_eh_object@GOTOFF(%ebx), %edi
    140 	movl	%edi, 4(%esp)
    141 	leal	__EH_FRAME_LIST__@GOTOFF(%ebx), %edi
    142 	movl	%edi, (%esp)
    143 	call	__register_frame_info@PLT
    144 
    145 1:
    146 	cmpl	$0, _Jv_RegisterClasses@GOT(%ebx)
    147 	je	2f
    148 	leal	__JCR_LIST__@GOTOFF(%ebx), %edi
    149 	movl	(%edi), %edi
    150 	testl	%edi, %edi
    151 	je 	2f
    152 	movl	%edi, (%esp)
    153 	call	_Jv_RegisterClasses@PLT
    154 2:
    155 
    156 	leal	-4+__CTOR_LIST_END__@GOTOFF(%ebx), %edi
    157 3:
    158 	movl	(%edi), %eax
    159 	cmpl	$-1, %eax
    160 	je	4f
    161 	call	*%eax
    162 	subl	$4, %edi
    163 	jmp	3b
    164 
    165 4:
    166 	addl	$8, %esp
    167 	popl	%edi
    168 	popl	%ebx
    169 	ret
    170 
    171 	.section	.init, "ax", @progbits
    172 	call	__do_global_ctors_aux
    173 	.section	.fini, "ax", @progbits
    174 	call	__do_global_dtors_aux
    175