* coding.c (make_conversion_work_buffer): Disable buffer modification
[bpt/emacs.git] / src / ecrt0.c
CommitLineData
b8098ef8 1/* C code startup routine.
429ab54e 2 Copyright (C) 1985, 1986, 1992, 2001, 2002, 2003, 2004,
8cabe764 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
b8098ef8
DL
4
5This file is part of GNU Emacs.
6
9ec0b715 7GNU Emacs is free software: you can redistribute it and/or modify
b8098ef8 8it under the terms of the GNU General Public License as published by
9ec0b715
GM
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
b8098ef8
DL
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
9ec0b715 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
b8098ef8
DL
19
20
21/* The standard Vax 4.2 Unix crt0.c cannot be used for Emacs
22 because it makes `environ' an initialized variable.
23 It is easiest to have a special crt0.c on all machines
24 though I don't know whether other machines actually need it. */
25
26/* On the vax and 68000, in BSD4.2 and USG5.2,
27 this is the data format on startup:
28 (vax) ap and fp are unpredictable as far as I know; don't use them.
29 sp -> word containing argc
30 word pointing to first arg string
31 [word pointing to next arg string]... 0 or more times
32 0
33Optionally:
34 [word pointing to environment variable]... 1 or more times
35 ...
36 0
37And always:
38 first arg string
39 [next arg string]... 0 or more times
40*/
41
b8098ef8
DL
42#ifdef emacs
43#include <config.h>
44#endif
45
46/* ******** WARNING ********
47 Do not insert any data definitions before data_start!
48 Since this is the first file linked, the address of the following
49 variable should correspond to the start of initialized data space.
50 On some systems this is a constant that is independent of the text
51 size for shared executables. On others, it is a function of the
52 text size. In short, this seems to be the most portable way to
53 discover the start of initialized data space dynamically at runtime,
54 for either shared or unshared executables, on either swapping or
55 virtual systems. It only requires that the linker allocate objects
56 in the order encountered, a reasonable model for most Unix systems.
57 Similarly, note that the address of _start() should be the start
58 of text space. Fred Fish, UniSoft Systems Inc. */
59
60int data_start = 0;
61
62#ifdef NEED_ERRNO
63int errno;
64#endif
65
4624371d 66#ifndef MSDOS
b8098ef8
DL
67char **environ;
68#endif
69
70#ifndef static
71/* On systems where the static storage class is usable, this function
72 should be declared as static. Otherwise, the static keyword has
73 been defined to be something else, and code for those systems must
74 take care of this declaration appropriately. */
75static start1 ();
76#endif
77
b8098ef8
DL
78#ifdef CRT0_DUMMIES
79
80/* Define symbol "start": here; some systems want that symbol. */
b8098ef8
DL
81asm(" .text ");
82asm(" .globl start ");
83asm(" start: ");
b8098ef8 84
b8098ef8
DL
85_start ()
86{
87/* On vax, nothing is pushed here */
b8098ef8
DL
88 start1 ();
89}
90
b8098ef8
DL
91static
92start1 (CRT0_DUMMIES argc, xargv)
93 int argc;
94 char *xargv;
95{
96 register char **argv = &xargv;
97 environ = argv + argc + 1;
98
99 if ((char *)environ == xargv)
100 environ--;
101 exit (main (argc, argv, environ));
102
103 /* Refer to `start1' so GCC will not think it is never called
104 and optimize it out. */
105 (void) &start1;
106}
107#else /* not CRT0_DUMMIES */
108
2749d28e 109/* This is a kludge. Now that the CRT0_DUMMIES mechanism above exists,
b8098ef8
DL
110 most of these machines could use the vax code above
111 with some suitable definition of CRT0_DUMMIES.
112 Then the symbol m68k could be flushed.
113 But I don't want to risk breaking these machines
114 in a version 17 patch release, so that change is being put off. */
115
116#ifdef m68k /* Can't do it all from C */
117 asm (" global _start");
118 asm (" text");
119 asm ("_start:");
b8098ef8 120 asm (" comm splimit%,4");
b8098ef8
DL
121 asm (" global exit");
122 asm (" text");
b8098ef8 123 asm (" mov.l %d0,splimit%");
b8098ef8
DL
124 asm (" jsr start1");
125 asm (" mov.l %d0,(%sp)");
126 asm (" jsr exit");
127 asm (" mov.l &1,%d0"); /* d0 = 1 => exit */
128 asm (" trap &0");
b8098ef8 129
b8098ef8
DL
130/* ignore takes care of skipping the a6 value pushed in start. */
131static
b8098ef8 132start1 (argc, xargv)
b8098ef8
DL
133 int argc;
134 char *xargv;
135{
136 register char **argv = &xargv;
137 environ = argv + argc + 1;
138
139 if ((char *)environ == xargv)
140 environ--;
b8098ef8
DL
141 exit (main (argc, argv, environ));
142}
143
2749d28e 144#endif /* m68k */
b8098ef8
DL
145
146#endif /* not CRT0_DUMMIES */
147
4a00783e 148#ifdef __sparc__
b8098ef8
DL
149asm (".global __start");
150asm (".text");
151asm ("__start:");
152asm (" mov 0, %fp");
153asm (" ld [%sp + 64], %o0");
154asm (" add %sp, 68, %o1");
155asm (" sll %o0, 2, %o2");
156asm (" add %o2, 4, %o2");
157asm (" add %o1, %o2, %o2");
158asm (" sethi %hi(_environ), %o3");
159asm (" st %o2, [%o3+%lo(_environ)]");
160asm (" andn %sp, 7, %sp");
161asm (" call _main");
162asm (" sub %sp, 24, %sp");
163asm (" call __exit");
164asm (" nop");
165
4a00783e 166#endif /* __sparc__ */
b8098ef8
DL
167
168#if __FreeBSD__ == 2
169char *__progname;
170#endif
ab5796a9
MB
171
172/* arch-tag: 4025c2fb-d6b1-4d29-b1b6-8100b6bd1e74
173 (do not change this comment) */