~kris/9p

9hist

5b25835660ca13782c2ecae7548505d2daa8261a — David du Colombier 33 years ago 4c26c55
Plan 9 from Bell Labs 1992-11-13
6 files changed, 183 insertions(+), 120 deletions(-)

M pc/bbmalloc.c
M pc/devfloppy.c
M pc/kbd.c
M pc/main.c
M pc/vga.c
M port/devbit.c
M pc/bbmalloc.c => pc/bbmalloc.c +43 -29
@@ 3,52 3,66 @@
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

static	char	bbarena[10000];
static	char	bbused[10];
/*
 * Allocate memory for use in kernel bitblts.
 *
 * This code will have to be interlocked if we ever get
 * a multiprocessor with a bitmapped display.
 */

void*
bbmalloc(int n)
/* a 0->3 bitblt can take 800 longs */
enum {
	narena=2,	/* put interrupt time stuff in separate arena */
	nbbarena=4096	/* number of words in an arena */
};

static ulong	bbarena[narena][nbbarena];
static ulong	*bbcur[narena] = {&bbarena[0][0], &bbarena[1][0]};
static ulong	*bblast[narena] = {0, 0};

#define INTENABLED(v)	((v)&(1<<9))
void *
bbmalloc(int nbytes)
{
	char *a;
	int s, i;
	int nw, a;
	int s;
	ulong *ans;

	nw = nbytes/sizeof(long);
	s = splhi();
	a = memchr(bbused, 0, sizeof(bbused));
	if(a) {
		i = a - bbused;
		a = bbarena + i*n;
		if(a+n <= bbarena+sizeof(bbarena)) {
			bbused[i] = 1;
			splx(s);
			return a;
		}
	}
	a = INTENABLED(s) ? 0 : 1;
	if(bbcur[a] + nw > &bbarena[a][nbbarena])
		ans = bbarena[a];
	else
		ans = bbcur[a];
	bbcur[a] = ans + nw;
	splx(s);
	print("too many bbmallocs\n");
	return bbarena;
	bblast[a] = ans;
	return ans;
}

void
bbfree(void *va, int n)
bbfree(void *p, int n)
{
	int s, i;
	int a, s;

	s = splhi();
	i = ((char*)va - bbarena) /n;
	if(i >= 0 && i < sizeof(bbused) && bbused[i]){
		bbused[i] = 0;
		splx(s);
		return;
	}
	a = INTENABLED(s) ? 0 : 1;
	if(p == bblast[a])
		bbcur[a] = (ulong *)(((char *)bblast[a]) + n);
	splx(s);
	print("sanity bbfree\n");
}

void
bbdflush(void *p, int n)
{
	USED(p, n);
}

int
bbonstack(void)
{
	if(u)
		return 1;
	return 0;
}

M pc/devfloppy.c => pc/devfloppy.c +1 -1
@@ 266,7 266,7 @@ floppyreset(void)
		dp->dt = T1440kb;
		setdef(dp);
		dp->cyl = -1;			/* because we don't know */
		dp->cache = (uchar*)xspanalloc(dp->t->tsize, BY2PG, 0);
		dp->cache = (uchar*)xspanalloc(dp->t->tsize, BY2PG, 64*1024);
		dp->ccyl = -1;
		dp->vers = 1;
	}

M pc/kbd.c => pc/kbd.c +0 -1
@@ 352,7 352,6 @@ ps2mouseputc(IOQ *q, int c)
		mouse.dx = msg[1];
		mouse.dy = -msg[2];
		mouse.track = 1;
		spllo();		/* mouse tracking kills uart0 */
		mouseclock();
	}
	return 0;

M pc/main.c => pc/main.c +3 -3
@@ 232,7 232,7 @@ confinit(void)

	/*
	 *  the first 640k is the standard useful memory
	 *  the next 128K is the display
	 *  the next 128K is the display, I/O mem, and BIOS
	 *  the last 256k belongs to the roms and other devices
	 */
	conf.npage0 = 640/4;


