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

📄 pcvt_drv.c

📁 freebsd v4.4内核源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		tp->t_state &= ~TS_BUSY; /* patch from Frank Maclachlan */	}out:	splx(s);}#endif /* PCVT_NETBSD || PCVT_FREEBSD >= 200 *//*---------------------------------------------------------------------------* *		/dev/console *---------------------------------------------------------------------------*/#if !PCVT_NETBSD	/* has moved to cons.c in netbsd-current */voidconsinit()		/* init for kernel messages during boot */{}#endif /* PCVT_NETBSD */#if PCVT_FREEBSD > 205void#elseint#endifpccnprobe(struct consdev *cp){	struct isa_device *dvp;#ifdef _I386_ISA_KBDIO_H_	kbdc = kbdc_open(IO_KBD);	/*	 * Don't reset the keyboard via `kbdio' just yet.	 * The system clock has not been calibrated...	 */	reset_keyboard = 0;#if PCVT_SCANSET == 2	/*	 * Turn off scancode translation early so that UserConfig 	 * and DDB can read the keyboard.	 */	empty_both_buffers(kbdc, 10);	set_controller_command_byte(kbdc, KBD_TRANSLATION, 0);#endif /* PCVT_SCANSET == 2 */#endif /* _I386_ISA_KBDIO_H_ */	/*	 * Take control if we are the highest priority enabled display device.	 */	dvp = find_display();	if (dvp == NULL || dvp->id_driver != &vtdriver) {		cp->cn_pri = CN_DEAD;		return;	}	/* initialize required fields */	cp->cn_dev = makedev(CDEV_MAJOR, 0);	cp->cn_pri = CN_INTERNAL;#if !PCVT_NETBSD#if !(PCVT_FREEBSD > 110 && PCVT_FREEBSD < 200)	cp->cn_tp = &pccons[0];#else	cp->cn_tp = pccons[0];#endif /* !(PCVT_FREEBSD > 110 && PCVT_FREEBSD < 200) */#endif /* !PCVT_NETBSD */#if PCVT_FREEBSD <= 205	return 1;#endif}#if PCVT_FREEBSD > 205void#elseint#endifpccninit(struct consdev *cp){	pcvt_is_console = 1;#if PCVT_FREEBSD <= 205	return 0;#endif}#if PCVT_FREEBSD > 205void#elseint#endifpccnputc(Dev_t dev, U_char c){#if PCVT_SW0CNOUTP	if(current_video_screen != 0)	{#if !PCVT_USL_VT_COMPAT		vgapage(0);#else		switch_screen(0, 0);#endif /* !PCVT_USL_VT_COMPAT */	}#endif /* PCVT_SW0CNOUTP */	if (c == '\n')		sput("\r", 1, 1, 0);	sput((char *) &c, 1, 1, 0); 	async_update(UPDATE_KERN);#if PCVT_FREEBSD <= 205	return 0;#endif}intpccngetc(Dev_t dev){	register int s;	static u_char *cp, cbuf[4]; /* Temp buf for multi-char key sequence. */	register u_char c;#ifdef XSERVER#if !PCVT_USL_VT_COMPAT	if (pcvt_xmode)		return 0;#else /* !PCVT_USL_VT_COMPAT */	if (pcvt_kbd_raw)		return 0;#endif /* !PCVT_USL_VT_COMPAT */#endif /* XSERVER */	if (cp && *cp)		/*		 * We still have a pending key sequence, e.g.		 * from an arrow key.  Deliver this one first.		 */		return (*cp++);	s = spltty();		/* block pcrint while we poll */	kbd_polling = 1;	cp = sgetc(0);	kbd_polling = 0;	splx(s);	c = *cp++;	if (c && *cp) {		/* Preserve the multi-char sequence for the next call. */		bcopy(cp, cbuf, 3); /* take care for a trailing '\0' */		cp = cbuf;	} else		cp = 0;#if ! (PCVT_FREEBSD >= 201)	/* this belongs to cons.c */	if (c == '\r')		c = '\n';#endif /* ! (PCVT_FREEBSD >= 201) */	return c;}#if PCVT_FREEBSD >= 200intpccncheckc(Dev_t dev){	char *cp;	int x = spltty();	kbd_polling = 1;	cp = sgetc(1);	kbd_polling = 0;	splx(x);	return (cp == NULL ? -1 : *cp);}#endif /* PCVT_FREEBSD >= 200 */#if PCVT_NETBSD >= 100voidpccnpollc(Dev_t dev, int on){	kbd_polling = on;	if (!on) {		register int s;		/*		 * If disabling polling, make sure there are no bytes left in		 * the FIFO, holding up the interrupt line.  Otherwise we		 * won't get any further interrupts.		 */		s = spltty();		pcrint();		splx(s);	}}#endif /* PCVT_NETBSD >= 100 *//*---------------------------------------------------------------------------* *	Set line parameters *---------------------------------------------------------------------------*/intpcparam(struct tty *tp, struct termios *t){	register int cflag = t->c_cflag;        /* and copy to tty */        tp->t_ispeed = t->c_ispeed;        tp->t_ospeed = t->c_ospeed;        tp->t_cflag = cflag;	return(0);}/* special characters */#define bs	8#define lf	10#define cr	13#define cntlc	3#define del	0177#define cntld	4intgetchar(void){	u_char	thechar;	int	x;	kbd_polling = 1;	x = splhigh();	sput(">", 1, 1, 0);	async_update(UPDATE_KERN);	thechar = *(sgetc(0));	kbd_polling = 0;	splx(x);	switch (thechar)	{		default:			if (thechar >= ' ')				sput(&thechar, 1, 1, 0);			return(thechar);		case cr:		case lf:			sput("\r\n", 1, 2, 0);			return(lf);		case bs:		case del:			 sput("\b \b", 1, 3, 0);			 return(thechar);		case cntlc:			 sput("^C\r\n", 1, 4, 0) ;			 cpu_reset();		case cntld:			 sput("^D\r\n", 1, 4, 0) ;			 return(0);	}}#define	DPAUSE 1voiddprintf(unsigned flgs, const char *fmt, ...){	va_list ap;	if((flgs&__debug) > DPAUSE)	{		__color = ffs(flgs&__debug)+1;		va_start(ap,fmt);		vprintf(fmt, ap);		va_end(ap);		if (flgs & DPAUSE || nrow%24 == 23)		{			int x;			x = splhigh();			if(nrow%24 == 23)				nrow = 0;			(void)sgetc(0);			splx(x);		}	}	__color = 0;}/*----------------------------------------------------------------------* *	read initial VGA palette (as stored by VGA ROM BIOS) into *	palette save area *----------------------------------------------------------------------*/voidvgapelinit(void){	register unsigned idx;	register struct rgb *val;	/* first, read all and store to first screen's save buffer */	for(idx = 0, val = vs[0].palette; idx < NVGAPEL; idx++, val++)		vgapaletteio(idx, val, 0 /* read it */);	/* now, duplicate for remaining screens */	for(idx = 1; idx < PCVT_NSCREENS; idx++)		bcopy(vs[0].palette, vs[idx].palette,		      NVGAPEL * sizeof(struct rgb));}#if defined XSERVER && !PCVT_USL_VT_COMPAT/*----------------------------------------------------------------------* *	initialize for X mode *	i.e.: grant current process (the X server) all IO privileges, *	and mark in static variable so other hooks can test for it, *	save all loaded fonts and screen pages to pageable buffers; *	if parameter `on' is false, the same procedure is done reverse. *----------------------------------------------------------------------*/static intpcvt_xmode_set(int on, struct proc *p){	static unsigned char *saved_fonts[NVGAFONTS];#if PCVT_SCREENSAVER	static unsigned saved_scrnsv_tmo = 0;#endif /* PCVT_SCREENSAVER */#if (PCVT_NETBSD > 9) || (PCVT_FREEBSD > 102)	struct trapframe *fp;#else	struct syscframe *fp;#endif /* PCVT_NETBSD > 9 */	int error, i;	/* X will only run on VGA and Hercules adaptors */	if(adaptor_type != VGA_ADAPTOR && adaptor_type != MDA_ADAPTOR)		return (EINVAL);#if PCVT_NETBSD > 9	fp = (struct trapframe *)p->p_regs;#else	fp = (struct syscframe *)p->p_regs;#endif /* PCVT_NETBSD > 9 */	if(on)	{		/*		 * Test whether the calling process has super-user privileges		 * and we're in insecure mode.		 * This prevents us from granting the potential security hole		 * `IO priv' to insufficiently privileged processes.		 */		error = suser(p->p_ucred, &p->p_acflag);		if (error != 0)			return (error);		if (securelevel > 0)			return (EPERM);		if(pcvt_xmode)			return 0;		pcvt_xmode = pcvt_kbd_raw = 1;		for(i = 0; i < totalfonts; i++)		{			if(vgacs[i].loaded)			{				saved_fonts[i] = (unsigned char *)					malloc(32 * 256, M_DEVBUF, M_WAITOK);				if(saved_fonts[i] == 0)				{					printf(				  "pcvt_xmode_set: no font buffer available\n");					return (EAGAIN);				}				else				{					vga_move_charset(i, saved_fonts[i], 1);				}			}			else			{				saved_fonts[i] = 0;			}		}#if PCVT_SCREENSAVER		if(saved_scrnsv_tmo = scrnsv_timeout)			pcvt_set_scrnsv_tmo(0);	/* turn it off */#endif /* PCVT_SCREENSAVER */		async_update(UPDATE_STOP);	/* turn off */		/* disable text output and save screen contents */		/* video board memory -> kernel memory */		bcopy(vsp->Crtat, vsp->Memory,		       vsp->screen_rowsize * vsp->maxcol * CHR);		vsp->Crtat = vsp->Memory;	/* operate in memory now */#ifndef _I386_ISA_KBDIO_H_#if PCVT_SCANSET == 2		/* put keyboard to return ancient PC scan codes */		kbc_8042cmd(CONTR_WRITE);#if PCVT_USEKBDSEC		/* security enabled */		outb(CONTROLLER_DATA,		 (COMMAND_SYSFLG|COMMAND_IRQEN|COMMAND_PCSCAN));#else				/* security disabled */		outb(CONTROLLER_DATA,		 (COMMAND_INHOVR|COMMAND_SYSFLG|COMMAND_IRQEN|COMMAND_PCSCAN));#endif /* PCVT_USEKBDSEC */#endif /* PCVT_SCANSET == 2 */#else /* _I386_ISA_KBDIO_H_ */#if PCVT_SCANSET == 2		/* put keyboard to return ancient PC scan codes */		set_controller_command_byte(kbdc, 			KBD_TRANSLATION, KBD_TRANSLATION); #endif /* PCVT_SCANSET == 2 */#endif /* !_I386_ISA_KBDIO_H_ */#if PCVT_NETBSD > 9		fp->tf_eflags |= PSL_IOPL;#else		fp->sf_eflags |= PSL_IOPL;#endif /* PCVT_NETBSD > 9 */	}	else	{		if(!pcvt_xmode)		/* verify if in X */			return 0;		pcvt_xmode = pcvt_kbd_raw = 0;		for(i = 0; i < totalfonts; i++)		{			if(saved_fonts[i])			{				vga_move_charset(i, saved_fonts[i], 0);				free(saved_fonts[i], M_DEVBUF);				saved_fonts[i] = 0;			}		}#if PCVT_NETBSD > 9		fp->tf_eflags &= ~PSL_IOPL;#else		fp->sf_eflags &= ~PSL_IOPL;#endif /* PCVT_NETBSD > 9 */#if PCVT_SCREENSAVER		if(saved_scrnsv_tmo)			pcvt_set_scrnsv_tmo(saved_scrnsv_tmo);#endif /* PCVT_SCREENSAVER */#ifndef _I386_ISA_KBDIO_H_#if PCVT_SCANSET == 2		kbc_8042cmd(CONTR_WRITE);#if PCVT_USEKBDSEC		/* security enabled */		outb(CONTROLLER_DATA,		 (COMMAND_SYSFLG|COMMAND_IRQEN));#else				/* security disabled */		outb(CONTROLLER_DATA,		 (COMMAND_INHOVR|COMMAND_SYSFLG|COMMAND_IRQEN));#endif /* PCVT_USEKBDSEC */#endif /* PCVT_SCANSET == 2 */#else /* _I386_ISA_KBDIO_H_ */#if PCVT_SCANSET == 2		set_controller_command_byte(kbdc, KBD_TRANSLATION, 0);#endif /* PCVT_SCANSET == 2 */#endif /* !_I386_ISA_KBDIO_H_ */		if(adaptor_type == MDA_ADAPTOR)		{		    /*		     * Due to the fact that HGC registers are write-only,		     * the Xserver can only make guesses about the state		     * the HGC adaptor has been before turning on X mode.		     * Thus, the display must be re-enabled now, and the		     * cursor shape and location restored.		     */		    outb(GN_DMCNTLM, 0x28); /* enable display, text mode */		    outb(addr_6845, CRTC_CURSORH); /* select high register */		    outb(addr_6845+1,			 ((vsp->Crtat + vsp->cur_offset) - Crtat) >> 8);		    outb(addr_6845, CRTC_CURSORL); /* select low register */		    outb(addr_6845+1,			 ((vsp->Crtat + vsp->cur_offset) - Crtat));		    outb(addr_6845, CRTC_CURSTART); /* select high register */		    outb(addr_6845+1, vsp->cursor_start);		    outb(addr_6845, CRTC_CUREND); /* select low register */		    outb(addr_6845+1, vsp->cursor_end);		  }		/* restore screen and re-enable text output */		/* kernel memory -> video board memory */		bcopy(vsp->Memory, Crtat,		       vsp->screen_rowsize * vsp->maxcol * CHR);		vsp->Crtat = Crtat;	/* operate on-screen now */		/* set crtc screen memory start address */		outb(addr_6845, CRTC_STARTADRH);		outb(addr_6845+1, (vsp->Crtat - Crtat) >> 8);		outb(addr_6845, CRTC_STARTADRL);		outb(addr_6845+1, (vsp->Crtat - Crtat));		async_update(UPDATE_START);	}	return 0;}#endif	/* XSERVER && !PCVT_USL_VT_COMPAT */#endif	/* NVT > 0 *//*-------------------------- E O F -------------------------------------*/

⌨️ 快捷键说明

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