1/* $NetBSD: crtbegin.S,v 1.6 2013/07/10 23:30:45 matt Exp $ */ 2/*- 3 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Matt Thomas of 3am Software Foundry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include <vax/asm.h> 32 33RCSID("$NetBSD: crtbegin.S,v 1.6 2013/07/10 23:30:45 matt Exp $") 34 35 .section .ctors, "aw", @progbits 36 .p2align 2 37__CTOR_LIST__: /* symbol is not used */ 38 .long -1 39 40 .section .dtors, "aw", @progbits 41 .p2align 2 42__DTOR_LIST__: 43 .long -1 44 45 .section .eh_frame, "a", @progbits 46 .p2align 2 47__EH_FRAME_LIST__: 48 49 .section .jcr, "aw", @progbits 50 .p2align 2 51__JCR_LIST__: 52 53 .section .data.rel, "aw", @progbits 54 .p2align 2 55 .type __dso_handle, @object 56 .size __dso_handle, 4 57 .globl __dso_handle 58 .hidden __dso_handle 59__dso_handle: 60#ifdef SHARED 61 .long __dso_handle 62#else 63 .long 0 64#endif 65 66 .local __dwarf_eh_object 67 .comm __dwarf_eh_object,32 68 .local __initialized 69 .comm __initialized,1 70 .local __finished 71 .comm __finished,1 72 73 .text 74/* 75 * All variables are local to this DSO so we can skip using GOT references 76 * and instead use PCREL references to access them. We do this regardless 77 * of being PIC since it isn't any additional overhead to do so. 78 * 79 * We don't setup a TOC since all of ours calls are indirect so it isn't 80 * needed. 81 */ 82 83_ENTRY(__do_global_dtors_aux, 0x0100) /* save r8 */ 84 tstb __finished /* done this already? */ 85 bneq 4f 86 movb $1, __finished /* mark it as done */ 87 88#ifdef SHARED 89 /* 90 * if (__cxa_finalize) 91 * __cxa_finalize(&__dso_handle); 92 */ 93 movab __cxa_finalize, %r0 94 beql 1f 95 pushal __dso_handle 96 calls $0, (%r0) 971: 98#endif /* SHARED */ 99 100 /* 101 * We use load with postincrement to advance the pointer along. 102 * We know the list ends with 0. If we load one, we must be done. 103 */ 104 moval __DTOR_LIST__+4, %r8 /* skip first entry */ 1052: movl (%r8)+, %r0 /* r0 = *r8++; */ 106 beql 3f 107 calls $0, (%r0) 108 brb 2b 1093: 110 111#ifdef SHARED 112 /* 113 * if (__deregister_frame_info) 114 * __deregister_frame_info(&__EH_FRAME_LIST__[0]); 115 */ 116 moval __deregister_frame_info, %r0 117 beql 4f 118 pushal __EH_FRAME_LIST__ 119 calls $0, (%r0) 120#endif /* SHARED */ 121 1224: ret 123END(__do_global_dtors_aux) 124 125 .weak __deregister_frame_info 126 .weak __cxa_finalize 127 128 .weak __register_frame_info 129 .weak _Jv_RegisterClasses 130 131_ENTRY(__do_global_ctors_aux, 0x0800) 132 tstb __initialized 133 bneq 4f 134 movb $1, __initialized 135 136 /* 137 * if (__register_frame_info) 138 * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) 139 */ 140 movab __register_frame_info, %r0 141 beql 1f 142 143 pushal __dwarf_eh_object 144 pushal __EH_FRAME_LIST__ 145 calls $0, (%r0) 1461: 147 148 /* 149 * if (_Jv_RegisterClasses && __JCR_LIST__[0]) 150 * _Jv_RegisterClasses(&__JCR_LIST__[0]); 151 */ 152 movab _Jv_RegisterClasses, %r0 153 beql 2f 154 155 pushal __JCR_LIST__ 156 calls $0, (%r0) 1572: 158 159 /* 160 * Get the end of the CTOR list. The first entry is -1 so if we 161 * load a negative address, we know we are done. 162 */ 163 164 moval __CTOR_LIST_END__, %r8 /* get end of list */ 1653: movl -(%r8), %r0 /* get function pointer with predec */ 166 blss 4f /* negative? done. */ 167 calls $0, (%r0) /* call it */ 168 brb 3b /* get next one */ 169 1704: ret 171END(__do_global_ctors_aux) 172 173 .hidden _C_LABEL(__CTOR_LIST_END__) 174 175 .section .init, "ax", @progbits 176 calls $0, __do_global_ctors_aux 177 .section .fini, "ax", @progbits 178 calls $0, __do_global_dtors_aux 179