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

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


## diffname mpc/main.c 1999/0121
## diff -e /dev/null /n/emeliedump/1999/0121/sys/src/brazil/mpc/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"

#define MAXCONF 1000

char *confname[MAXCONF];
char *confval[MAXCONF];
int nconf;

Conf	conf;

void
main(void)
{
	machinit();
}

void
machinit(void)
{
	IMM *io;
	int mf, osc;

	memset(m, 0, sizeof(*m));
	m->delayloop = 20000;
	m->cputype = getpvr()>>16;
	m->iomem = KADDR(INTMEM);

	io = m->iomem;
	osc = 5;
	mf = io->plprcr >> 20;
	m->oscclk = osc;
	m->speed = osc*(mf+1);
}

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);

//	arch->reset();
}

/*
 *  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);
}

// print without using interrupts
int
iprint(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;
	va_list arg;

	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);

	print("%s", buf);

	return n;
}


int
isaconfig(char *class, int ctlrno, ISAConf *isa)
{
	char cc[NAMELEN], *p, *q, *r;
	int n;

	sprint(cc, "%s%d", class, ctlrno);
	for(n = 0; n < nconf; n++){
		if(strncmp(confname[n], cc, NAMELEN))
			continue;
		isa->nopt = 0;
		p = confval[n];
		while(*p){
			while(*p == ' ' || *p == '\t')
				p++;
			if(*p == '\0')
				break;
			if(strncmp(p, "type=", 5) == 0){
				p += 5;
				for(q = isa->type; q < &isa->type[NAMELEN-1]; q++){
					if(*p == '\0' || *p == ' ' || *p == '\t')
						break;
					*q = *p++;
				}
				*q = '\0';
			}
			else if(strncmp(p, "port=", 5) == 0)
				isa->port = strtoul(p+5, &p, 0);
			else if(strncmp(p, "irq=", 4) == 0)
				isa->irq = strtoul(p+4, &p, 0);
			else if(strncmp(p, "mem=", 4) == 0)
				isa->mem = strtoul(p+4, &p, 0);
			else if(strncmp(p, "size=", 5) == 0)
				isa->size = strtoul(p+5, &p, 0);
			else if(strncmp(p, "freq=", 5) == 0)
				isa->freq = strtoul(p+5, &p, 0);
			else if(strncmp(p, "dma=", 4) == 0)
				isa->dma = strtoul(p+4, &p, 0);
			else if(isa->nopt < NISAOPT){
				r = isa->opt[isa->nopt];
				while(*p && *p != ' ' && *p != '\t'){
					*r++ = *p++;
					if(r-isa->opt[isa->nopt] >= ISAOPTLEN-1)
						break;
				}
				*r = '\0';
				isa->nopt++;
			}
			while(*p && *p != ' ' && *p != '\t')
				p++;
		}
		return 1;
	}
	return 0;
}

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;
}
.
## diffname mpc/main.c 1999/0122
## diff -e /n/emeliedump/1999/0121/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0122/sys/src/brazil/mpc/main.c
112a
void
confinit(void)
{
	int nbytes;
	ulong pa;

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

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

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

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

	/* set up other configuration parameters */
	conf.nswap = conf.npage*3;
	conf.nswppo = 4096;
	conf.nimage = 200;

	conf.copymode = 0;		/* copy on write */
}
.
39a
	m->cpuhz = m->speed*MHz;	/* general system clock (cycles) */
	m->clockgen = osc*MHz;		/* clock generator frequency (cycles) */
.
21a
	confinit();
	xinit();
	printinit();
	cpminit();
	uartinstall();
	print("hello world\n");

	delay(100);

	reset();

	*(uchar*)0 = 0;
	for(;;)
		;
.
18a
flash(void)
{
	int i;
	*(uchar*)(NIMMEM+0x2200) = 0;
	for(i=0; i<1000000; i++)
		;
	*(uchar*)(NIMMEM+0x2200) = 0x2;
	for(i=0; i<1000000; i++)
		;
}

void
.
## diffname mpc/main.c 1999/0123
## diff -e /n/emeliedump/1999/0122/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0123/sys/src/brazil/mpc/main.c
136c
//	putstrn(buf, n);
//	uartwait();
.
44,47d
41,42d
39c
delay(500);
	spllo();
	for(i=0; ; i++) {
		print("hello again %d\n", i);
		delay(100);
	}
