* add p cc
[mascara-docs.git] / compilers / pcc / pcc-libs-1.0.0 / csu / linux / crtbegin.c
blob58056f6f474255a38131905b519dae9e25953275
1 /* $Id: crtbegin.c,v 1.6 2009/08/16 23:07:07 gmcgarry Exp $ */
2 /*-
3 * Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
4 * All rights reserved.
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
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.
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.
35 #include "common.h"
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"
44 " .align 2\n"
45 "__CTOR_LIST__:\n"
46 #ifdef __x86_64__
47 " .quad -1\n"
48 #else
49 " .long -1\n"
50 #endif
51 " .section .dtors\n"
52 " .align 2\n"
53 "__DTOR_LIST__:\n"
54 #ifdef __x86_64__
55 " .quad -1\n"
56 #else
57 " .long -1\n"
58 #endif
62 static void
63 __ctors(void)
65 unsigned long i = (unsigned long) __CTOR_LIST__[0];
66 void (**p)(void);
68 if (i == (unsigned long) -1) {
69 for (i = 1; __CTOR_LIST__[i]; i++)
71 i--;
73 p = __CTOR_LIST__ + i;
74 while (i--)
75 (**p--)();
78 static void
79 __dtors(void)
81 void (**p)(void) = __DTOR_LIST__ + 1;
83 while (*p)
84 (**p++)();
87 void
88 __do_global_ctors_aux(void)
90 static int initialized;
92 if (!initialized) {
93 initialized = 1;
94 __ctors();
98 void
99 __do_global_dtors_aux(void)
101 static int finished;
103 if (finished)
104 return;
106 __dtors();
108 finished = 1;
111 #define MD_CALL_STATIC_FUNCTION(section, func) \
112 void __call_##func(void); \
113 void __call_##func(void) \
115 asm volatile (".section " #section); \
116 func(); \
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 $");