154359Sroberto/*	$NetBSD$	*/
2182007Sroberto/*-
354359Sroberto * Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
4182007Sroberto * All rights reserved.
5182007Sroberto *
654359Sroberto * Redistribution and use in source and binary forms, with or without
754359Sroberto * modification, are permitted provided that the following conditions
8182007Sroberto * are met:
9182007Sroberto *
10182007Sroberto * 1. Redistributions of source code must retain the above copyright
11182007Sroberto *    notice, this list of conditions and the following disclaimer.
12182007Sroberto * 2. Redistributions in binary form must reproduce the above copyright
13182007Sroberto *    notice, this list of conditions and the following disclaimer in
14182007Sroberto *    the documentation and/or other materials provided with the
15182007Sroberto *    distribution.
16182007Sroberto *
17182007Sroberto * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18182007Sroberto * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19182007Sroberto * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20182007Sroberto * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
21182007Sroberto * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22182007Sroberto * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
23182007Sroberto * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24182007Sroberto * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25182007Sroberto * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26182007Sroberto * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27182007Sroberto * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28182007Sroberto * SUCH DAMAGE.
29182007Sroberto */
30182007Sroberto
31182007Sroberto#include <machine/asm.h>
32182007Sroberto
33182007SrobertoRCSID("$NetBSD$")
3454359Sroberto
3554359Sroberto	.section	.ctors, "aw", @progbits
36285612Sdelphij	.align 4
3754359Sroberto__CTOR_LIST__:
3854359Sroberto	.long -1
3954359Sroberto
4054359Sroberto	.section	.dtors, "aw", @progbits
4154359Sroberto	.align 4
4254359Sroberto__DTOR_LIST__:
4354359Sroberto	.long -1
4454359Sroberto
4554359Sroberto	.section	.eh_frame, "a", @progbits
46285612Sdelphij	.align 4
4754359Sroberto__EH_FRAME_LIST__:
4854359Sroberto
4954359Sroberto	.section	.jcr, "aw", @progbits
5054359Sroberto	.align 4
51285612Sdelphij__JCR_LIST__:
52285612Sdelphij
5354359Sroberto	.section	.data.rel, "aw", @progbits
5454359Sroberto	.align 4
5554359Sroberto	.type	__dso_handle, @object
5654359Sroberto	.size	__dso_handle, 4
5754359Sroberto	.globl	__dso_handle
5854359Sroberto	.hidden	__dso_handle
5954359Sroberto__dso_handle:
6054359Sroberto#ifdef SHARED
6154359Sroberto	.long	__dso_handle
6254359Sroberto#else
6354359Sroberto	.long	0
6454359Sroberto#endif
6554359Sroberto
6654359Sroberto__dwarf_eh_object:
67285612Sdelphij	.zero	32
68285612Sdelphij
69285612Sdelphij__initialized:
70285612Sdelphij	.zero	1
7154359Sroberto__finished:
7254359Sroberto	.zero	1
7354359Sroberto
7454359Sroberto	.text
7554359Sroberto	.weak	__cxa_finalize
7654359Sroberto	.weak	__deregister_frame_info
7754359Sroberto	.weak	__register_frame_info
7854359Sroberto	.weak	_Jv_RegisterClasses
79285612Sdelphij
8054359Sroberto__get_thunk:
8154359Sroberto	movl	(%esp), %ebx
8254359Sroberto	ret
8354359Sroberto
8454359Sroberto__do_global_dtors_aux:
8554359Sroberto	pushl	%ebx
8654359Sroberto	pushl	%edi
8754359Sroberto	subl	$8, %esp
8854359Sroberto	call	__get_thunk
8954359Sroberto	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
90285612Sdelphij
91285612Sdelphij	cmpb	$0, __finished@GOTOFF(%ebx)
9254359Sroberto	jne	4f
9354359Sroberto	movb	$1, __finished@GOTOFF(%ebx)
9454359Sroberto
9554359Sroberto#ifdef SHARED
9654359Sroberto	cmpl	$0, __cxa_finalize@GOT(%ebx)
9754359Sroberto	je	1f
9854359Sroberto	movl	__dso_handle@GOTOFF(%ebx), %eax
9954359Sroberto	movl	%eax, (%esp)
10054359Sroberto	call	__cxa_finalize@PLT
10154359Sroberto1:
102285612Sdelphij#endif
10354359Sroberto
10454359Sroberto	leal	4+__DTOR_LIST__@GOTOFF(%ebx), %edi
10554359Sroberto2:
10654359Sroberto	movl	(%edi), %eax
10754359Sroberto	testl	%eax, %eax
10854359Sroberto	je	3f
10954359Sroberto	call	*%eax
11054359Sroberto	addl	$8, %edi
111285612Sdelphij	jmp	2b
11254359Sroberto3:
11354359Sroberto
11454359Sroberto	cmpl	$0, __deregister_frame_info@GOT(%ebx)
11554359Sroberto	je	4f
11654359Sroberto	leal	__EH_FRAME_LIST__@GOTOFF(%ebx), %eax
11754359Sroberto	movl	%eax, (%esp)
11854359Sroberto	call	__deregister_frame_info@PLT
11954359Sroberto4:
120285612Sdelphij	addl	$8, %esp
12154359Sroberto	popl	%edi
12254359Sroberto	popl	%ebx
12354359Sroberto	ret
12454359Sroberto
12554359Sroberto
12654359Sroberto__do_global_ctors_aux:
12754359Sroberto	pushl	%ebx
12854359Sroberto	pushl	%edi
129285612Sdelphij	subl	$8, %esp
13054359Sroberto	call	__get_thunk
13154359Sroberto	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
13254359Sroberto
13354359Sroberto	cmpb	$0, __initialized@GOTOFF(%ebx)
13454359Sroberto	jne	4f
13554359Sroberto	movb	$1, __initialized@GOTOFF(%ebx)
13654359Sroberto
137285612Sdelphij	cmpl	$0, __register_frame_info@GOT(%ebx)
13854359Sroberto	je	1f
13954359Sroberto	leal	__dwarf_eh_object@GOTOFF(%ebx), %edi
140285612Sdelphij	movl	%edi, 4(%esp)
14154359Sroberto	leal	__EH_FRAME_LIST__@GOTOFF(%ebx), %edi
142285612Sdelphij	movl	%edi, (%esp)
143285612Sdelphij	call	__register_frame_info@PLT
144285612Sdelphij
145285612Sdelphij1:
146285612Sdelphij	cmpl	$0, _Jv_RegisterClasses@GOT(%ebx)
147285612Sdelphij	je	2f
148285612Sdelphij	leal	__JCR_LIST__@GOTOFF(%ebx), %edi
14954359Sroberto	movl	(%edi), %edi
150285612Sdelphij	testl	%edi, %edi
15154359Sroberto	je 	2f
15254359Sroberto	movl	%edi, (%esp)
15354359Sroberto	call	_Jv_RegisterClasses@PLT
15454359Sroberto2:
15554359Sroberto
15654359Sroberto	leal	-4+__CTOR_LIST_END__@GOTOFF(%ebx), %edi
15754359Sroberto3:
15854359Sroberto	movl	(%edi), %eax
159285612Sdelphij	cmpl	$-1, %eax
16054359Sroberto	je	4f
16154359Sroberto	call	*%eax
16254359Sroberto	subl	$4, %edi
16354359Sroberto	jmp	3b
16454359Sroberto
16554359Sroberto4:
16654359Sroberto	addl	$8, %esp
16754359Sroberto	popl	%edi
16854359Sroberto	popl	%ebx
16954359Sroberto	ret
170285612Sdelphij
171285612Sdelphij	.section	.init, "ax", @progbits
172285612Sdelphij	call	__do_global_ctors_aux
17354359Sroberto	.section	.fini, "ax", @progbits
17454359Sroberto	call	__do_global_dtors_aux
17554359Sroberto