1 /* $NetBSD: crt0.c,v 1.28 2005/12/24 21:38:40 perry Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 extern void start
__P((void)) __asm ("start");
38 #if defined(sun) && defined(sparc)
39 static void __call
__P((void));
44 #define mmap(addr, len, prot, flags, fd, off) \
45 __syscall2((quad_t)SYS_mmap, (addr), (len), (prot), (flags), \
46 (fd), 0, (off_t)(off))
47 extern int __syscall2
__P((quad_t
, ...));
56 ld [%sp + 64], %l0 ! get argc
57 add %sp, 68, %l1 ! get argv
59 add %l2, 4, %l2 ! envp = argv + (argc << 2) + 4
61 sethi %hi(_environ), %l3
62 st %l2, [%l3+%lo(_environ)] ! *environ = l2
66 * We get a pointer to PSSTRINGS in %g1.
71 sethi %hi(___ps_strings), %l3
72 st %g1, [%l3+%lo(___ps_strings)]
77 * Finish diddling with stack.
80 andn %sp, 7, %sp ! align
81 sub %sp, 24, %sp ! expand to standard stack frame size
87 * if ((__progname = _strrchr(argv[0], '/')) == NULL)
88 * __progname = argv[0];
97 sethi %hi(___progname), %l7
100 __asm("call __strrchr");
102 __asm("call _strrchr");
108 st %l6, [%l7+%lo(___progname)]
110 st %o0, [%l7+%lo(___progname)]
115 /* Resolve symbols in dynamic libraries */
117 sethi %hi(__DYNAMIC), %o0
118 orcc %o0, %lo(__DYNAMIC), %o0
127 /* From here, all symbols should have been resolved, so we can use libc */
131 * monstartup((u_long)&eprol, (u_long)&etext);
134 sethi %hi(__mcleanup), %o0
136 or %o0, %lo(__mcleanup), %o0
137 sethi %hi(_eprol), %o0
138 or %o0, %lo(_eprol), %o0
139 sethi %hi(_etext), %o1
141 or %o1, %lo(_etext), %o1
147 * SunOS compatibility
156 * Move `argc', `argv', and `envp' from locals to parameters for `main'.
174 .set SYSCALL_G2RFLAG, 0x400
175 .set SYS___syscall, 198
177 sethi %hi(SYS___syscall), %g1
179 or %g1, %lo(SYS___syscall), %g1
183 or %g1, SYSCALL_G2RFLAG, %g1
197 * adjust the C generated pointer to the crt struct to the
198 * likings of ld.so, which is an offset relative to its %fp
206 /*NOTREACHED, control is transferred directly to our caller */
212 #if defined(LIBC_SCCS) && !defined(lint)
213 __RCSID("$NetBSD: crt0.c,v 1.28 2005/12/24 21:38:40 perry Exp $");
214 #endif /* LIBC_SCCS and not lint */