Sync usage with man page.
[netbsd-mini2440.git] / lib / csu / arm32 / crt0.c
blob31909495af24bf567ce9e2808b6ab021d6bb82a8
1 /* $NetBSD: crt0.c,v 1.12 2008/03/15 10:46:24 rearnsha Exp $ */
3 /*
4 * Copyright (C) 1997 Mark Brinicombe
5 * Copyright (C) 1995 Wolfgang Solfrank.
6 * Copyright (C) 1995 TooLs GmbH.
7 * All rights reserved.
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 by TooLs GmbH.
20 * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 #include <stdlib.h>
38 #include "common.h"
40 #if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5__) || \
41 defined (__ARM_ARCH_5T__) || defined (__ARM_ARCH_5TE__) || \
42 defined (__ARM_ARCH_5TEJ__)
43 #define _ARM_ARCH_5
44 #endif
46 #if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__)
47 #define _ARM_ARCH_4T
48 #endif
50 #undef mmap
51 #define mmap(addr, len, prot, flags, fd, off) \
52 __syscall(SYS_mmap, (addr), (len), (prot), (flags), \
53 (fd), 0, (off_t)(off))
55 extern void start(void) __asm("start");
56 void __start(int, char *[], char *[]);
58 __asm("
59 .text
60 .align 0
61 .global start
62 start:
63 /* Get ps_strings pointer from kernel */
64 teq r10, #0
65 ldr r3, Lps_strings
66 movne r0, #0
67 str r0, [r3]
69 /* Get argc, argv, and envp from stack */
70 ldr r0, [sp, #0x0000]
71 add r1, sp, #0x0004
72 add r2, r1, r0, lsl #2
73 add r2, r2, #0x0004
75 b " ___STRING(_C_LABEL(__start)) "
76 .align 0
77 Lps_strings:
78 .word " ___STRING(_C_LABEL(__ps_strings)) "
79 ");
81 #if defined(LIBC_SCCS) && !defined(lint)
82 __RCSID("$NetBSD: crt0.c,v 1.12 2008/03/15 10:46:24 rearnsha Exp $");
83 #endif /* LIBC_SCCS and not lint */
85 void
86 __start(int argc, char **argv, char **envp)
88 char *ap;
90 environ = envp;
92 if ((ap = argv[0]))
93 if ((__progname = _strrchr(ap, '/')) == NULL)
94 __progname = ap;
95 else
96 ++__progname;
98 #ifdef DYNAMIC
99 /* ld(1) convention: if DYNAMIC = 0 then statically linked */
100 if (&_DYNAMIC)
101 __load_rtld(&_DYNAMIC);
102 #endif /* DYNAMIC */
104 #ifdef MCRT0
105 atexit(_mcleanup);
106 monstartup((u_long)&eprol, (u_long)&etext);
107 #endif /* MCRT0 */
109 __asm("__callmain:"); /* Defined for the benefit of debuggers */
110 exit(main(argc, argv, envp));
113 #ifndef ntohl
114 inline in_addr_t
115 __crt0_swap(x)
116 in_addr_t x;
118 #if BYTE_ORDER == LITTLE_ENDIAN
119 return( ((x & 0x000000ff) << 24)
120 | ((x & 0x0000ff00) << 8)
121 | ((x & 0x00ff0000) >> 8)
122 | ((x & 0xff000000) >> 24));
123 #else
124 return x;
125 #endif /* BYTE_ORDER */
128 #define ntohl(x) __crt0_swap(x)
129 #define htonl(x) __crt0_swap(x)
130 #endif /* ntohl */
132 #ifdef DYNAMIC
133 __asm("
134 .text
135 .align 0
136 ___syscall:
137 swi 0
138 mvncs r0, #0
140 #ifdef _ARM_ARCH_4T
141 " bx lr
143 #else
144 " mov pc, lr
146 #endif
148 #endif /* DYNAMIC */
150 #include "common.c"
152 #ifdef MCRT0
153 __asm("
154 .text
155 .align 0
156 eprol:
158 #endif /* MCRT0 */