Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/mtx/main.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname mtx/main.c 2001/0810
## diff -e /dev/null /n/emeliedump/2001/0810/sys/src/9/mtx/main.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"init.h"
#include	"pool.h"

Conf	conf;
FPsave	initfp;

void
main(void)
{
//	xinit();
	printinit();
	i8250console();
	print("\nPlan 9\n");

	for(;;);
}
.
## diffname mtx/main.c 2001/1207
## diff -e /n/emeliedump/2001/0810/sys/src/9/mtx/main.c /n/emeliedump/2001/1207/sys/src/9/mtx/main.c
21c
void
machinit(void)
{
	memset(m, 0, sizeof(Mach));

	/*
	 * For polled uart output at boot, need
	 * a default delay constant. 100000 should
	 * be enough for a while. Cpuidentify will
	 * calculate the real value later.
	 */
//	m->loopconst = 100000;
}

static struct
{
	char	*name;
	char *val;
}
plan9ini[] =
{
	{ "console", "0" },
};

char*
getconf(char *name)
{
	int i;

	for(i = 0; i < nelem(plan9ini); i++)
		if(cistrcmp(name, plan9ini[i].name) == 0)
			return plan9ini[i].val;
	return nil;
}

void
init0(void)
{
//	char **p, *q, name[KNAMELEN];
//	int n;

print("init0\n");

	up->nerrlab = 0;

	spllo();

	/*
	 * These are o.k. because rootinit is null.
	 * Then early kproc's will have a root and dot.
	 */
	up->slash = namec("#/", Atodir, 0, 0);
	cnameclose(up->slash->name);
	up->slash->name = newcname("/");
	up->dot = cclone(up->slash);

	chandevinit();

	if(!waserror()){
		ksetenv("cputype", "power");
		if(cpuserver)
			ksetenv("service", "cpu");
		else
			ksetenv("service", "terminal");
		
/*
		for(p = confenv; *p; p++) {
			q = strchr(p[0], '=');
			if(q == 0)
				continue;
			n = q-p[0];
			if(n >= KNAMELEN)
				n = KNAMELEN-1;
			memmove(name, p[0], n);
			name[n] = 0;
			ksetenv(name, q+1);
		}
*/
		poperror();
	}
	kproc("alarm", alarmkproc, 0);
	touser((void*)(USTKTOP-8));
}

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;

	strcpy(p->text, "*init*");
	strcpy(p->user, eve);
	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-(1+MAXSYSARG)*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);
}

void
exit(int ispanic)
{
	int ms, once;

	lock(&active);
	if(ispanic)
		active.ispanic = ispanic;
	else if(m->machno == 0 && (active.machs & (1<<m->machno)) == 0)
		active.ispanic = 0;
	once = active.machs & (1<<m->machno);
	active.machs &= ~(1<<m->machno);
	active.exiting = 1;
	unlock(&active);

	if(once)
		print("cpu%d: exiting\n", m->machno);
	spllo();
	for(ms = 5*1000; ms > 0; ms -= TK2MS(2)){
		delay(TK2MS(2));
		if(active.machs == 0 && consactive() == 0)
			break;
	}

	if(active.ispanic && m->machno == 0){
		if(cpuserver)
			delay(10000);
		else
			for(;;);
	}
	else
		delay(1000);

	for(;;)
		;
}

/*
 *  set up floating point for a new process
 */
void
procsetup(Proc *p)
{
	USED(p);
}

/*
 *  Save the mach dependent part of the process state.
 */
void
procsave(Proc *p)
{
	USED(p);
}

void
confinit(void)
{
	int nbytes;
	ulong pa;

	conf.nmach = 1;		/* processors */
	conf.nproc = 60;	/* processes */

	// hard wire for now
	pa = 0x200000;		// leave 2 Meg for kernel
	nbytes = 8*1024*1024;	// leave room at the top as well
	
	conf.npage0 = nbytes/BY2PG;
	conf.base0 = pa;
	
	conf.npage1 = 0;
	conf.base1 = pa;

	conf.npage = conf.npage0 + conf.npage1;

	conf.upages = (conf.npage*60)/100;
	conf.ialloc = ((conf.npage-conf.upages)/2)*BY2PG;

	/* set up other configuration parameters */
	conf.nswap = 0;
	conf.nswppo = 0; 
	conf.nimage = 20;

	conf.copymode = 0;		/* copy on write */
}

