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

1990/0310/gnot/main.c (diff list | history)

gnot/main.c on 1990/03091
1990/03091    
#include	"u.h" 
#include	"lib.h" 
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
#include	"io.h" 
#include	"ureg.h" 
#include	"init.h" 
 
void 
main(void) 
{ 
	Lock l; 
	machinit(); 
	mmuinit(); 
	confinit(); 
	printinit(); 
	flushmmu(); 
	procinit0(); 
	pgrpinit(); 
	chaninit(); 
	alarminit(); 
	chandevreset(); 
1990/0310    
	streaminit(); 
1990/03091    
	pageinit(); 
	userinit(); 
	schedinit(); 
} 
 
void 
machinit(void) 
{ 
	int n; 
 
	n = m->machno; 
	memset(m, 0, sizeof(Mach)); 
	m->machno = n; 
	m->mmask = 1<<m->machno; 
} 
 
void 
mmuinit(void) 
{ 
	ulong l, d, i; 
 
	/* 
	 * Invalidate user addresses 
	 */ 
	for(l=0; l<4*1024*1024; l+=BY2PG) 
		putmmu(l, INVALIDPTE); 
	/* 
	 * Two meg of usable memory 
	 */ 
	for(i=1,l=KTZERO; i<2*1024*1024/BY2PG; l+=BY2PG,i++) 
		putkmmu(l, PPN(l)|PTEVALID|PTEKERNEL); 
	/* 
	 * Screen at two meg 
	 */ 
	for(i=0,d=DISPLAYRAM; i<256*1024/BY2PG; d+=BY2PG,l+=BY2PG,i++) 
		putkmmu(l, PPN(d)|PTEVALID|PTEKERNEL); 
} 
 
void 
init0(void) 
{ 
	m->proc = u->p; 
	u->p->state = Running; 
	u->p->mach = m; 
	spllo(); 
	chandevinit(); 
	 
	u->slash = (*devtab[0].attach)(0); 
	u->dot = clone(u->slash, 0); 
 
	touser(); 
} 
 
FPsave	initfp; 
 
void 
userinit(void) 
{ 
	Proc *p; 
	Seg *s; 
	User *up; 
 
	p = newproc(); 
	p->pgrp = newpgrp(); 
	strcpy(p->text, "*init*"); 
	strcpy(p->pgrp->user, "bootes"); 
/*	savefpregs(&initfp);	/**/ 
/*	p->fpstate = FPinit;	/**/ 
 
	/* 
	 * Kernel Stack 
	 */ 
	p->sched.pc = (ulong)init0; 
	p->sched.sp = USERADDR+BY2PG-20;	/* BUG */ 
	p->sched.sr = SUPER|SPL(7); 
	p->upage = newpage(0, 0, USERADDR|(p->pid&0xFFFF)); 
 
	/* 
	 * User 
	 */ 
	up = (User*)(p->upage->pa|KZERO); 
	up->p = p; 
 
	/* 
	 * User Stack 
	 */ 
	s = &p->seg[SSEG]; 
	s->proc = p; 
	s->o = neworig(USTKTOP-BY2PG, 1, OWRPERM, 0); 
	s->minva = USTKTOP-BY2PG; 
	s->maxva = USTKTOP; 
 
	/* 
	 * Text 
	 */ 
	s = &p->seg[TSEG]; 
	s->proc = p; 
	s->o = neworig(UTZERO, 1, 0, 0); 
	s->o->pte[0].page = newpage(0, 0, UTZERO); 
	memcpy((ulong*)(s->o->pte[0].page->pa|KZERO), initcode, sizeof initcode); 
	s->minva = UTZERO; 
	s->maxva = UTZERO+BY2PG; 
 
	ready(p); 
} 
 
void 
exit(void) 
{ 
	int i; 
 
	u = 0; 
	splhi(); 
	print("exiting\n"); 
	for(;;) 
		; 
} 
 
/* 
 * Insert new into list after where 
 */ 
void 
insert(List **head, List *where, List *new) 
{ 
	if(where == 0){ 
		new->next = *head; 
		*head = new; 
	}else{ 
		new->next = where->next; 
		where->next = new; 
	} 
		 
} 
 
/* 
 * Insert new into list at end 
 */ 
void 
append(List **head, List *new) 
{ 
	List *where; 
 
	where = *head; 
	if(where == 0) 
		*head = new; 
	else{ 
		while(where->next) 
			where = where->next; 
		where->next = new; 
	} 
	new->next = 0; 
} 
 
/* 
 * Delete old from list 
 */ 
void 
delete0(List **head, List *old) 
{ 
	List *l; 
 
	l = *head; 
	if(l == old){ 
		*head = old->next; 
		return; 
	} 
	while(l->next != old) 
		l = l->next; 
	l->next = old->next; 
} 
 
/* 
 * Delete old from list.  where->next is known to be old. 
 */ 
void 
delete(List **head, List *where, List *old) 
{ 
	if(where == 0){ 
		*head = old->next; 
		return; 
	} 
	where->next = old->next; 
} 
 
Conf	conf; 
 
void 
confinit(void) 
{ 
	conf.nmach = 1; 
	if(conf.nmach > MAXMACH) 
		panic("confinit"); 
	conf.nproc = 15; 
	conf.npgrp = 15; 
	conf.npage = (2*1024*1024)/BY2PG; 
	conf.npte = 500; 
	conf.nmod = 50; 
	conf.nalarm = 50; 
	conf.norig = 50; 
	conf.nchan = 100; 
	conf.nenv = 50; 
	conf.nenvchar = 4000; 
	conf.npgenv = 100; 
	conf.nmtab = 50; 
	conf.nmount = 100; 
	conf.nmntdev = 5; 
1990/0310    
	conf.nstream = 64; 
	conf.nqueue = 5 * conf.nstream; 
	conf.nblock = 16 * conf.nstream; 
1990/03091    
	conf.nsrv = 32; 
} 


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