.
35a
	trapinit();
.
33a
	clockinit();
.
32a
	int i;

.
## diffname mpc/main.c 1999/0126
## diff -e /n/emeliedump/1999/0123/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0126/sys/src/brazil/mpc/main.c
139,140c
	putstrn(buf, n);
	uartwait();
.
43c
	mmuinit();
.
## diffname mpc/main.c 1999/0127
## diff -e /n/emeliedump/1999/0126/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0127/sys/src/brazil/mpc/main.c
70a
}

void
bootargs(ulong base)
{
print("bootargs = %ux\n", base);
	USED(base);
}

void
init0(void)
{
	int i;

	up->nerrlab = 0;

print("spllo = %ux\n", 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);
	up->dot = cclone(up->slash, 0);

	chandevinit();

	if(!waserror()){
		ksetenv("cputype", "power");
		if(cpuserver)
			ksetenv("service", "cpu");
		else
			ksetenv("service", "terminal");
		for(i = 0; i < nconf; i++)
			if(confname[i] && confname[i][0] != '*')
				ksetenv(confname[i], confval[i]);
		poperror();
	}
	kproc("alarm", alarmkproc, 0);
	print("to user!!\n");
	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);
	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((ulong*)VA(k), initcode, sizeof initcode);
	kunmap(k);

	ready(p);
.
51a
	pageinit();
	procinit0();
	initseg();
	links();
	chandevreset();
	swapinit();
	userinit();
predawn = 0;
	schedinit();
}
.
49,50d
44,47c
if(0) {
	predawn = 0;
	print("spllo() = %ux\n", spllo());
	for(;;) {
		print("hello\n");
		delay(1000);
.
33,34d
15a
int	predawn = 1;

.
## diffname mpc/main.c 1999/0415
## diff -e /n/emeliedump/1999/0127/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0415/sys/src/brazil/mpc/main.c
262,263c
	pa = 0xffd00000;		// leave 1 Meg for kernel
	nbytes = 2*1024*1024;	// leave room at the top as well
.
75c
	osc = 50;
.
21,32d
## diffname mpc/main.c 1999/0508
## diff -e /n/emeliedump/1999/0415/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0508/sys/src/brazil/mpc/main.c
269a
}

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;
}

static char BOOTARGS[] = 
		"ether0=type=SCC port=1 ea=08003e27df94\r\n"
		"vgasize=640x480x8\r\n"
		"kernelpercent=40\r\n"
		"console=0 lcd\r\nbaud=9600\r\n";