@@ 271,8 271,8 @@ confinit(void)
	conf.npage1 = (i*MB - conf.base1)/BY2PG;
	conf.npage = conf.npage0 + conf.npage1;

	conf.ldepth = 1;
	pcnt = screenbits()-1;		/* Calculate % of memory for page pool */
	conf.ldepth = 0;
	pcnt = (1<<conf.ldepth)-1;		/* Calculate % of memory for page pool */
	pcnt = 70 - (pcnt*10);
	conf.upages = (conf.npage*pcnt)/100;
	if(conf.npage - conf.upages < 1572864/BY2PG)

M pc/vga.c => pc/vga.c +134 -83
@@ 17,13 17,20 @@ struct{
	int	bwid;
}out;

int islittle = 1;		/* little endian bit ordering in bytes */

/* imported */
extern	GSubfont defont0;
GSubfont *defont;
extern	Cursor arrow;
extern	GBitmap cursorback;
static	Lock colorlock;		/* color map lock */

/* exported */
GSubfont *defont;
int islittle = 1;		/* little endian bit ordering in bytes */
GBitmap	gscreen;

/* local */
static	Lock vgalock;
static	GBitmap	vgascreen;
static	ulong colormap[256][3];

/*
 *  screen dimensions


@@ 34,8 41,6 @@ static	Lock colorlock;		/* color map lock */
/*
 *  'soft' screen bitmap
 */
GBitmap	gscreen;
GBitmap	vgascreen;

typedef struct VGAmode	VGAmode;
struct VGAmode


@@ 48,7 53,7 @@ struct VGAmode
};

/*
 *  640x480 display, 16 bit color.
 *  640x480 display, 1, 2, or 4 bit color.
 */
VGAmode mode12 = 
{


@@ 70,6 75,29 @@ VGAmode mode12 =
	0x01, 0x10, 0x0f, 0x00, 0x00,
};

/*
 *  640x480 display, 8 bit color.
 */
VGAmode mode13 = 
{
	/* general */
	0xe7, 0x00,
	/* sequence */
	0x03, 0x01, 0x0f, 0x00, 0x0e,
	/* crt */
	0x65, 0x4f, 0x50, 0x88, 0x55, 0x9a, 0x09, 0x3e,
	0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0xe8, 0x8b, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xA3,
	0xff,
	/* graphics */
	0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
	0xff,
	/* attribute */
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
	0x41, 0x10, 0x0f, 0x00, 0x00,
};

static Rectangle mbb;
static Rectangle NULLMBB = {10000, 10000, -10000, -10000};



@@ 189,6 217,7 @@ printmode(VGAmode *v) {
	print("\n");
}

#ifdef asdf
void
dumpmodes(void) {
	VGAmode *v;


@@ 222,16 251,48 @@ dumpmodes(void) {
		print(" %02x", inb(ARR));
	}
}
#endif
#endif asdf

/*
 *  expand 3 and 6 bits of color to 32
 */
static ulong
x3to32(uchar x)
{
	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));
	return y;
}
static ulong
x6to32(uchar x)
{
	ulong y;

uchar *pad1, *pad2;
	x = x&0x3f;
	y = (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24))|(x<<(32-30));
	return y;
}

