Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/devcons.c

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


## diffname port/devcons.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/devcons.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"errno.h"

#include	"devtab.h"

static struct
{
	Lock;
	uchar	buf[4000];
	uchar	*in;
	uchar	*out;
	int	printing;
	int	c;
}printq;

typedef struct IOQ	IOQ;

#define	NQ	4096
struct IOQ{
	union{
		Lock;
		QLock;
	};
	uchar	buf[NQ];
	uchar	*in;
	uchar	*out;
	int	state;
	Rendez	r;
};

IOQ	kbdq;		/* qlock to getc; interrupt putc's */
IOQ	lineq;		/* lock to getc; interrupt putc's */

void
printinit(void)
{

	printq.in = printq.buf;
	printq.out = printq.buf;
	lock(&printq);		/* allocate lock */
	unlock(&printq);

	kbdq.in = kbdq.buf;
	kbdq.out = kbdq.buf;
	lineq.in = lineq.buf;
	lineq.out = lineq.buf;
	qlock(&kbdq);		/* allocate qlock */
	qunlock(&kbdq);
	lock(&lineq);		/* allocate lock */
	unlock(&lineq);

	duartinit();
}

/*
 * Put a string on the console.
 * n bytes of s are guaranteed to fit in the buffer and is ready to print.
 * Must be called splhi() and with printq locked.
 */
void
puts(char *s, int n)
{
	if(!printq.printing){
		printq.printing = 1;
		printq.c = *s++;
		n--;
	}
	memcpy(printq.in, s, n);
	printq.in += n;
	if(printq.in >= printq.buf+sizeof(printq.buf))
		printq.in = printq.buf;
}

/*
 * Print a string on the console.  This is the high level routine
 * with a queue to the interrupt handler.  BUG: There is no check against
 * overflow.
 */
void
putstrn(char *str, int n)
{
	int s, c, m;
	char *t;

	s = splhi();
	lock(&printq);
	while(n > 0){
		if(*str == '\n')
			puts("\r", 1);
		m = printq.buf+sizeof(printq.buf) - printq.in;
		if(n < m)
			m = n;
		t = memchr(str+1, '\n', m-1);
		if(t)
			if(t-str < m)
				m = t - str;
		puts(str, m);
		n -= m;
		str += m;
	}
	unlock(&printq);
	splx(s);
}

int
cangetc(IOQ *q)
{
	return q->in != q->out;
}

int
isbrkc(IOQ *q)
{
	uchar *p;

	for(p=q->out; p!=q->in; ){
		if(*p==0x04 || *p=='\n')
			return 1;
		p++;
		if(p >= q->buf+sizeof(q->buf))
			p = q->buf;
	}
	return 0;
}

int
getc(IOQ *q)
{
	int c;

	if(q->in == q->out)
		return -1;
	c = *q->out++;
	if(q->out == q->buf+sizeof(q->buf))
		q->out = q->buf;
	return c;
}

int
sprint(char *s, char *fmt, ...)
{
	char *out;

	out = donprint(s, s+PRINTSIZE, fmt, (&fmt+1));
	return out-s;
}

int
print(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;

	n = donprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	putstrn(buf, n);
	return n;
}

