Example #1
0
File: start.c Project: Abioy/FUZIX
void create_init(void)
{
	uint8_t *j;
	/* userspace: 0x100+ 0   1   2   3   4   5   6   7   8   9   A   B   C */
	const char arg[] =
	    { '/', 'i', 'n', 'i', 't', 0, 0, 1, 1, 0, 0, 0, 0 };

	init_process = ptab_alloc();
	udata.u_ptab = init_process;
	udata.u_top = 4096;	/* Plenty for the boot */
	map_init();
	newproc(init_process);

	init_process->p_status = P_RUNNING;

	/* wipe file table */
	for (j = udata.u_files; j < (udata.u_files + UFTSIZE); ++j) {
		*j = NO_FILE;
	}
	/* Poke the execve arguments into user data space so _execve() can read them back */
	uput(arg, PROGBASE, sizeof(arg));

	/* Set up things to look like the process is calling _execve() */
	udata.u_argn = (uint16_t) PROGBASE;
	/* FIXME - should be relative to PROGBASE... */
	udata.u_argn1 = 0x107;	/* Arguments (just "/init") */
	udata.u_argn2 = 0x10b;	/* Environment (none) */
}
Example #2
0
void
libinit(char *imod)
{
	struct passwd *pw;
	Proc *p;
	void *tos;
	char sys[64];

	setsid();

	gethostname(sys, sizeof(sys));
	kstrdup(&ossysname, sys);
	getnobody();

	if(dflag == 0)
		termset();

	setsigs();

	p = newproc();
	p->kstack = stackalloc(p, &tos);

	pw = getpwuid(getuid());
	if(pw != nil)
		kstrdup(&eve, pw->pw_name);
	else
		print("cannot getpwuid\n");
 
	p->env->uid = getuid();
	p->env->gid = getgid();

	executeonnewstack(tos, emuinit, imod);
}
Example #3
0
/* Set up a SLIP link to use AX.25 */
int
kiss_init(
struct iface *ifp
){
	int xdev;
	struct slip *sp;
	char *ifn;

	for(xdev = 0;xdev < SLIP_MAX;xdev++){
		sp = &Slip[xdev];
		if(sp->iface == NULL)
			break;
	}
	if(xdev >= SLIP_MAX) {
		printf("Too many slip devices\n");
		return -1;
	}
	ifp->ioctl = kiss_ioctl;
	ifp->raw = kiss_raw;
	ifp->show = slip_status;

	if(ifp->hwaddr == NULL)
		ifp->hwaddr = mallocw(AXALEN);
	memcpy(ifp->hwaddr,Mycall,AXALEN);
	ifp->xdev = xdev;

	sp->iface = ifp;
	sp->send = asy_send;
	sp->get = get_asy;
	sp->type = CL_KISS;
	ifp->rxproc = newproc( ifn = if_name( ifp, " rx" ),
		256,slip_rx,xdev,NULL,NULL,0);
	free(ifn);
	return 0;
}
unsigned int 
generate_table(int n_table)
{
	init_table_generator(n_table);

	pthread_t  *childs;
	childs = malloc(nchilds * sizeof(pthread_t));

	/*
	 * crea todos los threads
	 */
	int i;
	for(i = 0; i < nchilds ; i++){
		childs[i] = newproc(child, NULL);
	}
	/*
	 * espera a que acaben todos los threads
	 */
	for(i= 0; i <  nchilds; i++)
		pthread_join(childs[i], NULL);
	free(childs);

	close_hash_table3(&hash_table);

	printf("Colisiones: %u\n",coll);

	return i_index;	
}
Example #5
0
void
userinit(void)
{
	Proc *p;
	Osenv *o;

	p = newproc();
	o = p->env;

	o->fgrp = newfgrp(nil);
	o->pgrp = newpgrp();
	o->egrp = newegrp();
	kstrdup(&o->user, eve);

	strcpy(p->text, "interp");

	p->fpstate = FPINIT;

	/*	Kernel Stack
		N.B. The -12 for the stack pointer is important.
		4 bytes for gotolabel's return PC */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-8;

	ready(p);
}
Example #6
0
void
userinit(void)
{
	Proc *p;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	p->fpstate = FPinit;
	fpoff();

	/*
	 * Kernel Stack
	 *
	 * N.B. make sure there's enough space for syscall to check
	 *	for valid args and 
	 *	4 bytes for gotolabel's return PC
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);

	/* NB: no user stack nor text segments are set up */

	ready(p);
}
Example #7
0
File: main.c Project: 8l/inferno
void
userinit(void)
{
	Proc *p;
	Osenv *o;

	p = newproc();
	o = p->env;

	o->fgrp = newfgrp(nil);

	o->pgrp = newpgrp();
	o->egrp = newegrp();
	kstrdup(&o->user, eve);

	strcpy(p->text, "interp");

	/*
	 * Kernel Stack
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK;

	ready(p);
}
Example #8
0
void create_init(void)
{
	uint8_t *j;

	init_process = ptab_alloc();
	udata.u_ptab = init_process;
	udata.u_top = PROGLOAD + 4096;	/* Plenty for the boot */
	init_process->p_top = udata.u_top;
	map_init();
	newproc(init_process);

	udata.u_insys = 1;

	init_process->p_status = P_RUNNING;

	/* wipe file table */
	for (j = udata.u_files; j < (udata.u_files + UFTSIZE); ++j) {
		*j = NO_FILE;
	}
	/* Poke the execve arguments into user data space so _execve() can read them back */
	argptr = PROGLOAD;
	progptr = PROGLOAD + 2048;

	uzero((void *)progptr, 32);
	add_argument("/init");
}
Example #9
0
File: main.c Project: 8l/inferno
void
userinit(void)
{
	Proc *p;
	Osenv *o;

	p = newproc();
	o = p->env;

	o->fgrp = newfgrp(nil);
	o->pgrp = newpgrp();
	kstrdup(&o->user, eve);
	strcpy(p->text,"interp");

	p->fpstate = FPINIT;
	fpinit();

	/*
	 * Kernel Stack
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-8;
	p->sched.sp &= ~7;		/* SP must be 8-byte aligned */

	ready(p);
}
Example #10
0
void
kproc(char *name, void (*func)(void*), void *arg, int flags)
{
	Proc *p;
	Pgrp *pg;
	Fgrp *fg;
	Egrp *eg;
	int pid;
	void *tos;

	p = newproc();

	if(flags & KPDUPPG) {
		pg = up->env->pgrp;
		incref(&pg->r);
		p->env->pgrp = pg;
	}
	if(flags & KPDUPFDG) {
		fg = up->env->fgrp;
		incref(&fg->r);
		p->env->fgrp = fg;
	}
	if(flags & KPDUPENVG) {
		eg = up->env->egrp;
		incref(&eg->r);
		p->env->egrp = eg;
	}

	p->env->uid = up->env->uid;
	p->env->gid = up->env->gid;
	kstrdup(&p->env->user, up->env->user);

	strcpy(p->text, name);

	p->func = func;
	p->arg = arg;

	lock(&procs.l);
	if(procs.tail != nil) {
		p->prev = procs.tail;
		procs.tail->next = p;
	}
	else {
		procs.head = p;
		p->prev = nil;
	}
	procs.tail = p;
	unlock(&procs.l);

	if(flags & KPX11){
		p->kstack = nil;	/* never freed; also up not defined */
		tos = (char*)mallocz(X11STACK, 0) + X11STACK - sizeof(void*);
	}else
		p->kstack = stackalloc(p, &tos);
	pid = rfork_thread(RFPROC|RFMEM|RFNOWAIT, tos, tramp, p);
	if(pid < 0)
		panic("rfork");
}
Example #11
0
void
userinit(void)
{
	Proc *p;
	Segment *s;
	KMap *k;
	char **av;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	procsetup(p);

	/*
	 * Kernel Stack
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-MAXSYSARG*BY2WD;
	/*
	 * User Stack, pass input arguments to boot process
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(1, 0, USTKTOP-BY2PG);
	segpage(s, pg);
	k = kmap(pg);
	for(av = (char**)argbuf; *av; av++)
		*av += (USTKTOP - sizeof(argbuf)) - (ulong)argbuf;

	memmove((uchar*)VA(k) + BY2PG - sizeof(argbuf), argbuf, sizeof argbuf);
	kunmap(k);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(1, 0, UTZERO);
	pg->txtflush = ~0;
	segpage(s, pg);
	k = kmap(s->map[0]->pages[0]);
	memmove((uchar*)VA(k), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
}
Example #12
0
File: os.c Project: 8l/inferno
void
kproc(char *name, void (*func)(void*), void *arg, int flags)
{
	DWORD h;
	Proc *p;
	Pgrp *pg;
	Fgrp *fg;
	Egrp *eg;

	p = newproc();
	if(p == nil)
		panic("out of kernel processes");
	p->os = CreateEvent(NULL, FALSE, FALSE, NULL);
	if(p->os == NULL)
		panic("can't allocate os event");
		
	if(flags & KPDUPPG) {
		pg = up->env->pgrp;
		incref(&pg->r);
		p->env->pgrp = pg;
	}
	if(flags & KPDUPFDG) {
		fg = up->env->fgrp;
		incref(&fg->r);
		p->env->fgrp = fg;
	}
	if(flags & KPDUPENVG) {
		eg = up->env->egrp;
		incref(&eg->r);
		p->env->egrp = eg;
	}

	p->env->ui = up->env->ui;
	kstrdup(&p->env->user, up->env->user);
	strcpy(p->text, name);

	p->func = func;
	p->arg = arg;

	lock(&procs.l);
	if(procs.tail != nil) {
		p->prev = procs.tail;
		procs.tail->next = p;
	}
	else {
		procs.head = p;
		p->prev = nil;
	}
	procs.tail = p;
	unlock(&procs.l);

	p->pid = (int)CreateThread(0, 16384, tramp, p, 0, &h);
	if(p->pid <= 0)
		panic("ran out of  kernel processes");
}
Example #13
0
File: os.c Project: 8l/inferno
void
libinit(char *imod)
{
	WSADATA wasdat;
	DWORD lasterror, namelen;
	OSVERSIONINFO os;
	char sys[64], uname[64];
	wchar_t wuname[64];
	char *uns;

	os.dwOSVersionInfoSize = sizeof(os);
	if(!GetVersionEx(&os))
		panic("can't get os version");
	PlatformId = os.dwPlatformId;
	if (PlatformId == VER_PLATFORM_WIN32_NT) {	/* true for NT and 2000 */
		rebootok = 1;
	} else {
		rebootok = 0;
	}
	termset();

	if((int)INVALID_HANDLE_VALUE != -1 || sizeof(HANDLE) != sizeof(int))
		panic("invalid handle value or size");

	if(WSAStartup(MAKEWORD(1, 1), &wasdat) != 0)
		panic("no winsock.dll");

	gethostname(sys, sizeof(sys));
	kstrdup(&ossysname, sys);
	if(sflag == 0)
		SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)TrapHandler);

	path = getenv("PATH");
	if(path == nil)
		path = ".";

	up = newproc();
	if(up == nil)
		panic("cannot create kernel process");

	strcpy(uname, "inferno");
	namelen = sizeof(wuname);
	if(GetUserName(wuname, &namelen) != TRUE) {
		lasterror = GetLastError();	
		if(PlatformId == VER_PLATFORM_WIN32_NT || lasterror != ERROR_NOT_LOGGED_ON)
			print("cannot GetUserName: %d\n", lasterror);
	}else{
		uns = narrowen(wuname);
		snprint(uname, sizeof(uname), "%s", uns);
		free(uns);
	}
	kstrdup(&eve, uname);

	emuinit(imod);
}
Example #14
0
/* Call a subcommand based on the first token in an already-parsed line */
int
subcmd(
struct cmds tab[],
int argc,
char *argv[],
void *p)
{
	struct cmds *cmdp;
	char **pargv;
	int found = 0;
	int i;

	/* Strip off first token and pass rest of line to subcommand */
	if (argc < 2) {
		if (argc < 1)
			printf("SUBCMD - Don't know what to do?\n");
		else {
			printf("\"%s\" subcommands:\n", argv[0]);
			print_help(tab);
		}
		return -1;
	}
	argc--;
	argv++;
	for(cmdp = tab;cmdp->name != NULL;cmdp++){
		if(strncmp(argv[0],cmdp->name,strlen(argv[0])) == 0){
			found = 1;
			break;
		}
	}
	if(!found){
		printf("\"%s\" subcommands:\n", argv[-1]);
		print_help(tab);
		return -1;
	}
	if(argc < cmdp->argcmin){
		if(cmdp->argc_errmsg != NULL)
			printf("Usage: %s\n",cmdp->argc_errmsg);
		return -1;
	}
	if(cmdp->stksize == 0){
		return (*cmdp->func)(argc,argv,p);
	} else {
#ifndef SINGLE_THREADED
		/* Make private copy of argv and args */
		pargv = (char **)callocw(argc,sizeof(char *));
		for(i=0;i<argc;i++)
			pargv[i] = strdup(argv[i]);
		newproc(cmdp->name,cmdp->stksize,
		 (void (*)(int,void *,void *))cmdp->func,argc,pargv,p,1);
#endif
		return(0);
	}
}
Example #15
0
File: main.c Project: 99years/plan9
void
userinit(void)
{
	Proc *p;
	Segment *s;
	KMap *k;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	p->fpstate = FPinit;

	/*
	 *  Stack
	 *
	 * N.B. The -12 for the stack pointer is important.
	 *	4 bytes for gotolabel's return PC
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);

	/*
	 * User Stack
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(1, 0, USTKTOP-BY2PG);
	segpage(s, pg);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(1, 0, UTZERO);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	k = kmap(s->map[0]->pages[0]);
	memmove((ulong*)VA(k), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
}
Example #16
0
File: main.c Project: lkundrak/pcv7
/*
 * Initialization code.
 * Called from cold start routine as
 * soon as a stack and segmentation
 * have been established.
 * Functions:
 *	clear and free user core
 *	turn on clock
 *	hand craft 0th process
 *	call all initialization routines
 *	fork - process 0 to schedule
 *	     - process 1 execute bootstrap
 *
 * loop at low address in user mode -- /etc/init
 *	cannot be executed.
 */
main()
{

	startup();
	/*
	 * set up system process
	 */

#ifdef PDP11
	proc[0].p_addr = ka6->r[0];
#endif
	proc[0].p_addr = cpaddr;
	proc[0].p_size = USIZE;
	proc[0].p_stat = SRUN;
	proc[0].p_flag |= SLOAD|SSYS;
	proc[0].p_nice = NZERO;
	u.u_procp = &proc[0];
	u.u_cmask = CMASK;

	/*
	 * Initialize devices and
	 * set up 'known' i-nodes
	 */

	clkstart();
	cinit();
	binit();
	iinit();
	rootdir = iget(rootdev, (ino_t)ROOTINO);
	rootdir->i_flag &= ~ILOCK;
	u.u_cdir = iget(rootdev, (ino_t)ROOTINO);
	u.u_cdir->i_flag &= ~ILOCK;
	u.u_rdir = NULL;

	/*
	 * make init process
	 * enter scheduling loop
	 * with system process
	 */

	if(newproc()) {
		expand(USIZE + (int)btoc(szicode));
#ifdef PDP11
		estabur((unsigned)0, btoc(szicode), (unsigned)0, 0, RO);
#endif
		copyout((caddr_t)icode, (caddr_t)0, szicode);
		/*
		 * Return goes to loc. 0 of user init
		 * code just copied out.
		 */
		return;
	}
	sched();
}
Example #17
0
/*
 *  create the first process
 */
void
userinit(void)
{
	Proc *p;
	Segment *s;
	KMap *k;
	Page *pg;

	/* no processes yet */
	up = nil;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	/*
	 * Kernel Stack
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);

	/*
	 * User Stack
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(1, 0, USTKTOP-BY2PG);
	segpage(s, pg);
	k = kmap(pg);
	bootargs(VA(k));
	kunmap(k);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	p->seg[TSEG] = s;
	pg = newpage(1, 0, UTZERO);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	k = kmap(s->map[0]->pages[0]);
	memmove((ulong*)VA(k), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
}
Example #18
0
File: proc.c Project: npe9/harvey
void
kproc(char *name, void (*func)(void *), void *arg)
{
	Mach *m = machp();
	Proc *p;
	static Pgrp *kpgrp;

	p = newproc();
	p->psstate = 0;
	p->procmode = 0640;
	p->kp = 1;
	p->noswap = 1;

	p->scallnr = m->externup->scallnr;
	memmove(p->arg, m->externup->arg, sizeof(m->externup->arg));
	p->nerrlab = 0;
	p->slash = m->externup->slash;
	p->dot = m->externup->dot;
	if(p->dot)
		incref(p->dot);

	memmove(p->note, m->externup->note, sizeof(p->note));
	p->nnote = m->externup->nnote;
	p->notified = 0;
	p->lastnote = m->externup->lastnote;
	p->notify = m->externup->notify;
	p->ureg = 0;
	p->dbgreg = 0;

	procpriority(p, PriKproc, 0);

	kprocchild(p, func, arg);

	kstrdup(&p->user, eve);
	kstrdup(&p->text, name);
	if(kpgrp == 0)
		kpgrp = newpgrp();
	p->pgrp = kpgrp;
	incref(kpgrp);

	memset(p->time, 0, sizeof(p->time));
	p->time[TReal] = sys->ticks;
	ready(p);
	/*
	 *  since the bss/data segments are now shareable,
	 *  any mmu info about this process is now stale
	 *  and has to be discarded.
	 */
	p->newtlb = 1;
	mmuflush();
}
Example #19
0
File: proc.c Project: 99years/plan9
void
kproc(char *name, void (*func)(void *), void *arg)
{
	Proc *p;
	static Pgrp *kpgrp;

	p = newproc();
	p->psstate = 0;
	p->procmode = 0640;
	p->kp = 1;
	p->noswap = 1;

	p->fpsave = up->fpsave;
	p->scallnr = up->scallnr;
	p->s = up->s;
	p->nerrlab = 0;
	p->slash = up->slash;
	p->dot = up->dot;
	if(p->dot)
		incref(p->dot);

	memmove(p->note, up->note, sizeof(p->note));
	p->nnote = up->nnote;
	p->notified = 0;
	p->lastnote = up->lastnote;
	p->notify = up->notify;
	p->ureg = 0;
	p->dbgreg = 0;

	procpriority(p, PriKproc, 0);

	kprocchild(p, func, arg);

	kstrdup(&p->user, eve);
	kstrdup(&p->text, name);
	if(kpgrp == 0)
		kpgrp = newpgrp();
	p->pgrp = kpgrp;
	incref(kpgrp);

	memset(p->time, 0, sizeof(p->time));
	p->time[TReal] = MACHP(0)->ticks;
	ready(p);
}
Example #20
0
File: proc.c Project: 8l/inferno
void
kproc(char *name, void (*func)(void *), void *arg, int flags)
{
	Proc *p;
	Pgrp *pg;
	Fgrp *fg;
	Egrp *eg;

	p = newproc();
	p->psstate = 0;
	p->kp = 1;

	p->fpsave = up->fpsave;
	p->scallnr = up->scallnr;
	p->nerrlab = 0;

	kstrdup(&p->env->user, up->env->user);
	if(flags & KPDUPPG) {
		pg = up->env->pgrp;
		incref(pg);
		p->env->pgrp = pg;
	}
	if(flags & KPDUPFDG) {
		fg = up->env->fgrp;
		incref(fg);
		p->env->fgrp = fg;
	}
	if(flags & KPDUPENVG) {
		eg = up->env->egrp;
		if(eg != nil)
			incref(eg);
		p->env->egrp = eg;
	}

	kprocchild(p, func, arg);

	strcpy(p->text, name);

	ready(p);
}
Example #21
0
void hfdd_mbox (int dev, int *mbxs, void *n1, void *n2)
{
	if (hfdd_debug)
		log (-1, "incoming connection made - assign socket pair");

	/* use socket pair like bbs side, 08Jan2005 */
	if (j2socketpair (AF_LOCAL, SOCK_STREAM, 0, mbxs) == -1)
	{
		log (-1, "socketpair failed, errno %d", errno);
		return;
	}

	seteol (mbxs[0], "\r");
	seteol (mbxs[1], "\r");
/*
	seteol (mbxs[0], "\r\n");
	seteol (mbxs[1], "\r\n");
*/
	sockmode (mbxs[1], SOCK_ASCII);

	/*
	 * 09Oct2006, Maiko, Ouch !!! This process can easily use up 2000
	 * bytes of stack space if you can believe it - I observed this from
	 * live testing - had alot of crashing going on, until I realized just
	 * how much stack space this process uses when forwarding over HFDD !
	 *
	 * Forget 1024 or 2048 - At minimum, start with 4096 stack !!!
	 */
	newproc ("MBOX HF Server", 4096, mbx_incom, mbxs[1], n1, n2, 0);

	/*
	 * give the mailbox time to come up, then assign hfdd_fwdsock. This
	 * is very important, assigning hfdd_fwdsock before this, results
	 * in the keyboard handler (which waits for the assignment of the
	 * hfdd_fwdsock) to prematurely die with an invalid socket.
	 */
	hfdd_fwdsock = mbxs[0]; /* this is for our local access */
}
Example #22
0
startproc(Extsym *progname, int Class)
#endif
{
	register struct Entrypoint *p;

	p = ALLOC(Entrypoint);
	if(Class == CLMAIN) {
		puthead(CNULL, CLMAIN);
		if (progname)
		    strcpy (main_alias, progname->cextname);
	} else {
		if (progname) {
			/* Construct an empty subroutine with this name */
			/* in case the name is needed to force loading */
			/* of this block-data subprogram: the name can */
			/* appear elsewhere in an external statement. */
			entrypt(CLPROC, TYSUBR, (ftnint)0, progname, (chainp)0);
			endproc();
			newproc();
			}
		puthead(CNULL, CLBLOCK);
		}
	if(Class == CLMAIN)
		newentry( mkname(" MAIN"), 0 )->extinit = 1;
	p->entryname = progname;
	entries = p;

	procclass = Class;
	fprintf(diagfile, "   %s", (Class==CLMAIN ? "MAIN" : "BLOCK DATA") );
	if(progname) {
		fprintf(diagfile, " %s", progname->fextname);
		procname = progname->cextname;
		}
	fprintf(diagfile, ":\n");
	fflush(diagfile);
}
Example #23
0
int main(int argc, char ** argv) {
	char line[1024];
	char buf1[1024];
	char buf2[1024];
	int pid, newpid;
	char *sp1, *sp2;

	FILE *wlog = fopen("/dev/null", "w");
	FILE *rlog = fopen("/dev/null", "w");
	FILE *logfile;
	int opt;

	while ( (opt = getopt(argc, argv, "w:r:")) != -1 ) {
		switch (opt) {
		    case 'w':
			fclose(wlog);
			wlog = fopen(optarg, "w");
			break;

		    case 'r':
			fclose(rlog);
			rlog = fopen(optarg, "w");
			break;

		    default:
			fprintf(stderr, "Usage: %s [-w wlog-file] "
			                "[-r rlog-file]\n", argv[0]);
			return 1;
		}
	}

	if (fgets(line, 1024, stdin) &&
	    sscanf(line, "%d", &pid) == 1 ) {
		newproc(pid, getcwd((char *) NULL, 0) );
	} else {
		fprintf(stderr, "fl_stparse: Can't init using first line "
		                "of input!\n");
		return 1;
	}

	do {

		if ( sscanf(line, "%d fork() = %d", &pid, &newpid) == 2 ||
		     sscanf(line, "%d vfork() = %d", &pid, &newpid) == 2 ||
		     sscanf(line, "%d <... fork resumed> ) = %d",
							&pid, &newpid) == 2 ||
		     sscanf(line, "%d <... vfork resumed> ) = %d",
							&pid, &newpid) == 2) {
			sp1 = getproc(pid)->cwd;
			sp2 = malloc( strlen(sp1) + 1);
			strcpy(sp2, sp1);
			newproc(newpid, sp2 );
			continue;
		}

		if ( sscanf(line, "%d _exit(%d", &pid, &newpid) == 2 ||
		     sscanf(line, "%d exit_group(%d", &pid, &newpid) == 2 ) {
			freeproc(pid);
			continue;
		}

		if ( sscanf(line, "%d chdir(\"%[^\"]", &pid, buf1) == 2 ) {
			if (chdir(getproc(pid)->cwd) < 0 ||
			    chdir(buf1) < 0) {
				fprintf(stderr, "fl_stparse: Can't get proc %d's cwd! %s\n",
					pid, strerror(errno));
				exit(1);
			}
			setproc(pid, getcwd((char *) NULL, 0) );
			continue;
		}

		if ( sscanf(line, "%d open(\"%[^\"]\", %s",
						&pid, buf1, buf2) == 3 ) {

			if (strstr(buf2, "O_RDONLY") == NULL) logfile = wlog;
			else logfile = rlog;

			if (strstr(buf2, "O_DIRECTORY") != NULL) continue;

			if (buf1[0] == '/') {
				fprintf(logfile, "%d: %s\n", pid, buf1);
			} else {
				sp1 = getproc(pid)->cwd;
				if (!strcmp(sp1, "/")) sp1="";
				fprintf(logfile, "%d: %s/%s\n",
				                 pid, sp1, buf1);
			}
			continue;
		}

		if ( sscanf(line, "%d mkdir(\"%[^\"]\", ", &pid, buf1) == 2 ||
		     sscanf(line, "%d utime(\"%[^\"]\", ", &pid, buf1) == 2 ||
		     sscanf(line, "%d link(\"%[^\"]\", \"%[^\"]\"",
						&pid, buf2, buf1) == 3 ||
		     sscanf(line, "%d symlink(\"%[^\"]\", \"%[^\"]\"",
						&pid, buf2, buf1) == 3 ||
		     sscanf(line, "%d rename(\"%[^\"]\", \"%[^\"]\"",
						&pid, buf2, buf1) == 3 ) {
			if (buf1[0] == '/') {
				fprintf(wlog, "%d: %s\n", pid, buf1);
			} else {
				sp1 = getproc(pid)->cwd;
				if (!strcmp(sp1, "/")) sp1="";
				fprintf(wlog, "%d: %s/%s\n",
				              pid, sp1, buf1);
			}
			continue;
		}

	} while (fgets(line, 1024, stdin) != NULL);
	return 0;
}
Example #24
0
static int lp_create(lua_State *L)
{
	int err;
	loski_Process *proc;
	const char *exec;
	const char *path = NULL;
	char **argv = NULL;
	char *const *envl = NULL;
	FILE *stdin = NULL;
	FILE *stdout = NULL;
	FILE *stderr = NULL;
	
	if (lua_isstring(L, 1)) {
		
		int i;
		int argc = lua_gettop(L);
		argv = allocargs(L, argc); /* TODO: memory leak in case of arg erros */
		argv[0] = (char *)luaL_checkstring(L, 1);
		for (i = 1; i < argc; ++i)
			argv[i] = (char *)luaL_checkstring(L, i+1);
		exec = argv[0];
		
	} else if (lua_istable(L, 1)) {
		
		lua_settop(L, 1);
		exec = getstrfield(L, 1, "execfile");
		path = optstrfield(L, 1, "runpath", path);
		stdin = optfilefield(L, 1, "stdin");
		stdout = optfilefield(L, 1, "stdout");
		stderr = optfilefield(L, 1, "stderr");
		
		lua_getfield(L, 1, "arguments");
		if (lua_istable(L, 2)) {
			size_t i;
			size_t argc = lua_rawlen(L, 2);
			argv = allocargs(L, argc+1); /* TODO: memory leak in case of arg erros */
			argv[0] = (char *)exec;
			for(i = 1; i <= argc; ++i) {
				lua_rawgeti(L, 2, i);
				luaL_argcheck(L, 1, !lua_isstring(L, 3),
					"field "LUA_QL("arguments")" must contain only strings");
				argv[i] = (char *)lua_tostring(L, 3);
				lua_pop(L, 1); /* pop an argument string */
			}
		} else if (!lua_isnil(L, 2)) {
			luaL_argerror(L, 1, "field "LUA_QL("arguments")" must be a table");
		}
		lua_pop(L, 1); /* pop field 'arguments' */
		
		lua_getfield(L, 1, "environment");
		if (lua_istable(L, 2)) {
			envl = table2env(L);
		} else if (!lua_isnil(L, 2)) {
			luaL_argerror(L, 1, "field "LUA_QL("environment")" must be a table");
		}
		lua_pop(L, 1); /* pop field 'environment' */
		
	} else {
		return luaL_argerror(L, 1, "table or string expected");
	}
	proc = newproc(L); /* push a new proc structure on the stack */
	err = loski_createprocess(proc, exec, path, argv, envl, stdin, stdout, stderr);
	freememory(L, (void *)argv);
	freememory(L, (void *)envl);
	return pushresults(L, 1, err); /* return process */
}
Example #25
0
void
main(int argc, char **argv)
{
	int i, nets = 0;
	char *ann;

	rfork(RFNOTEG);
	formatinit();
	machinit();
	conf.confdev = "n";		/* Devnone */

	ARGBEGIN{
	case 'a':			/* announce on this net */
		ann = EARGF(usage());
		if (nets >= Maxnets) {
			fprint(2, "%s: too many networks to announce: %s\n",
				argv0, ann);
			exits("too many nets");
		}
		annstrs[nets++] = ann;
		break;
	case 'c':			/* use new, faster cache layout */
		oldcachefmt = 0;
		break;
	case 'f':			/* enter configuration mode first */
		conf.configfirst++;
		break;
	case 'm':			/* name device-map file */
		conf.devmap = EARGF(usage());
		break;
	default:
		usage();
		break;
	}ARGEND

	if (argc != 1)
		usage();
	conf.confdev = argv[0];	/* config string for dev holding full config */

	Binit(&bin, 0, OREAD);
	confinit();

	print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n",
		sizeof(Off)*8 - 1, NIBLOCK);
	printsizes();

	qlock(&reflock);
	qunlock(&reflock);
	serveq = newqueue(1000, "9P service");	/* tunable */
	raheadq = newqueue(1000, "readahead");	/* tunable */

	mbinit();
	netinit();
	scsiinit();

	files = malloc(conf.nfile * sizeof *files);
	for(i=0; i < conf.nfile; i++) {
		qlock(&files[i]);
		qunlock(&files[i]);
	}

	wpaths = malloc(conf.nwpath * sizeof(*wpaths));
	uid = malloc(conf.nuid * sizeof(*uid));
	gidspace = malloc(conf.gidspace * sizeof(*gidspace));
	authinit();

	print("iobufinit\n");
	iobufinit();

	arginit();
	boottime = time(nil);

	print("sysinit\n");
	sysinit();

	/*
	 * Ethernet i/o processes
	 */
	netstart();

	/*
	 * read ahead processes
	 */
	newproc(rahead, 0, "rah");

	/*
	 * server processes
	 */
	for(i=0; i < conf.nserve; i++)
		newproc(serve, 0, "srv");

	/*
	 * worm "dump" copy process
	 */
	newproc(wormcopy, 0, "wcp");

	/*
	 * processes to read the console
	 */
	consserve();

	/*
	 * "sync" copy process
	 * this doesn't return.
	 */
	procsetname("scp");
	synccopy();
}
Example #26
0
void
userinit(void)
{
	void *v;
	Proc *p;
	Segment *s;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	p->fpstate = FPinit;
	fpoff();

	/*
	 * Kernel Stack
	 *
	 * N.B. make sure there's enough space for syscall to check
	 *	for valid args and 
	 *	4 bytes for gotolabel's return PC
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);

	/*
	 * User Stack
	 *
	 * N.B. cannot call newpage() with clear=1, because pc kmap
	 * requires up != nil.  use tmpmap instead.
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(0, 0, USTKTOP-BY2PG);
	v = tmpmap(pg);
	memset(v, 0, BY2PG);
	segpage(s, pg);
	bootargs(v);
	tmpunmap(v);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(0, 0, UTZERO);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	v = tmpmap(pg);
	memset(v, 0, BY2PG);
	memmove(v, initcode, sizeof initcode);
	tmpunmap(v);

	ready(p);
}
Example #27
0
/*
 *  create the first process
 */
void
userinit(void)
{
	Proc *p;
	Segment *s;
	KMap *k;
	Page *pg;

	/* no processes yet */
	up = nil;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	/*
	 * Kernel Stack
	 */
	p->sched.pc = PTR2UINT(init0);
	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr));
	p->sched.sp = STACKALIGN(p->sched.sp);

	/*
	 * User Stack
	 *
	 * Technically, newpage can't be called here because it
	 * should only be called when in a user context as it may
	 * try to sleep if there are no pages available, but that
	 * shouldn't be the case here.
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(1, 0, USTKTOP-BY2PG);
	segpage(s, pg);
	k = kmap(pg);
	bootargs(VA(k));
	kunmap(k);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(1, 0, UTZERO);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	k = kmap(s->map[0]->pages[0]);
	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
}
Example #28
0
Proc*
setupseg(int core)
{
	Mach *m = machp();
	Segment *s;
	uintptr_t  ka;
	Proc *p;
	static Pgrp *kpgrp;
	Segment *tseg;
	int sno;

	// XXX: we're going to need this for locality domains.
	USED(core);

	p = newproc();
	p->psstate = 0;
	p->procmode = 0640;
	p->kp = 1;
	p->noswap = 1;

	p->scallnr = m->externup->scallnr;
	memmove(p->arg, m->externup->arg, sizeof(m->externup->arg));
	p->nerrlab = 0;
	p->slash = m->externup->slash;
	p->dot = m->externup->dot;
	if(p->dot)
		incref(p->dot);

	memmove(p->note, m->externup->note, sizeof(p->note));
	p->nnote = m->externup->nnote;
	p->notified = 0;
	p->lastnote = m->externup->lastnote;
	p->notify = m->externup->notify;
	p->ureg = 0;
	p->dbgreg = 0;

	kstrdup(&p->user, eve);
	if(kpgrp == 0)
		kpgrp = newpgrp();
	p->pgrp = kpgrp;
	incref(kpgrp);

	memset(p->time, 0, sizeof(p->time));
	p->time[TReal] = sys->ticks;

	procpriority(p, PriKproc, 0);


	// XXX: kluge 4 pages of address space for this.
	// how will it expand up? gives us <50 kprocs as is.

	/*
	  * we create the color and core at allocation time, not execution.  This
	  *  is probably not the best idea but it's a start.
	  */

	sno = 0;

	// XXX: now that we are asmalloc we are no long proc.
	/* Stack */
	ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 1));
	tseg = newseg(SG_STACK|SG_READ|SG_WRITE, ka, 1);
	tseg = p->seg[sno++];

	ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 1));
	s = newseg(SG_TEXT|SG_READ|SG_EXEC, ka, 1);
	p->seg[sno++] = s;
