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