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 #ifndef lint 8 static char sccsid[] = "@(#)crt0.c 5.1 (Berkeley) 05/30/85"; 9 #endif 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 33 asm("#define _start start"); 34 asm("#define _eprol eprol"); 35 extern unsigned char etext; 36 extern unsigned char eprol; 37 start() 38 { 39 struct kframe { 40 int kargc; 41 char *kargv[1]; /* size depends on kargc */ 42 char kargstr[1]; /* size varies */ 43 char kenvstr[1]; /* size varies */ 44 }; 45 /* 46 * ALL REGISTER VARIABLES!!! 47 */ 48 register int r11; /* needed for init */ 49 register struct kframe *kfp; /* r10 */ 50 register char **targv; 51 register char **argv; 52 53 #ifdef lint 54 kfp = 0; 55 initcode = initcode = 0; 56 #else not lint 57 asm(" movl sp,r10"); /* catch it quick */ 58 #endif not lint 59 for (argv = targv = &kfp->kargv[0]; *targv++; /* void */) 60 /* void */ ; 61 if (targv >= (char **)(*argv)) 62 --targv; 63 environ = targv; 64 asm("eprol:"); 65 #ifdef MCRT0 66 monstartup(&eprol, &etext); 67 #endif MCRT0 68 exit(main(kfp->kargc, argv, environ)); 69 } 70 asm("#undef _start"); 71 asm("#undef _eprol"); 72 73 #ifdef MCRT0 74 /*ARGSUSED*/ 75 exit(code) 76 register int code; /* r11 */ 77 { 78 monitor(0); 79 _cleanup(); 80 asm(" movl r11,r0"); 81 asm(" chmk $1"); 82 } 83 #endif MCRT0 84 85 #ifdef CRT0 86 /* 87 * null mcount and moncontrol, 88 * just in case some routine is compiled for profiling 89 */ 90 moncontrol(val) 91 int val; 92 { 93 94 } 95 asm(" .globl mcount"); 96 asm("mcount: rsb"); 97 #endif CRT0 98