static void
options(void)
{
	long i, n;
	char *cp, *p, *q;
	char *line[MAXCONF];

	/*
	 *  parse configuration args from dos file plan9.ini
	 */
	cp = BOOTARGS;	/* where b.com leaves its config */

	/*
	 * Strip out '\r', change '\t' -> ' '.
	 */
	p = cp;
	for(q = cp; *q; q++){
		if(*q == '\r')
			continue;
		if(*q == '\t')
			*q = ' ';
		*p++ = *q;
	}
	*p = 0;

	n = getcfields(cp, line, MAXCONF, "\n");
	for(i = 0; i < n; i++){
		if(*line[i] == '#')
			continue;
		cp = strchr(line[i], '=');
		if(cp == 0)
			continue;
		*cp++ = 0;
		if(cp - line[i] >= NAMELEN+1)
			*(line[i]+NAMELEN-1) = 0;
		confname[nconf] = line[i];
		confval[nconf] = cp;
		nconf++;
	}
.
74c
print("bootargs = %ulx\n", base);
.
45a
print("usrinit\n");
.
42a
	options();
.
19a
static void options(void);

.
10c
#define MAXCONF 32
.
## diffname mpc/main.c 1999/0608
## diff -e /n/emeliedump/1999/0508/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0608/sys/src/brazil/mpc/main.c
298a
		"ether1=type=589E port=0x300\r\n"
.
269,271c
	conf.nswap = 0; // conf.npage*3;
	conf.nswppo = 0; // 4096;
	conf.nimage = 20;
.
262a
	conf.npage1 = nbytes/BY2PG;
	conf.base1 = pa;

.
260,261c
	pa = 0xfff04000;
	nbytes = 1024*1024 - 0x4000;
.
251c
	conf.nproc = 30;	/* processes */
.
204a
	for(;;)
		;
.
72a

	*(ushort*)&(io->memc[4].base) = 0x8060;
.
49d
41a
// turn on pcmcia
*(uchar*)(NVRAMMEM+0x100001) |= 0x60;
//print("sr1=%ux sr2=%ux\n", *(uchar*)(NVRAMMEM+0x100000), *(uchar*)(NVRAMMEM+0x100001));

//print("sccr=%ulx\n", m->iomem->sccr);
.
## diffname mpc/main.c 1999/0609
## diff -e /n/emeliedump/1999/0608/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0609/sys/src/brazil/mpc/main.c
78a
//	*(ushort*)&(io->memc[7].option) = 0xffe0;
	*(ushort*)&(io->memc[7].base) = 0xff00;
.
46a
print("%ux %ux\n", m->iomem->memc[0].base, m->iomem->memc[7].base);
print("%ux %ux\n", m->iomem->memc[0].option, m->iomem->memc[7].option);
print("%ux\n", *(uchar*)(0xff000000));
.
## diffname mpc/main.c 1999/0618
## diff -e /n/emeliedump/1999/0609/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0618/sys/src/brazil/mpc/main.c
437a

.
330c
	ba = (Bootargs*)(NVRAMMEM+ 4*1024);
	if(ba->chksum == nvcsum(ba->args, sizeof(ba->args))) {
		cp = smalloc(strlen(ba->args)+1);
		memmove(cp, ba->args, strlen(ba->args)+1);
	} else
		cp = BOOTARGS;
print("bootargs = %s\n", cp);
.
325a
	Bootargs *ba;
.
315,318c
		"ether1=type=589E port=0x300\r\n";
.
281c
	conf.upages = (conf.npage*60)/100;
.
85a

.
83a

.
46,49d
44d
34,41c

.
17a
typedef struct Bootargs Bootargs;

struct Bootargs
{
	char	args[1000];
	uchar	chksum;
};

.
## diffname mpc/main.c 1999/0623
## diff -e /n/emeliedump/1999/0618/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0623/sys/src/brazil/mpc/main.c
312c
		"ether0=type=SCC port=1 ea=000086353a6b\r\n"
.
## diffname mpc/main.c 1999/0806
## diff -e /n/emeliedump/1999/0623/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0806/sys/src/brazil/mpc/main.c
262c
	conf.nproc = 40;	/* processes */
.
## diffname mpc/main.c 1999/0807
## diff -e /n/emeliedump/1999/0806/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0807/sys/src/brazil/mpc/main.c
262c
	conf.nproc = 60;	/* processes */
.
## diffname mpc/main.c 1999/0901
## diff -e /n/emeliedump/1999/0807/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0901/sys/src/brazil/mpc/main.c
245,252c
void
rdb(void)
{
	panic("rdb");
.
241,243c
	putstrn(s, n);
}
.
238,239c
void
serialputs(char *s, int n)
.
## diffname mpc/main.c 1999/0930
## diff -e /n/emeliedump/1999/0901/sys/src/brazil/mpc/main.c /n/emeliedump/1999/0930/sys/src/brazil/mpc/main.c
97,98d
45a
print("m->delayloop = %ld\n", m->delayloop);
	delayloopinit();
print("m->delayloop = %ld\n", m->delayloop);

.
## diffname mpc/main.c 1999/1210
## diff -e /n/emeliedump/1999/0930/sys/src/brazil/mpc/main.c /n/emeliedump/1999/1210/sys/src/9/mpc/main.c
437a
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;
}

/* dummy - not used */

void
iofree(int)
{
}

int
ioalloc(int, int, int, char*)
{
	return 1;
}

.
## diffname mpc/main.c 2000/0422
## diff -e /n/emeliedump/1999/1210/sys/src/9/mpc/main.c /n/emeliedump/2000/0422/sys/src/9/mpc/main.c
106a
	cnameclose(up->slash->name);
	up->slash->name = newcname("/");
.
## diffname mpc/main.c 2000/0516
## diff -e /n/emeliedump/2000/0422/sys/src/9/mpc/main.c /n/emeliedump/2000/0516/sys/src/9/mpc/main.c
438,475d
415c
	return 1;