void
panic(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;

	strcpy(buf, "panic: ");
	n = donprint(buf+7, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	buf[n] = '\n';
	putstrn(buf, n+1);
	exit();
}

int
pprint(char *fmt, ...)
{
	char buf[2*PRINTSIZE];
	Chan *c;
	int n;

	c = u->fd[2];
	if(c==0 || (c->mode!=OWRITE && c->mode!=ORDWR))
		return;
	n = sprint(buf, "%s %d: ", u->p->text, u->p->pid);
	n = donprint(buf+n, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	qlock(c);
	if(waserror()){
		qunlock(c);
		return;
	}
	(*devtab[c->type].write)(c, buf, n);
	c->offset += n;
	qunlock(c);
	return n;
}

void
prflush(void)
{
	while(printq.printing)
		delay(100);
}

/*
 * Get character to print at interrupt time.
 * Always called splhi from proc 0.
 */
int
conschar(void)
{
	uchar *p;
	int c;

	lock(&printq);
	p = printq.out;
	if(p == printq.in){
		printq.printing = 0;
		c = -1;
	}else{
		c = *p++;
		if(p >= printq.buf+sizeof(printq.buf))
			p = printq.buf;
		printq.out = p;
	}
	unlock(&printq);
	return c;
}

void
echo(int c)
{
	char ch;
	/*
	 * ^t hack BUG
	 */
	if(c == 0x14)
		DEBUG();
	else if(c == 0x0c)
		LANCEDEBUG();
	else if(c == 0x02)
		LANCEPRDEBQ();
	if(c == 0x15)
		putstrn("^U\n", 3);
	else{
		ch = c;
		putstrn(&ch, 1);
	}
}

/*
 * Put character into read queue at interrupt time.
 * Always called splhi from proc 0.
 */
void
kbdchar(int c)
{
	if(c == '\r')
		c = '\n';
	echo(c);
	*kbdq.in++ = c;
	if(kbdq.in == kbdq.buf+sizeof(kbdq.buf))
		kbdq.in = kbdq.buf;
	if(c=='\n' || c==0x04)
		wakeup(&kbdq.r);
}

void
printslave(void)
{
	int c;

	c = printq.c;
	if(c){
		printq.c = 0;
		duartxmit(c);
	}
}

int
consactive(void)
{
	return printq.in != printq.out;
}

/*
 * I/O interface
 */
enum{
	Qdir,
	Qcons,
	Qcputime,
	Qnull,
	Qpgrpid,
	Qpid,
	Qppid,
	Qtime,
	Quser,
};

Dirtab consdir[]={
	"cons",		Qcons,		0,	0600,
	"cputime",	Qcputime,	72,	0600,
	"null",		Qnull,		0,	0600,
	"pgrpid",	Qpgrpid,	12,	0600,
	"pid",		Qpid,		12,	0600,
	"ppid",		Qppid,		12,	0600,
	"time",		Qtime,		12,	0600,
	"user",		Quser,		0,	0600,
};

#define	NCONS	(sizeof consdir/sizeof(Dirtab))

ulong	boottime;		/* seconds since epoch at boot */

long
seconds(void)
{
	return boottime + MACHP(0)->ticks*MS2HZ/1000;
}

int
readnum(ulong off, char *buf, ulong n, ulong val, int size)
{
	char tmp[64];
	Op op = (Op){ tmp, tmp+sizeof(tmp), &val, size-1, 0, FUNSIGN|FLONG };

	numbconv(&op, 10);
	tmp[size-1] = ' ';
	off %= size;
	if(off+n > size)
		n = size-off;
	memcpy(buf, tmp+off, n);
	return n;
}

int
readstr(ulong off, char *buf, ulong n, char *str)
{
	int size;

	size = strlen(str);
	off %= size;
	if(off+n > size)
		n = size-off;
	memcpy(buf, str+off, n);
	return n;
}

void
consreset(void)
{
}

void
consinit(void)
{
}

Chan*
consattach(char *spec)
{
	return devattach('c', spec);
}

Chan*
consclone(Chan *c, Chan *nc)
{
	return devclone(c, nc);
}

int
conswalk(Chan *c, char *name)
{
	return devwalk(c, name, consdir, NCONS, devgen);
}

void
consstat(Chan *c, char *dp)
{
	devstat(c, dp, consdir, NCONS, devgen);
}

Chan*
consopen(Chan *c, int omode)
{
	if(c->qid==Quser && omode==(OWRITE|OTRUNC)){
		/* truncate? */
		if(strcmp(u->p->pgrp->user, "bootes") == 0)	/* BUG */
			u->p->pgrp->user[0] = 0;
		else
			error(0, Eperm);
	}
	return devopen(c, omode, consdir, NCONS, devgen);
}

void
conscreate(Chan *c, char *name, int omode, ulong perm)
{
	error(0, Eperm);
}

void
consclose(Chan *c)
{
}

long
consread(Chan *c, void *buf, long n)
{
	int ch, i, j, k;
	ulong l;
	uchar *out;
	char *cbuf = buf;
	char *user;
	int userlen;
	char tmp[6*NUMSIZE];

	if(n <= 0)
		return n;
	switch(c->qid&~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, consdir, NCONS, devgen);

	case Qcons:
		qlock(&kbdq);
		while(!cangetc(&lineq)){
			sleep(&kbdq.r, (int(*)(void*))isbrkc, &kbdq);
			do{
				ch = getc(&kbdq);
				switch(ch){
				case '\b':
					if(lineq.in != lineq.out){
						if(lineq.in == lineq.buf)
							lineq.in = lineq.buf+sizeof(lineq.buf);
						lineq.in--;
					}
					break;
				case 0x15:
					lineq.in = lineq.out;
					break;
				default:
					*lineq.in++ = ch;
					if(lineq.in == lineq.buf+sizeof(lineq.buf))
					lineq.in = lineq.buf;
				}
			}while(ch!='\n' && ch!=0x04);
		}
		i = 0;
		while(n>0){
			ch = getc(&lineq);
			if(ch == 0x04 || ch == -1)
				break;
			i++;
			*cbuf++ = ch;
			--n;
		}
		qunlock(&kbdq);
		return i;

	case Qcputime:
		k = c->offset % sizeof tmp;
		if(k+n > sizeof tmp)
			n = sizeof tmp - k;
		/* easiest to format in a separate buffer and copy out */
		for(i=0; i<6 && NUMSIZE*i<k+n; i++){
			l = u->p->time[i];
			if(i == TReal)
				l = MACHP(0)->ticks - l;
			l *= MS2HZ;
			readnum(0, tmp+NUMSIZE*i, NUMSIZE, l, NUMSIZE);
		}
		memcpy(buf, tmp+k, n);
		return n;

	case Qpgrpid:
		return readnum(c->offset, buf, n, u->p->pgrp->pgrpid, NUMSIZE);

	case Qpid:
		return readnum(c->offset, buf, n, u->p->pid, NUMSIZE);

	case Qppid:
		return readnum(c->offset, buf, n, u->p->parentpid, NUMSIZE);

	case Qtime:
		return readnum(c->offset, buf, n, boottime+MACHP(0)->ticks/(1000/MS2HZ), 12);

	case Quser:
		return readstr(c->offset, buf, n, u->p->pgrp->user);

	case Qnull:
		return 0;

	default:
		panic("consread %lux\n", c->qid);
		return 0;
	}
}

long
conswrite(Chan *c, void *va, long n)
{
	char cbuf[64];
	char buf[256];
	long l, m;
	char *a = va;

	switch(c->qid){
	case Qcons:
		/*
		 * Damn. Can't page fault in putstrn, so copy the data locally.
		 */
		l = n;
		while(l > 0){
			m = l;
			if(m > sizeof buf)
				m = sizeof buf;
			memcpy(buf, a, m);
			putstrn(a, m);
			a += m;
			l -= m;
		}
		break;

	case Qtime:
		if(n<=0 || boottime!=0)	/* only one write please */
			return 0;
		if(n >= sizeof cbuf)
			n = sizeof cbuf - 1;
		memcpy(cbuf, a, n);
		cbuf[n-1] = 0;
		boottime = strtoul(a, 0, 0);
		break;

	case Quser:
		if(u->p->pgrp->user[0])		/* trying to overwrite /dev/user */
			error(0, Eperm);
		if(c->offset >= NAMELEN-1)
			return 0;
		if(c->offset+n >= NAMELEN-1)
			n = NAMELEN-1 - c->offset;
		memcpy(u->p->pgrp->user+c->offset, a, n);
		u->p->pgrp->user[c->offset+n] = 0;
		break;

	case Qcputime:
	case Qpgrpid:
	case Qpid:
	case Qppid:
		error(0, Eperm);

	case Qnull:
		break;
	default:
		error(0, Egreg);
	}
	return n;
}

void
consremove(Chan *c)
{
	error(0, Eperm);
}

void
conswstat(Chan *c, char *dp)
{
	error(0, Eperm);
}

void
conserrstr(Error *e, char *buf)
{
	rooterrstr(e, buf);
}

void
consuserstr(Error *e, char *buf)
{
	strcpy(buf, u->p->pgrp->user);
}
.
## diffname port/devcons.c 1990/03042
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/devcons.c /n/bootesdump/1990/03042/sys/src/9/mips/devcons.c
241,244d
## diffname port/devcons.c 1990/03091
## diff -e /n/bootesdump/1990/03042/sys/src/9/mips/devcons.c /n/bootesdump/1990/03091/sys/src/9/mips/devcons.c
235a

.
147,150c
	return donprint(s, s+PRINTSIZE, fmt, (&fmt+1)) - s;
.
## diffname port/devcons.c 1990/0312
## diff -e /n/bootesdump/1990/03091/sys/src/9/mips/devcons.c /n/bootesdump/1990/0312/sys/src/9/mips/devcons.c
458c
		k = c->offset;
		if(k >= sizeof tmp)
			return 0;
.
339c
	if(off >= size)
		return 0;
.
326c
	if(off >= size)
		return 0;
.
## diffname port/devcons.c 1990/0321
## diff -e /n/bootesdump/1990/0312/sys/src/9/mips/devcons.c /n/bootesdump/1990/0321/sys/src/9/mips/devcons.c
193a
	poperror();
.
189c
		return 0;
.
183c
		return 0;
.
## diffname port/devcons.c 1990/0504
## diff -e /n/bootesdump/1990/0321/sys/src/9/mips/devcons.c /n/bootesdump/1990/0504/sys/src/9/mips/devcons.c
241a
	if(c == 0x16)
		dumpqueues();
.
## diffname port/devcons.c 1990/06111
## diff -e /n/bootesdump/1990/0504/sys/src/9/mips/devcons.c /n/bootesdump/1990/06111/sys/src/9/mips/devcons.c
185c
	n = doprint(buf+n, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
.
168c
	n = doprint(buf+7, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
.
156c
	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
.
147c
	return doprint(s, s+PRINTSIZE, fmt, (&fmt+1)) - s;
.
## diffname port/devcons.c 1990/0614
## diff -e /n/bootesdump/1990/06111/sys/src/9/mips/devcons.c /n/bootesdump/1990/0614/sys/src/9/mips/devcons.c
489c
		return readnum(c->offset, buf, n, boottime+TK2MS(MACHP(0)->ticks), 12);
.
473c
			l = TK2MS(l);
.
318c
	return boottime + TK2MS(MACHP(0)->ticks);
.
## diffname port/devcons.c 1990/0617
## diff -e /n/bootesdump/1990/0614/sys/src/9/mips/devcons.c /n/bootesdump/1990/0617/sys/src/9/mips/devcons.c
489c
		return readnum(c->offset, buf, n, boottime+TK2SEC(MACHP(0)->ticks), 12);
.
427a
		if(waserror()){
			qunlock(&kbdq);
			nexterror();
		}
.
## diffname port/devcons.c 1990/0620
## diff -e /n/bootesdump/1990/0617/sys/src/9/mips/devcons.c /n/bootesdump/1990/0620/sys/src/9/mips/devcons.c
318c
	return boottime + TK2SEC(MACHP(0)->ticks);
.
## diffname port/devcons.c 1990/0629
## diff -e /n/bootesdump/1990/0620/sys/src/9/mips/devcons.c /n/bootesdump/1990/0629/sys/src/9/mips/devcons.c
243c
		urpdump();
.
## diffname port/devcons.c 1990/0707
## diff -e /n/bootesdump/1990/0629/sys/src/9/mips/devcons.c /n/bootesdump/1990/0707/sys/src/9/mips/devcons.c
243c
		dumpqueues();
.
## diffname port/devcons.c 1990/0718
## diff -e /n/bootesdump/1990/0707/sys/src/9/mips/devcons.c /n/bootesdump/1990/0718/sys/src/9/mips/devcons.c
91a
	syslog(str, n);
.
## diffname port/devcons.c 1990/0720
## diff -e /n/bootesdump/1990/0718/sys/src/9/mips/devcons.c /n/bootesdump/1990/0720/sys/src/9/mips/devcons.c
589a
}

/*
 *  crash info
 */
void
sysloginit(void)
{
	Syslog *s;
	char *p;

	s = SYSLOG;
	if(s->magic!=SYSLOGMAGIC || s->next>=&s->buf[sizeof(s->buf)]
	|| s->next<s->buf){
		s->next = s->buf;
		s->magic = SYSLOGMAGIC;
	}
}

void
syslog(char *p, int n)
{
	int i;
	Syslog *s;
	char *end;

	s = SYSLOG;
	end = &s->buf[sizeof(s->buf)];
	while(n-- > 0){
		*s->next++ = *p++;
		if(s->next >= end)
			s->next = s->buf;
	}
}

long
readlog(ulong off, char *buf, ulong n)
{
	Syslog *s;
	int i;
	char *p;
	char *end;

	s = SYSLOG;

	/* past end */
	if(off >= sizeof(s->buf))
		return 0;

	/* trim length */
	if(off + n >= sizeof(s->buf))
		n = sizeof(s->buf) - off;

	/* point to start of area to be read */
	end = &s->buf[sizeof(s->buf)];
	p = s->next + off;
	if(p > end)
		p -= sizeof(s->buf);

	for(i = 0; i < n; i++){
		*buf++ = *p++;
		if(p >= end)
			p = s->buf;
	}
	return n;
.
498a
	case Qlog:
		return readlog(c->offset, buf, n);

.
303a
	"log",		Qlog,		sizeof(SYSLOG->buf),	0600,
.
292a
	Qlog,
.
## diffname port/devcons.c 1990/0907
## diff -e /n/bootesdump/1990/0720/sys/src/9/mips/devcons.c /n/bootesdump/1990/0907/sys/src/9/mips/devcons.c
171a
	dumpstack();
.
## diffname port/devcons.c 1990/0912
## diff -e /n/bootesdump/1990/0907/sys/src/9/mips/devcons.c /n/bootesdump/1990/0912/sys/src/9/mips/devcons.c
660c
	return a-buf;
.
655,656c
	/* skip offset */
	while(off-- > 0){
		if(p == s->next)
			return 0;
		p++;
	}

	/* copy out */
	while(n-- > 0){
		if(p == s->next)
			break;
		*a++ = *p++;
.
651,653c
	p = s->start;
.
645,648d
637a
	char *a = buf;
.
635d
628a
	if(restart){
		s->start = s->next + 1;
		if(s->start >= end)
			s->start = s->buf;
	}
	wbflush();
.
627a
		if(s->next == s->start)
			restart = 1;
.
623a
	restart = 0;
.
618c
	int restart;
.
609c
	|| s->start>=&s->buf[sizeof(s->buf)] || s->next<s->buf){
		s->start = s->buf;
.
600a
#define SYSLOGMAGIC	0x23456789
#define SYSLOG		((Syslog *)(UNCACHED | KZERO | 0x1B00))
typedef struct Syslog	Syslog;
struct Syslog
{
	ulong	magic;
	char	*start;
	char	*next;
	char	buf[BY2PG - 3*BY2WD];
};

.
599c
 *  kernel based system log, passed between crashes
.
306c
	"log",		Qlog,		BY2PG-8,	0600,
.
## diffname port/devcons.c 1990/0928
## diff -e /n/bootesdump/1990/0912/sys/src/9/mips/devcons.c /n/bootesdump/1990/0928/sys/src/9/mips/devcons.c
624a
	print("start/next is %lux/%lux was %lux/%lux\n", s->start, s->next,
		start, next);
.
619,620c
	next = s->next;
	start = s->start;
	if(s->magic!=SYSLOGMAGIC || next>=&s->buf[sizeof(s->buf)]
	|| start>=&s->buf[sizeof(s->buf)] || next<s->buf){
.
616c
	char *start, *next;
.
601,611d
172a
	s = SYSLOG;
	print("start/next is %lux/%lux\n", s->start, s->next);
.
166a
	Syslog *s;
.
57a
	sysloginit();		/* must be at the end of printinit */
.
38a
#define SYSLOGMAGIC	0x23456789
#define SYSLOG		((Syslog *)(UNCACHED | KZERO | 0x1B00))
typedef struct Syslog	Syslog;
struct Syslog
{
	ulong	magic;
	char	*start;
	char	*next;
	char	buf[2*BY2PG - 3*BY2WD];
};


.
## diffname port/devcons.c 1990/1018
## diff -e /n/bootesdump/1990/0928/sys/src/9/mips/devcons.c /n/bootesdump/1990/1018/sys/src/9/mips/devcons.c
686,694c
	wbflush();
.
679,684c
	x = splhi();
	lock(&printq);
	for(p = s->buf; p < end; p++)
		*p = *p;
	unlock(&printq);
	splx(x);
.
677d
675c
	while(n > 0){
		if(start + n > end)
			m = end - start;
		else
			m = n;
		memcpy(p, start, m);
		start += m;
		p += m;
		n -= m;
		if(start >= end)
			start = s->buf;
	}

	return p-buf;
}

/*
 *  Read and write every byte of the log.  This seems to ensure that
 *  on reboot, the bytes will really be in memory.  I don't understand -- presotto
 */
void
flushsyslog(void)
{
	Syslog *s;
	char *p, *end;
	int x;

	s = SYSLOG;
.
673a
	if(off + n > m)
		n = m - off;
	start += off;
	if(start > end)
		start -= sizeof(s->buf);
.
671,672c
	if(s->wrapped){
		start = s->next;
		m = sizeof(s->buf);
	} else {
		start = s->buf;
		m = s->next - start;
	}

	if(off > m)
.
669a
	end = &s->buf[sizeof(s->buf)];
.
668a
	n = len;
	p = buf;

	sysloginit();
.
667c
	char *start;
	int n, m;
	char *p;
.
665d
662c
readlog(ulong off, char *buf, ulong len)
.
653,657d
650,651c
		}
.
645,648c
	while(n){
		if(s->next + n > end)
			m = end - s->next;
		else
			m = n;
		memcpy(s->next, p, m);
		s->next += m;
		p += m;
		n -= m;
		if(s->next >= end){
			s->wrapped = 1;
.
642a
	sysloginit();
.
641a
	int m;
.
639d
632,633d
624,628c
	if(s->magic!=SYSLOGMAGIC || s->next>=&s->buf[sizeof(s->buf)] || s->next<s->buf){
		s->wrapped = 0;
.
621c
	int i;
.
323a
/*	"panic",	Qpanic,		0,	0666, /**/
.
311a
/*	Qpanic, /**/
.
187,188d
180d
70d
47c
	char	buf[2*1024];
.
45c
	int	wrapped;
.
39,40c
#define SYSLOGMAGIC	0xdeadbeaf
#define SYSLOG		((Syslog *)(UNCACHED | 0x1B00))
.
## diffname port/devcons.c 1990/11161
## diff -e /n/bootesdump/1990/1018/sys/src/9/mips/devcons.c /n/bootesdump/1990/11161/sys/src/9/mips/devcons.c
581a

	case Qvmereset:
		if(strcmp(u->p->pgrp->user, "bootes") != 0)
			error(0, Eperm);
		vmereset();
		break;

.
326a
	"vmereset",	Qvmereset,	0,	0600,
.
313a
	Qvmereset,
.
## diffname port/devcons.c 1990/11211
## diff -e /n/bootesdump/1990/11161/sys/src/9/mips/devcons.c /n/bootesdump/1990/11211/sys/src/9/mips/devcons.c
606,618c
	error(Eperm);
.
600c
	error(Eperm);
.
592c
		error(Egreg);
.
587c
			error(Eperm);
.
580c
		error(Eperm);
.
567c
			error(Eperm);
.
538c
	switch(c->qid.path){
.
442c
	switch(c->qid.path & ~CHDIR){
.
421c
	error(Eperm);
.
413c
			error(Eperm);
.
408c
	if(c->qid.path==Quser && omode==(OWRITE|OTRUNC)){
.
318,328c
	"cons",		{Qcons},	0,	0600,
	"cputime",	{Qcputime},	72,	0600,
	"log",		{Qlog},		BY2PG-8,	0600,
	"null",		{Qnull},	0,	0600,
/*	"panic",	{Qpanic},	0,	0666, /**/
	"pgrpid",	{Qpgrpid},	12,	0600,
	"pid",		{Qpid},		12,	0600,
	"ppid",		{Qppid},	12,	0600,
	"time",		{Qtime},	12,	0600,
	"user",		{Quser},	0,	0600,
	"vmereset",	{Qvmereset},	0,	0600,
.
## diffname port/devcons.c 1990/1231
## diff -e /n/bootesdump/1990/11211/sys/src/9/mips/devcons.c /n/bootesdump/1990/1231/sys/src/9/mips/devcons.c
257a
	if(c == 0xe)
		nonettoggle();
	if(c == 0xc)
		lancetoggle();
.
## diffname port/devcons.c 1991/0318
## diff -e /n/bootesdump/1991/0201/sys/src/9/mips/devcons.c /n/bootesdump/1991/0318/sys/src/9/power/devcons.c
694c
		memmove(p, start, m);
.
645c
		memmove(s->next, p, m);
.
576c
		memmove(u->p->pgrp->user+c->offset, a, n);
.
564c
		memmove(cbuf, a, n);
.
552c
			memmove(buf, a, m);
.
504c
		memmove(buf, tmp+k, n);
.
371c
	memmove(buf, str+off, n);
.
357c
	memmove(buf, tmp+off, n);
.
85c
	memmove(printq.in, s, n);
.
## diffname port/devcons.c 1991/0327
## diff -e /n/bootesdump/1991/0318/sys/src/9/power/devcons.c /n/bootesdump/1991/0327/sys/src/9/power/devcons.c
274a
	if(c == 0)	/* NULs cause trouble */
		return;
.
251a
	if(c == 0x10)
		panic("^p");
.
## diffname port/devcons.c 1991/0403
## diff -e /n/bootesdump/1991/0327/sys/src/9/power/devcons.c /n/bootesdump/1991/0403/sys/src/9/power/devcons.c
252c
	if(c == 0x18)
.
## diffname port/devcons.c 1991/0411
## diff -e /n/bootesdump/1991/0403/sys/src/9/power/devcons.c /n/bootesdump/1991/0411/sys/src/9/power/devcons.c
578,581c
		if(offset+n >= NAMELEN-1)
			n = NAMELEN-1 - offset;
		memmove(u->p->pgrp->user+offset, a, n);
		u->p->pgrp->user[offset+n] = 0;
.
576c
		if(offset >= NAMELEN-1)
.
539c
conswrite(Chan *c, void *va, long n, ulong offset)
.
527c
		return readlog(offset, buf, n);
.
524c
		return readstr(offset, buf, n, u->p->pgrp->user);
.
521c
		return readnum(offset, buf, n, boottime+TK2SEC(MACHP(0)->ticks), 12);
.
518c
		return readnum(offset, buf, n, u->p->parentpid, NUMSIZE);
.
515c
		return readnum(offset, buf, n, u->p->pid, NUMSIZE);
.
512c
		return readnum(offset, buf, n, u->p->pgrp->pgrpid, NUMSIZE);
.
495c
		k = offset;
.
438c
consread(Chan *c, void *buf, long n, ulong offset)
.
207c
	qunlock(&c->wrl);
.
205c
	(*devtab[c->type].write)(c, buf, n, c->offset);
.
202c
		qunlock(&c->wrl);
.
200c
	qlock(&c->wrl);
.
## diffname port/devcons.c 1991/0419
## diff -e /n/bootesdump/1991/0411/sys/src/9/power/devcons.c /n/bootesdump/1991/0419/sys/src/9/power/devcons.c
406a
Chan*
consclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

.
## diffname port/devcons.c 1991/0421
## diff -e /n/bootesdump/1991/0419/sys/src/9/power/devcons.c /n/bootesdump/1991/0421/sys/src/9/power/devcons.c
252c
	if(c == 0x10)
.
## diffname port/devcons.c 1991/0425
## diff -e /n/bootesdump/1991/0421/sys/src/9/power/devcons.c /n/bootesdump/1991/0425/sys/src/9/power/devcons.c
604a
		break;
.
603a
	case Qsysstat:
		for(id = 0; id < 32; id++) {
			if(active.machs & (1<<id)) {
				mp = MACHP(id);
				mp->cs = 0;
				mp->intr = 0;
				mp->syscall = 0;
				mp->pfault = 0;
				mp->tlbfault = 0;
				mp->tlbpurge = 0;
				mp->spinlock = 0;
			}
		}
.
550a
	Mach *mp;
.
549a
	int id;
.
534a
	case Qsysstat:
		j = 0;
		for(id = 0; id < 32; id++) {
			if(active.machs & (1<<id)) {
				mp = MACHP(id);
				j += sprint(&xbuf[j], "%d %d %d %d %d %d %d %d\n",
					id, mp->cs, mp->intr, mp->syscall, mp->pfault,
					    mp->tlbfault, mp->tlbpurge, mp->spinlock);
			}
		}

		return readstr(offset, buf, n, xbuf);
.
452c
	char tmp[6*NUMSIZE], xbuf[512];
	Mach *mp;
.
446c
	int ch, i, j, k, id;
.
336a
	"sysstat",	{Qsysstat},	0,	0600,
.
322a
	Qsysstat,
.
## diffname port/devcons.c 1991/0427
## diff -e /n/bootesdump/1991/0425/sys/src/9/power/devcons.c /n/bootesdump/1991/0427/sys/src/9/power/devcons.c
409,414d
## diffname port/devcons.c 1991/0607
## diff -e /n/bootesdump/1991/0427/sys/src/9/power/devcons.c /n/bootesdump/1991/0607/sys/src/9/power/devcons.c
646,761d
629a

.
628d
614a

	case Qlights:
		conslights(a, n);
		break;

.
610,613c
	case Qnoise:
		consnoise(a, n);
.
563a
	case Qrcons:
.
561a
	int id;
.
559d
552a
void
conslights(char *a, int n)
{
	int l;
	char line[128];
	char *lp;
	int c;

	lp = line;
	while(n--){
		*lp++ = c = *a++;
		if(c=='\n' || n==0 || lp==&line[sizeof(line)-1])
			break;
	}
	*lp = 0;
	lights(strtoul(line, 0, 0));
}

void
consnoise(char *a, int n)
{
	int freq;
	int duration;
	char line[128];
	char *lp;
	int c;

	lp = line;
	while(n--){
		*lp++ = c = *a++;
		if(c=='\n' || n==0 || lp==&line[sizeof(line)-1]){
			*lp = 0;
			freq = strtoul(line, &lp, 0);
			while(*lp==' ' || *lp=='\t')
				lp++;
			duration = strtoul(lp, &lp, 0);
			buzz(freq, duration);
			lp = line;
		}
	}
}

.
544,545d
542d
539c
					    mp->tlbfault, mp->tlbpurge, m->spinlock);
.
531a
	case Qklog:
		qlock(&klogq);
		if(waserror()){
			qunlock(&klogq);
			nexterror();
		}
		while(!cangetc(&klogq))
			sleep(&klogq.r, cangetc, &klogq);
		for(i=0; i<n; i++){
			if((ch=getc(&klogq)) == -1)
				break;
			*cbuf++ = ch;
		}
		poperror();
		qunlock(&klogq);
		return i;

	case Qmsec:
		return readnum(offset, buf, n, TK2MS(MACHP(0)->ticks), NUMSIZE);

.
529,530c
	case Qnull:
		return 0;
.
525a
	case Qclock:
		k = offset;
		if(k >= 2*NUMSIZE)
			return 0;
		if(k+n > 2*NUMSIZE)
			n = 2*NUMSIZE - k;
		readnum(0, tmp, NUMSIZE, MACHP(0)->ticks, NUMSIZE);
		readnum(0, tmp+NUMSIZE, NUMSIZE, HZ, NUMSIZE);
		memmove(buf, tmp+k, n);
		return n;

.
488c
			if(ch==-1 || (raw.ref==0 && ch==0x04))
.
486c
		while(n > 0){
.
483c
				unlock(&lineq);
			}while(raw.ref==0 && ch!='\n' && ch!=0x04);
.
479,481c
					*lineq.in = ch;
					if(lineq.in >= lineq.buf+sizeof(lineq.buf)-1)
						lineq.in = lineq.buf;
					else
						lineq.in++;
.
477a
				Default:
.
466a
				if(raw.ref){
					unlock(&lineq);
					goto Default;
				}
.
465a
				lock(&lineq);
.
464c
			sleep(&kbdq.r, isbrkc, &kbdq);
.
456a
	case Qrcons:
.
448c
	char tmp[6*NUMSIZE], xbuf[1024];
.
438a

.
436a
	if(c->qid.path==Qrcons && (c->flag&COPEN))
		decref(&raw);
.
418,423c
	int ch;

	switch(c->qid.path){
	case Quser:
		if(omode==(OWRITE|OTRUNC)){
			/* truncate? */
			if(strcmp(u->p->pgrp->user, "bootes") == 0)	/* BUG */
				u->p->pgrp->user[0] = 0;
			else
				error(Eperm);
		}
		break;
	case Qrcons:
		if(incref(&raw) == 1){
			lock(&lineq);
			while((ch=getc(&kbdq)) != -1){
				*lineq.in++ = ch;
				if(lineq.in == lineq.buf+sizeof(lineq.buf))
					lineq.in = lineq.buf;
			}
			unlock(&lineq);
		}
		break;
.
327,338c
	"cons",		{Qcons},	0,		0600,
	"cputime",	{Qcputime},	6*NUMSIZE,	0600,
	"lights",	{Qlights},	0,		0600,
	"noise",	{Qnoise},	0,		0600,
	"null",		{Qnull},	0,		0600,
	"pgrpid",	{Qpgrpid},	NUMSIZE,	0600,
	"pid",		{Qpid},		NUMSIZE,	0600,
	"ppid",		{Qppid},	NUMSIZE,	0600,
	"rcons",	{Qrcons},	0,		0600,
	"time",		{Qtime},	NUMSIZE,	0600,
	"user",		{Quser},	0,		0600,
	"klog",		{Qklog},	0,		0400,
	"msec",		{Qmsec},	NUMSIZE,	0400,
	"clock",	{Qclock},	2*NUMSIZE,	0400,
	"sysstat",	{Qsysstat},	0,		0600,
.
322c
	Qklog,
	Qmsec,
	Qclock,
.
319a
	Qrcons,
.
316d
314c
	Qlights,
	Qnoise,
.
298a
	if(++kbdq.count&1)
		kbdputc(&kbdq, kbdq.c);
.
294,297c
void
kbdclock(void)
{
	if(kbdq.repeat == 0)
		return;
	if(kbdq.repeat==1 && ++kbdq.count>HZ){
		kbdq.repeat = 2;
		kbdq.count = 0;
		return;
.
292c
	kbdq.repeat = rep;
	kbdq.count = 0;
}
.
290c
kbdrepeat(int rep)
.
286a
	return 0;
.
285c
	if(raw.ref || ch=='\n' || ch==0x04)
.
277,282c
	echo(ch);
	kbdq.c = ch;
	*kbdq.in++ = ch;
.
274,275c
int
kbdputc(IOQ *q, int ch)
.
258,263d
254,255c
	/*
	 * ^t hack BUG
	 */
	if(ctrlt == 2){
		ctrlt = 0;
		switch(c){
		case 0x14:
			break;	/* pass it on */
		case 'm':
			mntdump();
			return;
		case 'p':
			DEBUG();
			return;
		case 'q':
			dumpqueues();
			return;
		case 'r':
			exit();
			break;
		}
	}else if(c == 0x14){
		ctrlt++;
		return;
	}
	ctrlt = 0;
	if(raw.ref)
		return;
.
250c
	 * ^p hack
.
247a
	static int ctrlt;
.
219,243d
215,216c
	while(printq.in != printq.out) ;
.
173a
int
kprint(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	klogputs(buf, n);
	return n;
}

.
145,157d
134a
		if(raw.ref)
			return 1;
.
130c
isbrkc(KIOQ *q)
.
126c
	int s, m;
	uchar *nextin;

	s = splhi();
	lock(&klogq);
	while(n){
		m = &klogq.buf[NQ] - klogq.in;
		if(m > n)
			m = n;
		memmove(klogq.in, str, m);
		n -= m;
		str += m;
		nextin = klogq.in + m;
		if(nextin >= &klogq.buf[NQ])
			klogq.in = klogq.buf;
		else
			klogq.in = nextin;
	}
	unlock(&klogq);
	splx(s);
	wakeup(&klogq.r);
.
123,124c
/*
 *   Print a string in the kernel log.  Ignore overflow.
 */
void
klogputs(char *str, long n)
.
119,120d
115c
		if(printq.puts)
			(*printq.puts)(&printq, str, m);
		screenputs(str, m);
.
106,110c
		if(printq.puts && *str=='\n')
			(*printq.puts)(&printq, "\r", 1);
		m = n;
.
102,104d
92,94c
 *   Print a string on the console.  Convert \n to \r\n
.
80,88c
	initq(&printq);
	initq(&lineq);
	initq(&kbdq);
	kbdq.putc = kbdputc;
	initq(&klogq);
	initq(&mouseq);
	mouseq.putc = mouseputc;
.
78c
printinit(void)
.
73,75c
 *  init the queues and set the output routine
.
36,71d
23,34c
Ref	raw;		/* whether kbd i/o is raw (rcons is open) */
.
21c
IOQ	lineq;			/* lock to getc; interrupt putc's */
IOQ	printq;
IOQ	mouseq;
KIOQ	kbdq;
.
11,19c
struct {
	IOQ;			/* lock to klogputs */
	QLock;			/* qlock to getc */
}	klogq;
.
## diffname port/devcons.c 1991/0608
## diff -e /n/bootesdump/1991/0608/sys/src/9/power/devcons.c /n/bootesdump/1991/0608/sys/src/9/port/devcons.c
204c
			procdump();
.
191a

.
190c
	if(c==0x10 && conf.cntrlp)
.
148c
	if(conf.cntrlp)
		exit();
	else
		for(;;);
.
29a
	printq.puts = 0;
.
## diffname port/devcons.c 1991/0614
## diff -e /n/bootesdump/1991/0608/sys/src/9/port/devcons.c /n/bootesdump/1991/0614/sys/src/9/port/devcons.c
499a
		poperror();
.
## diffname port/devcons.c 1991/0620
## diff -e /n/bootesdump/1991/0614/sys/src/9/port/devcons.c /n/bootesdump/1991/0620/sys/src/9/port/devcons.c
406a
		if(conf.cntrlp)
			error(Eperm);
.
## diffname port/devcons.c 1991/0705
## diff -e /n/bootesdump/1991/0620/sys/src/9/port/devcons.c /n/bootesdump/1991/0705/sys/src/9/port/devcons.c
711a

	case Qswap:
		if(n >= sizeof buf)
			error(Egreg);
		memmove(buf, va, n);	/* so we can NUL-terminate */
		buf[n] = 0;
		fd = strtoul(buf, 0, 0);
		swc = fdtochan(fd, -1);
		setswapchan(swc);
		return n;
.
640c
	int id, fd;
	Chan *swc;
.
583a
	case Qswap:
		sprint(xbuf, "%d/%d memory %d/%d swap\n",
				palloc.user-palloc.freecount, palloc.user, 
				conf.nswap-swapalloc.free, conf.nswap);

		return readstr(offset, buf, n, xbuf);
.
314a
	"swap",		{Qswap},	0,		0666,
.
296a
	Qswap,
.
162c
	c = u->p->fgrp->fd[2];
.
## diffname port/devcons.c 1991/0717
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/devcons.c /n/bootesdump/1991/0717/sys/src/9/port/devcons.c
729a
		kickpager();
.
## diffname port/devcons.c 1991/0720
## diff -e /n/bootesdump/1991/0717/sys/src/9/port/devcons.c /n/bootesdump/1991/0720/sys/src/9/port/devcons.c
730d
420a
	case Qswap:
		kickpager();		/* start a pager if not already started */
		break;
.
161a
	if(u->p->fgrp == 0)
		return 0;

.
## diffname port/devcons.c 1991/0723
## diff -e /n/bootesdump/1991/0720/sys/src/9/port/devcons.c /n/bootesdump/1991/0723/sys/src/9/port/devcons.c
143a
	print("panic: %lux m=%lux\n", &fmt, m);
.
14c
}klogq;
.
## diffname port/devcons.c 1991/0727
## diff -e /n/bootesdump/1991/0723/sys/src/9/port/devcons.c /n/bootesdump/1991/0727/sys/src/9/port/devcons.c
237a
 * turn '\r' into '\n' before putting it into the queue
 */
int
kbdcr2nl(IOQ *q, int ch)
{
	if(ch == '\r')
		ch = '\n';
	return kbdputc(q, ch);
}

/*
.
## diffname port/devcons.c 1991/0807
## diff -e /n/bootesdump/1991/0727/sys/src/9/port/devcons.c /n/bootesdump/1991/0807/sys/src/9/port/devcons.c
144d
## diffname port/devcons.c 1991/0808
## diff -e /n/bootesdump/1991/0807/sys/src/9/port/devcons.c /n/bootesdump/1991/0808/sys/src/9/port/devcons.c
61a
unlock(&fuck);
splx(s);
.
47a
loop:
s = splhi();
if(!canlock(&fuck)){
	splx(s);
	goto loop;
}
.
46a
static Lock fuck;
.
## diffname port/devcons.c 1991/0809
## diff -e /n/bootesdump/1991/0808/sys/src/9/port/devcons.c /n/bootesdump/1991/0809/sys/src/9/port/devcons.c
69,70d
56,67c
		t = memchr(str, '\n', n);
		if(t){
			m = t - str;
			memmove(buf, str, m);
			buf[m] = '\r';
			buf[m+1] = '\n';
			(*printq.puts)(&printq, buf, m+2);
			str = t + 1;
			n -= m + 1;
		} else {
			(*printq.puts)(&printq, str, n);
			break;
		}
.
49,54c
	/*
	 *  if there's an attached bit mapped display,
	 *  put the message there.  screenputs is defined
	 *  as a null macro for systems that have no such
	 *  display.
	 */
	screenputs(str, n);

	/*
	 *  if there's a serial line being used as a console,
	 *  put the message there.  Tack a carriage return
	 *  before new lines.
	 */
	if(printq.puts == 0)
		return;
.
47d
45c
	char buf[PRINTSIZE+2];
	int m;
.
40c
 *   Print a string on the console.  Convert \n to \r\n for serial
 *   line consoles.  Locking of the queues is left up to the screen
 *   or uart code.  Multi-line messages to serial consoles may get
 *   interspersed with other messages.
.
## diffname port/devcons.c 1991/0911
## diff -e /n/bootesdump/1991/0809/sys/src/9/port/devcons.c /n/bootesdump/1991/0911/sys/src/9/port/devcons.c
164c
	strcpy(buf, "inconceivable: ");
.
## diffname port/devcons.c 1991/0913
## diff -e /n/bootesdump/1991/0911/sys/src/9/port/devcons.c /n/bootesdump/1991/0913/sys/src/9/port/devcons.c
628a
	case Qlights:
		errors("write only");
.
## diffname port/devcons.c 1991/0920
## diff -e /n/bootesdump/1991/0913/sys/src/9/port/devcons.c /n/bootesdump/1991/0920/sys/src/9/port/devcons.c
165c
	n = doprint(buf+strlen(buf), buf+sizeof(buf), fmt, (&fmt+1)) - buf;
.
## diffname port/devcons.c 1991/1011
## diff -e /n/bootesdump/1991/0920/sys/src/9/port/devcons.c /n/bootesdump/1991/1011/sys/src/9/port/devcons.c
767c
		swc = fdtochan(fd, -1, 1);
.
164c
	strcpy(buf, "panic: ");
.
## diffname port/devcons.c 1991/1022
## diff -e /n/bootesdump/1991/1011/sys/src/9/port/devcons.c /n/bootesdump/1991/1022/sys/src/9/port/devcons.c
227a
		case 'e':
			envdump();
			return;
.
## diffname port/devcons.c 1991/1102
## diff -e /n/bootesdump/1991/1022/sys/src/9/port/devcons.c /n/bootesdump/1991/1102/sys/src/9/port/devcons.c
790a

void
setterm(char *f)
{
	char buf[2*NAMELEN];

	sprint(buf, f, conffile);
	ksetenv("terminal", buf);
}
.
## diffname port/devcons.c 1991/1105
## diff -e /n/bootesdump/1991/1102/sys/src/9/port/devcons.c /n/bootesdump/1991/1105/sys/src/9/port/devcons.c
728,729c
		memmove(u->p->user+offset, a, n);
		u->p->user[offset+n] = 0;
.
722c
		if(u->p->user[0])		/* trying to overwrite /dev/user */
.
589c
		return readstr(offset, buf, n, u->p->user);
.
439,440c
			if(strcmp(u->p->user, "bootes") == 0)	/* BUG */
				u->p->user[0] = 0;
.
## diffname port/devcons.c 1991/1108
## diff -e /n/bootesdump/1991/1105/sys/src/9/port/devcons.c /n/bootesdump/1991/1108/sys/src/9/port/devcons.c
228,230d
## diffname port/devcons.c 1991/1109
## diff -e /n/bootesdump/1991/1108/sys/src/9/port/devcons.c /n/bootesdump/1991/1109/sys/src/9/port/devcons.c
435,436c
			if(strcmp(u->p->user, eve) == 0)
.
22a
char	eve[NAMELEN] = "bootes";

.
21c
Ref	raw;			/* whether kbd i/o is raw (rcons is open) */
.
## diffname port/devcons.c 1991/1112
## diff -e /n/bootesdump/1991/1109/sys/src/9/port/devcons.c /n/bootesdump/1991/1112/sys/src/9/port/devcons.c
757d
720,721d
619c
					    mp->tlbfault, mp->tlbpurge, mp->load);
.
435,442d
337,351c
	"cons",		{Qcons},	0,		0666,
	"cputime",	{Qcputime},	6*NUMSIZE,	0666,
	"lights",	{Qlights},	0,		0666,
	"noise",	{Qnoise},	0,		0666,
	"null",		{Qnull},	0,		0666,
	"pgrpid",	{Qpgrpid},	NUMSIZE,	0666,
	"pid",		{Qpid},		NUMSIZE,	0666,
	"ppid",		{Qppid},	NUMSIZE,	0666,
	"rcons",	{Qrcons},	0,		0666,
	"time",		{Qtime},	NUMSIZE,	0666,
	"user",		{Quser},	0,		0644,
	"klog",		{Qklog},	0,		0444,
	"msec",		{Qmsec},	NUMSIZE,	0444,
	"clock",	{Qclock},	2*NUMSIZE,	0444,
	"sysstat",	{Qsysstat},	0,		0444,
.
## diffname port/devcons.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/port/devcons.c /n/bootesdump/1991/1113/sys/src/9/port/devcons.c
623a
	case Qnoise:
		return 0;
.
605a
		xbuf[0] = 0;
.
478c
	char tmp[6*NUMSIZE], xbuf[512];
.
## diffname port/devcons.c 1991/1115
## diff -e /n/bootesdump/1991/1113/sys/src/9/port/devcons.c /n/bootesdump/1991/1115/sys/src/9/port/devcons.c
778a
	USED(c);
.
772a
	USED(c);
.
457a
	USED(c, name, omode, perm);
.
275a
	USED(q);
.
## diffname port/devcons.c 1991/1116
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/devcons.c /n/bootesdump/1991/1116/sys/src/9/port/devcons.c
696,702c
			bp = l;
			if(bp > sizeof buf)
				bp = sizeof buf;
			memmove(buf, a, bp);
			putstrn(a, bp);
			a += bp;
			l -= bp;
.
682c
	long l, bp;
.
## diffname port/devcons.c 1991/1127
## diff -e /n/bootesdump/1991/1116/sys/src/9/port/devcons.c /n/bootesdump/1991/1127/sys/src/9/port/devcons.c
783a
}

/*
 * Rand is huge and not worth it here.  Be small.  Borrowed from the white book.
 */
ulong	randn;
void
srand(char *s)
{
	randn = MACHP(0)->ticks * boottime;
	while(s && *s)
		randn = (randn << 1) ^ *s++;
}

int
nrand(int n)
{
	randn = randn*1103515245 + 12345;
	return (randn>>16) % n;
.
782c
	USED(c, dp);
.
766a
		print("conswrite: %d\n", c->qid.path);
.
725,729c
	case Qchal:
		if(offset != 0)
			error(Ebadarg);
		if(n != 8+NAMELEN+KEYLEN)
			error(Ebadarg);
		decrypt(evekey, a, n);
		if(memcmp(u->p->pgrp->crypt->chal, a, 8) != 0)
			errors("authentication failure");
		strncpy(u->p->user, a+8, NAMELEN);
		u->p->user[NAMELEN-1] = '\0';
		memmove(u->p->pgrp->crypt->key, a+NAMELEN+KEYLEN, KEYLEN);
		break;
.
717,722c
		if(offset != 0 || n >= NAMELEN-1)
			error(Ebadarg);
		if(n==strlen("none") && strncmp(a, "none", n)==0
		|| n==strlen(u->p->user) && strncmp(a, u->p->user, n)==0
		|| strcmp(u->p->user, eve)==0){
			memmove(u->p->user, a, n);
			u->p->user[n] = '\0';
		}else
			error(Eperm);
		if(!conf.cntrlp && strcmp(u->p->user, "none") != 0)
			memmove(eve, u->p->user, NAMELEN);
.
715a
	case Qcrypt:
		cb = c->aux;
		if(!cb){
			cb = c->aux = allocb(128);
			cb->type = 'E';
		}
		if(n < 8){
			if(n != 1 || a[0] != 'E' && a[0] != 'D')
				error(Ebadarg);
			cb->type = a[0];
			return 1;
		}
		if(n > cb->lim - cb->base)
			n = cb->lim - cb->base;
		memmove(cb->base, a, n);
		cb->wptr = cb->base + n;
		if(cb->type == 'E')
			encrypt(u->p->pgrp->crypt->key, cb->base, n);
		else
			decrypt(u->p->pgrp->crypt->key, cb->base, n);
		break;

	case Qkey:
		if(n != KEYLEN)
			error(Ebadarg);
		memmove(u->p->pgrp->crypt->key, a, KEYLEN);
		if(strcmp(u->p->user, eve) == 0)
			memmove(evekey, a, KEYLEN);
		break;

.
683a
	Block *cb;
.
630,631c
		print("consread %lux\n", c->qid);
		error(Egreg);
.
625,628d
579a
	case Qcrypt:
		cb = c->aux;
		if(!cb)
			return 0;
		if(n > cb->wptr - cb->base)
			n = cb->wptr - cb->base;
		memmove(buf, cb->base, n);
		return n;

	case Qchal:
		if(offset != 0 || n != 8)
			error(Ebadarg);
		chal = u->p->pgrp->crypt->chal;
		chal[0] = 0;
		for(i=1; i<8; i++)
			chal[i] = nrand(256);
		memmove(buf, chal, 8);
		encrypt(evekey, buf, 8);
		chal[0] = 1;
		return n;

.
479a
	Block *cb;
.
478c
	char *user, *chal;
.
470d
467a
	if(c->qid.path == Qcrypt && c->aux)
		freeb(c->aux);
	c->aux = 0;
.
452a
	c->aux = 0;
.
350,352c
	"sysstat",	{Qsysstat},	0,		0666,
.
347,348c
	"user",		{Quser},	0,		0666,
	"chal",		{Qchal},	8,		0666,
	"crypt",	{Qcrypt},	0,		0666,
	"key",		{Qkey},		KEYLEN,		0222,
.
343,345c
	"pgrpid",	{Qpgrpid},	NUMSIZE,	0444,
	"pid",		{Qpid},		NUMSIZE,	0444,
	"ppid",		{Qppid},	NUMSIZE,	0444,
.
339,341c
	"cputime",	{Qcputime},	6*NUMSIZE,	0444,
	"time",		{Qtime},	NUMSIZE,	0666,
	"clock",	{Qclock},	2*NUMSIZE,	0444,
	"msec",		{Qmsec},	NUMSIZE,	0444,
	"lights",	{Qlights},	0,		0222,
	"noise",	{Qnoise},	0,		0222,
.
334a
	Qcrypt,
	Qkey,
	Qchal,
.
23a
char	evekey[KEYLEN];
.
## diffname port/devcons.c 1991/1206
## diff -e /n/bootesdump/1991/1127/sys/src/9/port/devcons.c /n/bootesdump/1991/1206/sys/src/9/port/devcons.c
859c
 *  Rand is huge and not worth it here.  Be small.
 *  Borrowed from the white book.
.
736c
		if(n<=0 || boottime!=0)	/* write once file */
.
721c
		 * Can't page fault in putstrn, so copy the data locally.
.
315,317d
271,272c
 *  Put character into read queue at interrupt time.
 *  Always called splhi from processor 0.
.
260c
 *  turn '\r' into '\n' before putting it into the queue
.
## diffname port/devcons.c 1991/1207
## diff -e /n/bootesdump/1991/1206/sys/src/9/port/devcons.c /n/bootesdump/1991/1207/sys/src/9/port/devcons.c
796c
		memmove(u->p->pgrp->crypt->key, a+NAMELEN+DESKEYLEN, DESKEYLEN);
.
789c
		if(n != 8+NAMELEN+DESKEYLEN)
.
769c
			memmove(evekey, a, DESKEYLEN);
.
767c
		memmove(u->p->pgrp->crypt->key, a, DESKEYLEN);
.
765c
		if(n != DESKEYLEN)
.
354c
	"key",		{Qkey},		DESKEYLEN,	0222,
.
24c
char	evekey[DESKEYLEN];
.
## diffname port/devcons.c 1991/1211
## diff -e /n/bootesdump/1991/1207/sys/src/9/port/devcons.c /n/bootesdump/1991/1211/sys/src/9/port/devcons.c
441c
		if(strcmp(u->p->user, eve) != 0)
.
357c
	"swap",		{Qswap},	0,		0664,
.
350c
	"rcons",	{Qrcons},	0,		0660,
.
344,345c
	"lights",	{Qlights},	0,		0220,
	"noise",	{Qnoise},	0,		0220,
.
341c
	"time",		{Qtime},	NUMSIZE,	0664,
.
339c
	"cons",		{Qcons},	0,		0660,
.
## diffname port/devcons.c 1991/1220
## diff -e /n/bootesdump/1991/1211/sys/src/9/port/devcons.c /n/bootesdump/1991/1220/sys/src/9/port/devcons.c
782c
		if(!conf.cntrlp && strcmp(eve, "bootes") == 0)
.
## diffname port/devcons.c 1991/1223
## diff -e /n/bootesdump/1991/1220/sys/src/9/port/devcons.c /n/bootesdump/1991/1223/sys/src/9/port/devcons.c
278,283c
	r = ch;
	n = runetochar(buf, &r);
	if(n == 0)
		return 0;
	echo(r, buf, n);
	kbdq.c = r;
	for(i=0; i<n; i++){
		*kbdq.in++ = buf[i];
		if(kbdq.in == kbdq.buf+sizeof(kbdq.buf))
			kbdq.in = kbdq.buf;
	}
	if(raw.ref || r=='\n' || r==0x04)
.
276a
	int i, n;
	char buf[3];
	Rune r;

.
271c
 *  Put character, possibly a rune, into read queue at interrupt time.
.
253,256c
	else
		putstrn(buf, n);
.
251c
	if(r == 0x15)
.
244c
	}else if(r == 0x14){
.
228c
		switch(r){
.
220c
	if(r==0x10 && conf.cntrlp)
.
214d
212c
echo(Rune r, char *buf, int n)
.
## diffname port/devcons.c 1991/1224
## diff -e /n/bootesdump/1991/1223/sys/src/9/port/devcons.c /n/bootesdump/1991/1224/sys/src/9/port/devcons.c
735a
		}
		break;

	case Qconsctl:
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, a, n);
		buf[n] = 0;
		for(a = buf; a;){
			if(strncmp(a, "rawon", 5) == 0){
				lock(&lineq);
				while((ch=getc(&kbdq)) != -1){
					*lineq.in++ = ch;
					if(lineq.in == lineq.buf+sizeof(lineq.buf))
						lineq.in = lineq.buf;
				}
				unlock(&lineq);
				lock(&ctl);
				raw = 1;
				unlock(&ctl);
			} else if(strncmp(a, "rawoff", 6) == 0){
				lock(&ctl);
				raw = 0;
				unlock(&ctl);
			}
			if(a = strchr(a, ' '))
				a++;
.
722d
718c
	int id, fd, ch;
.
545c
			if(ch==-1 || (raw==0 && ch==0x04))
.
540c
			}while(raw==0 && ch!='\n' && ch!=0x04);
.
516c
				if(raw){
.
504d
478,479c
	/* last close of control file turns off raw */
	if(c->qid.path==Qconsctl && (c->flag&COPEN)){
		lock(&ctl);
		if(--ctl.ref == 0)
			raw = 0;
		unlock(&ctl);
	}
.
450,458c
		incref(&ctl);
.
447c
	case Qconsctl:
.
444,445d
357d
346a
	"consctl",	{Qconsctl},	0,		0220,
.
332d
324a
	Qconsctl,
.
290c
	if(raw || r=='\n' || r==0x04)
.
248c
	if(raw)
.
122c
		if(raw)
.
21c
static Ref	ctl;			/* number of opens to the control file */
static int	raw;			/* true if raw has been requested on a ctl file */
.
## diffname port/devcons.c 1992/0111
## diff -e /n/bootesdump/1991/1224/sys/src/9/port/devcons.c /n/bootesdump/1992/0111/sys/src/9/port/devcons.c
821c
			error(Eauth);
.
7c
#include	"../port/error.h"
.
## diffname port/devcons.c 1992/0114
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/devcons.c /n/bootesdump/1992/0114/sys/src/9/port/devcons.c
821c
			error(Eperm);
.
## diffname port/devcons.c 1992/0129
## diff -e /n/bootesdump/1992/0114/sys/src/9/port/devcons.c /n/bootesdump/1992/0129/sys/src/9/port/devcons.c
824c
		memmove(u->p->pgrp->crypt->key, a+8+NAMELEN, DESKEYLEN);
.
## diffname port/devcons.c 1992/0213
## diff -e /n/bootesdump/1992/0129/sys/src/9/port/devcons.c /n/bootesdump/1992/0213/sys/src/9/port/devcons.c
852a
		if(conf.cntrlp && strcmp(u->p->user, eve) != 0)
			error(Eperm);
.
## diffname port/devcons.c 1992/0226
## diff -e /n/bootesdump/1992/0213/sys/src/9/port/devcons.c /n/bootesdump/1992/0226/sys/src/9/port/devcons.c
852a
		kickpager();		/* start a pager if not already started */
.
451,453d
## diffname port/devcons.c 1992/0228
## diff -e /n/bootesdump/1992/0226/sys/src/9/port/devcons.c /n/bootesdump/1992/0228/sys/src/9/port/devcons.c
856a
		if(buf[0]<'0' && '9'<buf[0])
			error(Ebadarg);
.
## diffname port/devcons.c 1992/0310
## diff -e /n/bootesdump/1992/0228/sys/src/9/port/devcons.c /n/bootesdump/1992/0310/sys/src/9/port/devcons.c
862c
		break;
.
857c
		if(strncmp(buf, "start", 5) == 0){
			kickpager();		/* start a pager if not already started */
			break;
		}
		if(conf.cntrlp && strcmp(u->p->user, eve) != 0)
			error(Eperm);
		if(buf[0]<'0' || '9'<buf[0])
.
850,852d
## diffname port/devcons.c 1992/0312
## diff -e /n/bootesdump/1992/0310/sys/src/9/port/devcons.c /n/bootesdump/1992/0312/sys/src/9/port/devcons.c
904c
	static ulong randn;

	randn = randn*1103515245 + 12345 + MACHP(0)->ticks;
.
892,900d
## diffname port/devcons.c 1992/0317
## diff -e /n/bootesdump/1992/0312/sys/src/9/port/devcons.c /n/bootesdump/1992/0317/sys/src/9/port/devcons.c
382c
	Op op = { tmp, tmp+sizeof(tmp), &val, size-1, 0, FUNSIGN|FLONG };
.
## diffname port/devcons.c 1992/0318
## diff -e /n/bootesdump/1992/0317/sys/src/9/port/devcons.c /n/bootesdump/1992/0318/sys/src/9/port/devcons.c
605c
		chal[0] = RXstick;
.
600c
		chal[0] = RXschal;
.
382c
	Op op = (Op){ tmp, tmp+sizeof(tmp), &val, size-1, 0, FUNSIGN|FLONG };
.
## diffname port/devcons.c 1992/0319
## diff -e /n/bootesdump/1992/0318/sys/src/9/port/devcons.c /n/bootesdump/1992/0319/sys/src/9/port/devcons.c
242a
		case 't':
			tcpdump();
			break;
.
## diffname port/devcons.c 1992/0320
## diff -e /n/bootesdump/1992/0319/sys/src/9/port/devcons.c /n/bootesdump/1992/0320/sys/src/9/port/devcons.c
243,245d
## diffname port/devcons.c 1992/0321
## diff -e /n/bootesdump/1992/0320/sys/src/9/port/devcons.c /n/bootesdump/1992/0321/sys/src/9/port/devcons.c
864a
		break;

	case Qsysname:
		if(offset != 0)
			error(Ebadarg);
		if(n <= 0 || n >= NAMELEN)
			error(Ebadarg);
		strncpy(sysname, a, n);
		sysname[n] = 0;
		if(sysname[n-1] == '\n')
			sysname[n-1] = 0;
.
652a

	case Qsysname:
		return readstr(offset, buf, n, sysname);

.
364a
	"sysname",	{Qsysname},	0,		0664,
.
343a
	Qsysname,
.
25a
char	sysname[NAMELEN];
.
2c
#include	"../port/lib.h"
.
## diffname port/devcons.c 1992/0323
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/devcons.c /n/bootesdump/1992/0323/sys/src/9/port/devcons.c
608a
		return n;

	case Qkey:
		if(offset!=0 || n!=DESKEYLEN)
			error(Ebadarg);
		if(strcmp(u->p->user, eve)!=0 || conf.cntrlp==0)
			error(Eperm);
		memmove(buf, evekey, DESKEYLEN);
.
600c
		if(offset!=0 || n!=8)
.
364c
	"key",		{Qkey},		DESKEYLEN,	0622,
.
## diffname port/devcons.c 1992/0409
## diff -e /n/bootesdump/1992/0323/sys/src/9/port/devcons.c /n/bootesdump/1992/0409/sys/src/9/port/devcons.c
18d
15a
IOQ	mouseq;
.
## diffname port/devcons.c 1992/0411
## diff -e /n/bootesdump/1992/0409/sys/src/9/port/devcons.c /n/bootesdump/1992/0411/sys/src/9/port/devcons.c
231a
		case 'd':
			consdebug();
			return;
.
## diffname port/devcons.c 1992/0428
## diff -e /n/bootesdump/1992/0411/sys/src/9/port/devcons.c /n/bootesdump/1992/0428/sys/src/9/port/devcons.c
571a

	case Qnoteid:
		return readnum(offset, buf, n, u->p->noteid, NUMSIZE);
.
371a
	"sysname",	{Qsysname},	0,		0664,
	"sysstat",	{Qsysstat},	0,		0666,
	"time",		{Qtime},	NUMSIZE,	0664,
	"user",		{Quser},	0,		0666,
.
364,370d
359a
	"noteid",	{Qnoteid},	NUMSIZE,	0444,
.
358a
	"msec",		{Qmsec},	NUMSIZE,	0444,
.
355,357c
	"crypt",	{Qcrypt},	0,		0666,
	"key",		{Qkey},		DESKEYLEN,	0622,
	"klog",		{Qklog},	0,		0444,
.
351a
	"chal",		{Qchal},	8,		0666,
	"clock",	{Qclock},	2*NUMSIZE,	0444,
.
348a
	Qsysstat,
	Qtime,
	Quser,
.
345,347d
338,343d
333a
	Qnoteid,
.
332a
	Qmsec,
.
331a
	Qcrypt,
	Qdir,
	Qkey,
	Qklog,
.
328c
	Qchal,
	Qclock,
.
## diffname port/devcons.c 1992/0506
## diff -e /n/bootesdump/1992/0428/sys/src/9/port/devcons.c /n/bootesdump/1992/0506/sys/src/9/port/devcons.c
334d
327a
	Qdir,
.
## diffname port/devcons.c 1992/0520
## diff -e /n/bootesdump/1992/0506/sys/src/9/port/devcons.c /n/bootesdump/1992/0520/sys/src/9/port/devcons.c
679a
	return -1;		/* never reached */
.
## diffname port/devcons.c 1992/0522
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/devcons.c /n/bootesdump/1992/0522/sys/src/9/port/devcons.c
788c
		boottime = strtoul(a, 0, 0)-TK2SEC(MACHP(0)->ticks);
.
## diffname port/devcons.c 1992/0602
## diff -e /n/bootesdump/1992/0522/sys/src/9/port/devcons.c /n/bootesdump/1992/0602/sys/src/9/port/devcons.c
519d
516,517c
				if(raw)
.
## diffname port/devcons.c 1992/0603
## diff -e /n/bootesdump/1992/0602/sys/src/9/port/devcons.c /n/bootesdump/1992/0603/sys/src/9/port/devcons.c
610c
		for(i=1; i<AUTHLEN; i++)
.
## diffname port/devcons.c 1992/0611
## diff -e /n/bootesdump/1992/0603/sys/src/9/port/devcons.c /n/bootesdump/1992/0611/sys/src/9/port/devcons.c
179d
## diffname port/devcons.c 1992/0617
## diff -e /n/bootesdump/1992/0611/sys/src/9/port/devcons.c /n/bootesdump/1992/0617/sys/src/9/port/devcons.c
648a

	case Qhz:
		return readnum(offset, buf, n, HZ, NUMSIZE);
.
357a
	"hz",		{Qhz},		NUMSIZE,	0666,
.
333a
	Qhz,
.
## diffname port/devcons.c 1992/0619
## diff -e /n/bootesdump/1992/0617/sys/src/9/port/devcons.c /n/bootesdump/1992/0619/sys/src/9/port/devcons.c
230a
		case 'x':
			xsummary();
			break;
.
## diffname port/devcons.c 1992/0620
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/devcons.c /n/bootesdump/1992/0620/sys/src/9/port/devcons.c
242,244d
237,239d
## diffname port/devcons.c 1992/0704
## diff -e /n/bootesdump/1992/0620/sys/src/9/port/devcons.c /n/bootesdump/1992/0704/sys/src/9/port/devcons.c
233a
		case 'b':
			bitdebug();
			break;
.
## diffname port/devcons.c 1992/0711
## diff -e /n/bootesdump/1992/0704/sys/src/9/port/devcons.c /n/bootesdump/1992/0711/sys/src/9/port/devcons.c
688d
494,495c
	char *chal;
.
492d
## diffname port/devcons.c 1992/0725
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/devcons.c /n/bootesdump/1992/0725/sys/src/9/port/devcons.c
881c
		if(cpuserver && strcmp(u->p->user, eve) != 0)
.
830c
		if(!cpuserver && strcmp(eve, "bootes")==0)
.
823,828c
		strncpy(buf, a, NAMELEN);
		if(strcmp(buf, "none")==0
		|| strcmp(buf, u->p->user)==0
		|| strcmp(u->p->user, eve)==0)
			memmove(u->p->user, buf, NAMELEN);
		else
.
821c
		if(offset!=0 || n>=NAMELEN-1)
.
619c
		if(strcmp(u->p->user, eve)!=0 || !cpuserver)
.
220c
	if(r==0x10 && cpuserver)
.
174c
	if(cpuserver)
.
## diffname port/devcons.c 1992/0812
## diff -e /n/bootesdump/1992/0725/sys/src/9/port/devcons.c /n/bootesdump/1992/0812/sys/src/9/port/devcons.c
244c
			exit(0);
.
221c
		exit(0);
.
174,177c
	exit(1);
.
## diffname port/devcons.c 1992/0814
## diff -e /n/bootesdump/1992/0812/sys/src/9/port/devcons.c /n/bootesdump/1992/0814/sys/src/9/port/devcons.c
668c
		return readstr(offset, buf, n, tmp);
.
664c
		sprint(tmp, "%d/%d memory %d/%d swap\n",
.
661c
		n = readstr(offset, buf, n, b);
		free(b);
		return n;
.
656,658c
				readnum(0, bp, NUMSIZE, id, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->cs, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->intr, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->syscall, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->pfault, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->tlbfault, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->tlbpurge, NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, mp->load, NUMSIZE);
				bp += NUMSIZE;
				*bp++ = '\n';
.
651,652c
		b = smalloc(conf.nmach*(NUMSIZE*8+1) + 1);	/* +1 for NUL */
		bp = b;
.
492c
	char tmp[128];	/* must be >= 6*NUMSIZE */
.
490c
	char *chal, *b, *bp;
.
487c
	int ch, i, k, id;
.
## diffname port/devcons.c 1992/0825
## diff -e /n/bootesdump/1992/0814/sys/src/9/port/devcons.c /n/bootesdump/1992/0825/sys/src/9/port/devcons.c
935,938d
899c
		swc = fdtochan(fd, -1, 1, 0);
.
891c
			kickpager();
.
889a
		/* start a pager if not already started */
.
198,199c
	unlock(c);

.
196a

	lock(c);
.
191,195c

.
## diffname port/devcons.c 1992/0826
## diff -e /n/bootesdump/1992/0825/sys/src/9/port/devcons.c /n/bootesdump/1992/0826/sys/src/9/port/devcons.c
820c
			decrypt(u->p->pgrp->crypt->key, &cb[1], n);
.
813,818c
		if(n > MAXCRYPT)
			n = MAXCRYPT;
		memset(&cb[1], 0, MAXCRYPT);
		memmove(&cb[1], a, n);
		if(cb[0] == 'E')
			encrypt(u->p->pgrp->crypt->key, &cb[1], n);
.
810c
			cb[0] = a[0];
.
804,805c
			/* first byte determines whether encrypting or decrypting */
			cb = c->aux = smalloc(MAXCRYPT+1);
			cb[0] = 'E';
.
741,742c
	char *a = va, *cb;
.
594,596c
		if(n > MAXCRYPT)
			n = MAXCRYPT;
		memmove(buf, &cb[1], n);
.
488,489c
	char *chal, *b, *bp, *cb;
.
478c
		free(c->aux);
.
## diffname port/devcons.c 1992/1008
## diff -e /n/bootesdump/1992/0826/sys/src/9/port/devcons.c /n/bootesdump/1992/1008/sys/src/9/port/devcons.c
839a
		memset(u->p->pgrp->crypt->key, 0, DESKEYLEN);
.
## diffname port/devcons.c 1992/1009
## diff -e /n/bootesdump/1992/1008/sys/src/9/port/devcons.c /n/bootesdump/1992/1009/sys/src/9/port/devcons.c
840d
## diffname port/devcons.c 1992/1024
## diff -e /n/bootesdump/1992/1009/sys/src/9/port/devcons.c /n/bootesdump/1992/1024/sys/src/9/port/devcons.c
388c
	numbconv(&val, &fconv);
.
386c
	Fconv fconv = (Fconv){ tmp, tmp+sizeof(tmp), size-1, 0, 0, 'd' };
.
## diffname port/devcons.c 1993/0120
## diff -e /n/bootesdump/1992/1024/sys/src/9/port/devcons.c /n/bootesdump/1993/0120/sys/src/9/port/devcons.c
172a
	xsummary();
.
## diffname port/devcons.c 1993/0121
## diff -e /n/bootesdump/1993/0120/sys/src/9/port/devcons.c /n/bootesdump/1993/0121/sys/src/9/port/devcons.c
173d
## diffname port/devcons.c 1993/0204
## diff -e /n/bootesdump/1993/0121/sys/src/9/port/devcons.c /n/bootesdump/1993/0204/sys/src/9/port/devcons.c
386c
	Fconv fconv = (Fconv){ tmp, tmp+sizeof(tmp), size-1, 0, 0, 'u' };
.
## diffname port/devcons.c 1993/0216
## diff -e /n/bootesdump/1993/0204/sys/src/9/port/devcons.c /n/bootesdump/1993/0216/sys/src/9/port/devcons.c
197c
	poperror();
.
188a

	/* Can't afford to take an error in notify */
	if(waserror())
		return 0;

.
187c
	if(c == 0 || (c->mode!=OWRITE && c->mode!=ORDWR))
.
## diffname port/devcons.c 1993/0330
## diff -e /n/bootesdump/1993/0216/sys/src/9/port/devcons.c /n/bootesdump/1993/0330/sys/src/9/port/devcons.c
849,860c
	case Qauth:
		return authwrite(c, a, n);

	case Qauthcheck:
		return authcheck(c, a, n);
.
836,847c
		return userwrite(a, n);
.
834a
	case Qhostowner:
		return hostownerwrite(a, n);

	case Qhostdomain:
		return hostdomainwrite(a, n);

.
828,833c
		return keywrite(a, n);
.
804,826d
745c
	char *a = va;
.
622a
	case Qhostdomain:
		return readstr(offset, buf, n, hostdomain);

.
615,621c
	case Qhostowner:
		return readstr(offset, buf, n, eve);
.
603,613c
	case Qauth:
		return authread(c, cbuf, n);
.
594,601c
	case Qkey:
		return keyread(buf, n, offset);
.
493c
	char *b, *bp;
.
482,484d
476,480c
	switch(c->qid.path){
	case Qconsctl:
		if(c->flag&COPEN){
			lock(&ctl);
			if(--ctl.ref == 0)
				raw = 0;
			unlock(&ctl);
		}
	case Qauth:
	case Qauthcheck:
		authclose(c);
.
461d
456c
		if(!iseve())
.
453a
	c->aux = 0;
.
374c
 	"user",		{Quser},	NAMELEN,	0664,
.
358c
	"hostdomain",	{Qhostdomain},	DOMLEN,		0622,
	"hostowner",	{Qhostowner},	NAMELEN,	0622,
.
353c
	"authenticate",	{Qauth},	0,		0666,
	"authcheck",	{Qauthcheck},	0,		0666,
.
335a
	Qhostdomain,
	Qhostowner,
.
333d
328c
	Qauth,
	Qauthcheck,
.
202c

.
189,193d
187c
	if(c==0 || (c->mode!=OWRITE && c->mode!=ORDWR))
.
24,25d
## diffname port/devcons.c 1993/0401
## diff -e /n/bootesdump/1993/0330/sys/src/9/port/devcons.c /n/bootesdump/1993/0401/sys/src/9/port/devcons.c
190a
	poperror();
.
189a
	if(waserror())
		return 0;
.
## diffname port/devcons.c 1993/0402
## diff -e /n/bootesdump/1993/0401/sys/src/9/port/devcons.c /n/bootesdump/1993/0402/sys/src/9/port/devcons.c
357,358c
	"hostdomain",	{Qhostdomain},	DOMLEN,		0664,
	"hostowner",	{Qhostowner},	NAMELEN,	0664,
.
## diffname port/devcons.c 1993/0404
## diff -e /n/bootesdump/1993/0402/sys/src/9/port/devcons.c /n/bootesdump/1993/0404/sys/src/9/port/devcons.c
374c
 	"user",		{Quser},	NAMELEN,	0666,
.
## diffname port/devcons.c 1993/0408
## diff -e /n/bootesdump/1993/0404/sys/src/9/port/devcons.c /n/bootesdump/1993/0408/sys/src/9/port/devcons.c
558,559c
		if(k+n > 6*NUMSIZE)
			n = 6*NUMSIZE - k;
.
556c
		if(k >= 6*NUMSIZE)
.
## diffname port/devcons.c 1993/0428
## diff -e /n/bootesdump/1993/0408/sys/src/9/port/devcons.c /n/bootesdump/1993/0428/sys/src/9/port/devcons.c
806a

	case Qauthent:
		return authentwrite(c, a, n);
.
602a
	case Qauthent:
		return authentread(c, cbuf, n);

.
486a
		break;
.
485a
	case Qauthent:
.
483a
		break;
.
352a
	"authenticator", {Qauthent},	0,		0666,
.
325a
	Qauthent,
.
## diffname port/devcons.c 1993/0501
## diff -e /n/bootesdump/1993/0428/sys/src/9/port/devcons.c /n/fornaxdump/1993/0501/sys/src/brazil/port/devcons.c
854c
		if(cpuserver && !iseve())
.
816,818d
618c
		return readstr(offset, buf, n, up->user);
.
608,610d
586c
		return readnum(offset, buf, n, up->parentpid, NUMSIZE);
.
583c
		return readnum(offset, buf, n, up->pid, NUMSIZE);
.
580c
		return readnum(offset, buf, n, up->noteid, NUMSIZE);
.
577c
		return readnum(offset, buf, n, up->pgrp->pgrpid, NUMSIZE);
.
567c
			l = up->time[i];
.
491d
489d
486d
354d
326d
187c
	n = sprint(buf, "%s %d: ", up->text, up->pid);
.
184c
	c = up->fgrp->fd[2];
.
181c
	if(up->fgrp == 0)
.
21,22c
static Ref	ctl;		/* number of opens to the control file */
static int	raw;		/* true if ctl file is raw */
.
## diffname port/devcons.c 1993/0502
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0502/sys/src/brazil/port/devcons.c
549a
#endif asdf
.
511a
		return getline((char*)buf, n);
#ifdef asdf
.
## diffname port/devcons.c 1993/0506
## diff -e /n/fornaxdump/1993/0502/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0506/sys/src/brazil/port/devcons.c
552d
512,513d
## diffname port/devcons.c 1993/0601
## diff -e /n/fornaxdump/1993/0506/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0601/sys/src/brazil/port/devcons.c
771,773c
				kbd.raw = 0;
.
766,769c
				kbd.raw = 1;
				qunlock(&kbd);
.
760,764c
				qlock(&kbd);
				if(kbd.x){
					qwrite(kbdq, kbd.line, kbd.x, 1);
					kbd.x = 0;
.
733c
	int id, fd;
.
616,630c
		return qread(klogq, buf, n);
.
550,552c
		n = qread(lineq, buf, n);
		qunlock(&kbd);
		return n;
.
546,548c
			case 0x15:
				kbd.x = 0;
				break;
			default:
				kbd.line[kbd.x++] = ch;
				break;
			}
			if(kbd.x == sizeof(kbd.line) || ch == '\n' || ch == 0x04){
				if(ch == 0x04)
					kbd.x--;
				qwrite(lineq, kbd.line, kbd.x, 1);
			}
.
512,544c
		while(!qcanread(lineq)){
			qread(kbdq, &kbd.line[kbd.x], 1);
			ch = kbd.line[kbd.x];
			if(kbd.raw){
				i = splhi();
				qproduce(lineq, &kbd.line[kbd.x], 1);
				splx(i);
				continue;
			}
			switch(ch){
			case '\b':
				if(kbd.x)
					kbd.x--;
.
509c
			qunlock(&kbd);
.
507c
		qlock(&kbd);
.
479,482c
			qlock(&kbd);
			if(--kbd.ctl == 0)
				kbd.raw = 0;
			qunlock(&kbd);
.
459c
		qlock(&kbd);
		kbd.ctl++;
		qunlock(&kbd);
.
319c
	return qlen(printq) > 0;
.
312,313c
	if(++kbd.count&1)
		kbdputc(kbdq, kbd.c);
.
307,309c
	if(kbd.repeat==1 && ++kbd.count>HZ){
		kbd.repeat = 2;
		kbd.count = 0;
.
305c
	if(kbd.repeat == 0)
.
298,299c
	kbd.repeat = rep;
	kbd.count = 0;
.
284,291c
	qproduce(kbdq, buf, n);
.
274c
	int n;
.
272c
kbdputc(Queue *q, int ch)
.
269a
 *
 *  Called at interrupt time to process a character.
.
260c
kbdcr2nl(Queue *q, int ch)
.
257c
 *  Called by a uart interrupt for console input.
 *
 *  turn '\r' into '\n' before putting it into the queue.
.
249a

	/*
	 *  finally, the actual echoing
	 */
.
248c
	if(kbd.raw)
.
205c
	while(qlen(printq) > 0) ;
.
157c
	qwrite(klogq, buf, n, 1);
.
117,133d
87,115d
81c
			qwrite(printq, str, n, 1);
.
77c
			qwrite(printq, buf, m+2, 1);
.
68c
	if(printq == 0)
.
32,39c
	klogq = qopen(32*1024, 0, 0, 0);
	lineq = qopen(2*1024, 0, 0, 0);
.
26,28d
23a
	char	c;
	int	count;
	int	repeat;
} kbd;


.
21,22c
	int	raw;		/* true if we shouldn't process input */
	int	ctl;		/* number of opens to the control file */
	int	x;		/* index into line */
	char	line[1024];	/* current input line */
.
16,19c
static struct
{
	QLock;
.
11,14c
Queue	*mouseq;
Queue	*kbdq;		/* unprocessed console input */
Queue	*lineq;		/* processed console input */
Queue	*printq;	/* console output */
Queue	*klogq;
.
## diffname port/devcons.c 1993/0725
## diff -e /n/fornaxdump/1993/0601/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0725/sys/src/brazil/port/devcons.c
699a
				kbd.x = 0;
.
496a
		poperror();
.
492a
				kbd.x = 0;
.
489c
			if(kbd.x == sizeof(kbd.line) || eol){
.
484a
			case '\n':
			case 0x04:
				eol = 1;
.
476a
			eol = 0;
.
454a
	char *b, *bp;
	char tmp[128];		/* must be >= 6*NUMSIZE */
	char *cbuf = buf;
	int ch, i, k, id, eol;
.
451,453d
449d
## diffname port/devcons.c 1993/0731
## diff -e /n/fornaxdump/1993/0725/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0731/sys/src/brazil/port/devcons.c
739a

	case Qauthent:
		return authentwrite(c, a, n);
.
553a
	case Qauthent:
		return authentread(c, cbuf, n);

.
441a
	case Qauthent:
.
306a
	"authenticator", {Qauthent},	0,		0666,
.
279a
	Qauthent,
.
## diffname port/devcons.c 1993/0806
## diff -e /n/fornaxdump/1993/0731/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0806/sys/src/brazil/port/devcons.c
99a

.
79c
		}
		else {
.
71c
		if(t) {
.
69c

	while(n > 0) {
.
52a
	char buf[PRINTSIZE+2];
.
50d
## diffname port/devcons.c 1993/0807
## diff -e /n/fornaxdump/1993/0806/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0807/sys/src/brazil/port/devcons.c
231,232d
64,65c
	 *  put the message there.
.
## diffname port/devcons.c 1993/0819
## diff -e /n/fornaxdump/1993/0807/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0819/sys/src/brazil/port/devcons.c
183a
			ixsummary();
.
## diffname port/devcons.c 1993/0829
## diff -e /n/fornaxdump/1993/0819/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0829/sys/src/brazil/port/devcons.c
125a
	prflush();
.
## diffname port/devcons.c 1993/0905
## diff -e /n/fornaxdump/1993/0829/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0905/sys/src/brazil/port/devcons.c
161c
	while(consactive())
		;
.
124a
iprint("%s\n", buf);
.
## diffname port/devcons.c 1993/0906
## diff -e /n/fornaxdump/1993/0905/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0906/sys/src/brazil/port/devcons.c
125d
## diffname port/devcons.c 1993/0910
## diff -e /n/fornaxdump/1993/0906/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/0910/sys/src/brazil/port/devcons.c
614,616c
		k = 0;
		for(i = 0; i < NCOLOR; i++)
			k += palloc.freecol[i];

		sprint(tmp, "%d/%d memory %d/%d swap\n", palloc.user-k,
			palloc.user, conf.nswap-swapalloc.free, conf.nswap);
.
## diffname port/devcons.c 1993/1005
## diff -e /n/fornaxdump/1993/0910/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1005/sys/src/brazil/port/devcons.c
212,215c
	if(r == '\n'){
		if(printq)
			qproduce(printq, "\r", 1);
	} else if(r == 0x15){
		buf = "^U\n";
		n = 3;
	}
	screenputs(buf, n);
	if(printq)
		qproduce(printq, buf, n);
.
## diffname port/devcons.c 1993/1006
## diff -e /n/fornaxdump/1993/1005/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1006/sys/src/brazil/port/devcons.c
188,190d
## diffname port/devcons.c 1993/1016
## diff -e /n/fornaxdump/1993/1006/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1016/sys/src/brazil/port/devcons.c
198,200c
		break;
	case 3:
		if(r > '0' && r <= '9') {
			pid = (pid*10)+(r-'0');
			return;
		}
		print("PID %d\n", pid);
		p = proctab(0);
		ep = p+conf.nproc;
		for(; p < ep; p++) {
			if(p->pid == pid) {
				top = (ulong)p->kstack + KSTACK;
				for(l=(ulong)p->sched.sp; l < top; l += BY2WD) {
					v = *(ulong*)l;
					if(KTZERO < v && v < (ulong)&etext) {
						print("%lux=%lux\n", l, v);
						delay(100);
					}
				}
			}
		}
		break;
.
179c
	switch(ctrlt) {
	case 0:
		if(r == 0x14){
			ctrlt = 1;
			return;
		}
		break;
	case 1:
		if(r > '0' && r <= '9') {
			ctrlt = 3;
			pid = r-'0';
			return;
		}
		ctrlt = 2;
		return;
	case 2:
.
168c
	static int ctrlt, pid;
	ulong l, v, top;
	extern ulong etext;
	Proc *p, *ep;
.
## diffname port/devcons.c 1993/1031
## diff -e /n/fornaxdump/1993/1016/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1031/sys/src/brazil/port/devcons.c
484a
		break;
.
## diffname port/devcons.c 1993/1119
## diff -e /n/fornaxdump/1993/1031/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1119/sys/src/brazil/port/devcons.c
316c
	if(printq)
		return qlen(printq) > 0;
	return 0;
.
## diffname port/devcons.c 1993/1120
## diff -e /n/fornaxdump/1993/1119/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1120/sys/src/brazil/port/devcons.c
657,661c
		sprint(tmp, "%d/%d memory %d/%d swap\n",
			palloc.user-palloc.freecount,
.
## diffname port/devcons.c 1993/1217
## diff -e /n/fornaxdump/1993/1120/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1217/sys/src/brazil/port/devcons.c
214a
case 'q':
print("%lux\n", *(ulong*)0xe0000004);
print("%lux\n", *(ulong*)0x80000420);
print("%lux\n", *(ulong*)0x80000424);
for(pid = 0; pid < 30; pid++)
print(":%lux\n", ((ulong*)0xbfc00000)[pid]);
.
## diffname port/devcons.c 1993/1228
## diff -e /n/fornaxdump/1993/1217/sys/src/brazil/port/devcons.c /n/fornaxdump/1993/1228/sys/src/brazil/port/devcons.c
579,581d
372d
344d
## diffname port/devcons.c 1994/0208
## diff -e /n/fornaxdump/1993/1228/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0208/sys/src/brazil/port/devcons.c
737c
			putstrn0(a, bp, 1);
.
86a
void
putstrn(char *str, int n)
{
	putstrn0(str, n, 0);
}

.
79,81c
		} else {
			if(usewrite)
				qwrite(printq, str, n, 0);
			else {
				x = splhi();
				qproduce(printq, str, n);
				splx(x);
			}
.
76c
			if(usewrite)
				qwrite(printq, buf, m+2, 0);
			else {
				x = splhi();
				qproduce(printq, buf, m+2);
				splx(x);
			}
.
50c
	int m, x;
.
47,48c
static void
putstrn0(char *str, int n, int usewrite)
.
## diffname port/devcons.c 1994/0219
## diff -e /n/fornaxdump/1994/0208/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0219/sys/src/brazil/port/devcons.c
144a

.
## diffname port/devcons.c 1994/0224
## diff -e /n/fornaxdump/1994/0219/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0224/sys/src/brazil/port/devcons.c
142a
	spllo();
.
## diffname port/devcons.c 1994/0305
## diff -e /n/fornaxdump/1994/0224/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0305/sys/src/brazil/port/devcons.c
148a

.
## diffname port/devcons.c 1994/0313
## diff -e /n/fornaxdump/1994/0305/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0313/sys/src/brazil/port/devcons.c
242,263c
	}
	else if(r == 0x14){
		ctrlt++;
		return;
.
235,240d
225a
		case 'b':
			bitdebug();
			break;
.
202,217c
	if(ctrlt == 2){
.
## diffname port/devcons.c 1994/0316
## diff -e /n/fornaxdump/1994/0313/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0316/sys/src/brazil/port/devcons.c
191d
189d
## diffname port/devcons.c 1994/0319
## diff -e /n/fornaxdump/1994/0316/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0319/sys/src/brazil/port/devcons.c
209,211d
## diffname port/devcons.c 1994/0413
## diff -e /n/fornaxdump/1994/0319/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0413/sys/src/brazil/port/devcons.c
122a
fprint(int fd, char *fmt, ...)	/* needed so we can use user-level libg */
{
	char buf[PRINTSIZE];
	int n;

	USED(fd);
	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	putstrn(buf, n);

	return n;
}

int
.
## diffname port/devcons.c 1994/0624
## diff -e /n/fornaxdump/1994/0413/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0624/sys/src/brazil/port/devcons.c
6d
## diffname port/devcons.c 1994/0813
## diff -e /n/fornaxdump/1994/0624/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0813/sys/src/brazil/port/devcons.c
216a
		case 's':
			dumpstack();
			break;
.
## diffname port/devcons.c 1994/0902
## diff -e /n/fornaxdump/1994/0813/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/0902/sys/src/brazil/port/devcons.c
746c
					qwrite(kbdq, kbd.line, kbd.x);
.
543c
				qwrite(lineq, kbd.line, kbd.x);
.
141c
	qwrite(klogq, buf, n);
.
86c
				qwrite(printq, str, n);
.
76c
				qwrite(printq, buf, m+2);
.
37a
	qnoblock(lineq, 1);
.
36a
	qnoblock(klogq, 1);
.
## diffname port/devcons.c 1994/1124
## diff -e /n/fornaxdump/1994/0902/sys/src/brazil/port/devcons.c /n/fornaxdump/1994/1124/sys/src/brazil/port/devcons.c
521,523c
				qiwrite(lineq, &kbd.line[kbd.x], 1);
.
257c
		qiwrite(printq, buf, n);
.
250c
			qiwrite(printq, "\r", 1);
.
89,93c
			else 
				qiwrite(printq, str, n);
.
79,83c
			else
				qiwrite(printq, buf, m+2);
.
51c
	int m;
.
## diffname port/devcons.c 1995/0104
## diff -e /n/fornaxdump/1994/1124/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0104/sys/src/brazil/port/devcons.c
606,608d
357d
330d
130,140d
36,37d
14d
## diffname port/devcons.c 1995/0108
## diff -e /n/fornaxdump/1995/0104/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0108/sys/src/brazil/port/devcons.c
825a
}

long
consbwrite(Chan *c, Block *bp, ulong offset)
{
	return devbwrite(c, bp, offset);
.
642a
Block*
consbread(Chan *c, long n, ulong offset)
{
	return devbread(c, n, offset);
}

.
## diffname port/devcons.c 1995/0112
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0112/sys/src/brazil/port/devcons.c
734a
			} else if(strncmp(a, "ctlpon", 6) == 0){
				kbd.ctlpoff = 0;
			} else if(strncmp(a, "ctlpoff", 7) == 0){
				kbd.ctlpoff = 1;
.
188c
	if(r==0x10 && cpuserver && !kbd.ctlpoff)
.
26a
	int	ctlpoff;
.
## diffname port/devcons.c 1995/0117
## diff -e /n/fornaxdump/1995/0112/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0117/sys/src/brazil/port/devcons.c
97a
snprint(char *s, int n, char *fmt, ...)
{
	return doprint(s, s+n, fmt, (&fmt+1)) - s;
}

int
.
## diffname port/devcons.c 1995/0319
## diff -e /n/fornaxdump/1995/0117/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0319/sys/src/brazil/port/devcons.c
218a
		case 'k':
			if(!cpuserver)
				killbig();
			break;
.
## diffname port/devcons.c 1995/0804
## diff -e /n/fornaxdump/1995/0319/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0804/sys/src/brazil/port/devcons.c
865d
863c
conswstat(Chan*, char*)
.
858d
856c
consremove(Chan*)
.
460d
458c
conscreate(Chan*, char*, int, ulong)
.
275d
269c
kbdputc(Queue*, int ch)
.
127d
122c
fprint(int, char *fmt, ...)	/* needed so we can use user-level libg */
.
## diffname port/devcons.c 1995/0815
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0815/sys/src/brazil/port/devcons.c
278a
	kbd.c = r;
.
24c
	Rune	c;
.
## diffname port/devcons.c 1995/0910
## diff -e /n/fornaxdump/1995/0815/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0910/sys/src/brazil/port/devcons.c
880a
}

static struct
{
	QLock;
	Rendez	r;
	uchar	buf[4096];
	uchar	*ep;
	uchar	*rp;
	uchar	*wp;
	uchar	next;
	uchar	bits;
	uchar	wakeme;
} rb;

ulong randomcount;

void
randomreset(void)
{
	rb.ep = rb.buf + sizeof(rb.buf);
	rb.rp = rb.wp = rb.buf;
}

/*
 *  produce random bits in a circular buffer
 */
void
randomclock(void)
{
	int i;
	uchar *p;

	i = rb.rp - rb.wp;
	if(i == 1 || i == (1 - sizeof(rb.buf)))
		return;

	rb.bits = (rb.bits<<2) ^ randomcount;
	rb.next += 2;
	if(rb.next != 8)
		return;

	rb.next = 0;
	*rb.wp ^= rb.bits;
	p = rb.wp+1;
	if(p == rb.ep)
		p = rb.buf;
	rb.wp = p;

	if(rb.wakeme)
		wakeup(&rb.r);
}

static int
notempty(void*)
{
	return rb.wp != rb.rp;
}

/*
 *  consume random bytes from a circular buffer
 */
static ulong
randomread(uchar *p, ulong n)
{
	int i, sofar;
	uchar *e;

	if(waserror()){
		qunlock(&rb);
		nexterror();
	}

	qlock(&rb);
	for(sofar = 0; sofar < n; sofar += i){
		i = rb.wp - rb.rp;
		if(i == 0){
			rb.wakeme = 1;
			sleep(&rb.r, notempty, 0);
			rb.wakeme = 0;
			continue;
		}
		if(i < 0)
			i = rb.ep - rb.rp;
		if(i > n)
			i = n;
		memmove(p + sofar, rb.rp, i);
		e = rb.rp + i;
		if(e == rb.ep)
			e = rb.buf;
		rb.rp = e;
	}
	qunlock(&rb);
	poperror();

	return n;
.
644a
	case Qrandom:
		return randomread(buf, n);

.
408a
	randomreset();
.
358a
	"random",	{Qrandom},	0,		0664,
.
332a
	Qrandom,
.
32a
static ulong randomread(uchar*, ulong);
static void randomreset(void);

.
30d
## diffname port/devcons.c 1995/0913
## diff -e /n/fornaxdump/1995/0910/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0913/sys/src/brazil/port/devcons.c
982a

	wakeup(&rb.producer);
.
967c
			sleep(&rb.consumer, rbnotempty, 0);
.
943c
rbnotempty(void*)
.
939c
		wakeup(&rb.consumer);
.
926a
	randomcount = 0;
.
925a
	if(!rbnotfull(0))
		return;

.
922,923c
	if(randomcount == 0)
.
919d
910a
	kproc("genrandom", genrandom, 0);
.
908a
	up->basepri = PriNormal;
	up->priority = up->basepri;

	for(;;){
		if(!rbnotfull(0))
			sleep(&rb.producer, rbnotfull, 0);
		randomcount++;
	}
}

void
randominit(void)
{
.
907c
genrandom(void*)
.
905a
static int
rbnotfull(void*)
{
	int i;

	i = rb.rp - rb.wp;
	return i != 1 && i != (1 - sizeof(rb.buf));
}

.
894c
	Rendez	producer;
	Rendez	consumer;
.
418a
	randominit();
.
413d
33c
static void randominit(void);
.
## diffname port/devcons.c 1995/0914
## diff -e /n/fornaxdump/1995/0913/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/0914/sys/src/brazil/port/devcons.c
958c
	*rb.wp ^= rb.bits ^ *rb.rp;
.
952a

.
## diffname port/devcons.c 1995/1023
## diff -e /n/fornaxdump/1995/0914/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/1023/sys/src/brazil/port/devcons.c
998,1006c
		*p++ = *rb.rp;
		if(rb.rp+1 == rb.ep)
			rb.rp = rb.buf;
		else
			rb.rp = rb.rp+1;
.
993a
			wakeup(&rb.producer);
.
990,992c
	for(e = p + n; p < e; ){
		if(rb.wp == rb.rp){
.
981d
964a
	*rb.wp ^= rb.bits;
	if(rb.wp+1 == rb.ep)
		rb.wp = rb.buf;
	else
		rb.wp = rb.wp+1;

.
959,963d
957d
951,955c
	rb.next++;
	if(rb.next != 8/2)
.
948,949c
	rb.bits = (rb.bits<<2) ^ rb.randomcount;
	rb.randomcount = 0;
.
943,945c
	if(rb.randomcount == 0 || !rbnotfull(0))
.
925d
922a
		for(;;)
			if(++rb.randomcount > 1000000)
				break;
.
905d
893a
	ulong	randomcount;
.
## diffname port/devcons.c 1995/1030
## diff -e /n/fornaxdump/1995/1023/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/1030/sys/src/brazil/port/devcons.c
219a
		case 'q':
			scheddump();
			break;
.
## diffname port/devcons.c 1995/1121
## diff -e /n/fornaxdump/1995/1030/sys/src/brazil/port/devcons.c /n/fornaxdump/1995/1121/sys/src/brazil/port/devcons.c
934c
static void
.
## diffname port/devcons.c 1996/0119
## diff -e /n/fornaxdump/1995/1121/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/0119/sys/src/brazil/port/devcons.c
196,197c
	if(r==0x10 && cpuserver && !kbd.ctlpoff){
		lock(&active);
		active.exiting = 1;
		unlock(&active);
	}
.
## diffname port/devcons.c 1996/0214
## diff -e /n/fornaxdump/1996/0119/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/0214/sys/src/brazil/port/devcons.c
392c
	snprint(tmp, sizeof(tmp), "%*.0ud", size-1, val);
.
390d
166c
	va_start(arg, fmt);
	n = doprint(buf+n, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
.
156a
	va_list arg;
.
142c
	va_start(arg, fmt);
	n = doprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
.
138a
	va_list arg;
.
129c
	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
.
126a
	va_list arg;
.
117c
	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
.
114a
	va_list arg;
.
108c
	va_list arg;
	int n;

	va_start(arg, fmt);
	n = doprint(s, s+PRINTSIZE, fmt, arg) - s;
	va_end(arg);
	return n;
.
102c
	va_list arg;

	va_start(arg, fmt);
	n = doprint(s, s+n, fmt, arg) - s;
	va_end(arg);
	return n;
.
## diffname port/devcons.c 1996/0223
## diff -e /n/fornaxdump/1996/0214/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/0223/sys/src/brazil/port/devcons.c
8d
## diffname port/devcons.c 1996/03071
## diff -e /n/fornaxdump/1996/0223/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/03071/sys/src/brazil/port/devcons.c
828a
		break;

	case Qreboot:
		if(!iseve())
			error(Eperm);
		if(strncmp(a, "reboot", 6) == 0)
			exit(0);
.
390a
	"reboot",	{Qreboot},	0,		0664,
.
363a
	Qreboot,
.
## diffname port/devcons.c 1996/1029
## diff -e /n/fornaxdump/1996/03071/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/1029/sys/src/brazil/port/devcons.c
941a
int
nrand(int n)
{
	rb.randn ^= rb.bits;
	rb.randn = rb.randn*1103515245 + 12345 + MACHP(0)->ticks;
	return (rb.randn>>16) % n;
}
.
939a
	ushort	bits;
	ulong	randn;
.
938d
909,917d
## diffname port/devcons.c 1996/1031
## diff -e /n/fornaxdump/1996/1029/sys/src/brazil/port/devcons.c /n/fornaxdump/1996/1031/sys/src/brazil/port/devcons.c
937d
933a
static void
seednrand(void)
{
	randomread((uchar*)&rb.randn, sizeof(rb.randn));
}

.
452a
	static int seeded;

	if(!seeded){
		seednrand();
		seeded = 1;
	}
.
31,32c
static ulong	randomread(uchar*, ulong);
static void	randominit(void);
static void	seednrand(void);
.
## diffname port/devcons.c 1997/0123
## diff -e /n/fornaxdump/1996/1031/sys/src/brazil/port/devcons.c /n/fornaxdump/1997/0123/sys/src/brazil/port/devcons.c
138c
fprint(int, char *fmt, ...)
.
## diffname port/devcons.c 1997/0204
## diff -e /n/fornaxdump/1997/0123/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0204/sys/src/brazil/port/devcons.c
799c
		if(n<=0 || (boottime != 0 && !iseve()))	/* write once file */
.
## diffname port/devcons.c 1997/0205
## diff -e /n/emeliedump/1997/0204/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0205/sys/src/brazil/port/devcons.c
607c
		return readnum(offset, buf, n, rtctime(), 12);
.
## diffname port/devcons.c 1997/0327
## diff -e /n/emeliedump/1997/0205/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0327/sys/src/brazil/port/devcons.c
1025c
	uchar *e, *p;

	p = xp;
.
1023c
randomread(void *xp, ulong n)
.
1013,1018d
980a
	addclock0link(randomclock);
.
962a
static int
rbnotempty(void*)
{
	return rb.wp != rb.rp;
}

.
944c
	randomread((void*)&rb.randn, sizeof(rb.randn));
.
930a
	ulong	randomcount;
.
928d
924a
Dev consdevtab = {
	devreset,
	consinit,
	consattach,
	devclone,
	conswalk,
	consstat,
	consopen,
	devcreate,
	consclose,
	consread,
	devbread,
	conswrite,
	devbwrite,
	devremove,
	devwstat,
};

.
905,916d
898,903d
832,839d
696,743c
static long
.
545c
		while(!qcanread(lineq)) {
.
541c
		if(waserror()) {
.
537c
		return devdirread(c, buf, n, consdir, nelem(consdir), devgen);
.
523c
static long
.
497,503c
static void
.
494c
	return devopen(c, omode, consdir, nelem(consdir), devgen);
.
481c
static Chan*
.
478c
	devstat(c, dp, consdir, nelem(consdir), devgen);
.
475c
static void
.
472c
	return devwalk(c, name, consdir, nelem(consdir), devgen);
.
463,469c
static int
.
451c
static Chan*
.
440,445c
static void
.
401,402d
387d
385d
359d
357d
336,343d
241c
			if(consdebug != nil)
				consdebug();
.
204,210d
193c
	devtab[c->type]->write(c, buf, n, c->offset);
.
178c
	char buf[2*PRINTSIZE];
.
175c
	int n;
.
157a
	va_list arg;
	char buf[PRINTSIZE];
.
155,156d
142a
	va_list arg;
	char buf[PRINTSIZE];
.
140,141d
138c
fprint(int, char *fmt, ...)	/* needed so we can use user-level libg */
.
127a
	va_list arg;
	char buf[PRINTSIZE];
.
125,126d
114a
	va_list arg;
.
113d
41a
int
consactive(void)
{
	if(printq)
		return qlen(printq) > 0;
	return 0;
}

void
prflush(void)
{
	while(consactive())
		;
}

.
31c
static ulong	randomread(void*, ulong);
.
9,12c
Queue*	kbdq;			/* unprocessed console input */
Queue*	lineq;			/* processed console input */
Queue*	printq;			/* console output */
.
7a
void	(*consdebug)(void);
.
## diffname port/devcons.c 1997/0408
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0408/sys/src/brazil/port/devcons.c
830a
	'c',
	"cons",

.
## diffname port/devcons.c 1997/0410
## diff -e /n/emeliedump/1997/0408/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0410/sys/src/brazil/port/devcons.c
665a

	case Qdrivers:
		b = malloc(MBS);
		if(b == nil)
			error(Enomem);
		n = 0;
		for(i = 0; devtab[i] != nil; i++)
			n += snprint(b+n, MBS-n, "#%C %s\n", devtab[i]->dc,  devtab[i]->name);
		n = readstr(offset, buf, n, b);
		free(b);
		return n;
.
397a
enum
{
	MBS	=	1024,
};

.
379a
	"drivers",	{Qdrivers},	0,		0644,
.
372c
static Dirtab consdir[]={
.
353a
	Qdrivers,
.
## diffname port/devcons.c 1997/0413
## diff -e /n/emeliedump/1997/0410/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0413/sys/src/brazil/port/devcons.c
961a
}

static void
randominit(void)
{
	addclock0link(randomclock);
	rb.ep = rb.buf + sizeof(rb.buf);
	rb.rp = rb.wp = rb.buf;
	kproc("genrandom", genrandom, 0);
.
940c
static void
.
928,936d
## diffname port/devcons.c 1997/0417
## diff -e /n/emeliedump/1997/0413/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0417/sys/src/brazil/port/devcons.c
680c
			n += snprint(b+n, READSTR-n, "#%C %s\n", devtab[i]->dc,  devtab[i]->name);
.
675c
		b = malloc(READSTR);
.
400,404d
## diffname port/devcons.c 1997/0614
## diff -e /n/emeliedump/1997/0417/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0614/sys/src/brazil/port/devcons.c
983c
		rb.randn = rb.randn*1103515245 + 12345 + *rb.rp;
		*p++ = rb.randn;
.
## diffname port/devcons.c 1997/0616
## diff -e /n/emeliedump/1997/0614/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0616/sys/src/brazil/port/devcons.c
983,984c

		/*
		 *  beating clocks will be precictable if
		 *  they are synchronized.  Use a cheap pseudo
		 *  random number generator to obscure any cycles.
		 */
		x = rb.randn*1103515245 ^ *rb.rp;
		*p++ = rb.randn = x;

.
965a
	ulong x;
.
## diffname port/devcons.c 1997/0820
## diff -e /n/emeliedump/1997/0616/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0820/sys/src/brazil/port/devcons.c
555d
532,553c
			n = qread(lineq, buf, n);
.
525,530c
		if(kbd.raw) {
			if(qcanread(lineq))
				n = qread(lineq, buf, n);
			else
				n = qread(kbdq, buf, n);
		} else {
			while(!qcanread(lineq)) {
				qread(kbdq, &kbd.line[kbd.x], 1);
				ch = kbd.line[kbd.x];
				if(kbd.raw){
					qiwrite(lineq, kbd.line, kbd.x+1);
					kbd.x = 0;
					continue;
				}
				eol = 0;
				switch(ch){
				case '\b':
					if(kbd.x)
						kbd.x--;
					break;
				case 0x15:
					kbd.x = 0;
					break;
				case '\n':
				case 0x04:
					eol = 1;
				default:
					kbd.line[kbd.x++] = ch;
					break;
				}
				if(kbd.x == sizeof(kbd.line) || eol){
					if(ch == 0x04)
						kbd.x--;
					qwrite(lineq, kbd.line, kbd.x);
					kbd.x = 0;
				}
.
## diffname port/devcons.c 1997/0821
## diff -e /n/emeliedump/1997/0820/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0821/sys/src/brazil/port/devcons.c
528,529c
			else {
				/* read as much as possible */
				do {
					i = qread(kbdq, cbuf, n);
					cbuf += i;
					n -= i;
				} while (n>0 && qcanread(kbdq));
				n = cbuf - (char*)buf;
			}
.
## diffname port/devcons.c 1997/0831
## diff -e /n/emeliedump/1997/0821/sys/src/brazil/port/devcons.c /n/emeliedump/1997/0831/sys/src/brazil/port/devcons.c
795a
		}
.
794c
		if(strncmp(a, "reboot", 6) == 0){
			print("conswrite: reboot\n");
.
## diffname port/devcons.c 1997/1101
## diff -e /n/emeliedump/1997/0831/sys/src/brazil/port/devcons.c /n/emeliedump/1997/1101/sys/src/brazil/port/devcons.c
246a
			poolsummary();
.
152,166d
3a
#include	"pool.h"
.
## diffname port/devcons.c 1997/1105
## diff -e /n/emeliedump/1997/1101/sys/src/brazil/port/devcons.c /n/emeliedump/1997/1105/sys/src/brazil/port/devcons.c
39a
	if(lineq == nil)
		panic("printinit");
.
## diffname port/devcons.c 1998/0319
## diff -e /n/emeliedump/1997/1105/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0319/sys/src/brazil/port/devcons.c
700a
	ulong offset = off;
.
692c
conswrite(Chan *c, void *va, long n, vlong off)
.
500a
	ulong offset = off;
.
493c
consread(Chan *c, void *buf, long n, vlong off)
.
## diffname port/devcons.c 1998/0403
## diff -e /n/emeliedump/1998/0319/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0403/sys/src/brazil/port/devcons.c
820c
		swc = fdtochan(fd, -1, 1, 1);
.
## diffname port/devcons.c 1998/0422
## diff -e /n/emeliedump/1998/0403/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0422/sys/src/brazil/port/devcons.c
610a
	case Qauthcheck:
		return authcheckread(c, cbuf, n);

.
## diffname port/devcons.c 1998/0512
## diff -e /n/emeliedump/1998/0422/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0512/sys/src/brazil/port/devcons.c
104c
			else
.
## diffname port/devcons.c 1998/0610
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0610/sys/src/brazil/port/devcons.c
928a
			if(anyhigher())
				sched();
.
927c
			if(++rb.randomcount > 100000)
.
## diffname port/devcons.c 1998/0617
## diff -e /n/emeliedump/1998/0610/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0617/sys/src/brazil/port/devcons.c
1015a
	return n;
}

static long
qtimer(long n, vlong offset) {
	/* block until time ≥ offset;
	 * add n to offset
	 * return increment to offset (i.e., n)
	 */
	vlong time, rathole;

	for (;;) {
		rathole = µoffset/1000;
		time = offset/1000 - (rathole + TK2MS(MACHP(0)->ticks));
		if (time <= 0) break;
		tsleep(&up->sleep, return0, 0, (long)time);
	}
.
837a
	case Qtimer:
		error(Eperm);

.
684c
		n = readstr((ulong)offset, buf, n, b);
.
672c
		return readstr((ulong)offset, buf, n, sysname);
.
669c
		return readstr((ulong)offset, buf, n, tmp);
.
660c
		n = readstr((ulong)offset, buf, n, b);
.
633c
		return readnum((ulong)offset, buf, n, HZ, NUMSIZE);
.
630c
		return readnum((ulong)offset, buf, n, TK2MS(MACHP(0)->ticks), NUMSIZE);
.
624c
		return readstr((ulong)offset, buf, n, up->user);
.
621c
		return readstr((ulong)offset, buf, n, hostdomain);
.
618c
		return readstr((ulong)offset, buf, n, eve);
.
593a
	case Qtimer:
		return qtimer(n, offset);

.
592c
		return readnum((ulong)offset, buf, n, rtctime(), 12);
.
589c
		return readnum((ulong)offset, buf, n, up->parentpid, NUMSIZE);
.
586c
		return readnum((ulong)offset, buf, n, up->pid, NUMSIZE);
.
583c
		return readnum((ulong)offset, buf, n, up->pgrp->pgrpid, NUMSIZE);
.
506a
		consdir[qtimerentry].length = µoffset +
			(vlong)1000*TK2MS(MACHP(0)->ticks);
.
501c
	vlong offset = off;
.
452a
	if (c->qid.path == Qtimer)
		consdir[qtimerentry].length = µoffset +
			(vlong)1000*TK2MS(MACHP(0)->ticks);
.
429a

	if (qtimerentry < 0) {
		while (consdir[++qtimerentry].qid.path != Qtimer)
			;
		µoffset = (vlong)1000000*rtctime() -
			  (vlong)1000*TK2MS(MACHP(0)->ticks);
	}
.
385a
	"timer",	{Qtimer},	0,		0444,
.
358a
	Qtimer,
.
35a
int qtimerentry = -1;
vlong µoffset;

.
34a
static long	qtimer(long, vlong);
.
## diffname port/devcons.c 1998/0618
## diff -e /n/emeliedump/1998/0617/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0618/sys/src/brazil/port/devcons.c
860a
		break;
.
## diffname port/devcons.c 1998/0702
## diff -e /n/emeliedump/1998/0618/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0702/sys/src/brazil/port/devcons.c
906c
	uchar	buf[1024];
.
## diffname port/devcons.c 1998/0710
## diff -e /n/emeliedump/1998/0702/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0710/sys/src/brazil/port/devcons.c
622a
		memmove(buf, tmp+k, n);
		return n;

	case Qfastclock:
		ticks = fastticks(&fasthz);

		k = offset;
		if(k >= 4*NUMSIZE)
			return 0;
		if(k+n > 4*NUMSIZE)
			n = 4*NUMSIZE - k;
		readvlnum(0, tmp, 2*NUMSIZE, ticks, 2*NUMSIZE);
		readvlnum(0, tmp+2*NUMSIZE, 2*NUMSIZE, fasthz, 2*NUMSIZE);
.
517a
	uvlong ticks, fasthz;
.
403a
readvlnum(ulong off, char *buf, ulong n, uvlong val, int size)
{
	char tmp[64];

	snprint(tmp, sizeof(tmp), "%*.0ulld", size-1, val);
	tmp[size-1] = ' ';
	if(off >= size)
		return 0;
	if(off+n > size)
		n = size-off;
	memmove(buf, tmp+off, n);
	return n;
}

int
.
375a
	"fastclock",	{Qfastclock},	4*NUMSIZE,	0444,
.
347a
	Qfastclock,
.
## diffname port/devcons.c 1998/0731
## diff -e /n/emeliedump/1998/0710/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0731/sys/src/brazil/port/devcons.c
1076c
qtimer(long n, vlong offset)
{
.
959a
int
rand(void)
{
	nrand(1);
	return rb.randn;
}


.
955a
	if(rb.randn == 0)
		seedrand();
.
948c
seedrand(void)
.
465,470d
34c
static void	seedrand(void);
.
## diffname port/devcons.c 1998/0808
## diff -e /n/emeliedump/1998/0731/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0808/sys/src/brazil/port/devcons.c
1076,1093d
884,887d
624,626d
535,536d
477,479d
453,459d
393,394c
	"user",		{Quser},	NAMELEN,	0666,
.
364d
246a
			splx(x);
.
245a
			x = spllo();
.
214a
	int x;
.
37,39d
35d
## diffname port/devcons.c 1998/0811
## diff -e /n/emeliedump/1998/0808/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0811/sys/src/brazil/port/devcons.c
717c
		print("consread %lux\n", c->qid.path);
.
## diffname port/devcons.c 1998/0825
## diff -e /n/emeliedump/1998/0811/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0825/sys/src/brazil/port/devcons.c
867c
		print("conswrite: %lud\n", c->qid.path);
.
693c
		sprint(tmp, "%lud/%lud memory %lud/%lud swap\n",
.
422c
	snprint(tmp, sizeof(tmp), "%*.0lud", size-1, val);
.
189c
	n = sprint(buf, "%s %lud: ", up->text, up->pid);
.
## diffname port/devcons.c 1998/0829
## diff -e /n/emeliedump/1998/0825/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0829/sys/src/brazil/port/devcons.c
967,968c
		if(anyhigher())
			sched();
.
903c
struct Rb
.
## diffname port/devcons.c 1998/0912
## diff -e /n/emeliedump/1998/0829/sys/src/brazil/port/devcons.c /n/emeliedump/1998/0912/sys/src/brazil/port/devcons.c
4d
## diffname port/devcons.c 1999/0110
## diff -e /n/emeliedump/1998/0912/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0110/sys/src/brazil/port/devcons.c
235a
			pagersummary();
.
## diffname port/devcons.c 1999/0130
## diff -e /n/emeliedump/1999/0110/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0130/sys/src/brazil/port/devcons.c
375c
	"fastclock",	{Qfastclock},	4*NUMSIZE,	0664,
.
## diffname port/devcons.c 1999/0205
## diff -e /n/emeliedump/1999/0130/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0205/sys/src/brazil/port/devcons.c
780c
		if(n<=0 || !iseve())
.
607c
		return readnum((ulong)offset, buf, n, boottime+TK2SEC(MACHP(0)->ticks), 12);
.
## diffname port/devcons.c 1999/0218
## diff -e /n/emeliedump/1999/0205/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0218/sys/src/brazil/port/devcons.c
784,786c
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		nsec = strtol(cbuf, 0, 0);
		nsec *= 1000000000LL;
		settod(nsec, 0, 0);
		break;

	case Qfastclock:
		if(n<=0 || !iseve())
			return 0;
		if(n >= sizeof(cbuf))
			n = sizeof(cbuf)-1;
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		f = strtovl(cbuf, 0, 0);
		if(f <= 0L)
			error(Ebadarg);
		tod.hz = f;
		break;

	case Qnsec:
		if(n<=0 || !iseve())
			return 0;
		if(n >= sizeof cbuf)
			n = sizeof cbuf - 1;
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		nsec = strtovl(cbuf, &a, 0);
		delta = strtovl(a, &a, 0);
		n = strtol(a, &a, 0);
		settod(nsec, delta, n);
.
733a
	vlong f, nsec, delta;
.
659a
	case Qtime:
		x = gettod();
		x /= 1000000000LL;
		i = x;
		return readnum((ulong)offset, buf, n, i, NUMSIZE);

.
658c
		x = gettod();
		x /= 1000000LL;
		i = x;
		return readnum((ulong)offset, buf, n, i, NUMSIZE);
.
656a
	case Qnsec:
		x = gettod();
		return readvlnum((ulong)offset, buf, n, x, 2*NUMSIZE);

.
629c
		readvlnum(0, tmp+2*NUMSIZE, 2*NUMSIZE, tod.hz, 2*NUMSIZE);
.
621c
		if(tod.hz == 0L)
			ticks = fastticks((uvlong*)&tod.hz);
		else
			ticks = fastticks(nil);
.
606,608d
515,516c
	vlong offset = off, x;
	uvlong ticks;
.
399c
	vlong x;
	int i;

	x = gettod();
	x /= 1000000000LL;
	i = x;
	return i;
.
395a
struct
{
	Lock;
	vlong	hz;		/* frequency of fast clock */
	vlong	last;		/* last reading of fast clock */
	vlong	off;		/* offset from epoch to last */
	vlong	lastns;		/* last return value from gettod */
	vlong	bias;		/* current bias */
	vlong	delta;		/* amount to add to bias each slow clock tick */
	int	n;		/* number of times to add in delta */
	int	i;		/* number of times we've added in delta */
} tod;

void
settod(vlong now, vlong delta, int n)
{
	ilock(&tod);
	tod.last = fastticks(nil);
	tod.off = now;
	tod.delta = delta;
	tod.n = n;
	tod.i = 0;
	iunlock(&tod);
}

// largest vlong devided by 10, 100, ...
static vlong vlmax[9] = {
	9223372036LL,
	92233720368LL,
	922337203685LL,
	9223372036854LL,
	92233720368547LL,
	922337203685477LL,
	9223372036854775LL,
	92233720368547758LL,
	922337203685477580LL,
};
static vlong vlmult[9] = {
	1000000000LL,
	100000000LL,
	10000000LL,
	1000000LL,
	100000LL,
	10000LL,
	1000LL,
	100LL,
	10LL,
};

vlong
gettod(void)
{
	vlong x;
	int i;

	ilock(&tod);
	if(tod.hz == 0)
		x = fastticks((uvlong*)&tod.hz);
	else
		x = fastticks(nil);
	x -= tod.last;

	/* convert to nanoseconds */
	for(i = 0; i < 9; i++)
		if(x < vlmax[i]){
			x *= vlmult[i];
			break;
		}
	x /= tod.hz;
	if(i > 0)
		x *= vlmult[9-i];

	/* convert to epoch */
	x += tod.off;

	/* add in bias */
	x += tod.bias;

	if(x < tod.lastns)
		x = tod.lastns;
	tod.lastns = x;
	iunlock(&tod);

	return x;
}

void
fixtod(void)
{
	ilock(&tod);
	if(tod.n > tod.i)
		tod.bias += tod.delta;
	iunlock(&tod);
}

.
380a
	"nsec",		{Qnsec},	NUMSIZE,	0664,
.
352a
	Qnsec,
.
## diffname port/devcons.c 1999/0219
## diff -e /n/emeliedump/1999/0218/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0219/sys/src/brazil/port/devcons.c
931c
		todset(nsec, delta, n);
.
918c
		fasthz = f;
		todsetfreq(f);
.
905c
		todset(nsec, 0, 0);
.
771c
		x = todget();
.
765c
		x = todget();
.
761c
		x = todget();
.
732c
		readvlnum(0, tmp+2*NUMSIZE, 2*NUMSIZE, fasthz, 2*NUMSIZE);
.
721,722c
		if(fasthz == 0L)
			ticks = fastticks((uvlong*)&fasthz);
.
551a
	todinit();
.
396,504d
29a
vlong	fasthz;
.
## diffname port/devcons.c 1999/0228
## diff -e /n/emeliedump/1999/0219/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0228/sys/src/brazil/port/devcons.c
402c
	i = 0;
	if(val > bilbil){
		y = val/bilbil;
		i += sprint(num+i, "%lud", y);
		val -= y*bilbil;
		y = val/billion;
		i += sprint(num+i, "%9.9lud", y);
		val -= y*billion;
		y = val;
		sprint(num+i,  "%9.9lud", y);
	} else if(val > billion){
		y = val/billion;
		i += sprint(num+i, "%lud", y);
		val -= y*billion;
		y = val;
		sprint(num+i, "%9.9lud", y);
	} else {
		y = val;
		sprint(num+i, "%lud", y);
	}
	snprint(tmp, sizeof(tmp), "%*s", size-1, num);
.
400a
	char num[64];
	ulong y;
	int i;
.
396a
uvlong billion = 1000000000ULL;
uvlong bilbil = 1000000000ULL*1000000000ULL;

//
//  this routine is a hack till we get 64 bit ops faster
//
.
## diffname port/devcons.c 1999/0509
## diff -e /n/emeliedump/1999/0228/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0509/sys/src/brazil/port/devcons.c
656a

	case Qtiming:
		k = 0;
		if(n >= 3*8){
			ticks = fastticks((uvlong*)&fasthz);
			vlong2le(cbuf+16, fasthz);
			vlong2le(cbuf+8, ticks);
			k += 2*8;
		} else if(n >= 2*8){
			ticks = fastticks(nil);
			vlong2le(cbuf+8, ticks);
			k += 8;
		}
		if(n >= 8){
			ticks = todget();
			vlong2le(cbuf, ticks);
			k += 8;
		}
		return k;
			
.
530a

uvlong order = 0x0001020304050607ULL;

void
vlong2le(char *t, vlong from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&order;
	for(i = 0; i < 8; i++)
		t[i] = f[o[i]];
}

.
393a
	"timing",	{Qtiming},	3*8,		0664,
.
342a
	Qtiming,
.
## diffname port/devcons.c 1999/0531
## diff -e /n/emeliedump/1999/0509/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0531/sys/src/brazil/port/devcons.c
730c
		x = todget(nil);
.
724c
		x = todget(nil);
.
720c
		x = todget(nil);
.
688,689c
			vlong2le(cbuf, nsec);
.
681,684d
679a
			k += 8;
		}
		if(n >= 2*8){
.
678d
676a
		nsec = todget(&ticks);
.
558c
	vlong ticks, nsec;
.
## diffname port/devcons.c 1999/0710
## diff -e /n/emeliedump/1999/0531/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0710/sys/src/brazil/port/devcons.c
967a

	case Qzero:
		return n;
.
886,887c
		nsec = strtoll(cbuf, &a, 0);
		delta = strtoll(a, &a, 0);
.
872c
		f = strtoll(cbuf, 0, 0);
.
788a
	case Qzero:
		memset(buf, 0, n);
		return n;

.
396a
	"zero",	{Qzero},	0,	0666,
.
366a
	Qzero,
.
236c
			mallocsummary();
.
## diffname port/devcons.c 1999/0711
## diff -e /n/emeliedump/1999/0710/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0711/sys/src/brazil/port/devcons.c
1165a
	return n;
}

static uvlong uvorder = 0x0001020304050607ULL;

static uchar*
le2vlong(vlong *to, uchar *f)
{
	uchar *t, *o;
	int i;

	t = (uchar*)to;
	o = (uchar*)&uvorder;
	for(i = 0; i < sizeof(vlong); i++)
		t[o[i]] = f[i];
	return f+sizeof(vlong);
}

static uchar*
vlong2le(uchar *t, vlong from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&uvorder;
	for(i = 0; i < sizeof(vlong); i++)
		t[i] = f[o[i]];
	return t+sizeof(vlong);
}

static long order = 0x00010203;

static uchar*
le2long(long *to, uchar *f)
{
	uchar *t, *o;
	int i;

	t = (uchar*)to;
	o = (uchar*)&order;
	for(i = 0; i < sizeof(long); i++)
		t[o[i]] = f[i];
	return f+sizeof(long);
}

static uchar*
long2le(uchar *t, long from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&order;
	for(i = 0; i < sizeof(long); i++)
		t[i] = f[o[i]];
	return t+sizeof(long);
}

char *Ebadtimectl = "bad time control";

/*
 *  like the old #c/time but with added info.  Return
 *
 *	secs	nanosecs	fastticks	fasthz
 */
static int
readtime(ulong off, char *buf, int n)
{
	vlong	nsec, ticks;
	long sec;
	char str[7*NUMSIZE+4];	// extra 4 bytes are null plus doprint
				// reserving space for a frigging UTF
				// char

	nsec = todget(&ticks);
	if(fasthz == 0LL)
		fastticks((uvlong*)&fasthz);
	sec = nsec/1000000000ULL;
	snprint(str, sizeof(str), "%*.0lud %*.0llud %*.0llud %*.0llud ",
		NUMSIZE-1, sec,
		2*NUMSIZE-1, nsec,
		2*NUMSIZE-1, ticks,
		2*NUMSIZE-1, fasthz);
	return readstr(off, buf, n, str);
}

/*
 *  set the time in seconds
 */
static int
writetime(char *buf, int n)
{
	char b[13];
	long i;
	vlong now;

	if(n >= sizeof(b))
		error(Ebadtimectl);
	strncpy(b, buf, n);
	b[n] = 0;
	i = strtol(b, 0, 0);
	if(i <= 0)
		error(Ebadtimectl);
	now = i*1000000000LL;
	todset(now, 0, 0);
	return n;
}

/*
 *  read binary time info.  all numbers are little endian.
 *  ticks and nsec are syncronized.
 */
static int
readbintime(char *buf, int n)
{
	int i;
	vlong nsec, ticks;
	uchar *b = (uchar*)buf;

	i = 0;
	if(fasthz == 0LL)
		fastticks((uvlong*)&fasthz);
	nsec = todget(&ticks);
	if(n >= 3*sizeof(uvlong)){
		vlong2le(b+2*sizeof(uvlong), fasthz);
		i += sizeof(uvlong);
	}
	if(n >= 2*sizeof(uvlong)){
		vlong2le(b+sizeof(uvlong), ticks);
		i += sizeof(uvlong);
	}
	if(n >= 8){
		vlong2le(b, nsec);
		i += sizeof(vlong);
	}
	return i;
}

/*
 *  set any of the following
 *	- time in nsec
 *	- nsec trim applied over some seconds
 *	- clock frequency
 */
static int
writebintime(char *buf, int n)
{
	uchar *p;
	vlong delta;
	long period;

	n--;
	p = (uchar*)buf + 1;
	switch(*buf){
	case 'n':
		if(n < sizeof(vlong))
			error(Ebadtimectl);
		le2vlong(&delta, p);
		todset(delta, 0, 0);
		break;
	case 'd':
		if(n < sizeof(vlong)+sizeof(long))
			error(Ebadtimectl);
		p = le2vlong(&delta, p);
		le2long(&period, p);
		todset(-1, delta, period);
		break;
	case 'f':
		if(n < sizeof(uvlong))
			error(Ebadtimectl);
		le2vlong(&fasthz, p);
		todsetfreq(fasthz);
		break;
	}
.
885,897d
871,883c
	case Qbintime:
		if(!iseve())
			error(Eperm);
		return writebintime(a, n);
.
860,869c
		if(!iseve())
			error(Eperm);
		return writetime(a, n);
.
813d
805d
719,737d
667,694d
661,665c
	case Qbintime:
		return readbintime(buf, n);
.
650,659c
	case Qtime:
		return readtime((ulong)offset, buf, n);
.
559,560c
	vlong offset = off;
.
535,549d
408,445d
401,406d
398c
	"zero",		{Qzero},	0,		0666,
.
395,396c
	"time",		{Qtime},	7*NUMSIZE,	0664,
.
384,385d
382d
379d
374c
	"bintime",	{Qbintime},	24,		0664,
.
354,355d
349,350d
343,344c
	Qbintime,
.
34a
static int	readtime(ulong, char*, int);
static int	readbintime(char*, int);
static int	writetime(char*, int);
static int	writebintime(char*, int);
.
## diffname port/devcons.c 1999/0712
## diff -e /n/emeliedump/1999/0711/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0712/sys/src/brazil/port/devcons.c
922c
			if(++rb.randomcount > 0)
.
## diffname port/devcons.c 1999/0713
## diff -e /n/emeliedump/1999/0712/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0713/sys/src/brazil/port/devcons.c
922c
			if(++rb.randomcount > 100000)
.
## diffname port/devcons.c 1999/0714
## diff -e /n/emeliedump/1999/0713/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0714/sys/src/brazil/port/devcons.c
819,821d
392c
	"zero",		{Qzero},	0,		0444,
.
## diffname port/devcons.c 1999/0720
## diff -e /n/emeliedump/1999/0714/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0720/sys/src/brazil/port/devcons.c
773a
		if(strncmp(a, "panic", 5) == 0)
			panic("/dev/reboot");
.
## diffname port/devcons.c 1999/0728
## diff -e /n/emeliedump/1999/0720/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0728/sys/src/brazil/port/devcons.c
1091,1093c
		VLNUMSIZE-1, nsec,
		VLNUMSIZE-1, ticks,
		VLNUMSIZE-1, fasthz);
.
390c
	"time",		{Qtime},	NUMSIZE+3*VLNUMSIZE,	0664,
.
368a
enum
{
	VLNUMSIZE=	22,
};

.
## diffname port/devcons.c 1999/0820
## diff -e /n/emeliedump/1999/0728/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0820/sys/src/brazil/port/devcons.c
245a
			return;
		case 'D':
			consdebug = rdb;
.
158a
int
iprint(char *fmt, ...)
{
	int n, s;
	va_list arg;
	char buf[PRINTSIZE];

	s = splhi();
	va_start(arg, fmt);
	n = doprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
	serialputs(buf, n);
	splx(s);

	return n;
}

.
## diffname port/devcons.c 1999/0825
## diff -e /n/emeliedump/1999/0820/sys/src/brazil/port/devcons.c /n/emeliedump/1999/0825/sys/src/brazil/port/devcons.c
195a
void
_assert(char *fmt)
{
	panic("assert failed: %s", fmt);
}

.
## diffname port/devcons.c 1999/1005
## diff -e /n/emeliedump/1999/0825/sys/src/brazil/port/devcons.c /n/emeliedump/1999/1005/sys/src/brazil/port/devcons.c
411a
	"newkernel",	{Qnewkernel},	0,	0000,	/* stupid hack -rsc */
.
380a
	Qnewkernel,
.
270,272d
210c
	if(up == nil || up->fgrp == nil)
.
187a
	serialputs(buf, n+1);
	rdb();
.
182a
	splhi();
.
170a
//	screenputs(buf, n);
.
150a
	if(noprint)
		return -1;

.
143a
int noprint;

.
8c
void	(*consdebug)(void) = rdb;
.
## diffname port/devcons.c 1999/1016
## diff -e /n/emeliedump/1999/1005/sys/src/brazil/port/devcons.c /n/emeliedump/1999/1016/sys/src/brazil/port/devcons.c
276,277c
			if(consdebug == nil)
				consdebug = rdb;
			else
				consdebug = nil;
			print("consdebug now 0x%lx\n", consdebug);
			return;
		case 'D':
			if(consdebug == nil)
				consdebug = rdb;
			consdebug();
.
196c
	if(consdebug)
		consdebug();
.
8c
void	(*consdebug)(void) = nil;
.
## diffname port/devcons.c 2000/0120
## diff -e /n/emeliedump/1999/1016/sys/src/brazil/port/devcons.c /n/emeliedump/2000/0120/sys/src/9/port/devcons.c
821a
		if(strncmp(a, "malloc", 6) == 0){	/* rsc bug */
			a = malloc(2);
			strcpy(a, "hi");
			free(a);
			a = malloc(2);
			strcpy(a, "helo");
			free(a);
			panic("not reached conswrite");
		}
.
## diffname port/devcons.c 2000/0316
## diff -e /n/emeliedump/2000/0120/sys/src/9/port/devcons.c /n/emeliedump/2000/0316/sys/src/9/port/devcons.c
428d
396d
## diffname port/devcons.c 2000/0522
## diff -e /n/emeliedump/2000/0316/sys/src/9/port/devcons.c /n/emeliedump/2000/0522/sys/src/9/port/devcons.c
281c
			print("consdebug now 0x%p\n", consdebug);
.
## diffname port/devcons.c 2000/0609
## diff -e /n/emeliedump/2000/0522/sys/src/9/port/devcons.c /n/emeliedump/2000/0609/sys/src/9/port/devcons.c
949,1065c
	return randn;
.
941,942c
	randn = randn*1103515245 + 12345 + MACHP(0)->ticks;
	return (randn>>16) % n;
.
939c
	if(randn == 0)
.
933c
	randomread((void*)&randn, sizeof(randn));
.
914,928c
static	ulong	randn;
.
32,33d
## diffname port/devcons.c 2000/0706
## diff -e /n/emeliedump/2000/0609/sys/src/9/port/devcons.c /n/emeliedump/2000/0706/sys/src/9/port/devcons.c
141a
char*
seprint(char *buf, char *e, char *fmt, ...)
{
	char *out;
	va_list arg;

	va_start(arg, fmt);
	out = doprint(buf, e, fmt, arg);
	va_end(arg);
	return out;
}

.
## diffname port/devcons.c 2000/0913
## diff -e /n/emeliedump/2000/0706/sys/src/9/port/devcons.c /n/emeliedump/2000/0913/sys/src/9/port/devcons.c
1016,1017c
	char str[7*NUMSIZE];
.
## diffname port/devcons.c 2000/1020
## diff -e /n/emeliedump/2000/0913/sys/src/9/port/devcons.c /n/emeliedump/2000/1020/sys/src/9/port/devcons.c
484a
	kbdputcinit();
.
382,390c
	kbd.ir = kbd.iw = kbd.istage;
	kbd.ie = kbd.istage + sizeof(kbd.istage);
	addclock0link(kbdputcclock);
.
379,380c
static void
kbdputcinit(void)
.
375,376c
	char *iw;

	/* this amortizes cost of qproduce */
	if(kbd.iw != kbd.ir){
		iw = kbd.iw;
		if(iw < kbd.ir){
			echo(kbd.ir, kbd.ie-kbd.ir);
			kbd.ir = kbd.istage;
		}
		echo(kbd.ir, iw-kbd.ir);
		kbd.ir = iw;
	}
.
372,373c
/*
 *  we save up input characters till clock time to reduce
 *  per character interrupt overhead.
 */
static void
kbdputcclock(void)
.
364,368c
	for(i = 0; i < n; i++){
		next = kbd.iw+1;
		if(next >= kbd.ie)
			next = kbd.istage;
		if(next == kbd.ir)
			break;
		*kbd.iw = buf[i];
		kbd.iw = next;
	}
	iunlock(&kbd.lockputc);
.
361a
	ilock(&kbd.lockputc);		/* just a mutex */
.
360a
	char *next;
.
358c
	int i, n;
.
335c
		qiwrite(printq, ebuf, p - ebuf);
.
333c
	if(p == ebuf)
		return;
	screenputs(ebuf, p - ebuf);
.
326,331c
	p = ebuf;
	e = ebuf + sizeof(ebuf) - 4;
	while(n-- > 0){
		if(p >= e){
			screenputs(ebuf, p - ebuf);
			if(printq)
				qiwrite(printq, ebuf, p - ebuf);
			p = ebuf;
		}
		x = *buf++;
		if(x == '\n'){
			*p++ = '\r';
			*p++ = '\n';
		} else if(x == 0x15){
			*p++ = '^';
			*p++ = 'U';
			*p++ = '\n';
		} else
			*p++ = x;
.
315,319c

	qproduce(kbdq, buf, n);
.
313a
		ctrlt = 0;
.
269,276c
		if(ctrlt != 2){
			ctrlt = 0;
			continue;
		}

		/* ^T escapes */
		switch(*p){
.
260,267c
	e = buf+n;
	for(p = buf; p < e; p++){
		switch(*p){
		case 0x10:	/* ^P */
			if(cpuserver && !kbd.ctlpoff){
				active.exiting = 1;
				return;
			}
			break;
		case 0x14:	/* ^T */
			ctrlt++;
			continue;
		}
.
258a
	char *e, *p;
	char ebuf[128];
.
254c
echo(char *buf, int n)
.
26a

	/* someplace to save up characters at interrupt time before dumping them in the q */
	Lock	lockputc;
	char	istage[128];
	char	*iw;
	char	*ir;
	char	*ie;
.
23d
## diffname port/devcons.c 2000/1021
## diff -e /n/emeliedump/2000/1020/sys/src/9/port/devcons.c /n/emeliedump/2000/1021/sys/src/9/port/devcons.c
360c
		echoprintq(buf, n);
.
333,358c
	echoscreen(buf, n);
.
266d
258a
static void
echoscreen(char *buf, int n)
{
	char *e, *p;
	char ebuf[128];
	int x;

	p = ebuf;
	e = ebuf + sizeof(ebuf) - 4;
	while(n-- > 0){
		if(p >= e){
			screenputs(ebuf, p - ebuf);
			p = ebuf;
		}
		x = *buf++;
		if(x == 0x15){
			*p++ = '^';
			*p++ = 'U';
			*p++ = '\n';
		} else
			*p++ = x;
	}
	if(p != ebuf)
		screenputs(ebuf, p - ebuf);
}

static void
echoprintq(char *buf, int n)
{
	char *e, *p;
	char ebuf[128];
	int x;

	p = ebuf;
	e = ebuf + sizeof(ebuf) - 4;
	while(n-- > 0){
		if(p >= e){
			qiwrite(printq, ebuf, p - ebuf);
			p = ebuf;
		}
		x = *buf++;
		if(x == '\n'){
			*p++ = '\r';
			*p++ = '\n';
		} else if(x == 0x15){
			*p++ = '^';
			*p++ = 'U';
			*p++ = '\n';
		} else
			*p++ = x;
	}
	if(p != ebuf)
		qiwrite(printq, ebuf, p - ebuf);
}


.
## diffname port/devcons.c 2000/1101
## diff -e /n/emeliedump/2000/1021/sys/src/9/port/devcons.c /n/emeliedump/2000/1101/sys/src/9/port/devcons.c
827c
			putstrn0(buf, bp, 1);
.
403c
	next = kbd.iw+1;
	if(next >= kbd.ie)
		next = kbd.istage;
	if(next != kbd.ir){
		*kbd.iw = ch;
		kbd.iw = next;
	}
	iunlock(&kbd.lockputc);
	return 0;
.
401c
	char *next;

	ilock(&kbd.lockputc);		/* just a mutex */
	if(ch == '\r' && !kbd.raw)
.
399c
kbdcr2nl(Queue*, int ch)
.
396c
 *  turn '\r' into '\n' before putting it into the queue.  we
 *  can't type runs on alternate consoles, so don't worry about it.
.
385,387d
322a
	if(kbd.raw){
		qproduce(kbdq, buf, n);
		return;
	}
.
216a
	putstrn(buf, n+1);
.
214d
98,108c
		if(t && !kbd.raw) {
			m = t-str;
			if(usewrite){
				qwrite(printq, str, m);
				qwrite(printq, "\r\n", 2);
			} else {
				qiwrite(printq, str, m);
				qiwrite(printq, "\r\n", 2);
			}
			n -= m+1;
			str = t+1;
.
79d
65c
		if(m->ticks - now >= HZ)
			break;
.
63a
	ulong now;

	now = m->ticks;
.
29c
	char	istage[512];
.
## diffname port/devcons.c 2000/1104
## diff -e /n/emeliedump/2000/1101/sys/src/9/port/devcons.c /n/emeliedump/2000/1104/sys/src/9/port/devcons.c
388d
373,375c
			//x = spllo();
			//procdump();
			//splx(x);
print("procdump temporarily disabled\n");
.
349a
		ctrlt = 0;
.
347d
344,345c
		if(ctrlt != 2)
.
## diffname port/devcons.c 2000/1105
## diff -e /n/emeliedump/2000/1104/sys/src/9/port/devcons.c /n/emeliedump/2000/1105/sys/src/9/port/devcons.c
400c
 *  can't type runes on alternate consoles, so don't worry about it.
.
390a
	if(kbd.raw)
		return;
.
334c
			if(cpuserver && !kbd.ctlpoff && !kbd.raw){
.
326,329d
## diffname port/devcons.c 2000/1106
## diff -e /n/emeliedump/2000/1105/sys/src/9/port/devcons.c /n/emeliedump/2000/1106/sys/src/9/port/devcons.c
368,371c
			x = spllo();
			procdump();
			splx(x);
.
## diffname port/devcons.c 2000/1207
## diff -e /n/emeliedump/2000/1106/sys/src/9/port/devcons.c /n/emeliedump/2000/1207/sys/src/9/port/devcons.c
330c
			if(cpuserver && !kbd.ctlpoff){
.
## diffname port/devcons.c 2000/1214
## diff -e /n/emeliedump/2000/1207/sys/src/9/port/devcons.c /n/emeliedump/2000/1214/sys/src/9/port/devcons.c
1100d
## diffname port/devcons.c 2001/0115
## diff -e /n/emeliedump/2000/1214/sys/src/9/port/devcons.c /n/emeliedump/2001/0115/sys/src/9/port/devcons.c
396,397c
 *  turn '\r' into '\n' before putting it into the queue.
.
317d
27c
	/* a place to save up characters at interrupt time before dumping them in the queue */
.
24d
## diffname port/devcons.c 2001/0217
## diff -e /n/emeliedump/2001/0115/sys/src/9/port/devcons.c /n/emeliedump/2001/0217/sys/src/9/port/devcons.c
334a
			if(ctrlt > 2)
				ctrlt = 2;
.
## diffname port/devcons.c 2001/0316
## diff -e /n/emeliedump/2001/0217/sys/src/9/port/devcons.c /n/emeliedump/2001/0316/sys/src/9/port/devcons.c
860a
				qunlock(&kbd);
.
858a
				qlock(&kbd);
.
662,666d
## diffname port/devcons.c 2001/0430
## diff -e /n/emeliedump/2001/0316/sys/src/9/port/devcons.c /n/emeliedump/2001/0430/sys/src/9/port/devcons.c
428a
	if(kbd.ir == nil)
		return 0;		/* in case we're not inited yet */
	
.
## diffname port/devcons.c 2001/0527
## diff -e /n/emeliedump/2001/0430/sys/src/9/port/devcons.c /n/emeliedump/2001/0527/sys/src/9/port/devcons.c
992d
981c
	snprint(buf, sizeof buf, f, conffile);
.
979c
	char buf[64];
.
970c
		print("conswrite: 0x%llux\n", c->qid.path);
.
963,966c
		strncpy(buf, a, n);
		buf[n] = 0;
		if(buf[n-1] == '\n')
			buf[n-1] = 0;
		kstrdup(&sysname, buf);
.
961c
		if(n <= 0 || n >= sizeof buf)
.
893,901d
825c
	switch((ulong)c->qid.path){
.
808c
		print("consread 0x%llux\n", c->qid.path);
.
806a
	case Qosversion:
		n = readstr((ulong)offset, buf, n, "2000");
		return n;

.
786a
		if(sysname == nil)
			return 0;
.
729,737d
710a
	case Qkprint:
		return qread(kprintoq, buf, n);

.
639c
	switch((ulong)c->qid.path){
.
619,622c

	/* close of kprint allows other opens */
	case Qkprint:
		if(c->flag & COPEN){
			unlock(&kprintinuse);
			qhangup(kprintoq, nil);
		}
		break;
.
610d
608a
	switch((ulong)c->qid.path){
.
603c
	return c;
.
601a

	case Qkprint:
		if(!canlock(&kprintinuse)){
			c->flag &= ~COPEN;
			error(Einuse);
		}
		if(kprintoq == nil){
			kprintoq = qopen(8*1024, -1, 0, 0);
			if(kprintoq == nil){
				c->flag &= ~COPEN;
				error(Enomem);
			}
			qnoblock(kprintoq, 1);
		}else
			qreopen(kprintoq);
		break;
.
596,597d
593,594c
	c->aux = nil;
	c = devopen(c, omode, consdir, nelem(consdir), devgen);
	switch((ulong)c->qid.path){
.
587c
	return devstat(c, dp, n, consdir, nelem(consdir), devgen);
.
584,585c
static int
consstat(Chan *c, uchar *dp, int n)
.
581c
	return devwalk(c, nc, name,nname, consdir, nelem(consdir), devgen);
.
578,579c
static Walkqid*
conswalk(Chan *c, Chan *nc, char **name, int nname)
.
531c
	"user",		{Quser},	0,	0666,
.
521a
	"osversion",	{Qosversion},	0,		0444,
.
520a
	"kprint",		{Qkprint, 0, QTEXCL},	0,	DMEXCL|0440,
.
519c
	"hostowner",	{Qhostowner},	0,	0664,
.
510,512c
	".",	{Qdir, 0, QTDIR},	0,		DMDIR|0555,
.
490a
	Qosversion,
.
487a
	Qkprint,
.
479,481d
388,390c
	if(screenputs != nil)
		echoscreen(buf, n);
	if(serialoq)
		echoserialoq(buf, n);
.
313c
		qiwrite(serialoq, ebuf, p - ebuf);
.
298c
			qiwrite(serialoq, ebuf, p - ebuf);
.
288c
echoserialoq(char *buf, int n)
.
213c
	if(serialputs != nil)
		serialputs(buf, n+1);
.
206a
	kprintoq = nil;	/* don't try to write to /dev/kprint */

	if(panicking)
		for(;;);
	panicking = 1;

.
205a
	static int panicking;
.
193,194c
	if(screenputs != nil)
		screenputs(buf, n);
	if(serialputs != nil)
		serialputs(buf, n);
.
115c
				qiwrite(serialoq, str, n);
.
113c
				qwrite(serialoq, str, n);
.
106,107c
				qiwrite(serialoq, str, m);
				qiwrite(serialoq, "\r\n", 2);
.
103,104c
				qwrite(serialoq, str, m);
				qwrite(serialoq, "\r\n", 2);
.
96a
	}
.
95c
	if(kprintoq != nil && !qisclosed(kprintoq)){
		if(usewrite)
			qwrite(kprintoq, str, n);
		else
			qiwrite(kprintoq, str, n);
	}else if(screenputs != nil)
		screenputs(str, n);

	if(serialoq == nil){
		if(serialputs != nil)
			serialputs(str, n);
.
84,91c
	 *  if someone is reading /dev/kprint and the message
	 *  is from the kernel (as opposed to from conswrite),
	 *  put the message there.
	 *  if not and there's an attached bit mapped display,
	 *  put the message there.
	 *
.
55,56c
	if(serialoq)
		return qlen(serialoq) > 0;
.
34c
char	*sysname;
.
12c
Queue*	serialoq;			/* serial console output */
Queue*	kprintoq;			/* console output, for /dev/kprint */
Lock		kprintinuse;		/* test and set whether /dev/kprint is open */
.
8a
void	(*screenputs)(char*, int) = nil;
void	(*serialputs)(char*, int) = nil;
.
7a
#include	<auth.h>

.
## diffname port/devcons.c 2001/0819
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/devcons.c /n/emeliedump/2001/0819/sys/src/9/port/devcons.c
244c
//	dumpstack();
.
## diffname port/devcons.c 2001/0820
## diff -e /n/emeliedump/2001/0819/sys/src/9/port/devcons.c /n/emeliedump/2001/0820/sys/src/9/port/devcons.c
244c
	dumpstack();
.
## diffname port/devcons.c 2001/0904
## diff -e /n/emeliedump/2001/0820/sys/src/9/port/devcons.c /n/emeliedump/2001/0904/sys/src/9/port/devcons.c
848c
		snprint(tmp, sizeof tmp, "2000 %d", qiomaxatomic);
		n = readstr((ulong)offset, buf, n, tmp);
.
## diffname port/devcons.c 2001/0925
## diff -e /n/emeliedump/2001/0904/sys/src/9/port/devcons.c /n/emeliedump/2001/0925/sys/src/9/port/devcons.c
8c
#include	<authsrv.h>
.
## diffname port/devcons.c 2001/0929
## diff -e /n/emeliedump/2001/0925/sys/src/9/port/devcons.c /n/emeliedump/2001/0929/sys/src/9/port/devcons.c
925,927d
773,775d
543d
510d
## diffname port/devcons.c 2001/1111
## diff -e /n/emeliedump/2001/0929/sys/src/9/port/devcons.c /n/emeliedump/2001/1111/sys/src/9/port/devcons.c
592c
	addclock0link(kbdputcclock);
.
495,502d
38c
} kbd = {
	.iw	= kbd.istage,
	.ir	= kbd.istage,
	.ie	= kbd.istage + sizeof(kbd.istage),
};
.
16,18c
Queue*	serialoq;		/* serial console output */
Queue*	kprintoq;		/* console output, for /dev/kprint */
Lock	kprintinuse;		/* test and set whether /dev/kprint is open */
.
## diffname port/devcons.c 2001/1118
## diff -e /n/emeliedump/2001/1111/sys/src/9/port/devcons.c /n/emeliedump/2001/1118/sys/src/9/port/devcons.c
831a
		poperror();
.
829a
		if(waserror()){
			free(b);
			nexterror();
		}
.
805a
		poperror();
.
803a
		if(waserror()){
			free(b);
			nexterror();
		}
.
## diffname port/devcons.c 2001/1207
## diff -e /n/emeliedump/2001/1118/sys/src/9/port/devcons.c /n/emeliedump/2001/1207/sys/src/9/port/devcons.c
849c
		snprint(tmp, sizeof tmp, "2000");
.
634a
		c->iounit = qiomaxatomic;
.
## diffname port/devcons.c 2001/1231
## diff -e /n/emeliedump/2001/1207/sys/src/9/port/devcons.c /n/emeliedump/2001/1231/sys/src/9/port/devcons.c
544c
	"random",	{Qrandom},	0,		0444,
.
535c
	"drivers",	{Qdrivers},	0,		0444,
.
## diffname port/devcons.c 2002/0109
## diff -e /n/emeliedump/2001/1231/sys/src/9/port/devcons.c /n/emeliedump/2002/0109/sys/src/9/port/devcons.c
1026a
	devshutdown,
.
1012,1020d
957a
		}
		poperror();
		free(cb);
.
947,956c
		ct = lookupcmd(cb, reboottbl, nelem(reboottbl));
		switch(ct->index) {
		case CMreboot:
			rebootcmd(cb->nf-1, cb->f+1);
			break;
		case CMpanic:
.
943,945c
		cb = parsecmd(a, n);

		if(waserror()) {
			free(cb);
			nexterror();
.
870a
	Cmdbuf *cb;
	Cmdtab *ct;
.
52a
enum
{
	CMreboot,
	CMpanic,
};

Cmdtab reboottbl[] =
{
	CMreboot,	"reboot",	0,
	CMpanic,	"panic",	0,
};

.
## diffname port/devcons.c 2002/0115
## diff -e /n/emeliedump/2002/0109/sys/src/9/port/devcons.c /n/emeliedump/2002/0115/sys/src/9/port/devcons.c
106,107c
	 *  if someone is reading /dev/kprint,
.
## diffname port/devcons.c 2002/0217
## diff -e /n/emeliedump/2002/0115/sys/src/9/port/devcons.c /n/emeliedump/2002/0217/sys/src/9/port/devcons.c
286c
	n = vseprint(buf+n, buf+sizeof(buf), fmt, arg) - buf;
.
249c
	n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf;
.
221c
	n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf;
.
205c
	n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf;
.
157,191d
## diffname port/devcons.c 2002/0402
## diff -e /n/emeliedump/2002/0217/sys/src/9/port/devcons.c /n/emeliedump/2002/0402/sys/src/9/port/devcons.c
634c
			kprintinuse = 0;
.
598c
		if(tas(&kprintinuse) != 0){
.
18c
ulong	kprintinuse;		/* test and set whether /dev/kprint is open */
.
## diffname port/devcons.c 2002/0404
## diff -e /n/emeliedump/2002/0402/sys/src/9/port/devcons.c /n/emeliedump/2002/0404/sys/src/9/port/devcons.c
927c
		ct = lookupcmd(cb, rebootmsg, nelem(rebootmsg));
.
386c
			return;
.
383c
			return;
.
379c
			return;
#ifdef RSC
case 'Q':
{
extern void dumpschedlog(void);
dumpschedlog();
return;
}
#endif
.
359c
			return;
.
353c
			return;
.
350a
		case 'S':
			x = splhi();
			dumpstack();
			procdump();
			splx(x);
			return;
.
188c
	if(screenputs != nil && iprintscreenputs)
.
59c
Cmdtab rebootmsg[] =
.
18a
int		iprintscreenputs = 1;
.
## diffname port/devcons.c 2002/0410
## diff -e /n/emeliedump/2002/0404/sys/src/9/port/devcons.c /n/emeliedump/2002/0410/sys/src/9/port/devcons.c
387,394d
## diffname port/devcons.c 2002/0412
## diff -e /n/emeliedump/2002/0410/sys/src/9/port/devcons.c /n/emeliedump/2002/0412/sys/src/9/port/devcons.c
221c
		(*consdebug)();
.
218,219c
	uartputs(buf, n+1);
.
191,192c
	uartputs(buf, n);
.
124,125c
		uartputs(str, n);
.
12d
## diffname port/devcons.c 2002/0711
## diff -e /n/emeliedump/2002/0412/sys/src/9/port/devcons.c /n/emeliedump/2002/0711/sys/src/9/port/devcons.c
606c
			kprintoq = qopen(8*1024, Qcoalesce, 0, 0);
.
## diffname port/devcons.c 2002/0816
## diff -e /n/emeliedump/2002/0711/sys/src/9/port/devcons.c /n/emeliedump/2002/0816/sys/src/9/port/devcons.c
68c
	lineq = qopen(2*1024, 0, nil, nil);
.
## diffname port/devcons.c 2002/0821
## diff -e /n/emeliedump/2002/0816/sys/src/9/port/devcons.c /n/emeliedump/2002/0821/sys/src/9/port/devcons.c
779a
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE, dutycycle(mp), NUMSIZE);
.
760c
		b = smalloc(conf.nmach*(NUMSIZE*9+1) + 1);	/* +1 for NUL */
.
643a
/*
 *  calculate duty cycle for a processor (100-(%time in idlehands()))
 */
static int
dutycycle(Mach *mp)
{
	static ulong ticks;
	uvlong hz;
	int x;

	if(ticks == 0){
		fastticks(&hz);
		ticks = hz/HZ;
	}
	x = ticks - mp->avginidle;
	if(x < 0)
		return 0;
	x *= 100;
	return x/ticks;
}

.
## diffname port/devcons.c 2002/0822
## diff -e /n/emeliedump/2002/0821/sys/src/9/port/devcons.c /n/emeliedump/2002/0822/sys/src/9/port/devcons.c
802c
				readnum(0, bp, NUMSIZE,
					(mp->perf.avg_inidle*100)/mp->perf.period,
					NUMSIZE);
				bp += NUMSIZE;
				readnum(0, bp, NUMSIZE,
					(mp->perf.avg_inintr*100)/mp->perf.period,
					NUMSIZE);
.
781c
		b = smalloc(conf.nmach*(NUMSIZE*11+1) + 1);	/* +1 for NUL */
.
644,664d
## diffname port/devcons.c 2002/0924
## diff -e /n/emeliedump/2002/0822/sys/src/9/port/devcons.c /n/emeliedump/2002/0924/sys/src/9/port/devcons.c
384,385c
			killbig();
.
## diffname port/devcons.c 2002/0925
## diff -e /n/emeliedump/2002/0924/sys/src/9/port/devcons.c /n/emeliedump/2002/0925/sys/src/9/port/devcons.c
201d
19a
int		panicking;

.
## diffname port/devcons.c 2002/0928
## diff -e /n/emeliedump/2002/0925/sys/src/9/port/devcons.c /n/emeliedump/2002/0928/sys/src/9/port/devcons.c
567c
	/*
	 * at 115200 baud, the 1024 char buffer takes 56 ms to process,
	 * processing it every 22 ms should be fine
	 */
	addclock0link(kbdputcclock, 22);
.
36c
	char	istage[1024];
.
## diffname port/devcons.c 2003/0305
## diff -e /n/emeliedump/2002/0928/sys/src/9/port/devcons.c /n/emeliedump/2003/0305/sys/src/9/port/devcons.c
20c
int	panicking;
.
18c
int	iprintscreenputs = 1;
.
## diffname port/devcons.c 2003/0403
## diff -e /n/emeliedump/2003/0305/sys/src/9/port/devcons.c /n/emeliedump/2003/0403/sys/src/9/port/devcons.c
660a

.
465d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.