~kris/9p

9hist

272d8c89c21b85e29b56ece28df7532556858576 — David du Colombier 32 years ago 8ad30ad
Plan 9 from Bell Labs 1994-05-07
5 files changed, 58 insertions(+), 82 deletions(-)

M pc/clock.c
M pc/devvga.c
M port/portdat.h
M port/qio.c
M port/taslock.c
M pc/clock.c => pc/clock.c +11 -10
@@ 53,7 53,6 @@ clock(Ureg *ur, void *arg)
	m->ticks++;

	checkalarms();
	mouseclock();
	hardclock();
	uartclock();



@@ 70,16 69,18 @@ clock(Ureg *ur, void *arg)
	nrun = (nrdy+nrun)*1000;
	MACHP(0)->load = (MACHP(0)->load*19+nrun)/20;

	if(up == 0 || (ur->cs&0xffff) != UESEL || up->state != Running)
		return;

	if(anyready())
		sched();
	if(up && (ur->cs&0xffff) == UESEL && up->state == Running){
		if(anyready())
			sched();
	
		/* user profiling clock */
		spllo();		/* in case we fault */
		(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
		splhi();
	}

	/* user profiling clock */
	spllo();		/* in case we fault */
	(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);
	splhi();
	/* last because it could spllo() */
	mouseclock();
}

/*

M pc/devvga.c => pc/devvga.c +30 -57
@@ 132,9 132,7 @@ static void	cgascreenputc(int);
static void	cgascreenputs(char*, int);
static void	screenputc(char*);
static void	scroll(void);
static ulong	x3to32(uchar);
static ulong	x6to32(uchar);
static void	greyscale(void);
static ulong	xnto32(uchar, int);
static void	workinit(Bitmap*, int, int);
extern void	screenload(Rectangle, uchar*, int, int, int);
extern void	screenunload(Rectangle, uchar*, int, int, int);


@@ 309,8 307,6 @@ vgawrite(Chan *c, void *buf, long n, ulong offset)
		cbuf[n] = 0;
		if(strncmp(cbuf, "hwcursor", 8) == 0)
			hwcursor = 1;
		else if(strncmp(cbuf, "grey", 4) == 0)
			greyscale();
		break;
	case Qvgasize:
		if(offset != 0 || n >= sizeof(cbuf))


@@ 591,13 587,16 @@ setscreen(int maxx, int maxy, int ldepth)
	switch(ldepth){
	case 3:
		for(i = 0; i < 256; i++)
			setcolor(i, x3to32(i>>5), x3to32(i>>2), x3to32(i|(i<<1)));
			setcolor(i, xnto32(i>>5, 3), xnto32(i>>2, 3), xnto32(i<<1, 2));
		setcolor(0x55, xnto32(0x15, 6), xnto32(0x15, 6), xnto32(0x15, 6));
		setcolor(0xaa, xnto32(0x2a, 6), xnto32(0x2a, 6), xnto32(0x2a, 6));
		setcolor(0xff, xnto32(0x3f, 6), xnto32(0x3f, 6), xnto32(0x3f, 6));
		break;
	case 2:
	case 1:
	case 0:
		for(i = 0; i < 16; i++){
			x = x6to32((i*63)/15);
			x = xnto32((i*63)/15, 6);
			setcolor(i, x, x, x);
		}
		break;


@@ 976,60 975,22 @@ screenputs(char *s, int n)


/*
 *  expand 3 and 6 bits of color to 32
 *  expand n bits of color to 32
 */
static ulong
x3to32(uchar x)
xnto32(uchar x, int n)
{
	int s;
	ulong y;

	x = x&7;
	x= (x<<3)|x;
	y = (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24))|(x<<(32-30));
	x &= (1<<n)-1;
	y = 0;
	for(s = 32 - n; s > 0; s -= n)
		y |= x<<s;
	if(s < 0)
		y |= x>>(-s);
	return y;
}
static ulong
x6to32(uchar x)
{
	ulong y;

	x = x&0x3f;
	y = (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24))|(x<<(32-30));
	return y;
}
static ulong
x8to32(uchar x)
{
	ulong y;

	x = x&0xff;
	y = (x<<(32-8))|(x<<(32-16))|(x<<(32-24))|x;
	return y;
}
static void
greyscale(void)
{
	int i;
	ulong x;

	/* default color map (has to be outside the lock) */
	switch(gscreen.ldepth){
	case 3:
		for(i = 0; i < 256; i++){
			x = x8to32(i);
			setcolor(i, x, x, x);
		}
		break;
	case 2:
	case 1:
	case 0:
		for(i = 0; i < 16; i++){
			x = x6to32((i*63)/15);
			setcolor(i, x, x, x);
		}
		break;
	}
}

