plan 9 kernel history: overview | file list | diff list

1990/0427/power/main.c (diff list | history)

1990/0424/sys/src/9/power/main.c:12,191990/0427/sys/src/9/power/main.c:12,19 (short | long | prev | next)
1990/0424    
 */ 
int _argc; char **_argv; char **_env; 
 
char *argv[5]; 
char argx[4][64]; 
1990/0427    
char argbuf[512]; 
int argsize; 
1990/0424    
 
1990/0227    
void 
main(void) 
1990/0424/sys/src/9/power/main.c:43,601990/0427/sys/src/9/power/main.c:43,89
1990/0227    
	schedinit(); 
} 
 
1990/0427    
/* 
 *  copy arguments into a temporary buffer.  we do this because the arguments 
 *  are in memory that may be allocated to processes or kernel buffers. 
 */ 
1990/0227    
void 
1990/0424    
arginit(void) 
{ 
	int i; 
1990/0427    
	int i, n; 
	int nbytes; 
	int ssize; 
	char *p; 
	char **argv; 
	char *charp; 
1990/0424    
 
	if(_argc > 5) 
		_argc = 5; 
1990/0427    
	/* 
	 *  trim arguments to make them fit in the buffer 
	 */ 
	for(nbytes = i = 0; i < _argc; i++){ 
		n = strlen(_argv[i]) + 1; 
		ssize = BY2WD*(i+2) + ((nbytes+n+(BY2WD-1)) & ~(BY2WD-1)); 
		if(ssize > sizeof(argbuf)) 
			break; 
		nbytes += n; 
	} 
	_argc = i; 
	ssize = BY2WD*(i+1) + ((nbytes+(BY2WD-1)) & ~(BY2WD-1)); 
1990/0424    
 
	for(i = 1; i < _argc; i++){ 
		strcpy(argx[i-1], _argv[i]); 
		argv[i-1] = &(argx[i-1][0]); 
1990/0427    
	/* 
	 *  copy arguments into the buffer 
	 */ 
	argv = (char**)(argbuf + sizeof(argbuf) - ssize); 
	charp = (char*)(argbuf + sizeof(argbuf) - nbytes); 
	for(i=0; i<_argc; i++){ 
		argv[i] = charp; 
		n = strlen(_argv[i]) + 1; 
		memcpy(charp, _argv[i], n); 
		charp += n; 
1990/0424    
	} 
1990/0427    
	_argv = argv; 
 
	argsize = ssize; 
1990/0424    
} 
 
void 
1990/0424/sys/src/9/power/main.c:168,1841990/0427/sys/src/9/power/main.c:197,217
1990/0227    
init0(void) 
{ 
1990/0424    
	int i; 
1990/0427    
	ulong *sp; 
1990/0424    
 
1990/0227    
	m->proc = u->p; 
	u->p->state = Running; 
	u->p->mach = m; 
	spllo(); 
1990/0427    
 
1990/0227    
	chandevinit(); 
1990/0424    
 
1990/0227    
	u->slash = (*devtab[0].attach)(0); 
	u->dot = clone(u->slash, 0); 
 
	touser(); 
1990/0427    
	sp = (ulong*)(USTKTOP - argsize); 
 
	touser(sp); 
1990/0227    
} 
 
FPsave	initfp; 
1990/0424/sys/src/9/power/main.c:189,1941990/0427/sys/src/9/power/main.c:222,229
1990/0227    
	Proc *p; 
	Seg *s; 
	User *up; 
1990/0427    
	int i; 
	char **av; 
1990/0227    
 
	p = newproc(); 
	p->pgrp = newpgrp(); 
1990/0424/sys/src/9/power/main.c:211,2211990/0427/sys/src/9/power/main.c:246,262
1990/0227    
	up->p = p; 
 
	/* 
	 * User Stack 
1990/0427    
	 * User Stack, pass input arguments to boot process 
1990/0227    
	 */ 
	s = &p->seg[SSEG]; 
	s->proc = p; 
	s->o = neworig(USTKTOP-BY2PG, 1, OWRPERM, 0); 
1990/0427    
	s->o->pte[0].page = newpage(0, 0, USTKTOP-BY2PG); 
	memcpy((ulong*)(s->o->pte[0].page->pa|KZERO|(BY2PG-argsize)),  
		argbuf + sizeof(argbuf) - argsize, argsize); 
	av = (char **)(s->o->pte[0].page->pa|KZERO|(BY2PG-argsize)); 
	for(i = 0; i < _argc; i++) 
		av[i] += (char *)USTKTOP - (argbuf + sizeof(argbuf)); 
1990/0227    
	s->minva = USTKTOP-BY2PG; 
	s->maxva = USTKTOP; 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)