xref: /minix3/lib/csu/arch/vax/crtbegin.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: crtbegin.S,v 1.7 2014/03/16 11:41:30 joerg Exp $	*/
284d9c625SLionel Sambuc/*-
384d9c625SLionel Sambuc * Copyright (c) 2013 The NetBSD Foundation, Inc.
484d9c625SLionel Sambuc * All rights reserved.
584d9c625SLionel Sambuc *
684d9c625SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
784d9c625SLionel Sambuc * by Matt Thomas of 3am Software Foundry.
884d9c625SLionel Sambuc *
984d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1084d9c625SLionel Sambuc * modification, are permitted provided that the following conditions
1184d9c625SLionel Sambuc * are met:
1284d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1384d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer.
1484d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1584d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
1684d9c625SLionel Sambuc *    documentation and/or other materials provided with the distribution.
1784d9c625SLionel Sambuc *
1884d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1984d9c625SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2084d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2184d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2284d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2384d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2484d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2584d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2684d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2784d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2884d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
2984d9c625SLionel Sambuc */
3084d9c625SLionel Sambuc
3184d9c625SLionel Sambuc#include <vax/asm.h>
3284d9c625SLionel Sambuc
33*0a6a1f1dSLionel SambucRCSID("$NetBSD: crtbegin.S,v 1.7 2014/03/16 11:41:30 joerg Exp $")
3484d9c625SLionel Sambuc
3584d9c625SLionel Sambuc	.section	.ctors, "aw", @progbits
3684d9c625SLionel Sambuc	.p2align 2
3784d9c625SLionel Sambuc__CTOR_LIST__:		/* symbol is not used */
3884d9c625SLionel Sambuc	.long -1
3984d9c625SLionel Sambuc
4084d9c625SLionel Sambuc	.section	.dtors, "aw", @progbits
4184d9c625SLionel Sambuc	.p2align 2
4284d9c625SLionel Sambuc__DTOR_LIST__:
4384d9c625SLionel Sambuc	.long -1
4484d9c625SLionel Sambuc
4584d9c625SLionel Sambuc	.section	.eh_frame, "a", @progbits
4684d9c625SLionel Sambuc	.p2align 2
4784d9c625SLionel Sambuc__EH_FRAME_LIST__:
4884d9c625SLionel Sambuc
4984d9c625SLionel Sambuc	.section	.jcr, "aw", @progbits
5084d9c625SLionel Sambuc	.p2align 2
5184d9c625SLionel Sambuc__JCR_LIST__:
5284d9c625SLionel Sambuc
5384d9c625SLionel Sambuc	.section	.data.rel, "aw", @progbits
5484d9c625SLionel Sambuc	.p2align 2
5584d9c625SLionel Sambuc	.type	__dso_handle, @object
5684d9c625SLionel Sambuc	.size	__dso_handle, 4
5784d9c625SLionel Sambuc	.globl	__dso_handle
5884d9c625SLionel Sambuc	.hidden	__dso_handle
5984d9c625SLionel Sambuc__dso_handle:
6084d9c625SLionel Sambuc#ifdef SHARED
6184d9c625SLionel Sambuc	.long	__dso_handle
6284d9c625SLionel Sambuc#else
6384d9c625SLionel Sambuc	.long	0
6484d9c625SLionel Sambuc#endif
6584d9c625SLionel Sambuc
6684d9c625SLionel Sambuc	.local	__dwarf_eh_object
6784d9c625SLionel Sambuc	.comm	__dwarf_eh_object,32
6884d9c625SLionel Sambuc	.local	__initialized
6984d9c625SLionel Sambuc	.comm	__initialized,1
7084d9c625SLionel Sambuc	.local	__finished
7184d9c625SLionel Sambuc	.comm	__finished,1
7284d9c625SLionel Sambuc
7384d9c625SLionel Sambuc	.text
7484d9c625SLionel Sambuc/*
7584d9c625SLionel Sambuc * All variables are local to this DSO so we can skip using GOT references
7684d9c625SLionel Sambuc * and instead use PCREL references to access them.  We do this regardless
7784d9c625SLionel Sambuc * of being PIC since it isn't any additional overhead to do so.
7884d9c625SLionel Sambuc *
7984d9c625SLionel Sambuc * We don't setup a TOC since all of ours calls are indirect so it isn't
8084d9c625SLionel Sambuc * needed.
8184d9c625SLionel Sambuc */
8284d9c625SLionel Sambuc
83*0a6a1f1dSLionel Sambuc	.hidden __do_global_dtors_aux
84*0a6a1f1dSLionel Sambuc
8584d9c625SLionel Sambuc_ENTRY(__do_global_dtors_aux, 0x0100)		/* save r8 */
8684d9c625SLionel Sambuc	tstb	__finished			/* done this already? */
8784d9c625SLionel Sambuc	bneq	4f
8884d9c625SLionel Sambuc	movb	$1, __finished			/* mark it as done */
8984d9c625SLionel Sambuc
9084d9c625SLionel Sambuc#ifdef SHARED
9184d9c625SLionel Sambuc	/*
9284d9c625SLionel Sambuc	 * if (__cxa_finalize)
9384d9c625SLionel Sambuc	 *	__cxa_finalize(&__dso_handle);
9484d9c625SLionel Sambuc	 */
9584d9c625SLionel Sambuc	movab	__cxa_finalize, %r0
9684d9c625SLionel Sambuc	beql	1f
9784d9c625SLionel Sambuc	pushal	__dso_handle
9884d9c625SLionel Sambuc	calls	$0, (%r0)
9984d9c625SLionel Sambuc1:
10084d9c625SLionel Sambuc#endif /* SHARED */
10184d9c625SLionel Sambuc
10284d9c625SLionel Sambuc	/*
10384d9c625SLionel Sambuc	 * We use load with postincrement to advance the pointer along.
10484d9c625SLionel Sambuc	 * We know the list ends with 0.  If we load one, we must be done.
10584d9c625SLionel Sambuc	 */
10684d9c625SLionel Sambuc	moval	__DTOR_LIST__+4, %r8	/* skip first entry */
10784d9c625SLionel Sambuc2:	movl	(%r8)+, %r0		/* r0 = *r8++; */
10884d9c625SLionel Sambuc	beql	3f
10984d9c625SLionel Sambuc	calls	$0, (%r0)
11084d9c625SLionel Sambuc	brb	2b
11184d9c625SLionel Sambuc3:
11284d9c625SLionel Sambuc
11384d9c625SLionel Sambuc#ifdef SHARED
11484d9c625SLionel Sambuc	/*
11584d9c625SLionel Sambuc	 * if (__deregister_frame_info)
11684d9c625SLionel Sambuc	 *     __deregister_frame_info(&__EH_FRAME_LIST__[0]);
11784d9c625SLionel Sambuc	 */
11884d9c625SLionel Sambuc	moval	__deregister_frame_info, %r0
11984d9c625SLionel Sambuc	beql	4f
12084d9c625SLionel Sambuc	pushal	__EH_FRAME_LIST__
12184d9c625SLionel Sambuc	calls	$0, (%r0)
12284d9c625SLionel Sambuc#endif /* SHARED */
12384d9c625SLionel Sambuc
12484d9c625SLionel Sambuc4:	ret
12584d9c625SLionel SambucEND(__do_global_dtors_aux)
12684d9c625SLionel Sambuc
12784d9c625SLionel Sambuc	.weak	__deregister_frame_info
12884d9c625SLionel Sambuc	.weak	__cxa_finalize
12984d9c625SLionel Sambuc
13084d9c625SLionel Sambuc	.weak	__register_frame_info
13184d9c625SLionel Sambuc	.weak	_Jv_RegisterClasses
13284d9c625SLionel Sambuc
133*0a6a1f1dSLionel Sambuc	.hidden __do_global_ctors_aux
134*0a6a1f1dSLionel Sambuc
13584d9c625SLionel Sambuc_ENTRY(__do_global_ctors_aux, 0x0800)
13684d9c625SLionel Sambuc	tstb	__initialized
13784d9c625SLionel Sambuc	bneq	4f
13884d9c625SLionel Sambuc	movb	$1, __initialized
13984d9c625SLionel Sambuc
14084d9c625SLionel Sambuc	/*
14184d9c625SLionel Sambuc	 * if (__register_frame_info)
14284d9c625SLionel Sambuc	 *     __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object)
14384d9c625SLionel Sambuc	 */
14484d9c625SLionel Sambuc	movab	__register_frame_info, %r0
14584d9c625SLionel Sambuc	beql	1f
14684d9c625SLionel Sambuc
14784d9c625SLionel Sambuc	pushal	__dwarf_eh_object
14884d9c625SLionel Sambuc	pushal	__EH_FRAME_LIST__
14984d9c625SLionel Sambuc	calls	$0, (%r0)
15084d9c625SLionel Sambuc1:
15184d9c625SLionel Sambuc
15284d9c625SLionel Sambuc	/*
15384d9c625SLionel Sambuc	 * if (_Jv_RegisterClasses && __JCR_LIST__[0])
15484d9c625SLionel Sambuc	 *     _Jv_RegisterClasses(&__JCR_LIST__[0]);
15584d9c625SLionel Sambuc	 */
15684d9c625SLionel Sambuc	movab	_Jv_RegisterClasses, %r0
15784d9c625SLionel Sambuc	beql	2f
15884d9c625SLionel Sambuc
15984d9c625SLionel Sambuc	pushal	__JCR_LIST__
16084d9c625SLionel Sambuc	calls	$0, (%r0)
16184d9c625SLionel Sambuc2:
16284d9c625SLionel Sambuc
16384d9c625SLionel Sambuc	/*
16484d9c625SLionel Sambuc	 * Get the end of the CTOR list.  The first entry is -1 so if we
16584d9c625SLionel Sambuc	 * load a negative address, we know we are done.
16684d9c625SLionel Sambuc	 */
16784d9c625SLionel Sambuc
16884d9c625SLionel Sambuc	moval	__CTOR_LIST_END__, %r8	/* get end of list */
16984d9c625SLionel Sambuc3:	movl	-(%r8), %r0		/* get function pointer with predec */
17084d9c625SLionel Sambuc	blss	4f			/*  negative?  done. */
17184d9c625SLionel Sambuc	calls	$0, (%r0)		/* call it */
17284d9c625SLionel Sambuc	brb	3b			/* get next one */
17384d9c625SLionel Sambuc
17484d9c625SLionel Sambuc4:	ret
17584d9c625SLionel SambucEND(__do_global_ctors_aux)
17684d9c625SLionel Sambuc
17784d9c625SLionel Sambuc	.hidden	_C_LABEL(__CTOR_LIST_END__)
17884d9c625SLionel Sambuc
17984d9c625SLionel Sambuc	.section	.init, "ax", @progbits
18084d9c625SLionel Sambuc	calls	$0, __do_global_ctors_aux
18184d9c625SLionel Sambuc	.section	.fini, "ax", @progbits
18284d9c625SLionel Sambuc	calls	$0, __do_global_dtors_aux
183