//	s->color = acpicorecolor(core);

	/* Data. Shared. */
	// XXX; Now that the address space is all funky how are we going to handle shared data segments?
	ka = (uintptr_t)KADDR(asmalloc(0, BIGPGSZ, AsmMEMORY, 2));
	s = newseg(SG_DATA|SG_READ|SG_WRITE, ka, 1);
	p->seg[sno++] = s;
	s->color = tseg->color;

	/* BSS. Uses asm from data map. */
	p->seg[sno++] = newseg(SG_BSS|SG_READ|SG_WRITE, ka+BIGPGSZ, 1);
	p->seg[sno++]->color= tseg->color;


	nixprepage(-1);

	return p;
}
Example #29
0
File: main.c Project: 99years/plan9
void
userinit(void)
{
	Proc *p;
	Segment *s;
	KMap *k;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	/*
	 * Kernel Stack
	 *
	 * N.B. make sure there's enough space for syscall to check
	 *	for valid args and
	 *	space for gotolabel's return PC
	 * AMD64 stack must be quad-aligned.
	 */
	p->sched.pc = PTR2UINT(init0);
	p->sched.sp = PTR2UINT(p->kstack+KSTACK-sizeof(up->arg)-sizeof(uintptr));
	p->sched.sp = STACKALIGN(p->sched.sp);

	/*
	 * User Stack
	 *
	 * Technically, newpage can't be called here because it
	 * should only be called when in a user context as it may
	 * try to sleep if there are no pages available, but that
	 * shouldn't be the case here.
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BIGPGSZ);
	p->seg[SSEG] = s;

	pg = newpage(1, 0, USTKTOP-BIGPGSZ, BIGPGSZ, -1);
	segpage(s, pg);
	k = kmap(pg);
	bootargs(VA(k));
	kunmap(k);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(1, 0, UTZERO, BIGPGSZ, -1);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	k = kmap(s->map[0]->pages[0]);
	memmove(UINT2PTR(VA(k)), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
}
Example #30
0
/*
 * Initialization code.
 * Called from cold start routine as
 * soon as a stack and segmentation
 * have been established.
 * Functions:
 *  clear and free user core
 *  turn on clock
 *  hand craft 0th process
 *  call all initialization routines
 *  fork - process 0 to schedule
 *       - process 1 execute bootstrap
 */
int
main()
{
    register struct proc *p;
    register int i;
    register struct fs *fs = NULL;
    char inbuf[4];
    char inch;
    int s __attribute__((unused));

    startup();
    printf ("\n%s", version);
    cpuidentify();
    cnidentify();

    /*
     * Set up system process 0 (swapper).
     */
    p = &proc[0];
    p->p_addr = (size_t) &u;
    p->p_stat = SRUN;
    p->p_flag |= SLOAD | SSYS;
    p->p_nice = NZERO;

    u.u_procp = p;          /* init user structure */
    u.u_cmask = CMASK;
    u.u_lastfile = -1;
    for (i = 1; i < NGROUPS; i++)
        u.u_groups[i] = NOGROUP;
    for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++)
        u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max =
            RLIM_INFINITY;

    /* Initialize signal state for process 0 */
    siginit (p);

    /*
     * Initialize tables, protocols, and set up well-known inodes.
     */
#ifdef LOG_ENABLED
    loginit();
#endif
    coutinit();
    cinit();
    pqinit();
    ihinit();
    bhinit();
    binit();
    nchinit();
    clkstart();
    s = spl0();
    rdisk_init();

    pipedev = rootdev = get_boot_device();
    swapdev = get_swap_device();

    /* Mount a root filesystem. */
    for (;;) {
        if(rootdev!=-1)
        {
            fs = mountfs (rootdev, (boothowto & RB_RDONLY) ? MNT_RDONLY : 0,
                (struct inode*) 0);
        }
        if (fs)
            break;
        printf ("No root filesystem available!\n");
//      rdisk_list_partitions(RDISK_FS);
retry:
        printf ("Please enter device to boot from (press ? to list): ");
        inch=0;
        inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0;
        while((inch=cngetc()) != '\r')
        {
            switch(inch)
            {
                case '?':
                    printf("?\n");
                    rdisk_list_partitions(RDISK_FS);
                    printf ("Please enter device to boot from (press ? to list): ");
                    break;
                default:
                    printf("%c",inch);
                    inbuf[0] = inbuf[1];
                    inbuf[1] = inbuf[2];
                    inbuf[2] = inbuf[3];
                    inbuf[3] = inch;
                    break;
            }
        }

        inch = 0;
        if(inbuf[0]=='r' && inbuf[1]=='d')
        {
            if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks())
            {
                if(inbuf[3]>='a' && inbuf[3]<='d')
                {
                    rootdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1);
                    inch = 1;
                }
            }
        } else if(inbuf[1]=='r' && inbuf[2]=='d') {
            if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks())
            {
                rootdev=makedev(inbuf[3]-'0',0);
                inch = 1;
            }
        } else if(inbuf[3] == 0) {
            inch = 1;
        }
        if(inch==0)
        {
            printf("\nUnknown device.\n\n");
            goto retry;
        }
        printf ("\n\n");
    }
    printf ("phys mem  = %u kbytes\n", physmem / 1024);
    printf ("user mem  = %u kbytes\n", MAXMEM / 1024);
    if(minor(rootdev)==0)
    {
        printf ("root dev  = rd%d (%d,%d)\n",
            major(rootdev),
            major(rootdev), minor(rootdev)
        );
    } else {
        printf ("root dev  = rd%d%c (%d,%d)\n",
            major(rootdev), 'a'+minor(rootdev)-1,
            major(rootdev), minor(rootdev)
        );
    }

    printf ("root size = %u kbytes\n", fs->fs_fsize * DEV_BSIZE / 1024);
    mount[0].m_inodp = (struct inode*) 1;   /* XXX */
    mount_updname (fs, "/", "root", 1, 4);
    time.tv_sec = fs->fs_time;
    boottime = time;

    /* Find a swap file. */
    swapstart = 1;
    while(swapdev == -1)
    {
        printf("Please enter swap device (press ? to list): ");
        inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0;
        while((inch = cngetc())!='\r')
        {
            switch(inch)
            {
                case '?':
                    printf("?\n");
                    rdisk_list_partitions(RDISK_SWAP);
                    printf("Please enter swap device (press ? to list): ");
                    break;
                default:
                    printf("%c",inch);
                    inbuf[0] = inbuf[1];
                    inbuf[1] = inbuf[2];
                    inbuf[2] = inbuf[3];
                    inbuf[3] = inch;
                    break;
            }
        }
        inch = 0;
        if(inbuf[0]=='r' && inbuf[1]=='d')
        {
            if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks())
            {
                if(inbuf[3]>='a' && inbuf[3]<='d')
                {
                    swapdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1);
                    inch = 1;
                }
            }
        } else if(inbuf[1]=='r' && inbuf[2]=='d') {
            if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks())
            {
                swapdev=makedev(inbuf[3]-'0',0);
                inch = 1;
            }
        }

        if(minor(swapdev)!=0)
        {
            if(partition_type(swapdev)!=RDISK_SWAP)
            {
                printf("\nNot a swap partition!\n\n");
                swapdev=-1;
            }
        }
    }
    nswap = rdsize(swapdev);

    if(minor(swapdev)==0)
    {
        printf ("swap dev  = rd%d (%d,%d)\n",
            major(swapdev),
            major(swapdev), minor(swapdev)
        );
    } else {
        printf ("swap dev  = rd%d%c (%d,%d)\n",
            major(swapdev), 'a'+minor(swapdev)-1,
            major(swapdev), minor(swapdev)
        );
    }
    (*bdevsw[major(swapdev)].d_open)(swapdev, FREAD|FWRITE, S_IFBLK);
    printf ("swap size = %u kbytes\n", nswap * DEV_BSIZE / 1024);
    if (nswap <= 0)
        panic ("zero swap size");   /* don't want to panic, but what ? */
    mfree (swapmap, nswap, swapstart);

    /* Kick off timeout driven events by calling first time. */
    schedcpu (0);

    /* Set up the root file system. */
    rootdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO);
    iunlock (rootdir);
    u.u_cdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO);
    iunlock (u.u_cdir);
    u.u_rdir = NULL;

    /*
     * Make init process.
     */
    if (newproc (0) == 0) {
        /* Parent process with pid 0: swapper.
         * No return from sched. */
        sched();
    }
    /* Child process with pid 1: init. */
    s = splhigh();
    p = u.u_procp;
    p->p_dsize = icodeend - icode;
    p->p_daddr = USER_DATA_START;
    p->p_ssize = 1024;              /* one kbyte of stack */
    p->p_saddr = USER_DATA_END - 1024;
    bcopy ((caddr_t) icode, (caddr_t) USER_DATA_START, icodeend - icode);
    /*
     * return goes to location 0 of user init code
     * just copied out.
     */
    return 0;
}