kernel: scheduling fix for ARM
[minix.git] / lib / csu / hppa / crt0.c
blobcee69a2fffa35d59b34475e79b05748c33c18642
1 /* $NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $ */
3 /*
4 * Copyright (c) 2002 Matt Fredette
5 * Copyright (c) 1999 Klaus Klein
6 * Copyright (c) 1995 Christopher G. Demetriou
7 * All rights reserved.
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 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the
20 * NetBSD Project. See http://www.NetBSD.org/ for
21 * information about NetBSD.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
39 #include "common.h"
41 static void ___start(struct ps_strings *,
42 void (*cleanup)(void), const Obj_Entry *, int)
43 #ifdef __GNUC__
44 __attribute__((__used__))
45 #endif
48 __asm("\n"
49 " .text \n"
50 " .align 4 \n"
51 " .globl _start \n"
52 " .globl __start \n"
53 " .type _start,@function \n"
54 " .type __start,@function \n"
55 "_start: \n"
56 "__start: \n"
57 " .import _GLOBAL_OFFSET_TABLE_ \n"
58 "\n"
59 " bl L$lpc, %r27 \n"
60 " depi 0, 31, 2, %r27 \n"
61 "L$lpc: addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 8), %r27 \n"
62 " ldo R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 12)(%r1),%r27 \n"
63 " copy %r27, %r19 \n"
64 " b ___start \n"
65 " copy %r27, %arg3 \n");
67 static void
68 ___start(struct ps_strings *ps_strings,
69 void (*cleanup)(void), /* from shared loader */
70 const Obj_Entry *obj, /* from shared loader */
71 int dp)
73 int argc;
74 char **argv;
75 int fini_plabel[2];
77 argc = ps_strings->ps_nargvstr;
78 argv = ps_strings->ps_argvstr;
79 environ = ps_strings->ps_envstr;
81 if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
82 if ((__progname = _strrchr(__progname, '/')) == NULL)
83 __progname = argv[0];
84 else
85 __progname++;
88 if (ps_strings != (struct ps_strings *)0)
89 __ps_strings = ps_strings;
91 #ifdef DYNAMIC
92 if (&rtld_DYNAMIC != NULL)
93 _rtld_setup(cleanup, obj);
94 #endif
96 _libc_init();
98 #ifdef MCRT0
99 atexit(_mcleanup);
100 monstartup((u_long)&_eprol, (u_long)&_etext);
101 #endif
104 * Since crt0.o, crtbegin.o, and crtend.o are always
105 * compiled PIC, they must have %r19 set correctly on
106 * entry to any function they contain. However, when
107 * a program is linked statically, the linker does
108 * not fill a PLABEL relocation with a pointer to a
109 * true PLABEL, it just fills it with the offset of the
110 * function. This shows the linker's assumption that
111 * when linking statically, *all* of the code has *not*
112 * been compiled PIC. I guess to assume otherwise
113 * would be a performance hit, as you would end up
114 * with unnecessary PLABELs for function pointers.
116 * But here, passing the address of the PIC _fini to
117 * atexit, we must make sure that we pass a PLABEL.
119 fini_plabel[0] = (int)_fini;
120 if (fini_plabel[0] & 2)
121 /* _fini is already a PLABEL. */
122 atexit(_fini);
123 else {
124 fini_plabel[1] = dp;
125 atexit((void (*)(void))(((int)fini_plabel) | 2));
127 _init();
129 exit(main(argc, argv, environ));
133 * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
135 #if defined(LIBC_SCCS) && !defined(lint)
136 __RCSID("$NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $");
137 #endif /* LIBC_SCCS and not lint */
139 #include "common.c"