.
413c
		while(*p && *p != ' ' && *p != '\t')
			p++;
.
410,411c
			*r = '\0';
			isa->nopt++;
.
388,408c
			*q = '\0';
		}
		else if(strncmp(p, "port=", 5) == 0)
			isa->port = strtoul(p+5, &p, 0);
		else if(strncmp(p, "irq=", 4) == 0)
			isa->irq = strtoul(p+4, &p, 0);
		else if(strncmp(p, "mem=", 4) == 0)
			isa->mem = strtoul(p+4, &p, 0);
		else if(strncmp(p, "size=", 5) == 0)
			isa->size = strtoul(p+5, &p, 0);
		else if(strncmp(p, "freq=", 5) == 0)
			isa->freq = strtoul(p+5, &p, 0);
		else if(strncmp(p, "dma=", 4) == 0)
			isa->dma = strtoul(p+4, &p, 0);
		else if(isa->nopt < NISAOPT){
			r = isa->opt[isa->nopt];
			while(*p && *p != ' ' && *p != '\t'){
				*r++ = *p++;
				if(r-isa->opt[isa->nopt] >= ISAOPTLEN-1)
					break;
.
369,386c

	p = getconf(cc);
	if(p == 0)
		return 0;
print("%s=%s\n", cc, p);	
	isa->nopt = 0;
	while(*p){
		while(*p == ' ' || *p == '\t')
			p++;
		if(*p == '\0')
			break;
		if(strncmp(p, "type=", 5) == 0){
			p += 5;
			for(q = isa->type; q < &isa->type[NAMELEN-1]; q++){
				if(*p == '\0' || *p == ' ' || *p == '\t')
					break;
				*q = *p++;
.
366d
310,361d
282,283c
	conf.nswap = 0;
	conf.nswppo = 0; 
.
270,273c
	conf.npage1 = 0;
.
264,265c
	pa = 0x200000;		// leave 2 Meg for kernel
	nbytes = 8*1024*1024;	// leave room at the top as well
.
259a
	/* fix up confenv */
	for(p = confenv; *p; p++)
		*p = KADDR(*p);

.
258a
	char **p;
.
165,167d
119,121c
		
		for(p = confenv; *p; p++) {
			q = strchr(p[0], '=');
			if(q == 0)
				continue;
			n = q-p[0];
			if(n >= NAMELEN)
				n = NAMELEN-1;
			memmove(name, p[0], n);
			name[n] = 0;
			ksetenv(name, q+1);
		}
.
99a
print("init0\n");

.
98c
	char **p, *q, name[NAMELEN];
	int n;
.
91,92c
	char **p, *q;
	int n;

	n = strlen(name);

	for(p = confenv; *p; p++) {
		q = *p;
		if(strncmp(q, name, n) == 0 && q[n] == '=')
			return q+n+1;
	}
	return 0;
.
87,89c
char*
getconf(char *name)
.
84a
	/* enable check stop reset */
	io->plprcrk = KEEP_ALIVE_KEY;	// unlock
	io->plprcr |= IBIT(24);		// enable checkstop reset
	putmsr(getmsr() | MSR_RI | MSR_ME);
//	putmsr(getmsr() & ~MSR_ME);
.
81,83c
	active.machs = 1;
	active.exiting = 0;
.
71a
	m->stb = &stlb[0][0];
.
53d
42,49d
40a
print("hello world from kernel %ux %ux %ux\n", m->iomem->pddat, m->iomem->pddir, m->iomem->pdpar);
.
32a
	powerdownled();
.
28,29d
25a
/*
 * software tlb simulation
 */
Softtlb stlb[MAXMACH][STLBSIZE];

.
12,15d
10c
static char **confenv = (char**)(CONFPARSED);
.
## diffname mpc/main.c 2000/0817
## diff -e /n/emeliedump/2000/0516/sys/src/9/mpc/main.c /n/emeliedump/2000/0817/sys/src/9/mpc/main.c
41a
	spiinit();
.
## diffname mpc/main.c 2001/0527 # deleted
## diff -e /n/emeliedump/2000/0817/sys/src/9/mpc/main.c /n/emeliedump/2001/0527/sys/src/9/mpc/main.c
1,402d

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].