delete support for prof style profiling
[unix-history] / usr / src / lib / csu / i386 / crt0.c
CommitLineData
29b3c241
WN
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
d58fa3ae 5 * %sccs.include.redist.c%
29b3c241
WN
6 */
7
d58fa3ae 8#ifndef lint
d1208f5e 9static char sccsid[] = "@(#)crt0.c 5.6 (Berkeley) %G%";
d58fa3ae 10#endif /* not lint */
29b3c241 11
29b3c241
WN
12/*
13 * C start up routine.
14 * Robert Henry, UCB, 20 Oct 81
15 *
c4b3bba0
WN
16 * We make the following (true) assumption:
17 * 1) The only register variable that we can trust is ebp,
29b3c241 18 * which points to the base of the kernel calling frame.
29b3c241
WN
19 */
20
21char **environ = (char **)0;
22static int fd;
23
db2ba790
DS
24asm(".text");
25asm(".long 0xc000c000");
26
29b3c241 27extern unsigned char etext;
db2ba790
DS
28extern unsigned char eprol asm ("eprol");
29extern start() asm("start");
30
29b3c241
WN
31start()
32{
33 struct kframe {
34 int kargc;
35 char *kargv[1]; /* size depends on kargc */
36 char kargstr[1]; /* size varies */
37 char kenvstr[1]; /* size varies */
38 };
39 /*
40 * ALL REGISTER VARIABLES!!!
41 */
42 register struct kframe *kfp; /* r10 */
43 register char **targv;
44 register char **argv;
45 extern int errno;
46
47#ifdef lint
48 kfp = 0;
49 initcode = initcode = 0;
50#else not lint
db2ba790 51 asm("lea 4(%ebp),%ebx"); /* catch it quick */
29b3c241
WN
52#endif not lint
53 for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
54 /* void */ ;
55 if (targv >= (char **)(*argv))
56 --targv;
57 environ = targv;
58asm("eprol:");
59
60#ifdef paranoid
61 /*
62 * The standard I/O library assumes that file descriptors 0, 1, and 2
63 * are open. If one of these descriptors is closed prior to the start
64 * of the process, I/O gets very confused. To avoid this problem, we
65 * insure that the first three file descriptors are open before calling
66 * main(). Normally this is undefined, as it adds two unnecessary
67 * system calls.
68 */
69 do {
70 fd = open("/dev/null", 2);
71 } while (fd >= 0 && fd < 3);
72 close(fd);
73#endif paranoid
74
75#ifdef MCRT0
76 monstartup(&eprol, &etext);
77#endif MCRT0
78 errno = 0;
79 exit(main(kfp->kargc, argv, environ));
80}
29b3c241
WN
81
82#ifdef MCRT0
83/*ARGSUSED*/
84exit(code)
db2ba790 85 register int code;
29b3c241 86{
d1208f5e 87 _mcleanup();
29b3c241 88 _cleanup();
db2ba790
DS
89 asm("pushl 8(%ebp)") ;
90 asm("movl $1,%eax");
91 asm(".byte 0x9a; .long 0; .word 0");
29b3c241
WN
92}
93#endif MCRT0
94
95#ifdef CRT0
96/*
97 * null mcount and moncontrol,
98 * just in case some routine is compiled for profiling
99 */
100moncontrol(val)
101 int val;
102{
103
104}
db2ba790
DS
105asm(".globl mcount");
106asm("mcount: ret");
29b3c241 107#endif CRT0