crtbegin.S revision 1.5
11.5Smatt/*	$NetBSD: crtbegin.S,v 1.5 2013/07/10 22:55:40 matt Exp $	*/
21.1Smatt/*-
31.1Smatt * Copyright (c) 2013 The NetBSD Foundation, Inc.
41.1Smatt * All rights reserved.
51.1Smatt *
61.1Smatt * This code is derived from software contributed to The NetBSD Foundation
71.1Smatt * by Matt Thomas of 3am Software Foundry.
81.1Smatt *
91.1Smatt * Redistribution and use in source and binary forms, with or without
101.1Smatt * modification, are permitted provided that the following conditions
111.1Smatt * are met:
121.1Smatt * 1. Redistributions of source code must retain the above copyright
131.1Smatt *    notice, this list of conditions and the following disclaimer.
141.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
151.1Smatt *    notice, this list of conditions and the following disclaimer in the
161.1Smatt *    documentation and/or other materials provided with the distribution.
171.1Smatt *
181.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Smatt * POSSIBILITY OF SUCH DAMAGE.
291.1Smatt */
301.1Smatt
311.1Smatt#include <vax/asm.h>
321.1Smatt
331.5SmattRCSID("$NetBSD: crtbegin.S,v 1.5 2013/07/10 22:55:40 matt Exp $")
341.1Smatt
351.1Smatt	.section	.ctors, "aw", @progbits
361.1Smatt	.p2align 2
371.1Smatt__CTOR_LIST__:		/* symbol is not used */
381.3Smatt	.long -1
391.1Smatt
401.1Smatt	.section	.dtors, "aw", @progbits
411.1Smatt	.p2align 2
421.1Smatt__DTOR_LIST__:
431.3Smatt	.long -1
441.1Smatt
451.1Smatt	.section	.eh_frame, "a", @progbits
461.1Smatt	.p2align 2
471.1Smatt__EH_FRAME_LIST__:
481.1Smatt
491.1Smatt	.section	.jcr, "aw", @progbits
501.1Smatt	.p2align 2
511.1Smatt__JCR_LIST__:
521.1Smatt
531.1Smatt	.section	.data.rel, "aw", @progbits
541.1Smatt	.p2align 2
551.1Smatt	.type	__dso_handle, @object
561.1Smatt	.size	__dso_handle, 4
571.1Smatt	.globl	__dso_handle
581.1Smatt	.hidden	__dso_handle
591.1Smatt__dso_handle:
601.1Smatt#ifdef SHARED
611.3Smatt	.long	__dso_handle
621.1Smatt#else
631.3Smatt	.long	0
641.1Smatt#endif
651.1Smatt
661.1Smatt	.local	__dwarf_eh_object
671.2Smatt	.comm	__dwarf_eh_object,32
681.1Smatt	.local	__initialized
691.1Smatt	.comm	__initialized,1
701.1Smatt	.local	__finished
711.1Smatt	.comm	__finished,1
721.1Smatt
731.1Smatt	.text
741.1Smatt/*
751.1Smatt * All variables are local to this DSO so we can skip using GOT references
761.1Smatt * and instead use PCREL references to access them.  We do this regardless
771.1Smatt * of being PIC since it isn't any additional overhead to do so.
781.1Smatt *
791.1Smatt * We don't setup a TOC since all of ours calls are indirect so it isn't
801.1Smatt * needed.
811.1Smatt */
821.1Smatt
831.3Smatt_ENTRY(__do_global_dtors_aux, 0x0100)		/* save r8 */
841.1Smatt	tstb	__finished			/* done this already? */
851.1Smatt	bneq	4f
861.1Smatt	movb	$1, __finished			/* mark it as done */
871.1Smatt
881.1Smatt#ifdef SHARED
891.1Smatt	/*
901.1Smatt	 * if (__cxa_finalize)
911.1Smatt	 *	__cxa_finalize(&__dso_handle);
921.1Smatt	 */
931.1Smatt	movab	__cxa_finalize, %r0
941.4Smatt	beql	1f
951.1Smatt	pushal	__dso_handle
961.1Smatt	calls	$0, (%r0)
971.1Smatt1:
981.1Smatt#endif /* SHARED */
991.1Smatt
1001.1Smatt	/*
1011.1Smatt	 * We use load with postincrement to advance the pointer along.
1021.1Smatt	 * We know the list ends with 0.  If we load one, we must be done.
1031.1Smatt	 */
1041.2Smatt	moval	__DTOR_LIST__+4, %r8	/* skip first entry */
1051.1Smatt2:	movl	(%r8)+, %r0		/* r0 = *r8++; */
1061.1Smatt	beql	3f
1071.1Smatt	calls	$0, (%r0)
1081.1Smatt	brb	2b
1091.1Smatt3:
1101.1Smatt
1111.1Smatt#ifdef SHARED
1121.1Smatt	/*
1131.1Smatt	 * if (__deregister_frame_info)
1141.1Smatt	 *     __deregister_frame_info(&__EH_FRAME_LIST__[0]);
1151.1Smatt	 */
1161.1Smatt	moval	__deregister_frame_info, %r0
1171.5Smatt	beql	4f
1181.1Smatt	pushal	__EH_FRAME_LIST__
1191.1Smatt	calls	$0, (%r0)
1201.1Smatt#endif /* SHARED */
1211.1Smatt
1221.1Smatt4:	ret
1231.1Smatt
1241.1Smatt	.weak	__deregister_frame_info
1251.1Smatt	.weak	__cxa_finalize
1261.1Smatt
1271.1Smatt	.weak	__register_frame_info
1281.1Smatt	.weak	_Jv_RegisterClasses
1291.1Smatt
1301.3Smatt_ENTRY(__do_global_ctors_aux, 0x0800)
1311.1Smatt	tstb	__initialized
1321.1Smatt	bneq	4f
1331.1Smatt	movb	$1, __initialized
1341.1Smatt
1351.1Smatt	/*
1361.1Smatt	 * if (__register_frame_info)
1371.1Smatt	 *     __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object)
1381.1Smatt	 */
1391.1Smatt	movab	__register_frame_info, %r0
1401.1Smatt	beql	1f
1411.1Smatt
1421.1Smatt	pushal	__dwarf_eh_object
1431.1Smatt	pushal	__EH_FRAME_LIST__
1441.1Smatt	calls	$0, (%r0)
1451.1Smatt1:
1461.1Smatt
1471.1Smatt	/*
1481.1Smatt	 * if (_Jv_RegisterClasses && __JCR_LIST__[0])
1491.1Smatt	 *     _Jv_RegisterClasses(&__JCR_LIST__[0]);
1501.1Smatt	 */
1511.1Smatt	movab	_Jv_RegisterClasses, %r0
1521.1Smatt	beql	2f
1531.1Smatt
1541.1Smatt	pushal	__JCR_LIST__
1551.1Smatt	calls	$0, (%r0)
1561.1Smatt2:
1571.1Smatt
1581.1Smatt	/*
1591.1Smatt	 * Get the end of the CTOR list.  The first entry is -1 so if we
1601.1Smatt	 * load a negative address, we know we are done.
1611.1Smatt	 */
1621.1Smatt
1631.1Smatt	moval	__CTOR_LIST_END__, %r8	/* get end of list */
1641.1Smatt3:	movl	-(%r8), %r0		/* get function pointer with predec */
1651.1Smatt	blss	4f			/*  negative?  done. */
1661.1Smatt	calls	$0, (%r0)		/* call it */
1671.1Smatt	brb	3b			/* get next one */
1681.1Smatt
1691.1Smatt4:	ret
1701.1Smatt
1711.1Smatt	.hidden	_C_LABEL(__CTOR_LIST_END__)
1721.1Smatt
1731.1Smatt	.section	.init, "ax", @progbits
1741.1Smatt	calls	$0, __do_global_ctors_aux
1751.1Smatt	.section	.fini, "ax", @progbits
1761.1Smatt	calls	$0, __do_global_dtors_aux
177