1 /* $Id: crtbegin.c,v 1.6 2009/08/16 23:07:07 gmcgarry Exp $ */
3 * Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
32 * Run-time module which handles constructors and destructors.
37 void __do_global_ctors_aux(void);
38 void __do_global_dtors_aux(void);
40 extern void (*__CTOR_LIST__
[1])(void);
41 extern void (*__DTOR_LIST__
[1])(void);
43 asm( " .section .ctors\n"
65 unsigned long i
= (unsigned long) __CTOR_LIST__
[0];
68 if (i
== (unsigned long) -1) {
69 for (i
= 1; __CTOR_LIST__
[i
]; i
++)
73 p
= __CTOR_LIST__
+ i
;
81 void (**p
)(void) = __DTOR_LIST__
+ 1;
88 __do_global_ctors_aux(void)
90 static int initialized
;
99 __do_global_dtors_aux(void)
111 #define MD_CALL_STATIC_FUNCTION(section, func) \
112 void __call_##func(void); \
113 void __call_##func(void) \
115 asm volatile (".section " #section); \
117 asm volatile (".previous"); \
120 MD_CALL_STATIC_FUNCTION(.init
, __do_global_ctors_aux
)
121 MD_CALL_STATIC_FUNCTION(.fini
, __do_global_dtors_aux
)
123 IDENT("$Id: crtbegin.c,v 1.6 2009/08/16 23:07:07 gmcgarry Exp $");