crtbegin.S revision 1.4
1/* $NetBSD: crtbegin.S,v 1.4 2013/07/10 14:27:01 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.4 2013/07/10 14:27:01 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 bneq 4f 118 pushal __EH_FRAME_LIST__ 119 calls $0, (%r0) 120#endif /* SHARED */ 121 1224: ret 123 124 .weak __deregister_frame_info 125 .weak __cxa_finalize 126 127 .weak __register_frame_info 128 .weak _Jv_RegisterClasses 129 130_ENTRY(__do_global_ctors_aux, 0x0800) 131 tstb __initialized 132 bneq 4f 133 movb $1, __initialized 134 135 /* 136 * if (__register_frame_info) 137 * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) 138 */ 139 movab __register_frame_info, %r0 140 beql 1f 141 142 pushal __dwarf_eh_object 143 pushal __EH_FRAME_LIST__ 144 calls $0, (%r0) 1451: 146 147 /* 148 * if (_Jv_RegisterClasses && __JCR_LIST__[0]) 149 * _Jv_RegisterClasses(&__JCR_LIST__[0]); 150 */ 151 movab _Jv_RegisterClasses, %r0 152 beql 2f 153 154 pushal __JCR_LIST__ 155 calls $0, (%r0) 1562: 157 158 /* 159 * Get the end of the CTOR list. The first entry is -1 so if we 160 * load a negative address, we know we are done. 161 */ 162 163 moval __CTOR_LIST_END__, %r8 /* get end of list */ 1643: movl -(%r8), %r0 /* get function pointer with predec */ 165 blss 4f /* negative? done. */ 166 calls $0, (%r0) /* call it */ 167 brb 3b /* get next one */ 168 1694: ret 170 171 .hidden _C_LABEL(__CTOR_LIST_END__) 172 173 .section .init, "ax", @progbits 174 calls $0, __do_global_ctors_aux 175 .section .fini, "ax", @progbits 176 calls $0, __do_global_dtors_aux 177