|
|
1.1 root 1: /*-
2: * Copyright (c) 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * William Jolitz.
7: *
8: * Redistribution and use in source and binary forms are permitted
9: * provided that: (1) source distributions retain this entire copyright
10: * notice and comment, and (2) distributions including binaries display
11: * the following acknowledgement: ``This product includes software
12: * developed by the University of California, Berkeley and its contributors''
13: * in the documentation or other materials provided with the distribution
14: * and in all advertising materials mentioning features or use of this
15: * software. Neither the name of the University nor the names of its
16: * contributors may be used to endorse or promote products derived
17: * from this software without specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)crt0.c 5.2 (Berkeley) 5/14/90";
25: #endif /* not lint */
26:
27: /*
28: * C start up routine.
29: * Robert Henry, UCB, 20 Oct 81
30: *
31: * We make the following (true) assumption:
32: * 1) The only register variable that we can trust is ebp,
33: * which points to the base of the kernel calling frame.
34: */
35:
36: char **environ = (char **)0;
37: static int fd;
38:
39: asm("#define _start start");
40: asm("#define _eprol eprol");
41: asm(" .text");
42: asm(" .long 0xc000c000");
43: extern unsigned char etext;
44: extern unsigned char eprol;
45: start()
46: {
47: struct kframe {
48: int kargc;
49: char *kargv[1]; /* size depends on kargc */
50: char kargstr[1]; /* size varies */
51: char kenvstr[1]; /* size varies */
52: };
53: /*
54: * ALL REGISTER VARIABLES!!!
55: */
56: register struct kframe *kfp; /* r10 */
57: register char **targv;
58: register char **argv;
59: extern int errno;
60:
61: #ifdef lint
62: kfp = 0;
63: initcode = initcode = 0;
64: #else not lint
65: asm(" lea 4(%ebp),%ebx"); /* catch it quick */
66: #endif not lint
67: for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
68: /* void */ ;
69: if (targv >= (char **)(*argv))
70: --targv;
71: environ = targv;
72: asm("eprol:");
73:
74: #ifdef paranoid
75: /*
76: * The standard I/O library assumes that file descriptors 0, 1, and 2
77: * are open. If one of these descriptors is closed prior to the start
78: * of the process, I/O gets very confused. To avoid this problem, we
79: * insure that the first three file descriptors are open before calling
80: * main(). Normally this is undefined, as it adds two unnecessary
81: * system calls.
82: */
83: do {
84: fd = open("/dev/null", 2);
85: } while (fd >= 0 && fd < 3);
86: close(fd);
87: #endif paranoid
88:
89: #ifdef MCRT0
90: monstartup(&eprol, &etext);
91: #endif MCRT0
92: errno = 0;
93: exit(main(kfp->kargc, argv, environ));
94: }
95: asm("#undef _start");
96: asm("#undef _eprol");
97:
98: #ifdef MCRT0
99: /*ARGSUSED*/
100: exit(code)
101: register int code; /* r11 */
102: {
103: monitor(0);
104: _cleanup();
105: asm(" pushl 8(bp)") ;
106: asm(" movl $1,%eax");
107: asm(" .byte 0x9a; .long 0; .word 0");
108: }
109: #endif MCRT0
110:
111: #ifdef CRT0
112: /*
113: * null mcount and moncontrol,
114: * just in case some routine is compiled for profiling
115: */
116: moncontrol(val)
117: int val;
118: {
119:
120: }
121: asm(" .globl mcount");
122: asm("mcount: ret");
123: #endif CRT0
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.