Home | History | Annotate | Line # | Download | only in x86_64
crtbegin.S revision 1.2
      1 /*	$NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 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.2 2010/11/30 18:37:59 joerg Exp $")
     34 
     35 	.section	.ctors, "aw", @progbits
     36 	.align 8
     37 __CTOR_LIST__:
     38 	.quad -1
     39 
     40 	.section	.dtors, "aw", @progbits
     41 	.align 8
     42 __DTOR_LIST__:
     43 	.quad -1
     44 
     45 	.section	.eh_frame, "a", @progbits
     46 	.align 8
     47 __EH_FRAME_LIST__:
     48 
     49 	.section	.jcr, "aw", @progbits
     50 	.align 8
     51 __JCR_LIST__:
     52 
     53 	.section	.data.rel, "aw", @progbits
     54 	.align 8
     55 	.type	__dso_handle, @object
     56 	.size	__dso_handle, 8
     57 	.globl	__dso_handle
     58 	.hidden	__dso_handle
     59 __dso_handle:
     60 #ifdef SHARED
     61 	.quad	__dso_handle
     62 #else
     63 	.quad	0
     64 #endif
     65 
     66 __dwarf_eh_object:
     67 	.zero	64
     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 __do_global_dtors_aux:
     81 	cmpb	$0, __finished(%rip)
     82 	je	1f
     83 	ret
     84 1:
     85 	pushq	%rbx
     86 	movb	$1, __finished(%rip)
     87 
     88 
     89 #ifdef SHARED
     90 	cmpq	$0, __cxa_finalize@GOTPCREL(%rip)
     91 	je	2f
     92 	movq	__dso_handle(%rip), %rdi
     93 	call	__cxa_finalize@PLT
     94 2:
     95 #endif
     96 
     97 	leaq	8+__DTOR_LIST__(%rip), %rbx
     98 3:
     99 	movq	(%rbx), %rax
    100 	testq	%rax, %rax
    101 	je	4f
    102 	call	*%rax
    103 	addq	$8, %rbx
    104 	jmp	3b
    105 4:
    106 
    107 	cmpq	$0, __deregister_frame_info@GOTPCREL(%rip)
    108 	je	5f
    109 	leaq	__EH_FRAME_LIST__(%rip), %rdi
    110 	call	__deregister_frame_info@PLT
    111 5:
    112 	popq	%rbx
    113 	ret
    114 
    115 
    116 __do_global_ctors_aux:
    117 	cmpb	$0, __initialized(%rip)
    118 	je	1f
    119 	ret
    120 1:
    121 	pushq	%rbx
    122 	movb	$1, __initialized(%rip)
    123 
    124 	cmpq	$0, __register_frame_info@GOTPCREL(%rip)
    125 	je	2f
    126 	leaq	__dwarf_eh_object(%rip), %rsi
    127 	leaq	__EH_FRAME_LIST__(%rip), %rdi
    128 	call	__register_frame_info@PLT
    129 
    130 2:
    131 	cmpq	$0, _Jv_RegisterClasses@GOTPCREL(%rip)
    132 	je	3f
    133 	leaq	__JCR_LIST__(%rip), %rdi
    134 	cmpq	$0, (%rdi)
    135 	je 	3f
    136 	call	_Jv_RegisterClasses@PLT
    137 3:
    138 
    139 	leaq	-8+__CTOR_LIST_END__(%rip), %rbx
    140 4:
    141 	movq	(%rbx), %rax
    142 	cmpq	$-1, %rax
    143 	je	5f
    144 	call	*%rax
    145 	subq	$8, %rbx
    146 	jmp	4b
    147 
    148 5:
    149 	popq	%rbx
    150 
    151 	ret
    152 
    153 	.section	.init, "ax", @progbits
    154 	call	__do_global_ctors_aux
    155 	.section	.fini, "ax", @progbits
    156 	call	__do_global_dtors_aux
    157