void
setscreen(int maxx, int maxy, int ldepth)
{
	int len;
	int len, vgamaxy, width, i, x;
	uchar *p;

	if(ldepth == 3)
		setmode(&mode13);
	else
		setmode(&mode12);

	/* allocate a new soft bitmap area */
	width = (maxx*(1<<ldepth))/32;
	len = width * BY2WD * maxy;
	p = xalloc(len);
	if(p == 0)
		panic("can't alloc screen bitmap");
	mbb = NULLMBB;

	/*


@@ 241,33 302,26 @@ setscreen(int maxx, int maxy, int ldepth)
		vgascreen.ldepth = 3;
	else
		vgascreen.ldepth = 0;
	vgascreen.base = (void*)SCREENMEM;
	vgascreen.width = (maxx*(1<<vgascreen.ldepth))/32;
	vgamaxy = maxy % ((64*1024)/vgascreen.width);
	vgascreen.base = (void*)SCREENMEM;
	vgascreen.r.min = Pt(0, 0);
	vgascreen.r.max = Pt(maxx, maxy);
	vgascreen.r.max = Pt(maxx, vgamaxy);
	vgascreen.clipr = vgascreen.r;
	memset(vgascreen.base, 0xff, vgascreen.width * BY2WD * vgamaxy);

	/*
	 *  setup new soft screen, free memory for old screen
	 */
	if(gscreen.base)
		xfree(gscreen.base);
	gscreen.ldepth = ldepth;
	gscreen.width = (maxx*(1<<ldepth))/32;
	gscreen.width = width;
	gscreen.r.min = Pt(0, 0);
	gscreen.r.max = Pt(maxx, maxy);
	gscreen.clipr = gscreen.r;
	len = gscreen.width * BY2WD * maxy;
	if(gscreen.base){
		free(gscreen.base);
		p = smalloc(len + 2*1024);
	} else
		p = malloc(len + 2*1024);
	pad1 = p;
	pad2 = p + 1024 + len;
	memset(pad1, 0, 1024);
	memset(pad2, 0, 1024);
	gscreen.base = (ulong*)(p+1024);
	memset((char*)gscreen.base, 0xff, len);
	memset((void*)SCREENMEM, 0xff, vgascreen.width * BY2WD * maxy);
	gscreen.base = (ulong*)p;
	memset(gscreen.base, 0xff, len);

	/*
	 *  set depth of cursor backup area


@@ 280,16 334,34 @@ setscreen(int maxx, int maxy, int ldepth)
	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = defont0.info[' '].width;

	/*
	 *  default color map
	 */
	switch(ldepth){
	case 3:
		for(i = 0; i < 256; i++)
			setcolor(i, x3to32(i>>5), x3to32(i>>2), x3to32(i<<1));
		break;
	case 2:
	case 1:
	case 0:
		gscreen.ldepth = 3;
		for(i = 0; i < 16; i++){
			x = x6to32((i*63)/15);
			setcolor(i, x, x, x);
		}
		gscreen.ldepth = ldepth;
		break;
	}
}

void
screeninit(void)
{
	int i, x;
	int i;
	ulong *l;

	setmode(&mode12);

	/*
	 *  arrow is defined as a big endian
	 */


@@ 315,19 387,6 @@ screeninit(void)
	if(conf.maxy == 0)
		conf.maxy = MAXY;
	setscreen(conf.maxx, conf.maxy, conf.ldepth);

	/*
	 *  set up color map
	 */
	lock(&colorlock);
	outb(CMWX, 0);
	for(i = 0; i < 16; i++){
		x = (i*63)/15;
		outb(CM, x);
		outb(CM, x);
		outb(CM, x);
	}
	unlock(&colorlock);
}

/*


@@ 344,7 403,8 @@ mbbrect(Rectangle r)
		mbb.max.x = r.max.x;
	if (r.max.y > mbb.max.y)
		mbb.max.y = r.max.y;
	screenupdate();
	if (Dy(mbb) > 32 || Dx(mbb) > 32)
		mousescreenupdate();
}

void


@@ 369,8 429,8 @@ unlocktseng(void) {
/*
 *  copy litte endian soft screen to big endian hard screen
 */
void
screenupdate(void)
static void
vgaupdate(void)
{
	uchar *sp, *hp;
	int y, len, incs, inch, off, page, y2pg, ey;


@@ 380,14 440,6 @@ screenupdate(void)
	r = mbb;
	mbb = NULLMBB;

	if(nocheck==0 && memcmp(pad1, pad2, 1024)){
		nocheck = 1;
		print("b: %d %d %d %d\n", r.min.x, r.min.y, r.max.x, r.max.y);
		nocheck = 0;
		memset(pad1, 0, 1024);
		memset(pad2, 0, 1024);
	}

	if(Dy(r) < 0)
		return;



@@ 454,6 506,7 @@ screenupdate(void)
		y2pg = (64*1024/BY2WD)/gscreen.width;
		off = (r.min.y % y2pg) * gscreen.width * BY2WD + r.min.x;
		hp = (uchar*)(vgascreen.base) + off;
		off = r.min.y * gscreen.width * BY2WD + r.min.x;
		sp = (uchar*)(gscreen.base) + off;
		len = r.max.x - r.min.x;
		if(len < 1)


@@ 475,13 528,22 @@ screenupdate(void)
		}
		break;
	}
}

