1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(LIBC_SCCS) && !defined(lint)
8: static char sccsid[] = "@(#)crt0.c 5.3 (Berkeley) 3/9/86";
9: #endif LIBC_SCCS and not lint
10:
11: /*
12: * C start up routine.
13: * Robert Henry, UCB, 20 Oct 81
14: *
15: * We make the following (true) assumptions:
16: * 1) when the kernel calls start, it does a jump to location 2,
17: * and thus avoids the register save mask. We are NOT called
18: * with a calls! see sys1.c:setregs().
19: * 2) The only register variable that we can trust is sp,
20: * which points to the base of the kernel calling frame.
21: * Do NOT believe the documentation in exec(2) regarding the
22: * values of fp and ap.
23: * 3) We can allocate as many register variables as we want,
24: * and don't have to save them for anybody.
25: * 4) Because of the ways that asm's work, we can't have
26: * any automatic variables allocated on the stack, because
27: * we must catch the value of sp before any automatics are
28: * allocated.
29: */
30:
31: char **environ = (char **)0;
32: static int fd;
33:
34: asm("#define _start start");
35: asm("#define _eprol eprol");
36: extern unsigned char etext;
37: extern unsigned char eprol;
38: start()
39: {
40: struct kframe {
41: int kargc;
42: char *kargv[1]; /* size depends on kargc */
43: char kargstr[1]; /* size varies */
44: char kenvstr[1]; /* size varies */
45: };
46: /*
47: * ALL REGISTER VARIABLES!!!
48: */
49: register int r11; /* needed for init */
50: register struct kframe *kfp; /* r10 */
51: register char **targv;
52: register char **argv;
53: extern int errno;
54:
55: #ifdef lint
56: kfp = 0;
57: initcode = initcode = 0;
58: #else not lint
59: asm(" movl sp,r10"); /* catch it quick */
60: #endif not lint
61: for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
62: /* void */ ;
63: if (targv >= (char **)(*argv))
64: --targv;
65: environ = targv;
66: asm("eprol:");
67:
68: #ifdef paranoid
69: /*
70: * The standard I/O library assumes that file descriptors 0, 1, and 2
71: * are open. If one of these descriptors is closed prior to the start
72: * of the process, I/O gets very confused. To avoid this problem, we
73: * insure that the first three file descriptors are open before calling
74: * main(). Normally this is undefined, as it adds two unnecessary
75: * system calls.
76: */
77: do {
78: fd = open("/dev/null", 2);
79: } while (fd >= 0 && fd < 3);
80: close(fd);
81: #endif paranoid
82:
83: #ifdef MCRT0
84: monstartup(&eprol, &etext);
85: #endif MCRT0
86: errno = 0;
87: exit(main(kfp->kargc, argv, environ));
88: }
89: asm("#undef _start");
90: asm("#undef _eprol");
91:
92: #ifdef MCRT0
93: /*ARGSUSED*/
94: exit(code)
95: register int code; /* r11 */
96: {
97: monitor(0);
98: _cleanup();
99: asm(" movl r11,r0");
100: asm(" chmk $1");
101: }
102: #endif MCRT0
103:
104: #ifdef CRT0
105: /*
106: * null mcount and moncontrol,
107: * just in case some routine is compiled for profiling
108: */
109: moncontrol(val)
110: int val;
111: {
112:
113: }
114: asm(" .globl mcount");
115: asm("mcount: rsb");
116: #endif CRT0
Defined functions
exit
defined in line
94; used 1 times
start
defined in line
38;
never used
Defined variables
environ
defined in line
31; used 73 times
- in line 65,
87
- in /usr/src/bin/login.c line
343-353(4),
547-571(13)
- in /usr/src/bin/su.c line
130,
157,
178
- in /usr/src/etc/getty/main.c line
235-236(2)
- in /usr/src/lib/libc/gen/getenv.c line
17
- in /usr/src/new/B/src/bed/unix.c line
445,
451,
462-467(3)
- in /usr/src/new/X/comsat/comsat.c line
420
- in /usr/src/new/icon/bin/icont.c line
96,
106-107(2)
- in /usr/src/new/icon/pilib/icont.c line
95,
105-106(2)
- in /usr/src/new/mh/sbr/putenv.c line
24,
32-36(2),
47
- in /usr/src/new/mh/uip/post.c line
2345
- in /usr/src/new/mh/uip/slocal.c line
944
- in /usr/src/new/mh/uip/umhook.c line
117
- in /usr/src/new/nntp/rrn/util.c line
446,
458-472(7),
481-482(3)
- in /usr/src/new/rn/util.c line
442,
454-468(7),
477-478(3)
- in /usr/src/new/spms/src/bin/pexec/execcmd.c line
57
- in /usr/src/ucb/lisp/franz/lisp.c line
37
- in /usr/src/ucb/printenv.c line
34-35(2)
- in /usr/src/usr.bin/uucp/uucpd.c line
56
- in /usr/src/usr.bin/uucp/uuxqt.c line
175
- in /usr/src/usr.lib/libU77/getenv_.c line
29
fd
defined in line
32; used 4 times
sccsid
defined in line
8;
never used
Defined struct's