static int
getcfields(char* lp, char** fields, int n, char* sep)
{
	int i;

	for(i = 0; lp && *lp && i < n; i++){
		while(*lp && strchr(sep, *lp) != 0)
			*lp++ = 0;
		if(*lp == 0)
			break;
		fields[i] = lp;
		while(*lp && strchr(sep, *lp) == 0){
			if(*lp == '\\' && *(lp+1) == '\n')
				*lp++ = ' ';
			lp++;
		}
	}

	return i;
}

int
isaconfig(char *class, int ctlrno, ISAConf *isa)
{
	int i;
	char cc[KNAMELEN], *p;

	sprint(cc, "%s%d", class, ctlrno);

	p = getconf(cc);
	if(p == 0)
		return 0;
	isa->nopt = tokenize(p, isa->opt, NISAOPT);
	for(i = 0; i < isa->nopt; i++){
		p = isa->opt[i];
		if(cistrncmp(p, "type=", 5) == 0)
			isa->type = p + 5;
		else if(cistrncmp(p, "port=", 5) == 0)
			isa->port = strtoul(p+5, &p, 0);
		else if(cistrncmp(p, "irq=", 4) == 0)
			isa->irq = strtoul(p+4, &p, 0);
		else if(cistrncmp(p, "dma=", 4) == 0)
			isa->dma = strtoul(p+4, &p, 0);
		else if(cistrncmp(p, "mem=", 4) == 0)
			isa->mem = strtoul(p+4, &p, 0);
		else if(cistrncmp(p, "size=", 5) == 0)
			isa->size = strtoul(p+5, &p, 0);
		else if(cistrncmp(p, "freq=", 5) == 0)
			isa->freq = strtoul(p+5, &p, 0);
	}
	return 1;
}

int
cistrcmp(char *a, char *b)
{
	int ac, bc;

	for(;;){
		ac = *a++;
		bc = *b++;
	
		if(ac >= 'A' && ac <= 'Z')
			ac = 'a' + (ac - 'A');
		if(bc >= 'A' && bc <= 'Z')
			bc = 'a' + (bc - 'A');
		ac -= bc;
		if(ac)
			return ac;
		if(bc == 0)
			break;
	}
	return 0;
}

int
cistrncmp(char *a, char *b, int n)
{
	unsigned ac, bc;

	while(n > 0){
		ac = *a++;
		bc = *b++;
		n--;

		if(ac >= 'A' && ac <= 'Z')
			ac = 'a' + (ac - 'A');
		if(bc >= 'A' && bc <= 'Z')
			bc = 'a' + (bc - 'A');

		ac -= bc;
		if(ac)
			return ac;
		if(bc == 0)
			break;
	}

	return 0;
.
19a
//	cpuidentify();
//	confinit();
//	xinit();
	trapinit();
print("trapinit done\n");
*(ulong*)-1 = 0;
print("survived!\n");
spllo();
putdec(64);
print("still here\n");
{ void (*f)(void); f = (void (*)(void))0x200; f(); }
for(;;);
//	printinit();
//	cpuidprint();
//	mmuinit();
//	procinit0();
//	initseg();
//	links();
//	chandevreset();
//	pageinit();
//	swapinit();
//	userinit();
//	schedinit();
}
.
16,17c
	conf.nmach = 1;
	machinit();
	active.machs = 1;
	active.exiting = 0;
.
## diffname mtx/main.c 2001/1208
## diff -e /n/emeliedump/2001/1207/sys/src/9/mtx/main.c /n/emeliedump/2001/1208/sys/src/9/mtx/main.c
217,218c
	firmware();
.
60a
void
cpuidprint(void)
{
	char *id;

	id = "?";
	switch(m->cputype) {
	case 9:
		id = "PowerPC 604e";
		break;
	default:
		panic("unknown PowerPC");
		break;
	}
	print("cpu0: %s\n", id);
}

.
58c
	m->loopconst = 100000;
m->loopconst = 5000;

	active.machs = 1;
	active.exiting = 0;
.
50a
//	m->cputype = getpvr()>>16;
.
44a
spllo();
putdec(64);
putmsr(getmsr() | MSR_IR | MSR_DR);
*(ulong*)-1 = 0;
firmware();
.
26,33d
22d
18,19c
	clockinit();
.
15a
	memset(edata, 0, (ulong)end-(ulong)edata);
.
## diffname mtx/main.c 2001/1212
## diff -e /n/emeliedump/2001/1208/sys/src/9/mtx/main.c /n/emeliedump/2001/1212/sys/src/9/mtx/main.c
265,267c
	pa = PGROUND(PADDR(end));
	nbytes = 256*1024*1024;	// hard wire for now
.
72,74d
67c
	id = "unknown PowerPC";
.
47c
	m->cputype = getpvr()>>16;
