~kris/9p

9hist

94fab7720a0f9bb7462ae58f0d1794e231ed5a64 — David du Colombier 34 years ago 585d887
Plan 9 from Bell Labs 1991-12-11
11 files changed, 124 insertions(+), 74 deletions(-)

M pc/dat.h
M pc/devhard.c
M pc/devrtc.c
M pc/kbd.c
M pc/l.s
M pc/main.c
M pc/mmu.c
M pc/vga.c
M port/devcons.c
M port/portfns.h
M ss/screen.c
M pc/dat.h => pc/dat.h +0 -1
@@ 181,7 181,6 @@ struct Segdesc
	ulong	d1;
};


struct
{
	Lock;

M pc/devhard.c => pc/devhard.c +16 -10
@@ 226,9 226,21 @@ hardattach(char *spec)
			dp->bytes = 512;
			hardsetbuf(dp, 1);
			hardident(dp);
			dp->cyl = dp->id.lcyls;
			dp->heads = dp->id.lheads;
			dp->sectors = dp->id.ls2t;
			switch(dp->id.magic){
			case 0xA5A:	/* conner drive on the AT&T NSX (safari) */
				dp->cyl = dp->id.lcyls;
				dp->heads = dp->id.lheads;
				dp->sectors = dp->id.ls2t;
				break;
			case 0x324A:	/* hard drive on the AT&T 6386 */
				dp->cyl = dp->id.lcyls - 4;
				dp->heads = dp->id.lheads;
				dp->sectors = dp->id.ls2t - 1;
				break;
			default:
				print("unknown hard disk type\n");
				errors("unknown hard disk type");
			}
			dp->bytes = 512;
			dp->cap = dp->bytes * dp->cyl * dp->heads * dp->sectors;
			dp->online = 1;


@@ 542,7 554,6 @@ hardident(Drive *dp)
	cp = dp->cp;
	qlock(cp);
	if(waserror()){
print("waserror in hardident\n");
		qunlock(cp);
		nexterror();
	}


@@ 557,16 568,11 @@ print("waserror in hardident\n");
	outb(cp->pbase+Pcmd, Cident);
	sleep(&cp->r, cmddone, cp);
	if(cp->status & Serr){
print("bad disk magic\n");
		print("bad disk ident status\n");
		errors("disk I/O error");
	}
	memmove(&dp->id, cp->buf, dp->bytes);

	if(dp->id.magic != 0xA5A){
print("bad disk magic\n");
		errors("bad disk magic");
	}

	poperror();
	qunlock(cp);
}

M pc/devrtc.c => pc/devrtc.c +4 -0
@@ 6,6 6,10 @@
#include	"errno.h"
#include	"devtab.h"

/*
 *  real time clock and non-volatile ram
 */

enum {
	Paddr=		0x70,	/* address port */
	Pdata=		0x71,	/* data port */

M pc/kbd.c => pc/kbd.c +30 -13
@@ 191,7 191,7 @@ i8042reset(void)
	outready();
	outb(Cmd, 0xD1);
	outready();
	outb(Data, 0xDE);
	outb(Data, 0x0);
	outready();
}



