1 /* $OpenBSD: crt0.c,v 1.13 2012/12/22 12:14:32 kettenis Exp $ */
4 * Copyright (c) 2001 Michael Shalayeff
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
29 int global
__asm ("$global$") = 0;
31 #include <sys/param.h>
32 #include <sys/syscall.h>
33 #include <sys/fcntl.h>
38 typedef char Obj_Entry
;
41 * Lots of the chunks of this file cobbled together from pieces of
42 * other OpenBSD crt files, including the common code.
47 extern void __init(void);
48 extern void __fini(void);
51 extern void monstartup(u_long
, u_long
);
52 extern void _mcleanup(void);
53 extern unsigned char etext
, eprol
;
56 static char *__strrchr(const char *p
, char ch
);
58 char *__progname
= "";
59 char __progname_storage
[NAME_MAX
+1];
61 void ___start(struct ps_strings
*arginfo
, void (*cleanup
)(void));
64 ".import $global$, data\n\t"
65 ".import ___start, code\n\t"
68 ".export _start, entry\n\t"
69 ".export __start, entry\n\t"
70 ".type _start,@function\n\t"
71 ".type __start,@function\n\t"
75 ".callinfo frame=0, calls\n\t"
78 "depi 0, 31, 2, %r27\n\t"
79 "L$lpc: addil L'$global$ - ($PIC_pcrel$0 - 8), %r27\n\t"
80 "ldo R'$global$ - ($PIC_pcrel$0 - 12)(%r1),%r27\n\t"
88 ___start(struct ps_strings
*arginfo
, void (*cleanup
)(void))
93 argv
= arginfo
->ps_argvstr
;
94 environ
= arginfo
->ps_envstr
;
95 if ((namep
= argv
[0]) != NULL
) { /* NULL ptr if argc = 0 */
96 if ((__progname
= __strrchr(namep
, '/')) == NULL
)
100 for (s
= __progname_storage
; *__progname
&&
101 s
< &__progname_storage
[sizeof __progname_storage
- 1]; )
102 *s
++ = *__progname
++;
104 __progname
= __progname_storage
;
112 monstartup((u_long
)&eprol
, (u_long
)&etext
);
117 exit(main(arginfo
->ps_nargvstr
, argv
, environ
));
121 __strrchr(const char *p
, char ch
)
125 for (save
= NULL
;; ++p
) {
134 __asm (".export eprol, entry\n\t.label eprol");