annotate src/ecrt0.c @ 36224:600506f65cbf

Fix copyright notice.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 20 Feb 2001 12:30:16 +0000
parents 9400865ec7cf
children 23a1cea22d13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25844
Dave Love <fx@gnu.org>
parents:
diff changeset
1 /* C code startup routine.
Dave Love <fx@gnu.org>
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
Dave Love <fx@gnu.org>
parents:
diff changeset
3
Dave Love <fx@gnu.org>
parents:
diff changeset
4 This file is part of GNU Emacs.
Dave Love <fx@gnu.org>
parents:
diff changeset
5
Dave Love <fx@gnu.org>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
Dave Love <fx@gnu.org>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
Dave Love <fx@gnu.org>
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
Dave Love <fx@gnu.org>
parents:
diff changeset
9 any later version.
Dave Love <fx@gnu.org>
parents:
diff changeset
10
Dave Love <fx@gnu.org>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
Dave Love <fx@gnu.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
Dave Love <fx@gnu.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Dave Love <fx@gnu.org>
parents:
diff changeset
14 GNU General Public License for more details.
Dave Love <fx@gnu.org>
parents:
diff changeset
15
Dave Love <fx@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
Dave Love <fx@gnu.org>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
Dave Love <fx@gnu.org>
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Dave Love <fx@gnu.org>
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
Dave Love <fx@gnu.org>
parents:
diff changeset
20
Dave Love <fx@gnu.org>
parents:
diff changeset
21
Dave Love <fx@gnu.org>
parents:
diff changeset
22 /* The standard Vax 4.2 Unix crt0.c cannot be used for Emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
23 because it makes `environ' an initialized variable.
Dave Love <fx@gnu.org>
parents:
diff changeset
24 It is easiest to have a special crt0.c on all machines
Dave Love <fx@gnu.org>
parents:
diff changeset
25 though I don't know whether other machines actually need it. */
Dave Love <fx@gnu.org>
parents:
diff changeset
26
Dave Love <fx@gnu.org>
parents:
diff changeset
27 /* On the vax and 68000, in BSD4.2 and USG5.2,
Dave Love <fx@gnu.org>
parents:
diff changeset
28 this is the data format on startup:
Dave Love <fx@gnu.org>
parents:
diff changeset
29 (vax) ap and fp are unpredictable as far as I know; don't use them.
Dave Love <fx@gnu.org>
parents:
diff changeset
30 sp -> word containing argc
Dave Love <fx@gnu.org>
parents:
diff changeset
31 word pointing to first arg string
Dave Love <fx@gnu.org>
parents:
diff changeset
32 [word pointing to next arg string]... 0 or more times
Dave Love <fx@gnu.org>
parents:
diff changeset
33 0
Dave Love <fx@gnu.org>
parents:
diff changeset
34 Optionally:
Dave Love <fx@gnu.org>
parents:
diff changeset
35 [word pointing to environment variable]... 1 or more times
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ...
Dave Love <fx@gnu.org>
parents:
diff changeset
37 0
Dave Love <fx@gnu.org>
parents:
diff changeset
38 And always:
Dave Love <fx@gnu.org>
parents:
diff changeset
39 first arg string
Dave Love <fx@gnu.org>
parents:
diff changeset
40 [next arg string]... 0 or more times
Dave Love <fx@gnu.org>
parents:
diff changeset
41 */
Dave Love <fx@gnu.org>
parents:
diff changeset
42
Dave Love <fx@gnu.org>
parents:
diff changeset
43 /* On the 16000, at least in the one 4.2 system I know about,
Dave Love <fx@gnu.org>
parents:
diff changeset
44 the initial data format is
Dave Love <fx@gnu.org>
parents:
diff changeset
45 sp -> word containing argc
Dave Love <fx@gnu.org>
parents:
diff changeset
46 word containing argp
Dave Love <fx@gnu.org>
parents:
diff changeset
47 word pointing to first arg string, and so on as above
Dave Love <fx@gnu.org>
parents:
diff changeset
48 */
Dave Love <fx@gnu.org>
parents:
diff changeset
49
Dave Love <fx@gnu.org>
parents:
diff changeset
50 #ifdef emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
51 #include <config.h>
Dave Love <fx@gnu.org>
parents:
diff changeset
52 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
53
Dave Love <fx@gnu.org>
parents:
diff changeset
54 /* ******** WARNING ********
Dave Love <fx@gnu.org>
parents:
diff changeset
55 Do not insert any data definitions before data_start!
Dave Love <fx@gnu.org>
parents:
diff changeset
56 Since this is the first file linked, the address of the following
Dave Love <fx@gnu.org>
parents:
diff changeset
57 variable should correspond to the start of initialized data space.
Dave Love <fx@gnu.org>
parents:
diff changeset
58 On some systems this is a constant that is independent of the text
Dave Love <fx@gnu.org>
parents:
diff changeset
59 size for shared executables. On others, it is a function of the
Dave Love <fx@gnu.org>
parents:
diff changeset
60 text size. In short, this seems to be the most portable way to
Dave Love <fx@gnu.org>
parents:
diff changeset
61 discover the start of initialized data space dynamically at runtime,
Dave Love <fx@gnu.org>
parents:
diff changeset
62 for either shared or unshared executables, on either swapping or
Dave Love <fx@gnu.org>
parents:
diff changeset
63 virtual systems. It only requires that the linker allocate objects
Dave Love <fx@gnu.org>
parents:
diff changeset
64 in the order encountered, a reasonable model for most Unix systems.
Dave Love <fx@gnu.org>
parents:
diff changeset
65 Similarly, note that the address of _start() should be the start
Dave Love <fx@gnu.org>
parents:
diff changeset
66 of text space. Fred Fish, UniSoft Systems Inc. */
Dave Love <fx@gnu.org>
parents:
diff changeset
67
Dave Love <fx@gnu.org>
parents:
diff changeset
68 int data_start = 0;
Dave Love <fx@gnu.org>
parents:
diff changeset
69
Dave Love <fx@gnu.org>
parents:
diff changeset
70 #ifdef NEED_ERRNO
Dave Love <fx@gnu.org>
parents:
diff changeset
71 int errno;
Dave Love <fx@gnu.org>
parents:
diff changeset
72 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
73
Dave Love <fx@gnu.org>
parents:
diff changeset
74 #ifndef DONT_NEED_ENVIRON
Dave Love <fx@gnu.org>
parents:
diff changeset
75 char **environ;
Dave Love <fx@gnu.org>
parents:
diff changeset
76 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
77
Dave Love <fx@gnu.org>
parents:
diff changeset
78 #ifndef static
Dave Love <fx@gnu.org>
parents:
diff changeset
79 /* On systems where the static storage class is usable, this function
Dave Love <fx@gnu.org>
parents:
diff changeset
80 should be declared as static. Otherwise, the static keyword has
Dave Love <fx@gnu.org>
parents:
diff changeset
81 been defined to be something else, and code for those systems must
Dave Love <fx@gnu.org>
parents:
diff changeset
82 take care of this declaration appropriately. */
Dave Love <fx@gnu.org>
parents:
diff changeset
83 static start1 ();
Dave Love <fx@gnu.org>
parents:
diff changeset
84 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
85
Dave Love <fx@gnu.org>
parents:
diff changeset
86 #ifdef APOLLO
Dave Love <fx@gnu.org>
parents:
diff changeset
87 extern char *malloc(), *realloc(), *(*_libc_malloc) (), *(*_libc_realloc)();
Dave Love <fx@gnu.org>
parents:
diff changeset
88 extern void free(), (*_libc_free) (); extern int main();
Dave Love <fx@gnu.org>
parents:
diff changeset
89 std_$call void unix_$main();
Dave Love <fx@gnu.org>
parents:
diff changeset
90
Dave Love <fx@gnu.org>
parents:
diff changeset
91 _start()
Dave Love <fx@gnu.org>
parents:
diff changeset
92 {
Dave Love <fx@gnu.org>
parents:
diff changeset
93 _libc_malloc = malloc;
Dave Love <fx@gnu.org>
parents:
diff changeset
94 _libc_realloc = realloc;
Dave Love <fx@gnu.org>
parents:
diff changeset
95 _libc_free = free;
Dave Love <fx@gnu.org>
parents:
diff changeset
96 unix_$main(main); /* no return */
Dave Love <fx@gnu.org>
parents:
diff changeset
97 }
Dave Love <fx@gnu.org>
parents:
diff changeset
98 #endif /* APOLLO */
Dave Love <fx@gnu.org>
parents:
diff changeset
99
Dave Love <fx@gnu.org>
parents:
diff changeset
100 #if defined(orion) || defined(pyramid) || defined(celerity) || defined(ALLIANT) || defined(clipper) || defined(sps7)
Dave Love <fx@gnu.org>
parents:
diff changeset
101
Dave Love <fx@gnu.org>
parents:
diff changeset
102 #if defined(sps7) && defined(V3x)
Dave Love <fx@gnu.org>
parents:
diff changeset
103 asm(" section 10");
Dave Love <fx@gnu.org>
parents:
diff changeset
104 asm(" ds.b 0xb0");
Dave Love <fx@gnu.org>
parents:
diff changeset
105 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
106
Dave Love <fx@gnu.org>
parents:
diff changeset
107 #ifdef ALLIANT
Dave Love <fx@gnu.org>
parents:
diff changeset
108 /* _start must initialize _curbrk and _minbrk on the first startup;
Dave Love <fx@gnu.org>
parents:
diff changeset
109 when starting up after dumping, it must initialize them to what they were
Dave Love <fx@gnu.org>
parents:
diff changeset
110 before the dumping, since they are in the shared library and
Dave Love <fx@gnu.org>
parents:
diff changeset
111 are not dumped. See ADJUST_EXEC_HEADER in m-alliant.h. */
Dave Love <fx@gnu.org>
parents:
diff changeset
112 extern unsigned char *_curbrk, *_minbrk;
Dave Love <fx@gnu.org>
parents:
diff changeset
113 extern unsigned char end;
Dave Love <fx@gnu.org>
parents:
diff changeset
114 unsigned char *_setbrk = &end;
Dave Love <fx@gnu.org>
parents:
diff changeset
115 #ifdef ALLIANT_2800
Dave Love <fx@gnu.org>
parents:
diff changeset
116 unsigned char *_end = &end;
Dave Love <fx@gnu.org>
parents:
diff changeset
117 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
118 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
119
Dave Love <fx@gnu.org>
parents:
diff changeset
120 #ifndef DUMMIES
Dave Love <fx@gnu.org>
parents:
diff changeset
121 #define DUMMIES
Dave Love <fx@gnu.org>
parents:
diff changeset
122 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
123
Dave Love <fx@gnu.org>
parents:
diff changeset
124 _start (DUMMIES argc, argv, envp)
Dave Love <fx@gnu.org>
parents:
diff changeset
125 int argc;
Dave Love <fx@gnu.org>
parents:
diff changeset
126 char **argv, **envp;
Dave Love <fx@gnu.org>
parents:
diff changeset
127 {
Dave Love <fx@gnu.org>
parents:
diff changeset
128 #ifdef ALLIANT
Dave Love <fx@gnu.org>
parents:
diff changeset
129 #ifdef ALLIANT_2800
Dave Love <fx@gnu.org>
parents:
diff changeset
130 _curbrk = _end;
Dave Love <fx@gnu.org>
parents:
diff changeset
131 _minbrk = _end;
Dave Love <fx@gnu.org>
parents:
diff changeset
132 #else
Dave Love <fx@gnu.org>
parents:
diff changeset
133 _curbrk = _setbrk;
Dave Love <fx@gnu.org>
parents:
diff changeset
134 _minbrk = _setbrk;
Dave Love <fx@gnu.org>
parents:
diff changeset
135 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
136 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
137
Dave Love <fx@gnu.org>
parents:
diff changeset
138 environ = envp;
Dave Love <fx@gnu.org>
parents:
diff changeset
139
Dave Love <fx@gnu.org>
parents:
diff changeset
140 exit (main (argc, argv, envp));
Dave Love <fx@gnu.org>
parents:
diff changeset
141 }
Dave Love <fx@gnu.org>
parents:
diff changeset
142
Dave Love <fx@gnu.org>
parents:
diff changeset
143 #endif /* orion or pyramid or celerity or alliant or clipper */
Dave Love <fx@gnu.org>
parents:
diff changeset
144
Dave Love <fx@gnu.org>
parents:
diff changeset
145 #if defined (ns16000) && !defined (sequent) && !defined (UMAX) && !defined (CRT0_DUMMIES)
Dave Love <fx@gnu.org>
parents:
diff changeset
146
Dave Love <fx@gnu.org>
parents:
diff changeset
147 _start ()
Dave Love <fx@gnu.org>
parents:
diff changeset
148 {
Dave Love <fx@gnu.org>
parents:
diff changeset
149 /* On 16000, _start pushes fp onto stack */
Dave Love <fx@gnu.org>
parents:
diff changeset
150 start1 ();
Dave Love <fx@gnu.org>
parents:
diff changeset
151 }
Dave Love <fx@gnu.org>
parents:
diff changeset
152
Dave Love <fx@gnu.org>
parents:
diff changeset
153 /* ignore takes care of skipping the fp value pushed in start. */
Dave Love <fx@gnu.org>
parents:
diff changeset
154 static
Dave Love <fx@gnu.org>
parents:
diff changeset
155 start1 (ignore, argc, argv)
Dave Love <fx@gnu.org>
parents:
diff changeset
156 int ignore;
Dave Love <fx@gnu.org>
parents:
diff changeset
157 int argc;
Dave Love <fx@gnu.org>
parents:
diff changeset
158 register char **argv;
Dave Love <fx@gnu.org>
parents:
diff changeset
159 {
Dave Love <fx@gnu.org>
parents:
diff changeset
160 environ = argv + argc + 1;
Dave Love <fx@gnu.org>
parents:
diff changeset
161
Dave Love <fx@gnu.org>
parents:
diff changeset
162 if (environ == *argv)
Dave Love <fx@gnu.org>
parents:
diff changeset
163 environ--;
Dave Love <fx@gnu.org>
parents:
diff changeset
164 exit (main (argc, argv, environ));
Dave Love <fx@gnu.org>
parents:
diff changeset
165 }
Dave Love <fx@gnu.org>
parents:
diff changeset
166 #endif /* ns16000, not sequent and not UMAX, and not the CRT0_DUMMIES method */
Dave Love <fx@gnu.org>
parents:
diff changeset
167
Dave Love <fx@gnu.org>
parents:
diff changeset
168 #ifdef UMAX
Dave Love <fx@gnu.org>
parents:
diff changeset
169 _start()
Dave Love <fx@gnu.org>
parents:
diff changeset
170 {
Dave Love <fx@gnu.org>
parents:
diff changeset
171 asm(" exit [] # undo enter");
Dave Love <fx@gnu.org>
parents:
diff changeset
172 asm(" .set exitsc,1");
Dave Love <fx@gnu.org>
parents:
diff changeset
173 asm(" .set sigcatchall,0x400");
Dave Love <fx@gnu.org>
parents:
diff changeset
174
Dave Love <fx@gnu.org>
parents:
diff changeset
175 asm(" .globl _exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
176 asm(" .globl start");
Dave Love <fx@gnu.org>
parents:
diff changeset
177 asm(" .globl __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
178 asm(" .globl _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
179 asm(" .globl _environ");
Dave Love <fx@gnu.org>
parents:
diff changeset
180 asm(" .globl _sigvec");
Dave Love <fx@gnu.org>
parents:
diff changeset
181 asm(" .globl sigentry");
Dave Love <fx@gnu.org>
parents:
diff changeset
182
Dave Love <fx@gnu.org>
parents:
diff changeset
183 asm("start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
184 asm(" br .xstart");
Dave Love <fx@gnu.org>
parents:
diff changeset
185 asm(" .org 0x20");
Dave Love <fx@gnu.org>
parents:
diff changeset
186 asm(" .double p_glbl,0,0xf00000,0");
Dave Love <fx@gnu.org>
parents:
diff changeset
187 asm(" .org 0x30");
Dave Love <fx@gnu.org>
parents:
diff changeset
188 asm(".xstart:");
Dave Love <fx@gnu.org>
parents:
diff changeset
189 asm(" adjspb $8");
Dave Love <fx@gnu.org>
parents:
diff changeset
190 asm(" movd 8(sp),0(sp) # argc");
Dave Love <fx@gnu.org>
parents:
diff changeset
191 asm(" addr 12(sp),r0");
Dave Love <fx@gnu.org>
parents:
diff changeset
192 asm(" movd r0,4(sp) # argv");
Dave Love <fx@gnu.org>
parents:
diff changeset
193 asm("L1:");
Dave Love <fx@gnu.org>
parents:
diff changeset
194 asm(" movd r0,r1");
Dave Love <fx@gnu.org>
parents:
diff changeset
195 asm(" addqd $4,r0");
Dave Love <fx@gnu.org>
parents:
diff changeset
196 asm(" cmpqd $0,0(r1) # null args term ?");
Dave Love <fx@gnu.org>
parents:
diff changeset
197 asm(" bne L1");
Dave Love <fx@gnu.org>
parents:
diff changeset
198 asm(" cmpd r0,0(4(sp)) # end of 'env' or 'argv' ?");
Dave Love <fx@gnu.org>
parents:
diff changeset
199 asm(" blt L2");
Dave Love <fx@gnu.org>
parents:
diff changeset
200 asm(" addqd $-4,r0 # envp's are in list");
Dave Love <fx@gnu.org>
parents:
diff changeset
201 asm("L2:");
Dave Love <fx@gnu.org>
parents:
diff changeset
202 asm(" movd r0,8(sp) # env");
Dave Love <fx@gnu.org>
parents:
diff changeset
203 asm(" movd r0,@_environ # indir is 0 if no env ; not 0 if env");
Dave Love <fx@gnu.org>
parents:
diff changeset
204 asm(" movqd $0,tos # setup intermediate signal handler");
Dave Love <fx@gnu.org>
parents:
diff changeset
205 asm(" addr @sv,tos");
Dave Love <fx@gnu.org>
parents:
diff changeset
206 asm(" movzwd $sigcatchall,tos");
Dave Love <fx@gnu.org>
parents:
diff changeset
207 asm(" jsr @_sigvec");
Dave Love <fx@gnu.org>
parents:
diff changeset
208 asm(" adjspb $-12");
Dave Love <fx@gnu.org>
parents:
diff changeset
209 asm(" jsr @_main");
Dave Love <fx@gnu.org>
parents:
diff changeset
210 asm(" adjspb $-12");
Dave Love <fx@gnu.org>
parents:
diff changeset
211 asm(" movd r0,tos");
Dave Love <fx@gnu.org>
parents:
diff changeset
212 asm(" jsr @_exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
213 asm(" adjspb $-4");
Dave Love <fx@gnu.org>
parents:
diff changeset
214 asm(" addr @exitsc,r0");
Dave Love <fx@gnu.org>
parents:
diff changeset
215 asm(" svc");
Dave Love <fx@gnu.org>
parents:
diff changeset
216 asm(" .align 4 # sigvec arg");
Dave Love <fx@gnu.org>
parents:
diff changeset
217 asm("sv:");
Dave Love <fx@gnu.org>
parents:
diff changeset
218 asm(" .double sigentry");
Dave Love <fx@gnu.org>
parents:
diff changeset
219 asm(" .double 0");
Dave Love <fx@gnu.org>
parents:
diff changeset
220 asm(" .double 0");
Dave Love <fx@gnu.org>
parents:
diff changeset
221
Dave Love <fx@gnu.org>
parents:
diff changeset
222 asm(" .comm p_glbl,1");
Dave Love <fx@gnu.org>
parents:
diff changeset
223 }
Dave Love <fx@gnu.org>
parents:
diff changeset
224 #endif /* UMAX */
Dave Love <fx@gnu.org>
parents:
diff changeset
225
Dave Love <fx@gnu.org>
parents:
diff changeset
226 #ifdef CRT0_DUMMIES
Dave Love <fx@gnu.org>
parents:
diff changeset
227
Dave Love <fx@gnu.org>
parents:
diff changeset
228 /* Define symbol "start": here; some systems want that symbol. */
Dave Love <fx@gnu.org>
parents:
diff changeset
229 #ifdef DOT_GLOBAL_START
Dave Love <fx@gnu.org>
parents:
diff changeset
230 asm(" .text ");
Dave Love <fx@gnu.org>
parents:
diff changeset
231 asm(" .globl start ");
Dave Love <fx@gnu.org>
parents:
diff changeset
232 asm(" start: ");
Dave Love <fx@gnu.org>
parents:
diff changeset
233 #endif /* DOT_GLOBAL_START */
Dave Love <fx@gnu.org>
parents:
diff changeset
234
Dave Love <fx@gnu.org>
parents:
diff changeset
235 #ifdef NODOT_GLOBAL_START
Dave Love <fx@gnu.org>
parents:
diff changeset
236 asm(" text ");
Dave Love <fx@gnu.org>
parents:
diff changeset
237 asm(" global start ");
Dave Love <fx@gnu.org>
parents:
diff changeset
238 asm(" start: ");
Dave Love <fx@gnu.org>
parents:
diff changeset
239 #endif /* NODOT_GLOBAL_START */
Dave Love <fx@gnu.org>
parents:
diff changeset
240
Dave Love <fx@gnu.org>
parents:
diff changeset
241 #ifdef m68000
Dave Love <fx@gnu.org>
parents:
diff changeset
242
Dave Love <fx@gnu.org>
parents:
diff changeset
243 /* GCC 2.1, when optimization is turned off, seems to want to push a
Dave Love <fx@gnu.org>
parents:
diff changeset
244 word of garbage on the stack, which screws up the CRT0_DUMMIES
Dave Love <fx@gnu.org>
parents:
diff changeset
245 hack. So we hand-code _start in assembly language. */
Dave Love <fx@gnu.org>
parents:
diff changeset
246 asm(".text ");
Dave Love <fx@gnu.org>
parents:
diff changeset
247 asm(" .even ");
Dave Love <fx@gnu.org>
parents:
diff changeset
248 asm(".globl __start ");
Dave Love <fx@gnu.org>
parents:
diff changeset
249 asm("__start: ");
Dave Love <fx@gnu.org>
parents:
diff changeset
250 asm(" link a6,#0 ");
Dave Love <fx@gnu.org>
parents:
diff changeset
251 asm(" jbsr _start1 ");
Dave Love <fx@gnu.org>
parents:
diff changeset
252 asm(" unlk a6 ");
Dave Love <fx@gnu.org>
parents:
diff changeset
253 asm(" rts ");
Dave Love <fx@gnu.org>
parents:
diff changeset
254
Dave Love <fx@gnu.org>
parents:
diff changeset
255 #else /* not m68000 */
Dave Love <fx@gnu.org>
parents:
diff changeset
256
Dave Love <fx@gnu.org>
parents:
diff changeset
257 _start ()
Dave Love <fx@gnu.org>
parents:
diff changeset
258 {
Dave Love <fx@gnu.org>
parents:
diff changeset
259 /* On vax, nothing is pushed here */
Dave Love <fx@gnu.org>
parents:
diff changeset
260 /* On sequent, bogus fp is pushed here */
Dave Love <fx@gnu.org>
parents:
diff changeset
261 start1 ();
Dave Love <fx@gnu.org>
parents:
diff changeset
262 }
Dave Love <fx@gnu.org>
parents:
diff changeset
263
Dave Love <fx@gnu.org>
parents:
diff changeset
264 #endif /* possibly m68000 */
Dave Love <fx@gnu.org>
parents:
diff changeset
265
Dave Love <fx@gnu.org>
parents:
diff changeset
266 static
Dave Love <fx@gnu.org>
parents:
diff changeset
267 start1 (CRT0_DUMMIES argc, xargv)
Dave Love <fx@gnu.org>
parents:
diff changeset
268 int argc;
Dave Love <fx@gnu.org>
parents:
diff changeset
269 char *xargv;
Dave Love <fx@gnu.org>
parents:
diff changeset
270 {
Dave Love <fx@gnu.org>
parents:
diff changeset
271 register char **argv = &xargv;
Dave Love <fx@gnu.org>
parents:
diff changeset
272 environ = argv + argc + 1;
Dave Love <fx@gnu.org>
parents:
diff changeset
273
Dave Love <fx@gnu.org>
parents:
diff changeset
274 if ((char *)environ == xargv)
Dave Love <fx@gnu.org>
parents:
diff changeset
275 environ--;
Dave Love <fx@gnu.org>
parents:
diff changeset
276 exit (main (argc, argv, environ));
Dave Love <fx@gnu.org>
parents:
diff changeset
277
Dave Love <fx@gnu.org>
parents:
diff changeset
278 /* Refer to `start1' so GCC will not think it is never called
Dave Love <fx@gnu.org>
parents:
diff changeset
279 and optimize it out. */
Dave Love <fx@gnu.org>
parents:
diff changeset
280 (void) &start1;
Dave Love <fx@gnu.org>
parents:
diff changeset
281 }
Dave Love <fx@gnu.org>
parents:
diff changeset
282 #else /* not CRT0_DUMMIES */
Dave Love <fx@gnu.org>
parents:
diff changeset
283
Dave Love <fx@gnu.org>
parents:
diff changeset
284 /* "m68k" and "m68000" both stand for m68000 processors,
Dave Love <fx@gnu.org>
parents:
diff changeset
285 but with different program-entry conventions.
Dave Love <fx@gnu.org>
parents:
diff changeset
286 This is a kludge. Now that the CRT0_DUMMIES mechanism above exists,
Dave Love <fx@gnu.org>
parents:
diff changeset
287 most of these machines could use the vax code above
Dave Love <fx@gnu.org>
parents:
diff changeset
288 with some suitable definition of CRT0_DUMMIES.
Dave Love <fx@gnu.org>
parents:
diff changeset
289 Then the symbol m68k could be flushed.
Dave Love <fx@gnu.org>
parents:
diff changeset
290 But I don't want to risk breaking these machines
Dave Love <fx@gnu.org>
parents:
diff changeset
291 in a version 17 patch release, so that change is being put off. */
Dave Love <fx@gnu.org>
parents:
diff changeset
292
Dave Love <fx@gnu.org>
parents:
diff changeset
293 #ifdef m68k /* Can't do it all from C */
Dave Love <fx@gnu.org>
parents:
diff changeset
294 asm (" global _start");
Dave Love <fx@gnu.org>
parents:
diff changeset
295 asm (" text");
Dave Love <fx@gnu.org>
parents:
diff changeset
296 asm ("_start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
297 #ifndef NU
Dave Love <fx@gnu.org>
parents:
diff changeset
298 #ifdef STRIDE
Dave Love <fx@gnu.org>
parents:
diff changeset
299 asm (" comm havefpu%,2");
Dave Love <fx@gnu.org>
parents:
diff changeset
300 #else /* m68k, not STRIDE */
Dave Love <fx@gnu.org>
parents:
diff changeset
301 asm (" comm splimit%,4");
Dave Love <fx@gnu.org>
parents:
diff changeset
302 #endif /* STRIDE */
Dave Love <fx@gnu.org>
parents:
diff changeset
303 asm (" global exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
304 asm (" text");
Dave Love <fx@gnu.org>
parents:
diff changeset
305 #ifdef STRIDE
Dave Love <fx@gnu.org>
parents:
diff changeset
306 asm (" trap &3");
Dave Love <fx@gnu.org>
parents:
diff changeset
307 asm (" mov.w %d0,havefpu%");
Dave Love <fx@gnu.org>
parents:
diff changeset
308 #else /* m68k, not STRIDE */
Dave Love <fx@gnu.org>
parents:
diff changeset
309 asm (" mov.l %d0,splimit%");
Dave Love <fx@gnu.org>
parents:
diff changeset
310 #endif /* STRIDE */
Dave Love <fx@gnu.org>
parents:
diff changeset
311 #endif /* not NU */
Dave Love <fx@gnu.org>
parents:
diff changeset
312 asm (" jsr start1");
Dave Love <fx@gnu.org>
parents:
diff changeset
313 asm (" mov.l %d0,(%sp)");
Dave Love <fx@gnu.org>
parents:
diff changeset
314 asm (" jsr exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
315 asm (" mov.l &1,%d0"); /* d0 = 1 => exit */
Dave Love <fx@gnu.org>
parents:
diff changeset
316 asm (" trap &0");
Dave Love <fx@gnu.org>
parents:
diff changeset
317 #else /* m68000, not m68k */
Dave Love <fx@gnu.org>
parents:
diff changeset
318
Dave Love <fx@gnu.org>
parents:
diff changeset
319 #ifdef m68000
Dave Love <fx@gnu.org>
parents:
diff changeset
320
Dave Love <fx@gnu.org>
parents:
diff changeset
321 #ifdef ISI68K
Dave Love <fx@gnu.org>
parents:
diff changeset
322 /* Added by ESM Sun May 24 12:44:02 1987 to get new ISI library to work */
Dave Love <fx@gnu.org>
parents:
diff changeset
323 /* Edited by Ray Mon May 15 15:59:56 EST 1989 so we can compile with gcc */
Dave Love <fx@gnu.org>
parents:
diff changeset
324 #if defined(BSD4_3) && !defined(__GNUC__)
Dave Love <fx@gnu.org>
parents:
diff changeset
325 static foo () {
Dave Love <fx@gnu.org>
parents:
diff changeset
326 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
327 asm (" .globl is68020");
Dave Love <fx@gnu.org>
parents:
diff changeset
328 asm ("is68020:");
Dave Love <fx@gnu.org>
parents:
diff changeset
329 #ifndef BSD4_3
Dave Love <fx@gnu.org>
parents:
diff changeset
330 asm (" .long 0x00000000");
Dave Love <fx@gnu.org>
parents:
diff changeset
331 asm (" .long 0xffffffff");
Dave Love <fx@gnu.org>
parents:
diff changeset
332 /* End of stuff added by ESM */
Dave Love <fx@gnu.org>
parents:
diff changeset
333 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
334 asm (" .text");
Dave Love <fx@gnu.org>
parents:
diff changeset
335 asm (" .globl __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
336 asm ("__start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
337 asm (" .word 0");
Dave Love <fx@gnu.org>
parents:
diff changeset
338 asm (" link a6,#0");
Dave Love <fx@gnu.org>
parents:
diff changeset
339 asm (" jbsr _start1");
Dave Love <fx@gnu.org>
parents:
diff changeset
340 asm (" unlk a6");
Dave Love <fx@gnu.org>
parents:
diff changeset
341 asm (" rts");
Dave Love <fx@gnu.org>
parents:
diff changeset
342 #if defined(BSD4_3) && !defined(__GNUC__)
Dave Love <fx@gnu.org>
parents:
diff changeset
343 }
Dave Love <fx@gnu.org>
parents:
diff changeset
344 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
345 #else /* not ISI68K */
Dave Love <fx@gnu.org>
parents:
diff changeset
346
Dave Love <fx@gnu.org>
parents:
diff changeset
347 _start ()
Dave Love <fx@gnu.org>
parents:
diff changeset
348 {
Dave Love <fx@gnu.org>
parents:
diff changeset
349 #ifdef sun
Dave Love <fx@gnu.org>
parents:
diff changeset
350 finitfp_();
Dave Love <fx@gnu.org>
parents:
diff changeset
351 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
352 /* On 68000, _start pushes a6 onto stack */
Dave Love <fx@gnu.org>
parents:
diff changeset
353 start1 ();
Dave Love <fx@gnu.org>
parents:
diff changeset
354 }
Dave Love <fx@gnu.org>
parents:
diff changeset
355 #endif /* not ISI68k */
Dave Love <fx@gnu.org>
parents:
diff changeset
356 #endif /* m68000 */
Dave Love <fx@gnu.org>
parents:
diff changeset
357 #endif /* m68k */
Dave Love <fx@gnu.org>
parents:
diff changeset
358
Dave Love <fx@gnu.org>
parents:
diff changeset
359 #if defined(m68k) || defined(m68000)
Dave Love <fx@gnu.org>
parents:
diff changeset
360 /* ignore takes care of skipping the a6 value pushed in start. */
Dave Love <fx@gnu.org>
parents:
diff changeset
361 static
Dave Love <fx@gnu.org>
parents:
diff changeset
362 #if defined(m68k)
Dave Love <fx@gnu.org>
parents:
diff changeset
363 start1 (argc, xargv)
Dave Love <fx@gnu.org>
parents:
diff changeset
364 #else
Dave Love <fx@gnu.org>
parents:
diff changeset
365 start1 (ignore, argc, xargv)
Dave Love <fx@gnu.org>
parents:
diff changeset
366 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
367 int argc;
Dave Love <fx@gnu.org>
parents:
diff changeset
368 char *xargv;
Dave Love <fx@gnu.org>
parents:
diff changeset
369 {
Dave Love <fx@gnu.org>
parents:
diff changeset
370 register char **argv = &xargv;
Dave Love <fx@gnu.org>
parents:
diff changeset
371 environ = argv + argc + 1;
Dave Love <fx@gnu.org>
parents:
diff changeset
372
Dave Love <fx@gnu.org>
parents:
diff changeset
373 if ((char *)environ == xargv)
Dave Love <fx@gnu.org>
parents:
diff changeset
374 environ--;
Dave Love <fx@gnu.org>
parents:
diff changeset
375 #ifdef sun_68881
Dave Love <fx@gnu.org>
parents:
diff changeset
376 asm(" jsr f68881_used");
Dave Love <fx@gnu.org>
parents:
diff changeset
377 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
378 #ifdef sun_fpa
Dave Love <fx@gnu.org>
parents:
diff changeset
379 asm(" jsr ffpa_used");
Dave Love <fx@gnu.org>
parents:
diff changeset
380 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
381 #ifdef sun_soft
Dave Love <fx@gnu.org>
parents:
diff changeset
382 asm(" jsr start_float");
Dave Love <fx@gnu.org>
parents:
diff changeset
383 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
384 exit (main (argc, argv, environ));
Dave Love <fx@gnu.org>
parents:
diff changeset
385 }
Dave Love <fx@gnu.org>
parents:
diff changeset
386
Dave Love <fx@gnu.org>
parents:
diff changeset
387 #endif /* m68k or m68000 */
Dave Love <fx@gnu.org>
parents:
diff changeset
388
Dave Love <fx@gnu.org>
parents:
diff changeset
389 #endif /* not CRT0_DUMMIES */
Dave Love <fx@gnu.org>
parents:
diff changeset
390
Dave Love <fx@gnu.org>
parents:
diff changeset
391 #ifdef hp9000s300
Dave Love <fx@gnu.org>
parents:
diff changeset
392 int argc_value;
Dave Love <fx@gnu.org>
parents:
diff changeset
393 char **argv_value;
Dave Love <fx@gnu.org>
parents:
diff changeset
394 #ifdef OLD_HP_ASSEMBLER
Dave Love <fx@gnu.org>
parents:
diff changeset
395 asm(" text");
Dave Love <fx@gnu.org>
parents:
diff changeset
396 asm(" globl __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
397 asm(" globl _exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
398 asm(" globl _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
399 asm("__start");
Dave Love <fx@gnu.org>
parents:
diff changeset
400 asm(" dc.l 0");
Dave Love <fx@gnu.org>
parents:
diff changeset
401 asm(" subq.w #0x1,d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
402 asm(" move.w d0,float_soft");
Dave Love <fx@gnu.org>
parents:
diff changeset
403 asm(" move.l 0x4(a7),d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
404 asm(" beq.s skip_1");
Dave Love <fx@gnu.org>
parents:
diff changeset
405 asm(" move.l d0,a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
406 asm(" clr.l -0x4(a0)");
Dave Love <fx@gnu.org>
parents:
diff changeset
407 asm("skip_1");
Dave Love <fx@gnu.org>
parents:
diff changeset
408 asm(" move.l a7,a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
409 asm(" subq.l #0x8,a7");
Dave Love <fx@gnu.org>
parents:
diff changeset
410 asm(" move.l (a0),(a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
411 asm(" move.l (a0),_argc_value");
Dave Love <fx@gnu.org>
parents:
diff changeset
412 asm(" addq.l #0x4,a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
413 asm(" move.l a0,0x4(a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
414 asm(" move.l a0,_argv_value");
Dave Love <fx@gnu.org>
parents:
diff changeset
415 asm("incr_loop");
Dave Love <fx@gnu.org>
parents:
diff changeset
416 asm(" tst.l (a0)+");
Dave Love <fx@gnu.org>
parents:
diff changeset
417 asm(" bne.s incr_loop");
Dave Love <fx@gnu.org>
parents:
diff changeset
418 asm(" move.l 0x4(a7),a1");
Dave Love <fx@gnu.org>
parents:
diff changeset
419 asm(" cmp.l (a1),a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
420 asm(" blt.s skip_2");
Dave Love <fx@gnu.org>
parents:
diff changeset
421 asm(" subq.l #0x4,a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
422 asm("skip_2");
Dave Love <fx@gnu.org>
parents:
diff changeset
423 asm(" move.l a0,0x8(a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
424 asm(" move.l a0,_environ");
Dave Love <fx@gnu.org>
parents:
diff changeset
425 asm(" jsr _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
426 asm(" addq.l #0x8,a7");
Dave Love <fx@gnu.org>
parents:
diff changeset
427 asm(" move.l d0,-(a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
428 asm(" jsr _exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
429 asm(" move.w #0x1,d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
430 asm(" trap #0x0");
Dave Love <fx@gnu.org>
parents:
diff changeset
431 asm(" comm float_soft,4");
Dave Love <fx@gnu.org>
parents:
diff changeset
432 /* float_soft is allocated in this way because C would
Dave Love <fx@gnu.org>
parents:
diff changeset
433 put an underscore character in its name otherwise. */
Dave Love <fx@gnu.org>
parents:
diff changeset
434
Dave Love <fx@gnu.org>
parents:
diff changeset
435 #else /* new hp assembler */
Dave Love <fx@gnu.org>
parents:
diff changeset
436
Dave Love <fx@gnu.org>
parents:
diff changeset
437 asm(" text");
Dave Love <fx@gnu.org>
parents:
diff changeset
438 asm(" global float_loc");
Dave Love <fx@gnu.org>
parents:
diff changeset
439 asm(" set float_loc,0xFFFFB000");
Dave Love <fx@gnu.org>
parents:
diff changeset
440 asm(" global fpa_loc");
Dave Love <fx@gnu.org>
parents:
diff changeset
441 asm(" set fpa_loc,0xfff08000");
Dave Love <fx@gnu.org>
parents:
diff changeset
442 asm(" global __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
443 asm(" global _exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
444 asm(" global _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
445 asm("__start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
446 asm(" byte 0,0,0,0");
Dave Love <fx@gnu.org>
parents:
diff changeset
447 asm(" subq.w &1,%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
448 asm(" mov.w %d0,float_soft");
Dave Love <fx@gnu.org>
parents:
diff changeset
449 asm(" mov.w %d1,flag_68881");
Dave Love <fx@gnu.org>
parents:
diff changeset
450 #ifndef HPUX_68010
Dave Love <fx@gnu.org>
parents:
diff changeset
451 asm(" beq.b skip_float");
Dave Love <fx@gnu.org>
parents:
diff changeset
452 asm(" fmov.l &0x7400,%fpcr");
Dave Love <fx@gnu.org>
parents:
diff changeset
453 /* asm(" fmov.l &0x7480,%fpcr"); */
Dave Love <fx@gnu.org>
parents:
diff changeset
454 #endif /* HPUX_68010 */
Dave Love <fx@gnu.org>
parents:
diff changeset
455 asm("skip_float:");
Dave Love <fx@gnu.org>
parents:
diff changeset
456 asm(" mov.l %a0,%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
457 asm(" add.l %d0,%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
458 asm(" subx.w %d1,%d1");
Dave Love <fx@gnu.org>
parents:
diff changeset
459 asm(" mov.w %d1,flag_68010");
Dave Love <fx@gnu.org>
parents:
diff changeset
460 asm(" add.l %d0,%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
461 asm(" subx.w %d1,%d1");
Dave Love <fx@gnu.org>
parents:
diff changeset
462 asm(" mov.w %d1,flag_fpa");
Dave Love <fx@gnu.org>
parents:
diff changeset
463 asm(" tst.l %d2");
Dave Love <fx@gnu.org>
parents:
diff changeset
464 asm(" ble.b skip_3");
Dave Love <fx@gnu.org>
parents:
diff changeset
465 asm(" lsl flag_68881");
Dave Love <fx@gnu.org>
parents:
diff changeset
466 asm(" lsl flag_fpa");
Dave Love <fx@gnu.org>
parents:
diff changeset
467 asm("skip_3:");
Dave Love <fx@gnu.org>
parents:
diff changeset
468 asm(" mov.l 4(%a7),%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
469 asm(" beq.b skip_1");
Dave Love <fx@gnu.org>
parents:
diff changeset
470 asm(" mov.l %d0,%a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
471 asm(" clr.l -4(%a0)");
Dave Love <fx@gnu.org>
parents:
diff changeset
472 asm("skip_1:");
Dave Love <fx@gnu.org>
parents:
diff changeset
473 asm(" mov.l %a7,%a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
474 asm(" subq.l &8,%a7");
Dave Love <fx@gnu.org>
parents:
diff changeset
475 asm(" mov.l (%a0),(%a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
476 asm(" mov.l (%a0),_argc_value");
Dave Love <fx@gnu.org>
parents:
diff changeset
477 asm(" addq.l &4,%a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
478 asm(" mov.l %a0,4(%a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
479 asm(" mov.l %a0,_argv_value");
Dave Love <fx@gnu.org>
parents:
diff changeset
480 asm("incr_loop:");
Dave Love <fx@gnu.org>
parents:
diff changeset
481 asm(" tst.l (%a0)+");
Dave Love <fx@gnu.org>
parents:
diff changeset
482 asm(" bne.b incr_loop");
Dave Love <fx@gnu.org>
parents:
diff changeset
483 asm(" mov.l 4(%a7),%a1");
Dave Love <fx@gnu.org>
parents:
diff changeset
484 asm(" cmp.l %a0,(%a1)");
Dave Love <fx@gnu.org>
parents:
diff changeset
485 asm(" blt.b skip_2");
Dave Love <fx@gnu.org>
parents:
diff changeset
486 asm(" subq.l &4,%a0");
Dave Love <fx@gnu.org>
parents:
diff changeset
487 asm("skip_2:");
Dave Love <fx@gnu.org>
parents:
diff changeset
488 asm(" mov.l %a0,8(%a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
489 asm(" mov.l %a0,_environ");
Dave Love <fx@gnu.org>
parents:
diff changeset
490 asm(" jsr _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
491 asm(" addq.l &8,%a7");
Dave Love <fx@gnu.org>
parents:
diff changeset
492 asm(" mov.l %d0,-(%a7)");
Dave Love <fx@gnu.org>
parents:
diff changeset
493 asm(" jsr _exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
494 asm(" mov.w &1,%d0");
Dave Love <fx@gnu.org>
parents:
diff changeset
495 asm(" trap &0");
Dave Love <fx@gnu.org>
parents:
diff changeset
496 asm(" comm float_soft, 4");
Dave Love <fx@gnu.org>
parents:
diff changeset
497 asm(" comm flag_68881, 4");
Dave Love <fx@gnu.org>
parents:
diff changeset
498 asm(" comm flag_68010, 4");
Dave Love <fx@gnu.org>
parents:
diff changeset
499 asm(" comm flag_68040, 4");
Dave Love <fx@gnu.org>
parents:
diff changeset
500 asm(" comm flag_fpa, 4");
Dave Love <fx@gnu.org>
parents:
diff changeset
501
Dave Love <fx@gnu.org>
parents:
diff changeset
502 #endif /* new hp assembler */
Dave Love <fx@gnu.org>
parents:
diff changeset
503 #endif /* hp9000s300 */
Dave Love <fx@gnu.org>
parents:
diff changeset
504
Dave Love <fx@gnu.org>
parents:
diff changeset
505 #ifdef GOULD
Dave Love <fx@gnu.org>
parents:
diff changeset
506
Dave Love <fx@gnu.org>
parents:
diff changeset
507 /* startup code has to be in near text rather
Dave Love <fx@gnu.org>
parents:
diff changeset
508 than fartext as allocated by the C compiler. */
Dave Love <fx@gnu.org>
parents:
diff changeset
509 asm(" .text");
Dave Love <fx@gnu.org>
parents:
diff changeset
510 asm(" .align 2");
Dave Love <fx@gnu.org>
parents:
diff changeset
511 asm(" .globl __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
512 asm(" .text");
Dave Love <fx@gnu.org>
parents:
diff changeset
513 asm("__start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
514 /* setup base register b1 (function base). */
Dave Love <fx@gnu.org>
parents:
diff changeset
515 asm(" .using b1,.");
Dave Love <fx@gnu.org>
parents:
diff changeset
516 asm(" tpcbr b1");
Dave Love <fx@gnu.org>
parents:
diff changeset
517 /* setup base registers b3 through b7 (data references). */
Dave Love <fx@gnu.org>
parents:
diff changeset
518 asm(" file basevals,b3");
Dave Love <fx@gnu.org>
parents:
diff changeset
519 /* setup base register b2 (stack pointer); it should be
Dave Love <fx@gnu.org>
parents:
diff changeset
520 aligned on a 8-word boundary; but because it is pointing
Dave Love <fx@gnu.org>
parents:
diff changeset
521 to argc, its value should be remembered (in r5). */
Dave Love <fx@gnu.org>
parents:
diff changeset
522 asm(" movw b2,r4");
Dave Love <fx@gnu.org>
parents:
diff changeset
523 asm(" movw b2,r5");
Dave Love <fx@gnu.org>
parents:
diff changeset
524 asm(" andw #~0x1f,r4");
Dave Love <fx@gnu.org>
parents:
diff changeset
525 asm(" movw r4,b2");
Dave Love <fx@gnu.org>
parents:
diff changeset
526 /* allocate stack frame to do some work. */
Dave Love <fx@gnu.org>
parents:
diff changeset
527 asm(" subea 16w,b2");
Dave Love <fx@gnu.org>
parents:
diff changeset
528 /* initialize signal catching for UTX/32 1.2; this is
Dave Love <fx@gnu.org>
parents:
diff changeset
529 necessary to make restart from saved image work. */
Dave Love <fx@gnu.org>
parents:
diff changeset
530 asm(" movea sigcatch,r1");
Dave Love <fx@gnu.org>
parents:
diff changeset
531 asm(" movw r1,8w[b2]");
Dave Love <fx@gnu.org>
parents:
diff changeset
532 asm(" svc #1,#150");
Dave Love <fx@gnu.org>
parents:
diff changeset
533 /* setup address of argc for start1. */
Dave Love <fx@gnu.org>
parents:
diff changeset
534 asm(" movw r5,8w[b2]");
Dave Love <fx@gnu.org>
parents:
diff changeset
535 asm(" func #1,_start1");
Dave Love <fx@gnu.org>
parents:
diff changeset
536 asm(" halt");
Dave Love <fx@gnu.org>
parents:
diff changeset
537 /* space for ld to store base register initial values. */
Dave Love <fx@gnu.org>
parents:
diff changeset
538 asm(" .align 5");
Dave Love <fx@gnu.org>
parents:
diff changeset
539 asm("basevals:");
Dave Love <fx@gnu.org>
parents:
diff changeset
540 asm(" .word __base3,__base4,__base5,__base6,__base7");
Dave Love <fx@gnu.org>
parents:
diff changeset
541
Dave Love <fx@gnu.org>
parents:
diff changeset
542 static
Dave Love <fx@gnu.org>
parents:
diff changeset
543 start1 (xargc)
Dave Love <fx@gnu.org>
parents:
diff changeset
544 int *xargc;
Dave Love <fx@gnu.org>
parents:
diff changeset
545 {
Dave Love <fx@gnu.org>
parents:
diff changeset
546 register int argc;
Dave Love <fx@gnu.org>
parents:
diff changeset
547 register char **argv;
Dave Love <fx@gnu.org>
parents:
diff changeset
548
Dave Love <fx@gnu.org>
parents:
diff changeset
549 argc = *xargc;
Dave Love <fx@gnu.org>
parents:
diff changeset
550 argv = (char **)(xargc) + 1;
Dave Love <fx@gnu.org>
parents:
diff changeset
551 environ = argv + argc + 1;
Dave Love <fx@gnu.org>
parents:
diff changeset
552
Dave Love <fx@gnu.org>
parents:
diff changeset
553 if (environ == argv)
Dave Love <fx@gnu.org>
parents:
diff changeset
554 environ--;
Dave Love <fx@gnu.org>
parents:
diff changeset
555 exit (main (argc, argv, environ));
Dave Love <fx@gnu.org>
parents:
diff changeset
556
Dave Love <fx@gnu.org>
parents:
diff changeset
557 }
Dave Love <fx@gnu.org>
parents:
diff changeset
558
Dave Love <fx@gnu.org>
parents:
diff changeset
559 #endif /* GOULD */
Dave Love <fx@gnu.org>
parents:
diff changeset
560
Dave Love <fx@gnu.org>
parents:
diff changeset
561 #ifdef elxsi
Dave Love <fx@gnu.org>
parents:
diff changeset
562 #include <elxsi/argvcache.h>
Dave Love <fx@gnu.org>
parents:
diff changeset
563
Dave Love <fx@gnu.org>
parents:
diff changeset
564 extern char **environ;
Dave Love <fx@gnu.org>
parents:
diff changeset
565 extern int errno;
Dave Love <fx@gnu.org>
parents:
diff changeset
566 extern void _init_doscan(), _init_iob();
Dave Love <fx@gnu.org>
parents:
diff changeset
567 extern char end[];
Dave Love <fx@gnu.org>
parents:
diff changeset
568 char *_init_brk = end;
Dave Love <fx@gnu.org>
parents:
diff changeset
569
Dave Love <fx@gnu.org>
parents:
diff changeset
570 _start()
Dave Love <fx@gnu.org>
parents:
diff changeset
571 {
Dave Love <fx@gnu.org>
parents:
diff changeset
572 environ = exec_cache.ac_envp;
Dave Love <fx@gnu.org>
parents:
diff changeset
573 brk (_init_brk);
Dave Love <fx@gnu.org>
parents:
diff changeset
574 errno = 0;
Dave Love <fx@gnu.org>
parents:
diff changeset
575 _init_doscan ();
Dave Love <fx@gnu.org>
parents:
diff changeset
576 _init_iob ();
Dave Love <fx@gnu.org>
parents:
diff changeset
577 _exit (exit (main (exec_cache.ac_argc,
Dave Love <fx@gnu.org>
parents:
diff changeset
578 exec_cache.ac_argv,
Dave Love <fx@gnu.org>
parents:
diff changeset
579 exec_cache.ac_envp)));
Dave Love <fx@gnu.org>
parents:
diff changeset
580 }
Dave Love <fx@gnu.org>
parents:
diff changeset
581 #endif /* elxsi */
Dave Love <fx@gnu.org>
parents:
diff changeset
582
Dave Love <fx@gnu.org>
parents:
diff changeset
583
Dave Love <fx@gnu.org>
parents:
diff changeset
584 #ifdef sparc
Dave Love <fx@gnu.org>
parents:
diff changeset
585 asm (".global __start");
Dave Love <fx@gnu.org>
parents:
diff changeset
586 asm (".text");
Dave Love <fx@gnu.org>
parents:
diff changeset
587 asm ("__start:");
Dave Love <fx@gnu.org>
parents:
diff changeset
588 asm (" mov 0, %fp");
Dave Love <fx@gnu.org>
parents:
diff changeset
589 asm (" ld [%sp + 64], %o0");
Dave Love <fx@gnu.org>
parents:
diff changeset
590 asm (" add %sp, 68, %o1");
Dave Love <fx@gnu.org>
parents:
diff changeset
591 asm (" sll %o0, 2, %o2");
Dave Love <fx@gnu.org>
parents:
diff changeset
592 asm (" add %o2, 4, %o2");
Dave Love <fx@gnu.org>
parents:
diff changeset
593 asm (" add %o1, %o2, %o2");
Dave Love <fx@gnu.org>
parents:
diff changeset
594 asm (" sethi %hi(_environ), %o3");
Dave Love <fx@gnu.org>
parents:
diff changeset
595 asm (" st %o2, [%o3+%lo(_environ)]");
Dave Love <fx@gnu.org>
parents:
diff changeset
596 asm (" andn %sp, 7, %sp");
Dave Love <fx@gnu.org>
parents:
diff changeset
597 asm (" call _main");
Dave Love <fx@gnu.org>
parents:
diff changeset
598 asm (" sub %sp, 24, %sp");
Dave Love <fx@gnu.org>
parents:
diff changeset
599 asm (" call __exit");
Dave Love <fx@gnu.org>
parents:
diff changeset
600 asm (" nop");
Dave Love <fx@gnu.org>
parents:
diff changeset
601
Dave Love <fx@gnu.org>
parents:
diff changeset
602 #endif /* sparc */
Dave Love <fx@gnu.org>
parents:
diff changeset
603
Dave Love <fx@gnu.org>
parents:
diff changeset
604 #if __FreeBSD__ == 2
Dave Love <fx@gnu.org>
parents:
diff changeset
605 char *__progname;
Dave Love <fx@gnu.org>
parents:
diff changeset
606 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
607 #ifdef __bsdi__
Dave Love <fx@gnu.org>
parents:
diff changeset
608 #include <sys/param.h> /* for version number */
Dave Love <fx@gnu.org>
parents:
diff changeset
609 #if defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199501)
Dave Love <fx@gnu.org>
parents:
diff changeset
610 char *__progname;
Dave Love <fx@gnu.org>
parents:
diff changeset
611 #endif
Dave Love <fx@gnu.org>
parents:
diff changeset
612 #endif /* __bsdi__ */