@@ 299,13 299,14 @@ middle(int newval)
int
kbdintr0(void)
{
	int s, c, nc;
	int s, c, i, nk, nc;
	static int esc1, esc2;
	static int shift;
	static int caps;
	static int ctl;
	static int num;
	static int lstate, k1, k2;
	static int lstate;
	static uchar kc[5];
	int keyup;

	/*


@@ 343,7 344,6 @@ kbdintr0(void)
	c &= 0x7f;
	if(c > sizeof kbtab){
		print("unknown key %ux\n", c|keyup);
		kbdputc(&kbdq, k1);
		return 0;
	}



@@ 390,21 390,38 @@ kbdintr0(void)
			c &= 0x1f;
		switch(lstate){
		case 1:
			k1 = c;
			kc[0] = c;
			lstate = 2;
			return 0;
			if(c == 'X')
				lstate = 3;
			break;
		case 2:
			k2 = c;
			kc[1] = c;
			c = latin1(kc);
			nk = 2;
		putit:
			lstate = 0;
			c = latin1(k1, k2);
			if(c == 0){
				kbdputc(&kbdq, k1);
				c = k2;
			}
			/* fall through */
			if(c != -1)
				kbdputc(&kbdq, c);
			else for(i=0; i<nk; i++)
				kbdputc(&kbdq, kc[i]);
			break;
		case 3:
		case 4:
		case 5:
			kc[lstate-2] = c;
			lstate++;
			break;
		case 6:
			kc[4] = c;
			c = unicode(kc);
			nk = 5;
			goto putit;
		default:
			kbdputc(&kbdq, c);
			break;
		}
		return 0;
	} else {
		switch(c){
		case Caps:

M pc/l.s => pc/l.s +13 -9
@@ 27,9 27,7 @@ TEXT	origin(SB),$0
	MOVW	BX,ES
	MOVL	$0,SI
	MOVL	SI,DI
	CLD
	REP
	MOVSL
	CLD; REP; MOVSL
/*	JMPFAR	0X8000:$lowcore(SB) /**/
	 BYTE	$0xEA
	 WORD	$lowcore(SB)


@@ 95,8 93,7 @@ TEXT	mode32bit(SB),$0
	LEAL	end-KZERO(SB),CX
	SUBL	DI,CX
	SHRL	$2,CX
	REP
	MOVSL
	CLD; REP; MOVSL

	/*
	 *  make a bottom level page table page that maps the first


@@ 158,6 155,13 @@ TEXT	tokzero(SB),$0
	ADDL	$(MACHSIZE-4),SP	/* start stack under machine struct */
	MOVL	$0, u(SB)

	/*
	 *  clear flags
	 */
	MOVL	$0,AX
	PUSHL	AX
	POPFL

	CALL	main(SB)

loop:


@@ 220,8 224,7 @@ TEXT	inss(SB),$0
	MOVL	p+0(FP),DX
	MOVL	a+4(FP),DI
	MOVL	c+8(FP),CX
	CLD
	REP; OP16; INSL
	CLD; REP; OP16; INSL
	RET

/*


@@ 231,8 234,7 @@ TEXT	outss(SB),$0
	MOVL	p+0(FP),DX
	MOVL	a+4(FP),SI
	MOVL	c+8(FP),CX
	CLD
	REP; OP16; OUTSL
	CLD; REP; OP16; OUTSL
	RET

/*


@@ 558,6 560,8 @@ TEXT	touser(SB),$0
	MOVL	$(UDSEL),AX
	MOVW	AX,DS
	MOVW	AX,ES
	MOVW	AX,GS
	MOVW	AX,FS
	IRETL

/*

M pc/main.c => pc/main.c +2 -2
@@ 21,7 21,7 @@ main(void)
	confinit();
	screeninit();
	printinit();
	print("%ludK bytes of physical memory\n", (conf.base1 + conf.npage1*BY2PG)/1024);
	print("\n\n%ludK bytes of physical memory\n", (conf.base1 + conf.npage1*BY2PG)/1024);
	mmuinit();
	trapinit();
	mathinit();


@@ 389,7 389,7 @@ exit(void)
		headreset();		/* via headland chip */
		break;
	case At:
		i8042reset();			/* via keyboard controller */
		i8042reset();		/* via keyboard controller */
		break;
	}
}

M pc/mmu.c => pc/mmu.c +1 -0
@@ 160,6 160,7 @@ mmuinit(void)
	/*
	 *  set up the task segment
	 */
	memset(&tss, 0, sizeof(tss));
	tss.sp0 = USERADDR+BY2PG;
	tss.ss0 = KDSEL;
	tss.cr3 = ktoppg.pa;

M pc/vga.c => pc/vga.c +4 -4
@@ 52,8 52,8 @@ enum
	CRX=		0x3D4,		/* index to crt registers */
	CR=		0x3D5,		/* crt registers */
	 Cvre=		 0x11,		/*  vertical retrace end */
	ARX=		0x3C0,		/* index to attribute registers */
	AR=		0x3C1,		/* attribute registers */
	ARW=		0x3C0,		/* attribute registers (writing) */
	ARR=		0x3C1,		/* attribute registers (reading) */
};

typedef struct VGAmode	VGAmode;


@@ 113,8 113,8 @@ void
arout(int reg, int val)
{
	inb(0x3DA);
	outb(ARX, reg | 0x20);
	outb(AR, val);
	outb(ARW, reg | 0x20);
	outb(ARW, val);
}
void
crout(int reg, int val)

M port/devcons.c => port/devcons.c +7 -7
@@ 336,25 336,25 @@ enum{
};

Dirtab consdir[]={
	"cons",		{Qcons},	0,		0666,
	"cons",		{Qcons},	0,		0660,
	"cputime",	{Qcputime},	6*NUMSIZE,	0444,
	"time",		{Qtime},	NUMSIZE,	0666,
	"time",		{Qtime},	NUMSIZE,	0664,
	"clock",	{Qclock},	2*NUMSIZE,	0444,
	"msec",		{Qmsec},	NUMSIZE,	0444,
	"lights",	{Qlights},	0,		0222,
	"noise",	{Qnoise},	0,		0222,
	"lights",	{Qlights},	0,		0220,
	"noise",	{Qnoise},	0,		0220,
	"null",		{Qnull},	0,		0666,
	"pgrpid",	{Qpgrpid},	NUMSIZE,	0444,
	"pid",		{Qpid},		NUMSIZE,	0444,
	"ppid",		{Qppid},	NUMSIZE,	0444,
	"rcons",	{Qrcons},	0,		0666,
	"rcons",	{Qrcons},	0,		0660,
	"user",		{Quser},	0,		0666,
	"chal",		{Qchal},	8,		0666,
	"crypt",	{Qcrypt},	0,		0666,
	"key",		{Qkey},		DESKEYLEN,	0222,
	"klog",		{Qklog},	0,		0444,
	"sysstat",	{Qsysstat},	0,		0666,
	"swap",		{Qswap},	0,		0666,
	"swap",		{Qswap},	0,		0664,
};

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