.
25,40c
	printinit();
	cpuidprint();
	mmuinit();
	procinit0();
	initseg();
	links();
	chandevreset();
	pageinit();
	swapinit();
	userinit();
	schedinit();
.
22,23c
	confinit();
	xinit();
.
## diffname mtx/main.c 2001/1214
## diff -e /n/emeliedump/2001/1212/sys/src/9/mtx/main.c /n/emeliedump/2001/1214/sys/src/9/mtx/main.c
258,260c

	conf.npage0 = memsize/BY2PG;
.
255c
	conf.nproc = 60;		/* processes */
.
252a
	extern ulong memsize;	/* passed in from ROM monitor */
.
251d
221c
		else if(conf.monitor)
.
## diffname mtx/main.c 2001/1215
## diff -e /n/emeliedump/2001/1214/sys/src/9/mtx/main.c /n/emeliedump/2001/1215/sys/src/9/mtx/main.c
26a
pcihinv(nil);
firmware();
.
23a
	raveninit();
.
## diffname mtx/main.c 2001/1218
## diff -e /n/emeliedump/2001/1215/sys/src/9/mtx/main.c /n/emeliedump/2001/1218/sys/src/9/mtx/main.c
35a
spllo();
for(;;);
.
30a
	hwintrinit();
	clockinit();
	kbdinit();
.
28,29d
19c
	ioinit();
.
## diffname mtx/main.c 2001/1219
## diff -e /n/emeliedump/2001/1218/sys/src/9/mtx/main.c /n/emeliedump/2001/1219/sys/src/9/mtx/main.c
174c
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);
.
163,164c
	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

.
143a
for(;;);
.
104,105d
56,57c
//	m->loopconst = 100000;
m->loopconst = 5000;			/* dog slow, the cache must be off */
.
37,38d
## diffname mtx/main.c 2002/0104
## diff -e /n/emeliedump/2001/1219/sys/src/9/mtx/main.c /n/emeliedump/2002/0104/sys/src/9/mtx/main.c
139a
print("touser forestalled\n");
.
## diffname mtx/main.c 2002/0108
## diff -e /n/emeliedump/2002/0104/sys/src/9/mtx/main.c /n/emeliedump/2002/0108/sys/src/9/mtx/main.c
140,141d
## diffname mtx/main.c 2002/0109
## diff -e /n/emeliedump/2002/0108/sys/src/9/mtx/main.c /n/emeliedump/2002/0109/sys/src/9/mtx/main.c
195a
}

/* still to do */
void
reboot(void*, void*, ulong)
{
	exit(0);
.
122c
			ksetenv("service", "terminal", 0);
.
120c
			ksetenv("service", "cpu", 0);
.
118c
		ksetenv("cputype", "power", 0);
.
82a
	{ "ether0", "type=2114x" },
.
## diffname mtx/main.c 2002/0110
## diff -e /n/emeliedump/2002/0109/sys/src/9/mtx/main.c /n/emeliedump/2002/0110/sys/src/9/mtx/main.c
287c
		/*
		 * Hack for the big boys. Only good while physmem < 4GB.
		 * Give the kernel a max. of 16MB + enough to allocate the
		 * page pool.
		 * This is an overestimate as conf.upages < conf.npages.
		 * The patch of nimage is a band-aid, scanning the whole
		 * page list in imagereclaim just takes too long.
		 */
		if(kpages > (16*MB + conf.npage*sizeof(Page))/BY2PG){
			kpages = (16*MB + conf.npage*sizeof(Page))/BY2PG;
			conf.nimage = 2000;
			kpages += (conf.nproc*KSTACK)/BY2PG;
		}
	} else {
		if(userpcnt < 10) {
			if(conf.npage*BY2PG < 16*MB)
				userpcnt = 40;
			else
				userpcnt = 60;
		}
		kpages = conf.npage - (conf.npage*userpcnt)/100;

		/*
		 * Make sure terminals with low memory get at least
		 * 4MB on the first Image chunk allocation.
		 */
		if(conf.npage*BY2PG < 16*MB)
			imagmem->minarena = 4*1024*1024;
	}
	conf.upages = conf.npage - kpages;
	conf.ialloc = (kpages/2)*BY2PG;

	/*
	 * Guess how much is taken by the large permanent
	 * datastructures. Mntcache and Mntrpc are not accounted for
	 * (probably ~300KB).
	 */
	kpages *= BY2PG;
	kpages -= conf.upages*sizeof(Page)
		+ conf.nproc*sizeof(Proc)
		+ conf.nimage*sizeof(Image)
		+ conf.nswap
		+ conf.nswppo*sizeof(Page);
	mainmem->maxsize = kpages;
	if(!cpuserver){
		/*
		 * give terminals lots of image memory, too; the dynamic
		 * allocation will balance the load properly, hopefully.
		 * be careful with 32-bit overflow.
		 */
		imagmem->maxsize = kpages;
	}

