crtbegin.S revision 1.1
11.1Smatt/* $NetBSD: crtbegin.S,v 1.1 2013/06/21 15:54:08 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.1SmattRCSID("$NetBSD: crtbegin.S,v 1.1 2013/06/21 15:54:08 matt Exp $") 341.1Smatt 351.1Smatt .section .ctors, "aw", @progbits 361.1Smatt .p2align 2 371.1Smatt__CTOR_LIST__: /* symbol is not used */ 381.1Smatt .word -1 391.1Smatt 401.1Smatt .section .dtors, "aw", @progbits 411.1Smatt .p2align 2 421.1Smatt__DTOR_LIST__: 431.1Smatt 441.1Smatt .section .eh_frame, "a", @progbits 451.1Smatt .p2align 2 461.1Smatt__EH_FRAME_LIST__: 471.1Smatt 481.1Smatt .section .jcr, "aw", @progbits 491.1Smatt .p2align 2 501.1Smatt__JCR_LIST__: 511.1Smatt 521.1Smatt .section .data.rel, "aw", @progbits 531.1Smatt .p2align 2 541.1Smatt .type __dso_handle, @object 551.1Smatt .size __dso_handle, 4 561.1Smatt .globl __dso_handle 571.1Smatt .hidden __dso_handle 581.1Smatt__dso_handle: 591.1Smatt#ifdef SHARED 601.1Smatt .word __dso_handle 611.1Smatt#else 621.1Smatt .word 0 631.1Smatt#endif 641.1Smatt 651.1Smatt .local __dwarf_eh_object 661.1Smatt .comm __dwarf_eh_object,24 671.1Smatt .local __initialized 681.1Smatt .comm __initialized,1 691.1Smatt .local __finished 701.1Smatt .comm __finished,1 711.1Smatt 721.1Smatt .text 731.1Smatt/* 741.1Smatt * All variables are local to this DSO so we can skip using GOT references 751.1Smatt * and instead use PCREL references to access them. We do this regardless 761.1Smatt * of being PIC since it isn't any additional overhead to do so. 771.1Smatt * 781.1Smatt * We don't setup a TOC since all of ours calls are indirect so it isn't 791.1Smatt * needed. 801.1Smatt */ 811.1Smatt 821.1Smatt .type __do_global_dtors_aux, @function 831.1Smatt__do_global_dtors_aux: 841.1Smatt .word 0x0100 /* save r8 */ 851.1Smatt tstb __finished /* done this already? */ 861.1Smatt bneq 4f 871.1Smatt movb $1, __finished /* mark it as done */ 881.1Smatt 891.1Smatt#ifdef SHARED 901.1Smatt /* 911.1Smatt * if (__cxa_finalize) 921.1Smatt * __cxa_finalize(&__dso_handle); 931.1Smatt */ 941.1Smatt movab __cxa_finalize, %r0 951.1Smatt bneq 1f 961.1Smatt pushal __dso_handle 971.1Smatt calls $0, (%r0) 981.1Smatt1: 991.1Smatt#endif /* SHARED */ 1001.1Smatt 1011.1Smatt /* 1021.1Smatt * We use load with postincrement to advance the pointer along. 1031.1Smatt * We know the list ends with 0. If we load one, we must be done. 1041.1Smatt */ 1051.1Smatt moval __DTOR_LIST__, %r8 /* skip first entry */ 1061.1Smatt2: movl (%r8)+, %r0 /* r0 = *r8++; */ 1071.1Smatt beql 3f 1081.1Smatt calls $0, (%r0) 1091.1Smatt brb 2b 1101.1Smatt3: 1111.1Smatt 1121.1Smatt#ifdef SHARED 1131.1Smatt /* 1141.1Smatt * if (__deregister_frame_info) 1151.1Smatt * __deregister_frame_info(&__EH_FRAME_LIST__[0]); 1161.1Smatt */ 1171.1Smatt moval __deregister_frame_info, %r0 1181.1Smatt bneq 4f 1191.1Smatt pushal __EH_FRAME_LIST__ 1201.1Smatt calls $0, (%r0) 1211.1Smatt#endif /* SHARED */ 1221.1Smatt 1231.1Smatt4: ret 1241.1Smatt 1251.1Smatt .weak __deregister_frame_info 1261.1Smatt .weak __cxa_finalize 1271.1Smatt 1281.1Smatt .weak __register_frame_info 1291.1Smatt .weak _Jv_RegisterClasses 1301.1Smatt 1311.1Smatt .type __do_global_ctors_aux, @function 1321.1Smatt__do_global_ctors_aux: 1331.1Smatt tstb __initialized 1341.1Smatt bneq 4f 1351.1Smatt movb $1, __initialized 1361.1Smatt 1371.1Smatt /* 1381.1Smatt * if (__register_frame_info) 1391.1Smatt * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) 1401.1Smatt */ 1411.1Smatt movab __register_frame_info, %r0 1421.1Smatt beql 1f 1431.1Smatt 1441.1Smatt pushal __dwarf_eh_object 1451.1Smatt pushal __EH_FRAME_LIST__ 1461.1Smatt calls $0, (%r0) 1471.1Smatt1: 1481.1Smatt 1491.1Smatt /* 1501.1Smatt * if (_Jv_RegisterClasses && __JCR_LIST__[0]) 1511.1Smatt * _Jv_RegisterClasses(&__JCR_LIST__[0]); 1521.1Smatt */ 1531.1Smatt movab _Jv_RegisterClasses, %r0 1541.1Smatt beql 2f 1551.1Smatt 1561.1Smatt pushal __JCR_LIST__ 1571.1Smatt calls $0, (%r0) 1581.1Smatt2: 1591.1Smatt 1601.1Smatt /* 1611.1Smatt * Get the end of the CTOR list. The first entry is -1 so if we 1621.1Smatt * load a negative address, we know we are done. 1631.1Smatt */ 1641.1Smatt 1651.1Smatt moval __CTOR_LIST_END__, %r8 /* get end of list */ 1661.1Smatt3: movl -(%r8), %r0 /* get function pointer with predec */ 1671.1Smatt blss 4f /* negative? done. */ 1681.1Smatt calls $0, (%r0) /* call it */ 1691.1Smatt brb 3b /* get next one */ 1701.1Smatt 1711.1Smatt4: ret 1721.1Smatt 1731.1Smatt .hidden _C_LABEL(__CTOR_LIST_END__) 1741.1Smatt 1751.1Smatt .section .init, "ax", @progbits 1761.1Smatt calls $0, __do_global_ctors_aux 1771.1Smatt .section .fini, "ax", @progbits 1781.1Smatt calls $0, __do_global_dtors_aux 179