⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vgasavage.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
	PBD2			= 0x8174,	SBD1			= 0x8178,	/* Secondary Bitmap Descriptor: read/write */	SBD2			= 0x817C,};/* mastered data transfer registers *//* configuration/status registers */enum {	XStatus0			= 0x48C00,	/* Status Word 0: read only */	  /* rev. A silicon differs from rev. B; use AltStatus0 */	  CBEMaskA		= 0x1FFFF,	/* filled command buffer entries */	  CBEShiftA		= 0,	  BciIdleA		= 1<<17,	/* BCI idle */	  Ge3IdleA		= 1<<18,	/* 3D engine idle */	  Ge2IdleA		= 1<<19,	/* 2D engine idle */	  McpIdleA		= 1<<20,	/* motion compensation processor idle */	  MeIdleA		= 1<<22,	/* master engine idle */	  PfPendA		= 1<<23,	/* page flip pending */	  CBEMaskB		= 0x1FFFFF,	  CBEShiftB		= 0,	  BciIdleB		= 1<<25,	  Ge3IdleB		= 1<<26,	  Ge2IdleB		= 1<<27,	  McpIdleB		= 1<<28,	  MeIdleB		= 1<<30,	  PfPendB		= 1<<31,	AltStatus0		= 0x48C60,	/* Alternate Status Word 0: read only */	  CBEMask		= 0x1FFFF,	  CBEShift		= 0,	  /* the Savage4 manual says bits 17..23 for these, like Status0 */	  /* empirically, they are bits 21..26 */	  BciIdle		= 1<<21,	  Ge3Idle		= 1<<22,	  Ge2Idle		= 1<<23,	  McpIdle		= 1<<24,	  MeIdle		= 1<<25,	  PfPend		= 1<<26,	XStatus1			= 0x48C04,	/* Status Word 1: read only */	  /* contains event tag 1, event tag 0, both 16 bits */	XStatus2			= 0x48C08,	/* Status Word 2: read only */	  ScanMask		= 0x3FF,	/* current scan line */	  ScanShift		= 0,	  VRTMask		= 0x7F100,	/* vert retrace count */	  VRTShift		= 11,	CbThresh		= 0x48C10,	/* Command Buffer Thresholds: read/write */	CobOff			= 0x48C14,	/* Command Overflow Buffer: read/write */	CobPtr			= 0x48C18,	/* Command Overflow Buffer Pointers: read/write */	  CobEna		= 1<<2,		/* command overflow buffer enable */	  CobBciEna		= 1<<3,		/* BCI function enable */	  CbeMask		= 0xFFFF8000,	/* no. of entries in command buffer */	  CbeShift		= 15,	AltStatus1		= 0x48C64,	/* Alternate Status Word 1: read onnly */	  /* contains current texture surface tag, vertex buffer tag */};struct {	ulong idletimeout;	ulong tostatw[16];} savagestats;enum {	Maxloop = 1<<20};static voidsavagewaitidle(VGAscr *scr){	long x;	ulong *statw, mask, goal;	switch(scr->id){	case SAVAGE4:	case PROSAVAGEP:	case PROSAVAGEK:	case PROSAVAGE8:		/* wait for engine idle and FIFO empty */		statw = (ulong*)((uchar*)scr->mmio+AltStatus0);		mask = CBEMask | Ge2Idle;		goal = Ge2Idle;		break;	/* case SAVAGEMXMV: ? */	/* case SAVAGEMX: ? */	/* case SAVAGEIX: ? */	case SUPERSAVAGEIXC16:	case SAVAGEIXMV:	case SAVAGEMXMV:		/* wait for engine idle and FIFO empty */		statw = (ulong*)((uchar*)scr->mmio+XStatus0);		mask = CBEMaskA | Ge2IdleA;		goal = Ge2IdleA;		break;	default:		/* 		 * best we can do: can't print or we'll call ourselves.		 * savageinit is supposed to not let this happen.		 */			return;	}	for(x=0; x<Maxloop; x++)		if((*statw & mask) == goal)			return;	savagestats.tostatw[savagestats.idletimeout++&15] = *statw;	savagestats.tostatw[savagestats.idletimeout++&15] = (ulong)statw;}static intsavagefill(VGAscr *scr, Rectangle r, ulong sval){	uchar *mmio;	mmio = (uchar*)scr->mmio;	*(ulong*)(mmio+FgColor) = sval;	*(ulong*)(mmio+BgColor) = sval;	*(ulong*)(mmio+BgMix) = SrcFg|MixNew;	*(ulong*)(mmio+FgMix) = SrcFg|MixNew;	*(ushort*)(mmio+RectY) = r.min.y;	*(ushort*)(mmio+RectX) = r.min.x;	*(ushort*)(mmio+Width) = Dx(r)-1;	*(ushort*)(mmio+Height) = Dy(r)-1;	*(ulong*)(mmio+DrawCmd) = CmdMagic | DoDraw | CmdFill | DrawRight | DrawDown;	savagewaitidle(scr);	return 1;}static intsavagescroll(VGAscr *scr, Rectangle r, Rectangle sr){	uchar *mmio;	ulong cmd;	Point dp, sp;	cmd = CmdMagic | DoDraw | CmdBitblt | SrcPBD | DstGBD;	if(r.min.x <= sr.min.x){		cmd |= DrawRight;		dp.x = r.min.x;		sp.x = sr.min.x;	}else{		dp.x = r.max.x-1;		sp.x = sr.max.x-1;	}	if(r.min.y <= sr.min.y){		cmd |= DrawDown;		dp.y = r.min.y;		sp.y = sr.min.y;	}else{		dp.y = r.max.y-1;		sp.y = sr.max.y-1;	}	mmio = (uchar*)scr->mmio;	*(ushort*)(mmio+SourceX) = sp.x;	*(ushort*)(mmio+SourceY) = sp.y;	*(ushort*)(mmio+DestX) = dp.x;	*(ushort*)(mmio+DestY) = dp.y;	*(ushort*)(mmio+Width) = Dx(r)-1;	*(ushort*)(mmio+Height) = Dy(r)-1;	*(ulong*)(mmio+BgMix) = SrcDisp|MixNew;	*(ulong*)(mmio+FgMix) = SrcDisp|MixNew;	*(ulong*)(mmio+DrawCmd) = cmd;	savagewaitidle(scr);	return 1;}static voidsavageblank(VGAscr*, int blank){	uchar seqD;	/*	 * Will handle DPMS to monitor	 */	vgaxo(Seqx, 8, vgaxi(Seqx,8)|0x06);	seqD = vgaxi(Seqx, 0xD);	seqD &= 0x03;	if(blank)		seqD |= 0x50;	vgaxo(Seqx, 0xD, seqD);	/*	 * Will handle LCD	 */	if(blank)		vgaxo(Seqx, 0x31, vgaxi(Seqx, 0x31) & ~0x10);	else		vgaxo(Seqx, 0x31, vgaxi(Seqx, 0x31) | 0x10);}voidsavageinit(VGAscr *scr){	uchar *mmio;	ulong bd;	/* if you add chip IDs here be sure to update savagewaitidle */	switch(scr->id){	case SAVAGE4:	case PROSAVAGEP:	case PROSAVAGEK:	case PROSAVAGE8:	case SAVAGEIXMV:	case SUPERSAVAGEIXC16:	case SAVAGEMXMV:		break;	default:		print("unknown savage %.4lux\n", scr->id);		return;	}	mmio = (uchar*)scr->mmio;	if(mmio == nil) {		print("savageinit: no mmio\n");		return;	}	/* 2D graphics engine software reset */	*(ushort*)(mmio+SubsystemCtl) = GeSoftReset;	delay(2);	*(ushort*)(mmio+SubsystemCtl) = 0;	savagewaitidle(scr);	/* disable BCI as much as possible */	*(ushort*)(mmio+CobPtr) &= ~CobBciEna;	*(ushort*)(mmio+GBD2) &= ~GBDBciEna;	savagewaitidle(scr);	/* enable 32-bit writes, disable clipping */	*(ushort*)(mmio+MfMiscCtl) = MfMiscMagic|W32Ena|ClipDis;	savagewaitidle(scr);	/* enable all read, write planes */	*(ulong*)(mmio+BitplaneRmask) = ~0;	*(ulong*)(mmio+BitplaneWmask) = ~0;	savagewaitidle(scr);	/* turn on linear access, 2D engine */	*(ulong*)(mmio+AdvFunCtl) |= GeEna|LaEna;	savagewaitidle(scr);	/* set bitmap descriptors */	bd = (scr->gscreen->depth<<DepthShift) |		(Dx(scr->gscreen->r)<<StrideShift) | BlockWriteDis		| BDS64;	*(ulong*)(mmio+GBD1) = 0;	*(ulong*)(mmio+GBD2) = bd;	*(ulong*)(mmio+PBD1) = 0;	*(ulong*)(mmio+PBD2) = bd;	*(ulong*)(mmio+SBD1) = 0;	*(ulong*)(mmio+SBD2) = bd;	/*	 * For some reason, the GBD needs to get programmed twice,	 * once before the PBD, SBD, and once after.	 * This empirically makes it get set right.	 * I would like to better understand the ugliness	 * going on here.	 */	*(ulong*)(mmio+GBD1) = 0;	*(ulong*)(mmio+GBD2) = bd;	*(ushort*)(mmio+GBD2+2) = bd>>16;	savagewaitidle(scr);	scr->fill = savagefill;	scr->scroll = savagescroll;	scr->blank = savageblank;	hwblank = 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -