xref: /original-bsd/lib/csu/vax/crt0.c (revision fbed46ce)
1 static	char *sccsid = "@(#)crt0.c	4.3 (Berkeley) 01/13/82";
2 
3 /*
4  *	C start up routine.
5  *	Robert Henry, UCB, 20 Oct 81
6  *
7  *	We make the following (true) assumptions:
8  *	1) when the kernel calls start, it does a jump to location 2,
9  *	and thus avoids the register save mask.  We are NOT called
10  *	with a calls!  see sys1.c:setregs().
11  *	2) The only register variable that we can trust is sp,
12  *	which points to the base of the kernel calling frame.
13  *	Do NOT believe the documentation in exec(2) regarding the
14  *	values of fp and ap.
15  *	3) We can allocate as many register variables as we want,
16  *	and don't have to save them for anybody.
17  *	4) Because of the ways that asm's work, we can't have
18  *	any automatic variables allocated on the stack, because
19  *	we must catch the value of sp before any automatics are
20  *	allocated.
21  */
22 
23 char **environ;
24 
25 asm("#define _start start");
26 start()
27 {
28 	struct kframe {
29 		int	kargc;
30 		char	*kargv[1];	/* size depends on kargc */
31 		char	kargstr[1];	/* size varies */
32 		char	kenvstr[1];	/* size varies */
33 	};
34 	/*
35 	 *	ALL REGISTER VARIABLES!!!
36 	 */
37 	register struct kframe *kfp;	/* r11 */
38 	register char **targv;
39 	register char **argv;
40 
41 #ifdef lint
42 	kfp = 0;
43 #else not lint
44 	asm("	movl	sp,r11");	/* catch it quick */
45 #endif not lint
46 	for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
47 		/* void */ ;
48 	if (targv >= (char **)(*argv))
49 		--targv;
50 	environ = targv;
51 	exit(main(kfp->kargc, argv, environ));
52 }
53 
54 /*
55  * null mcount, just in case some routine is compiled for profiling
56  */
57 asm("	.globl	mcount");
58 asm("mcount:	rsb");
59