crtbegin.S revision 1.9
11.9Srin/* $NetBSD: crtbegin.S,v 1.9 2023/07/28 07:17:30 rin 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.9SrinRCSID("$NetBSD: crtbegin.S,v 1.9 2023/07/28 07:17:30 rin 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.7Sjoerg .hidden __do_global_dtors_aux 841.7Sjoerg 851.9Srin_ENTRY(__do_global_dtors_aux, R8) 861.1Smatt tstb __finished /* done this already? */ 871.1Smatt bneq 4f 881.1Smatt movb $1, __finished /* mark it as done */ 891.1Smatt 901.1Smatt#ifdef SHARED 911.1Smatt /* 921.1Smatt * if (__cxa_finalize) 931.1Smatt * __cxa_finalize(&__dso_handle); 941.1Smatt */ 951.1Smatt movab __cxa_finalize, %r0 961.4Smatt beql 1f 971.1Smatt pushal __dso_handle 981.1Smatt calls $0, (%r0) 991.1Smatt1: 1001.1Smatt#endif /* SHARED */ 1011.1Smatt 1021.1Smatt /* 1031.1Smatt * We use load with postincrement to advance the pointer along. 1041.1Smatt * We know the list ends with 0. If we load one, we must be done. 1051.1Smatt */ 1061.2Smatt moval __DTOR_LIST__+4, %r8 /* skip first entry */ 1071.1Smatt2: movl (%r8)+, %r0 /* r0 = *r8++; */ 1081.1Smatt beql 3f 1091.1Smatt calls $0, (%r0) 1101.1Smatt brb 2b 1111.1Smatt3: 1121.1Smatt 1131.1Smatt#ifdef SHARED 1141.1Smatt /* 1151.1Smatt * if (__deregister_frame_info) 1161.1Smatt * __deregister_frame_info(&__EH_FRAME_LIST__[0]); 1171.1Smatt */ 1181.1Smatt moval __deregister_frame_info, %r0 1191.5Smatt beql 4f 1201.1Smatt pushal __EH_FRAME_LIST__ 1211.1Smatt calls $0, (%r0) 1221.1Smatt#endif /* SHARED */ 1231.1Smatt 1241.1Smatt4: ret 1251.6SmattEND(__do_global_dtors_aux) 1261.1Smatt 1271.1Smatt .weak __deregister_frame_info 1281.1Smatt .weak __cxa_finalize 1291.1Smatt 1301.1Smatt .weak __register_frame_info 1311.1Smatt .weak _Jv_RegisterClasses 1321.1Smatt 1331.7Sjoerg .hidden __do_global_ctors_aux 1341.7Sjoerg 1351.9Srin_ENTRY(__do_global_ctors_aux, R8) 1361.1Smatt tstb __initialized 1371.1Smatt bneq 4f 1381.1Smatt movb $1, __initialized 1391.1Smatt 1401.1Smatt /* 1411.1Smatt * if (__register_frame_info) 1421.1Smatt * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) 1431.1Smatt */ 1441.1Smatt movab __register_frame_info, %r0 1451.1Smatt beql 1f 1461.1Smatt 1471.1Smatt pushal __dwarf_eh_object 1481.1Smatt pushal __EH_FRAME_LIST__ 1491.1Smatt calls $0, (%r0) 1501.1Smatt1: 1511.1Smatt 1521.1Smatt /* 1531.1Smatt * if (_Jv_RegisterClasses && __JCR_LIST__[0]) 1541.1Smatt * _Jv_RegisterClasses(&__JCR_LIST__[0]); 1551.1Smatt */ 1561.1Smatt movab _Jv_RegisterClasses, %r0 1571.1Smatt beql 2f 1581.1Smatt 1591.1Smatt pushal __JCR_LIST__ 1601.1Smatt calls $0, (%r0) 1611.1Smatt2: 1621.1Smatt 1631.1Smatt /* 1641.1Smatt * Get the end of the CTOR list. The first entry is -1 so if we 1651.1Smatt * load a negative address, we know we are done. 1661.1Smatt */ 1671.1Smatt 1681.1Smatt moval __CTOR_LIST_END__, %r8 /* get end of list */ 1691.1Smatt3: movl -(%r8), %r0 /* get function pointer with predec */ 1701.1Smatt blss 4f /* negative? done. */ 1711.1Smatt calls $0, (%r0) /* call it */ 1721.1Smatt brb 3b /* get next one */ 1731.1Smatt 1741.1Smatt4: ret 1751.6SmattEND(__do_global_ctors_aux) 1761.1Smatt 1771.1Smatt .hidden _C_LABEL(__CTOR_LIST_END__) 1781.1Smatt 1791.1Smatt .section .init, "ax", @progbits 1801.1Smatt calls $0, __do_global_ctors_aux 1811.1Smatt .section .fini, "ax", @progbits 1821.1Smatt calls $0, __do_global_dtors_aux 183