1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)crt0.c 5.8 (Berkeley) 07/16/92"; 10 #endif /* not lint */ 11 12 /* 13 * C start up routine. 14 * Robert Henry, UCB, 20 Oct 81 15 * 16 * We make the following (true) assumption: 17 * 1) The only register variable that we can trust is ebp, 18 * which points to the base of the kernel calling frame. 19 */ 20 21 char **environ = (char **)0; 22 static int fd; 23 24 asm(".text"); 25 asm(".long 0xc000c000"); 26 27 extern unsigned char etext; 28 extern unsigned char eprol asm ("eprol"); 29 extern start() asm("start"); 30 31 start() 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 extern void _mcleanup(); 47 48 #ifdef lint 49 kfp = 0; 50 initcode = initcode = 0; 51 #else not lint 52 asm("lea 4(%ebp),%ebx"); /* catch it quick */ 53 #endif not lint 54 for (argv = targv = &kfp->kargv[0]; *targv++; /* void */) 55 /* void */ ; 56 if (targv >= (char **)(*argv)) 57 --targv; 58 environ = targv; 59 asm("eprol:"); 60 61 #ifdef paranoid 62 /* 63 * The standard I/O library assumes that file descriptors 0, 1, and 2 64 * are open. If one of these descriptors is closed prior to the start 65 * of the process, I/O gets very confused. To avoid this problem, we 66 * insure that the first three file descriptors are open before calling 67 * main(). Normally this is undefined, as it adds two unnecessary 68 * system calls. 69 */ 70 do { 71 fd = open("/dev/null", 2); 72 } while (fd >= 0 && fd < 3); 73 close(fd); 74 #endif paranoid 75 76 #ifdef MCRT0 77 atexit(_mcleanup); 78 monstartup(&eprol, &etext); 79 #endif MCRT0 80 errno = 0; 81 exit(main(kfp->kargc, argv, environ)); 82 } 83 84 #ifdef CRT0 85 /* 86 * null moncontrol just in case some routine is compiled for profiling 87 */ 88 moncontrol(val) 89 int val; 90 { 91 92 } 93 #endif /* CRT0 */ 94