void
screenupdate(void)
{
	lock(&vgalock);
	vgaupdate();
	unlock(&vgalock);
}

	if(nocheck==0 && memcmp(pad1, pad2, 1024)){
		nocheck = 1;
		print("a: %d %d %d %d\n", r.min.x, r.min.y, r.max.x, r.max.y);
		nocheck = 0;
		memset(pad1, 0, 1024);
		memset(pad2, 0, 1024);
void
mousescreenupdate(void)
{
	if(canlock(&vgalock)){
		vgaupdate();
		unlock(&vgalock);
	}
}



@@ 497,11 559,9 @@ screenputnl(void)
	r = Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height);
	gbitblt(&gscreen, r.min, &gscreen, r, flipD[0]);
	mbbrect(r);
	screenupdate();
	vgaupdate();
}

Lock screenlock;

void
screenputs(char *s, int n)
{


@@ 541,7 601,7 @@ screenputs(char *s, int n)
	}
	rs.max = Pt(gscreen.r.max.x, out.pos.y+defont0.height);
	mbbrect(rs);
	screenupdate();
	vgaupdate();
}

int


@@ 552,39 612,29 @@ screenbits(void)


void
mousescreenupdate(void)
{
	screenupdate();
}

static ulong
expand(uchar x)
{
	return (x<<(32-6))|(x<<(32-12))|(x<<(32-18))|(x<<(32-24));
}

void
getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
{
	p &= (1<<(1<<gscreen.ldepth))-1;
	lock(&colorlock);
	outb(CMRX, p);
	*pr = expand(inb(CM));
	*pg = expand(inb(CM));
	*pb = expand(inb(CM));
	unlock(&colorlock);
	lock(&vgalock);
	*pr = colormap[p][0];
	*pg = colormap[p][1];
	*pb = colormap[p][2];
	unlock(&vgalock);
}

int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
	p &= (1<<(1<<gscreen.ldepth))-1;
	lock(&colorlock);
	lock(&vgalock);
	colormap[p][0] = r;
	colormap[p][1] = g;
	colormap[p][2] = b;
	outb(CMWX, p);
	outb(CM, r>>(32-6));
	outb(CM, g>>(32-6));
	outb(CM, b>>(32-6));
	unlock(&colorlock);
	unlock(&vgalock);
	return ~0;
}



@@ 605,6 655,7 @@ hwcursmove(int x, int y)
void
mouseclock(void)
{
	spllo();	/* so we don't cause lost chars on the uart */
	mouseupdate(1);
}


M port/devbit.c => port/devbit.c +2 -3
@@ 1602,9 1602,9 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
		}

	poperror();
	screenupdate();
	if(isoff)
		cursoron(1);
	screenupdate();
	qunlock(&bit);
	return n;
}


@@ 1959,7 1959,6 @@ cursoron(int dolock)
		gbitblt(&gscreen, cursor.r.min,
			&set, Rect(0, 0, 16, 16), flipping? flipD[S|D] : S|D);
		mbbrect(cursor.r);
		screenupdate();
	}
	if(dolock)
		unlock(&cursor);


@@ 1975,7 1974,7 @@ cursoroff(int dolock)
	if(--cursor.visible == 0) {
		gbitblt(&gscreen, cursor.r.min, &cursorback, Rect(0, 0, 16, 16), S);
		mbbrect(cursor.r);
		screenupdate();
		mousescreenupdate();
	}
	if(dolock)
		unlock(&cursor);