//	conf.monitor = 1;	/* BUG */
.
282,285c
	if(cpuserver) {
		if(userpcnt < 10)
			userpcnt = 70;
		kpages = conf.npage - (conf.npage*userpcnt)/100;
.
279,280c
	conf.nmach = 1;
	conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
	if(cpuserver)
		conf.nproc *= 3;
	if(conf.nproc > 2000)
		conf.nproc = 2000;
	conf.nimage = 200;
	conf.nswap = conf.nproc*80;
	conf.nswppo = 4096;
	conf.copymode = 0;			/* copy on write */
.
266,267c
	if(p = getconf("*kernelpercent"))
		userpcnt = 100 - strtol(p, 0, 0);
	else
		userpcnt = 0;
.
263c
	char *p;
	int userpcnt;
	ulong pa, kpages;
.
## diffname mtx/main.c 2002/0112
## diff -e /n/emeliedump/2002/0110/sys/src/9/mtx/main.c /n/emeliedump/2002/0112/sys/src/9/mtx/main.c
257c
	if(p->fpstate == FPactive){
		if(p->state != Moribund) {
			/*
			 * Fpsave() stores without handling pending
			 * unmasked exeptions. Postnote() can't be called
			 * here as sleep() already has up->rlock, so
			 * the handling of pending exceptions is delayed
			 * until the process runs again and generates an
			 * emulation fault to activate the FPU.
			 */
			fpsave(&up->fpsave);
		}
		fpoff(p);
		p->fpstate = FPinactive;
	}
.
248c
	p->fpstate = FPinit;
.
56a
	/* turn on caches (instruction only for now) */
	puthid0(gethid0() | BIT(16));
//puthid0(gethid0() | BIT(16) | BIT(17));	/* and data */

.
54,55c
	m->loopconst = 100000;
.
37a
	fpsave(&initfp);
	initfp.fpscr = 0;
.
## diffname mtx/main.c 2002/0116
## diff -e /n/emeliedump/2002/0112/sys/src/9/mtx/main.c /n/emeliedump/2002/0116/sys/src/9/mtx/main.c
273d
263,271c
		if(p->state != Moribund)
.
59,60c
//	puthid0(gethid0() | BIT(16));
puthid0(gethid0() | BIT(16) | BIT(17));	/* and data */
.
## diffname mtx/main.c 2002/0119
## diff -e /n/emeliedump/2002/0116/sys/src/9/mtx/main.c /n/emeliedump/2002/0119/sys/src/9/mtx/main.c
265c
//		fpoff(p);
.
## diffname mtx/main.c 2002/0124
## diff -e /n/emeliedump/2002/0119/sys/src/9/mtx/main.c /n/emeliedump/2002/0124/sys/src/9/mtx/main.c
265d
58,60c
	/* turn on caches */
	puthid0(gethid0() | BIT(16) | BIT(17));
.
## diffname mtx/main.c 2002/0126
## diff -e /n/emeliedump/2002/0124/sys/src/9/mtx/main.c /n/emeliedump/2002/0126/sys/src/9/mtx/main.c
243c
	watchreset();
.
## diffname mtx/main.c 2002/0212
## diff -e /n/emeliedump/2002/0126/sys/src/9/mtx/main.c /n/emeliedump/2002/0212/sys/src/9/mtx/main.c
144a
	kproc("mmusweep", mmusweep, 0);
.
## diffname mtx/main.c 2002/0217
## diff -e /n/emeliedump/2002/0212/sys/src/9/mtx/main.c /n/emeliedump/2002/0217/sys/src/9/mtx/main.c
20a
	quotefmtinstall();
.
## diffname mtx/main.c 2002/0403
## diff -e /n/emeliedump/2002/0217/sys/src/9/mtx/main.c /n/emeliedump/2002/0403/sys/src/9/mtx/main.c
140c
			if(name[0] != '*')
				ksetenv(name, q+1, 0);
			ksetenv(name, q+1, 1);
.
123a
		snprint(buf, sizeof(buf), "power %s mtx", conffile);
		ksetenv("terminal", buf, 0);
.
106a
	char buf[2*KNAMELEN];
.
## diffname mtx/main.c 2002/0410
## diff -e /n/emeliedump/2002/0403/sys/src/9/mtx/main.c /n/emeliedump/2002/0410/sys/src/9/mtx/main.c
34a
	timersinit();
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].