/*
 *  paging routines for different cards


@@ 1364,7 1325,7 @@ setcursor(ulong *setbits, ulong *clrbits, int offx, int offy)
void
cursoron(int dolock)
{
	int xoff, yoff;
	int xoff, yoff, s;
	Rectangle r;
	uchar *a;
	struct {


@@ 1377,8 1338,11 @@ cursoron(int dolock)

	if(cursor.disable)
		return;
	if(dolock)
	if(dolock){
		s = 0;		/* to avoid compiler warning */
		lock(&cursor);
	} else
		s = spllo();	/* to avoid freezing out the eia ports */

	if(hwcursor)
		(*vgacard->mvcursor)(mousexy());


@@ 1430,21 1394,30 @@ cursoron(int dolock)

	if(dolock)
		unlock(&cursor);
	else
		splx(s);
}

void
cursoroff(int dolock)
{
	int s;

	if(hwcursor)
		return;
	if(cursor.disable)
		return;
	if(dolock)
	if(dolock){
		s = 0;		/* to avoid a compiler warning */
		lock(&cursor);
	} else
		s = spllo();	/* to avoid freezing out the eia ports */
	if(--cursor.visible == 0 && cursor.tl > 0)
		screenload(cursor.clipr, (uchar*)backbits, cursor.tl, cursor.l, 0);
	if(dolock)
		unlock(&cursor);
	else
		splx(s);
}

static void

M port/portdat.h => port/portdat.h +7 -2
@@ 118,6 118,12 @@ struct Path
	char	elem[NAMELEN];
};

enum
{
	BINTR	=	(1<<0),
	BFREE	=	(1<<1),
};

struct Block
{
	Block*	next;


@@ 126,8 132,7 @@ struct Block
	uchar*	wp;			/* first empty byte */
	uchar*	lim;			/* 1 past the end of the buffer */
	uchar*	base;			/* start of the buffer */
	uchar	flag;
	uchar	intr;
	ulong	flag;
};
#define BLEN(s)	((s)->wp - (s)->rp)


M port/qio.c => port/qio.c +9 -12
@@ 44,14 44,11 @@ struct Queue

enum
{
	/* Block.flag */
	Bfilled=1,		/* block filled */

	/* Queue.state */	
	Qstarve=	(1<<0),		/* consumer starved */
	Qmsg=		(1<<1),		/* message stream */
	Qclosed=	(1<<2),
	Qflow=		(1<<3),
	Qstarve		= (1<<0),	/* consumer starved */
	Qmsg		= (1<<1),	/* message stream */
	Qclosed		= (1<<2),
	Qflow		= (1<<3),
};

void


@@ 80,7 77,7 @@ iallocb(int size)

	size = sizeof(Block) + size + (BY2V-1);
	if(ialloc.bytes > conf.ialloc){
		iprint("ialloc limit exceeded %d/%d\n", ialloc.bytes, conf.ialloc);
		iprint("ialloc limit %d/%d\n", ialloc.bytes, conf.ialloc);
		return 0;
	}
	b = mallocz(size, 0);


@@ 96,11 93,11 @@ iallocb(int size)
	b->rp = b->base;
	b->wp = b->base;
	b->lim = ((uchar*)b) + size;
	b->intr = 1;
	b->flag = BINTR;

	lock(&ialloc);
	ilock(&ialloc);
	ialloc.bytes += b->lim - b->base;
	unlock(&ialloc);
	iunlock(&ialloc);

	return b;
}


@@ 108,7 105,7 @@ iallocb(int size)
void
freeb(Block *b)
{
	if(b->intr) {
	if(b->flag & BINTR) {
		ilock(&ialloc);
		ialloc.bytes -= b->lim - b->base;
		iunlock(&ialloc);

M port/taslock.c => port/taslock.c +1 -1
@@ 29,7 29,7 @@ ilock(Lock *l)
		l->sr = x;
		return;
	}

/* print("ilock loop %lux\n", getcallerpc(0)); */
	for(;;){
		while(l->key)
			;