@@ 438,7 438,7 @@ consopen(Chan *c, int omode)

	switch(c->qid.path){
	case Qrcons:
		if(conf.cntrlp)
		if(strcmp(u->p->user, eve) != 0)
			error(Eperm);
		if(incref(&raw) == 1){
			lock(&lineq);

M port/portfns.h => port/portfns.h +2 -1
@@ 106,7 106,7 @@ int	kprint(char*, ...);
void	kproc(char*, void(*)(void*), void*);
void	ksetenv(char*, char*);
void	ksetterm(char*);
int	latin1(int, int);
long	latin1(uchar*);
void	lights(int);
void	lock(Lock*);
void	lockinit(void);


@@ 238,6 238,7 @@ void	uncachepage(Page*);
long	unionread(Chan*, void*, long);
void	unlock(Lock*);
void	unlockpage(Page*);
long	unicode(uchar*);
void	userinit(void);
void	validaddr(ulong, ulong, int);
void*	vmemchr(void*, int, int);

M ss/screen.c => ss/screen.c +45 -27
@@ 244,66 244,84 @@ kbdstate(IOQ *q, int c)
	static caps = 0;
	static long startclick;
	static int repeatc;
	static int kbdstate, k1, k2;
	int tc;
	static int lstate;
	static uchar kc[4];
	uchar ch, code;
	int i, nk;

	tc = kbdmap[shift][c&0x7F];
	ch = kbdmap[shift][c&0x7F];
	if(c==0x7F){	/* all keys up */
    norepeat:
		kbdrepeat(0);
		return;
	}
	if(tc == 0xFF)	/* shouldn't happen; ignore */
	if(ch == 0xFF)	/* shouldn't happen; ignore */
		return;
	if(c & 0x80){	/* key went up */
		if(tc == 0xF0){		/* control */
		if(ch == 0xF0){		/* control */
			shift &= ~2;
			goto norepeat;
		}
		if(tc == 0xF1){	/* shift */
		if(ch == 0xF1){	/* shift */
			shift &= ~1;
			goto norepeat;
		}
		if(tc == 0xF2){	/* caps */
		if(ch == 0xF2){	/* caps */
			goto norepeat;
		}
		goto norepeat;
	}
	if(tc == 0xF0){		/* control */
	if(ch == 0xF0){		/* control */
		shift |= 2;
		goto norepeat;
	}
	if(tc==0xF1){	/* shift */
	if(ch==0xF1){	/* shift */
		shift |= 1;
		goto norepeat;
	}
	if(tc==0xF2){	/* caps */
	if(ch==0xF2){	/* caps */
		caps ^= 1;
		goto norepeat;
	}
	if(caps && 'a'<=tc && tc<='z')
		tc |= ' ';
	repeatc = tc;
	if(caps && 'a'<=ch && ch<='z')
		ch |= ' ';
	repeatc = ch;
	kbdrepeat(1);
	if(tc == 0xB6)	/* Compose */
		kbdstate = 1;
	if(ch == 0xB6)	/* Compose */
		lstate = 1;
	else{
		switch(kbdstate){
		switch(lstate){
		case 1:
			k1 = tc;
			kbdstate = 2;
			kc[0] = ch;
			lstate = 2;
			if(ch == 'X')
				lstate = 3;
			break;
		case 2:
			k2 = tc;
			tc = latin1(k1, k2);
			if(c == 0){
				kbdputc(&kbdq, k1);
				tc = k2;
			}
			/* fall through */
			kc[1] = ch;
			c = latin1(kc);
			nk = 2;
		putit:
			lstate = 0;
			if(c != -1)
				kbdputc(&kbdq, c);
			else for(i=0; i<nk; i++)
				kbdputc(&kbdq, kc[i]);
			break;
		case 3:
		case 4:
		case 5:
			kc[lstate-2] = ch;
			lstate++;
			break;
		case 6:
			kc[4] = ch;
			c = unicode(kc);
			nk = 5;
			goto putit;
		default:
			kbdstate = 0;
			kbdputc(&kbdq, tc);
			kbdputc(&kbdq, ch);
			break;
		}
	}
}