summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/syscons/syscons.c818
-rw-r--r--sys/i386/isa/syscons.c818
-rw-r--r--sys/isa/syscons.c818
3 files changed, 1296 insertions, 1158 deletions
diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c
index e43f3c1..c7c49c3 100644
--- a/sys/dev/syscons/syscons.c
+++ b/sys/dev/syscons/syscons.c
@@ -34,19 +34,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from:@(#)syscons.c 1.3 940129
- * $Id: syscons.c,v 1.48 1994/08/13 03:50:16 wollman Exp $
- *
+ * $Id: syscons.c,v 1.1 1994/07/03 20:50:34 sos Exp $
*/
#include "sc.h"
#if NSC > 0
-#if !defined(__FreeBSD__)
-#define FAT_CURSOR
-#endif
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -63,18 +57,21 @@
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/timerreg.h>
+#include <i386/isa/kbdtables.h>
#include <i386/i386/cons.h>
#include <machine/console.h>
#include <machine/psl.h>
#include <machine/frame.h>
#include <machine/pc/display.h>
-#include <i386/isa/iso8859.font>
-#include <i386/isa/kbdtables.h>
#if !defined(NCONS)
#define NCONS 12
#endif
+#if !defined(NO_HARDFONTS)
+#include <i386/isa/iso8859.font>
+#endif
+
/* status flags */
#define LOCK_KEY_MASK 0x0000F
#define LED_MASK 0x00007
@@ -87,15 +84,21 @@
#define VIDEOMEM 0x000A0000
/* misc defines */
-#define MAX_ESC_PAR 3
+#define MAX_ESC_PAR 5
#define TEXT80x25 1
#define TEXT80x50 2
+#define LOAD 1
+#define SAVE 0
#define COL 80
#define ROW 25
#define BELL_DURATION 5
#define BELL_PITCH 800
#define TIMER_FREQ 1193182 /* should be in isa.h */
-#define PCBURST 256
+#define CONSOLE_BUFSIZE 1024
+#define PCBURST 128
+#define FONT_8_LOADED 0x001
+#define FONT_14_LOADED 0x002
+#define FONT_16_LOADED 0x004
/* defines related to hardware addresses */
#define MONO_BASE 0x3B4 /* crt controller base mono */
@@ -164,33 +167,37 @@ static default_attr kernel_default = {
(FG_BLACK | BG_LIGHTGREY) << 8
};
-#define CONSOLE_BUFFER_SIZE 1024
-int console_buffer_count;
-char console_buffer[CONSOLE_BUFFER_SIZE];
-
static scr_stat console[NCONS];
static scr_stat *cur_console = &console[0];
static scr_stat *new_scp, *old_scp;
static term_stat kernel_console;
static default_attr *current_default;
+static int console_buffer_count;
+static char console_buffer[CONSOLE_BUFSIZE];
static int switch_in_progress = 0;
static u_short *crtat = 0;
static u_int crtc_addr = MONO_BASE;
static char crtc_vga = 0;
static u_char shfts = 0, ctls = 0, alts = 0, agrs = 0, metas = 0;
static u_char nlkcnt = 0, clkcnt = 0, slkcnt = 0, alkcnt = 0;
+static char *font_8 = NULL, *font_14 = NULL, *font_16 = NULL;
+static int fonts_loaded = 0;
static char palette[3*256];
static const u_int n_fkey_tab = sizeof(fkey_tab) / sizeof(*fkey_tab);
static int cur_cursor_pos = -1;
static char in_putc = 0;
static char polling = 0;
+#if ASYNCH
+static u_char kbd_reply = 0;
+#endif
static int delayed_next_scr;
static char saved_console = -1; /* saved console number */
-static long scrn_blank_time = 0; /* screen saver timout value */
+static long scrn_blank_time = 0; /* screen saver timeout value */
static int scrn_blanked = 0; /* screen saver active flag */
static int scrn_saver = 0; /* screen saver routine */
static long scrn_time_stamp;
static u_char scr_map[256];
+
extern int hz;
extern struct timeval time;
@@ -234,18 +241,14 @@ static u_char *get_fstr(u_int c, u_int *len);
static void update_leds(int which);
static void kbd_wait(void);
static void kbd_cmd(u_char command);
-static void kbd_cmd2(u_char command, u_char arg);
-static int kbd_reply(void);
static void set_mode(scr_stat *scp);
static void set_border(int color);
-static void load_font(int segment, int size, char* font);
+static void copy_font(int direction, int segment, int size, char* font);
static void save_palette(void);
static void load_palette(void);
static void change_winsize(struct tty *tp, int x, int y);
-
/* available screen savers */
-
static void none_saver(int test);
static void blank_saver(int test);
static void fade_saver(int test);
@@ -266,18 +269,6 @@ static const struct {
#define NUM_SCRN_SAVERS (sizeof(screen_savers) / sizeof(screen_savers[0]))
/* OS specific stuff */
-
-#if defined(NetBSD)
-#define VIRTUAL_TTY(x) pc_tty[x] ? (pc_tty[x]) : (pc_tty[x] = ttymalloc())
-#define CONSOLE_TTY pc_tty[NCONS] ? (pc_tty[NCONS]) : (pc_tty[NCONS] = ttymalloc())
-#define frametype struct trapframe
-#define eflags tf_eflags
-extern u_short *Crtat;
-struct tty *pc_tty[NCONS+1];
-int ttrstrt();
-#endif
-
-#if defined(__FreeBSD__)
#if 0
#define VIRTUAL_TTY(x) (pccons[x] = ttymalloc(pccons[x]))
#define CONSOLE_TTY (pccons[NCONS] = ttymalloc(pccons[NCONS]))
@@ -288,60 +279,71 @@ struct tty *pccons[NCONS+1];
struct tty pccons[NCONS+1];
#endif
#define timeout_t timeout_func_t
-#define frametype struct trapframe
-#define eflags tf_eflags
#define MONO_BUF (KERNBASE+0xB0000)
#define CGA_BUF (KERNBASE+0xB8000)
-#endif
-
-#if defined(__386BSD__) && !defined(__FreeBSD__)
-#define VIRTUAL_TTY(x) &pccons[x]
-#define CONSOLE_TTY &pccons[NCONS]
-#define frametype struct syscframe
-#define eflags sf_eflags
-#define timeout_t caddr_t
-#define MONO_BUF (0xFE0B0000)
-#define CGA_BUF (0xFE0B8000)
-struct tty pccons[NCONS+1];
-#endif
-
-#if defined(__386BSD__) || defined(__FreeBSD__)
-u_short *Crtat = (u_short *)MONO_BUF;
-void consinit(void) {scinit();}
#include "ddb.h"
#if NDDB > 0
#define DDB 1
#endif
-#endif
+u_short *Crtat = (u_short *)MONO_BUF;
+void consinit(void) {scinit();}
struct isa_driver scdriver = {
pcprobe, pcattach, "sc",
};
-int pcprobe(struct isa_device *dev)
+int
+pcprobe(struct isa_device *dev)
{
+ int i, retries = 5;
+ unsigned char val;
+
/* Enable interrupts and keyboard controller */
kbd_wait();
outb(KB_STAT, KB_WRITE);
- kbd_cmd(0x4D);
+ kbd_wait();
+ outb(KB_DATA, KB_MODE);
- /* Start keyboard stuff RESET */
- for (;;) {
- kbd_cmd(KB_RESET);
- if (kbd_reply() == KB_ACK && /* command accepted */
- kbd_reply() == 0xaa) /* self test passed */
- break;
- printf("Keyboard reset failed\n");
-#ifdef KBD_RESET_FAIL_OK
- break;
-#endif
+ /* flush any noise in the buffer */
+ while (inb(KB_STAT) & KB_BUF_FULL) {
+ DELAY(10);
+ (void) inb(KB_DATA);
+ }
+
+ /* Reset keyboard hardware */
+ while (retries--) {
+ kbd_wait();
+ outb(KB_DATA, KB_RESET);
+ for (i=0; i<100000; i++) {
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK || val == KB_ECHO)
+ goto gotres;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+gotres:
+ if (!retries)
+ printf("scprobe: keyboard won't accept RESET command\n");
+ else {
+gotack:
+ DELAY(10);
+ while ((inb(KB_STAT) & KB_BUF_FULL) == 0) DELAY(10);
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ goto gotack;
+ if (val != KB_RESET_DONE)
+ printf("scprobe: keyboard RESET failed %02x\n", val);
}
return (IO_KBDSIZE);
}
-int pcattach(struct isa_device *dev)
+int
+pcattach(struct isa_device *dev)
{
scr_stat *scp;
int start = -1, end = -1, i;
@@ -370,15 +372,28 @@ int pcattach(struct isa_device *dev)
if (crtc_vga) {
get_cursor_shape(&start, &end);
#endif
+#if !defined(NO_HARDFONTS)
+ font_8 = font_8x8;
+ font_14 = font_8x14;
+ font_16 = font_8x16;
+ fonts_loaded = FONT_8_LOADED|FONT_14_LOADED|FONT_16_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
+ copy_font(LOAD, 0, 16, font_16);
+#else
+ font_8 = (char *)malloc(8*256, M_DEVBUF, M_NOWAIT);
+ font_14 = (char *)malloc(14*256, M_DEVBUF, M_NOWAIT);
+ font_16 = (char *)malloc(16*256, M_DEVBUF, M_NOWAIT);
+ copy_font(SAVE, 0, 16, font_16);
+ fonts_loaded = FONT_16_LOADED;
+#endif
save_palette();
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
}
current_default = &user_default;
for (i = 0; i < NCONS; i++) {
scp = &console[i];
- scp->scr_buf = (u_short *)malloc(COL * ROW * 2, M_DEVBUF, M_NOWAIT);
+ scp->scr_buf = (u_short *)malloc(COL * ROW * 2,
+ M_DEVBUF, M_NOWAIT);
scp->mode = TEXT80x25;
scp->term.esc = 0;
scp->term.std_attr = current_default->std_attr;
@@ -391,13 +406,14 @@ int pcattach(struct isa_device *dev)
scp->ysize = ROW;
scp->bell_pitch = BELL_PITCH;
scp->bell_duration = BELL_DURATION;
- scp->status = 0;
+ scp->status = NLKED;
scp->pid = 0;
scp->proc = NULL;
scp->smode.mode = VT_AUTO;
if (i > 0) {
scp->crt_base = scp->crtat = scp->scr_buf;
- fillw(scp->term.cur_attr|scr_map[0x20], scp->scr_buf, COL*ROW);
+ fillw(scp->term.cur_attr|scr_map[0x20],
+ scp->scr_buf, COL*ROW);
}
}
/* get cursor going */
@@ -406,11 +422,13 @@ int pcattach(struct isa_device *dev)
console[0].cursor_end);
#endif
cursor_pos(1);
+ update_leds(console[0].status);
return 0;
}
-static struct tty *get_tty_ptr(dev_t dev)
+static struct tty
+*get_tty_ptr(dev_t dev)
{
int unit = minor(dev);
@@ -422,7 +440,8 @@ static struct tty *get_tty_ptr(dev_t dev)
}
-static scr_stat *get_scr_stat(dev_t dev)
+static scr_stat
+*get_scr_stat(dev_t dev)
{
int unit = minor(dev);
@@ -434,7 +453,8 @@ static scr_stat *get_scr_stat(dev_t dev)
}
-static int get_scr_num()
+static int
+get_scr_num()
{
int i = 0;
@@ -442,7 +462,9 @@ static int get_scr_num()
return i < NCONS ? i : 0;
}
-int pcopen(dev_t dev, int flag, int mode, struct proc *p)
+
+int
+pcopen(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
@@ -453,7 +475,6 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
tp->t_param = pcparam;
tp->t_dev = dev;
if (!(tp->t_state & TS_ISOPEN)) {
- tp->t_state |= TS_WOPEN;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
@@ -470,7 +491,8 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcclose(dev_t dev, int flag, int mode, struct proc *p)
+int
+pcclose(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
struct scr_stat *scp;
@@ -491,7 +513,8 @@ int pcclose(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcread(dev_t dev, struct uio *uio, int flag)
+int
+pcread(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -501,7 +524,8 @@ int pcread(dev_t dev, struct uio *uio, int flag)
}
-int pcwrite(dev_t dev, struct uio *uio, int flag)
+int
+pcwrite(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -511,11 +535,8 @@ int pcwrite(dev_t dev, struct uio *uio, int flag)
}
-/*
- * Got a console interrupt, keyboard action !
- * Catch the character, and see who it goes to.
- */
-void scintr(int unit)
+void
+scintr(int unit)
{
static struct tty *cur_tty;
int c, len;
@@ -556,10 +577,8 @@ void scintr(int unit)
}
-/*
- * Set line parameters
- */
-int pcparam(struct tty *tp, struct termios *t)
+int
+pcparam(struct tty *tp, struct termios *t)
{
int cflag = t->c_cflag;
@@ -571,11 +590,12 @@ int pcparam(struct tty *tp, struct termios *t)
}
-int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
+int
+pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{
int i, error;
struct tty *tp;
- frametype *fp;
+ struct trapframe *fp;
scr_stat *scp;
tp = get_tty_ptr(dev);
@@ -627,17 +647,23 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case CONS_80x50TEXT: /* set 80x50 text mode */
if (!crtc_vga)
return ENXIO;
- scp->mode = TEXT80x50;
- scp->ysize = 50;
- free(scp->scr_buf, M_DEVBUF);
- scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*2,
- M_DEVBUF, M_NOWAIT);
- if (scp != cur_console)
- scp->crt_base = scp->scr_buf;
- set_mode(scp);
- clear_screen(scp);
- change_winsize(tp, scp->xsize, scp->ysize);
- return 0;
+ /* is there a 8x8 font loaded ? */
+ if (fonts_loaded & FONT_8_LOADED) {
+ scp->mode = TEXT80x50;
+ scp->ysize = 50;
+ free(scp->scr_buf, M_DEVBUF);
+ scp->scr_buf =
+ (u_short *)malloc(scp->xsize * scp->ysize * 2,
+ M_DEVBUF, M_NOWAIT);
+ if (scp != cur_console)
+ scp->crt_base = scp->scr_buf;
+ set_mode(scp);
+ clear_screen(scp);
+ change_winsize(tp, scp->xsize, scp->ysize);
+ return 0;
+ }
+ else
+ return EINVAL;
case CONS_GETVERS: /* get version number */
*(int*)data = 0x103; /* version 1.3 */
@@ -750,13 +776,13 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return 0;
case KDENABIO: /* allow io operations */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
return 0;
case KDDISABIO: /* disallow io operations (default) */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
return 0;
case KDSETMODE: /* set current mode of this (virtual) console */
@@ -764,9 +790,9 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KD_TEXT: /* switch to TEXT (known) mode */
/* restore fonts & palette ! */
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
/* FALL THROUGH */
@@ -815,7 +841,10 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KDSETRAD: /* set keyboard repeat & delay rates */
if (*data & 0x80)
return EINVAL;
- kbd_cmd2(KB_SETRAD, *data);
+ i = spltty();
+ kbd_cmd(KB_SETRAD);
+ kbd_cmd(*data);
+ splx(i);
return 0;
case KDSKBMODE: /* set keyboard mode */
@@ -926,48 +955,63 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case PIO_FONT8x8: /* set 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x8, sizeof(font_8x8));
- load_font(1, 8, font_8x8);
+ bcopy(data, font_8, 8*256);
+ fonts_loaded |= FONT_8_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
return 0;
case GIO_FONT8x8: /* get 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x8, data, sizeof(font_8x8));
- return 0;
+ if (fonts_loaded & FONT_8_LOADED) {
+ bcopy(font_8, data, 8*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x14: /* set 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x14, sizeof(font_8x14));
- load_font(2, 14, font_8x14);
+ bcopy(data, font_14, 14*256);
+ fonts_loaded |= FONT_14_LOADED;
+ copy_font(LOAD, 2, 14, font_14);
return 0;
case GIO_FONT8x14: /* get 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x14, data, sizeof(font_8x14));
- return 0;
+ if (fonts_loaded & FONT_14_LOADED) {
+ bcopy(font_14, data, 14*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x16: /* set 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x16, sizeof(font_8x16));
- load_font(0, 16, font_8x16);
+ bcopy(data, font_16, 16*256);
+ fonts_loaded |= FONT_16_LOADED;
+ copy_font(LOAD, 0, 16, font_16);
return 0;
case GIO_FONT8x16: /* get 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x16, data, sizeof(font_8x16));
- return 0;
+ if (fonts_loaded & FONT_16_LOADED) {
+ bcopy(font_16, data, 16*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case CONSOLE_X_MODE_ON: /* just to be compatible */
if (saved_console < 0) {
saved_console = get_scr_num();
switch_scr(minor(dev));
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
scp->status |= UNKNOWN_MODE;
scp->status |= KBD_RAW_MODE;
return 0;
@@ -975,12 +1019,12 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return EAGAIN;
case CONSOLE_X_MODE_OFF:/* just to be compatible */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
scp->status &= ~UNKNOWN_MODE;
@@ -999,7 +1043,7 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
*/
if (data)
sysbeep(TIMER_FREQ/((int*)data)[0],
- ((int*)data)[1]*hz/3000);
+ ((int*)data)[1]*hz/1000);
else
sysbeep(scp->bell_pitch, scp->bell_duration);
return 0;
@@ -1018,7 +1062,8 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
}
-void pcxint(dev_t dev)
+void
+pcxint(dev_t dev)
{
struct tty *tp = get_tty_ptr(dev);
@@ -1032,9 +1077,9 @@ void pcxint(dev_t dev)
}
-void pcstart(struct tty *tp)
+void
+pcstart(struct tty *tp)
{
-#if defined(NetBSD) || defined(__FreeBSD__)
struct clist *rbp;
int i, s, len;
u_char buf[PCBURST];
@@ -1042,7 +1087,7 @@ void pcstart(struct tty *tp)
if (scp->status & SLKED)
return;
- s = spltty(); /* Isn't start always called at spltty? */
+ s = spltty();
if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
tp->t_state |= TS_BUSY;
splx(s);
@@ -1069,58 +1114,11 @@ void pcstart(struct tty *tp)
}
}
splx(s);
-
-#else /* __386BSD__ */
-
- int c, s, len, i;
- scr_stat *scp = get_scr_stat(tp->t_dev);
- u_char buf[PCBURST];
-
- if (scp->status & SLKED)
- return;
- s = spltty();
- if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
- for (;;) {
- if (RB_LEN(tp->t_out) <= tp->t_lowat) {
- if (tp->t_state & TS_ASLEEP) {
- tp->t_state &= ~TS_ASLEEP;
- wakeup((caddr_t)tp->t_out);
- }
- selwakeup(&tp->t_wsel);
- }
- if (RB_LEN(tp->t_out) == 0)
- break;
- if (scp->status & SLKED)
- break;
- len = 0;
- while( len < PCBURST) {
- buf[len++] = getc(tp->t_out);
- if( RB_LEN(tp->t_out) == 0)
- break;
- }
- tp->t_state |= TS_BUSY;
- splx(s);
- for(i=0;i<len;i++)
- ansi_put(scp, buf[i]);
- s = spltty();
- tp->t_state &= ~TS_BUSY;
- }
- tp->t_state |= TS_BUSY;
- if( in_putc == 0) {
- int i;
- for(i=0;i<console_buffer_count;i++) {
- scput(console_buffer[i]);
- }
- console_buffer_count = 0;
- }
- tp->t_state &= ~TS_BUSY;
- }
- splx(s);
-#endif
}
-void pccnprobe(struct consdev *cp)
+void
+pccnprobe(struct consdev *cp)
{
int maj;
@@ -1132,19 +1130,18 @@ void pccnprobe(struct consdev *cp)
/* initialize required fields */
cp->cn_dev = makedev(maj, NCONS);
cp->cn_pri = CN_INTERNAL;
-#if defined(__386BSD__) && !defined(__FreeBSD__)
- cp->cn_tp = CONSOLE_TTY;
-#endif
}
-void pccninit(struct consdev *cp)
+void
+pccninit(struct consdev *cp)
{
scinit();
}
-void pccnputc(dev_t dev, char c)
+void
+pccnputc(dev_t dev, char c)
{
if (c == '\n')
scput('\r');
@@ -1162,7 +1159,8 @@ void pccnputc(dev_t dev, char c)
}
-int pccngetc(dev_t dev)
+int
+pccngetc(dev_t dev)
{
int s = spltty(); /* block scintr while we poll */
int c = scgetc(0);
@@ -1171,11 +1169,15 @@ int pccngetc(dev_t dev)
return(c);
}
-static void none_saver(int test)
+
+static void
+none_saver(int test)
{
}
-static void fade_saver(int test)
+
+static void
+fade_saver(int test)
{
static int count = 0;
int i;
@@ -1205,7 +1207,9 @@ static void fade_saver(int test)
}
}
-static void blank_saver(int test)
+
+static void
+blank_saver(int test)
{
u_char val;
if (test) {
@@ -1220,21 +1224,14 @@ static void blank_saver(int test)
}
}
-static u_long rand_next = 1;
-
-static int rand()
-{
- return ((rand_next = rand_next * 1103515245 + 12345) & 0x7FFFFFFF);
-}
+#define NUM_STARS 50
/*
* Alternate saver that got its inspiration from a well known utility
- * package for an unfamous OS.
+ * package for an inferior^H^H^H^H^H^Hfamous OS.
*/
-
-#define NUM_STARS 50
-
-static void star_saver(int test)
+static void
+star_saver(int test)
{
scr_stat *scp = cur_console;
int cell, i;
@@ -1258,16 +1255,16 @@ static void star_saver(int test)
scrn_blanked = 1;
for(i=0; i<NUM_STARS; i++) {
stars[i][0] =
- rand() % (scp->xsize*scp->ysize);
+ random() % (scp->xsize*scp->ysize);
stars[i][1] = 0;
}
}
- cell = rand() % NUM_STARS;
+ cell = random() % NUM_STARS;
*((u_short*)(Crtat + stars[cell][0])) =
scr_map[pattern[stars[cell][1]]] |
- colors[rand()%sizeof(colors)] << 8;
- if ((stars[cell][1]+=(rand()%4)) >= sizeof(pattern)-1) {
- stars[cell][0] = rand() % (scp->xsize*scp->ysize);
+ colors[random()%sizeof(colors)] << 8;
+ if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
+ stars[cell][0] = random() % (scp->xsize*scp->ysize);
stars[cell][1] = 0;
}
}
@@ -1282,9 +1279,10 @@ static void star_saver(int test)
}
-static void snake_saver(int test)
+static void
+snake_saver(int test)
{
- const char saves[] = {"FreeBSD"};
+ const char saves[] = {"FreeBSD-2.0"};
static u_char *savs[sizeof(saves)-1];
static int dirx, diry;
int f;
@@ -1320,11 +1318,11 @@ static void snake_saver(int test)
f = (savs[0] - (u_char *)Crtat) / 2;
if ((f % scp->xsize) == 0 ||
(f % scp->xsize) == scp->xsize - 1 ||
- (rand() % 50) == 0)
+ (random() % 50) == 0)
dirx = -dirx;
if ((f / scp->xsize) == 0 ||
(f / scp->xsize) == scp->ysize - 1 ||
- (rand() % 20) == 0)
+ (random() % 20) == 0)
diry = -diry;
savs[0] += 2*dirx + 2*diry;
for (f=sizeof(saves)-2; f>=0; f--)
@@ -1341,7 +1339,9 @@ static void snake_saver(int test)
}
}
-static void cursor_shape(int start, int end)
+
+static void
+cursor_shape(int start, int end)
{
outb(crtc_addr, 10);
outb(crtc_addr+1, start & 0xFF);
@@ -1351,7 +1351,8 @@ static void cursor_shape(int start, int end)
#if !defined(FAT_CURSOR)
-static void get_cursor_shape(int *start, int *end)
+static void
+get_cursor_shape(int *start, int *end)
{
outb(crtc_addr, 10);
*start = inb(crtc_addr+1) & 0x1F;
@@ -1361,7 +1362,8 @@ static void get_cursor_shape(int *start, int *end)
#endif
-static void cursor_pos(int force)
+static void
+cursor_pos(int force)
{
int pos;
@@ -1381,7 +1383,8 @@ static void cursor_pos(int force)
}
-static void clear_screen(scr_stat *scp)
+static void
+clear_screen(scr_stat *scp)
{
move_crsr(scp, 0, 0);
fillw(scp->term.cur_attr | scr_map[0x20], scp->crt_base,
@@ -1389,12 +1392,9 @@ static void clear_screen(scr_stat *scp)
}
-static int switch_scr(u_int next_scr)
+static int
+switch_scr(u_int next_scr)
{
- if (in_putc) { /* delay switch if in putc */
- delayed_next_scr = next_scr+1;
- return 0;
- }
if (switch_in_progress &&
(cur_console->proc != pfind(cur_console->pid)))
switch_in_progress = 0;
@@ -1412,7 +1412,10 @@ static int switch_scr(u_int next_scr)
return EINVAL;
}
}
-
+ if (in_putc) { /* delay switch if in putc */
+ delayed_next_scr = next_scr+1;
+ return 0;
+ }
switch_in_progress = 1;
old_scp = cur_console;
new_scp = &console[next_scr];
@@ -1446,7 +1449,8 @@ static int switch_scr(u_int next_scr)
}
-static void exchange_scr(void)
+static void
+exchange_scr(void)
{
struct tty *tp;
@@ -1460,9 +1464,9 @@ static void exchange_scr(void)
bcopy(new_scp->scr_buf, Crtat, new_scp->xsize * new_scp->ysize * 2);
update_leds(new_scp->status);
if ((old_scp->status & UNKNOWN_MODE) && crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
if (old_scp->status & KBD_RAW_MODE || new_scp->status & KBD_RAW_MODE)
@@ -1471,7 +1475,8 @@ static void exchange_scr(void)
}
-static void move_crsr(scr_stat *scp, int x, int y)
+static void
+move_crsr(scr_stat *scp, int x, int y)
{
if (x < 0 || y < 0 || x >= scp->xsize || y >= scp->ysize)
return;
@@ -1480,7 +1485,9 @@ static void move_crsr(scr_stat *scp, int x, int y)
scp->crtat = scp->crt_base + scp->ypos * scp->xsize + scp->xpos;
}
-static void move_up(u_short *s, u_short *d, u_int len)
+
+static void
+move_up(u_short *s, u_short *d, u_int len)
{
s += len;
d += len;
@@ -1488,13 +1495,17 @@ static void move_up(u_short *s, u_short *d, u_int len)
*--d = *--s;
}
-static void move_down(u_short *s, u_short *d, u_int len)
+
+static void
+move_down(u_short *s, u_short *d, u_int len)
{
while (len-- > 0)
*d++ = *s++;
}
-static void scan_esc(scr_stat *scp, u_char c)
+
+static void
+scan_esc(scr_stat *scp, u_char c)
{
static u_char ansi_col[16] =
{0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15};
@@ -1762,39 +1773,45 @@ static void scan_esc(scr_stat *scp, u_char c)
break;
case 'm': /* change attribute */
- if (scp->term.num_param == 0)
- n = 0;
- else
- n = scp->term.param[0];
- switch (n) {
- case 0: /* back to normal */
+ if (scp->term.num_param == 0) {
scp->term.cur_attr = scp->term.std_attr;
break;
- case 1: /* highlight (bold) */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 4: /* highlight (underline) */
- scp->term.cur_attr &= 0x0F00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 5: /* blink */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x8000;
- break;
- case 7: /* reverse video */
- scp->term.cur_attr = scp->term.rev_attr;
- break;
- case 30: case 31: case 32: case 33: /* set fg color */
- case 34: case 35: case 36: case 37:
- scp->term.cur_attr = (scp->term.cur_attr & 0xF0FF)
- | (ansi_col[(n - 30) & 7] << 8);
- break;
- case 40: case 41: case 42: case 43: /* set bg color */
- case 44: case 45: case 46: case 47:
- scp->term.cur_attr = (scp->term.cur_attr & 0x0FFF)
- | (ansi_col[(n - 40) & 7] << 12);
- break;
+ }
+ for (i = 0; i < scp->term.num_param; i++) {
+ switch (n = scp->term.param[i]) {
+ case 0: /* back to normal */
+ scp->term.cur_attr = scp->term.std_attr;
+ break;
+ case 1: /* highlight (bold) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 4: /* highlight (underline) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 5: /* blink */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x8000;
+ break;
+ case 7: /* reverse video */
+ scp->term.cur_attr = scp->term.rev_attr;
+ break;
+ case 30: case 31: /* set fg color */
+ case 32: case 33: case 34:
+ case 35: case 36: case 37:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0xF8FF)
+ | (ansi_col[(n-30) & 7] << 8);
+ break;
+ case 40: case 41: /* set bg color */
+ case 42: case 43: case 44:
+ case 45: case 46: case 47:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0x8FFF)
+ | (ansi_col[(n-40) & 7] << 12);
+ break;
+ }
}
break;
@@ -1923,7 +1940,8 @@ static void scan_esc(scr_stat *scp, u_char c)
}
-static void ansi_put(scr_stat *scp, u_char c)
+static void
+ansi_put(scr_stat *scp, u_char c)
{
if (scp->status & UNKNOWN_MODE)
return;
@@ -1995,7 +2013,9 @@ static void ansi_put(scr_stat *scp, u_char c)
switch_scr(delayed_next_scr - 1);
}
-static void scinit(void)
+
+static void
+scinit(void)
{
u_short volatile *cp = Crtat + (CGA_BUF-MONO_BUF)/sizeof(u_short), was;
unsigned cursorat;
@@ -2046,7 +2066,7 @@ static void scinit(void)
console[0].border = BG_BLACK;;
console[0].xsize = COL;
console[0].ysize = ROW;
- console[0].status = 0;
+ console[0].status = NLKED;
console[0].pid = 0;
console[0].proc = NULL;
console[0].smode.mode = VT_AUTO;
@@ -2063,7 +2083,8 @@ static void scinit(void)
}
-static void scput(u_char c)
+static void
+scput(u_char c)
{
scr_stat *scp = &console[0];
term_stat save;
@@ -2081,13 +2102,14 @@ static void scput(u_char c)
scp->term = save;
--in_putc;
} else {
- if( console_buffer_count < CONSOLE_BUFFER_SIZE)
+ if( console_buffer_count < CONSOLE_BUFSIZE)
console_buffer[console_buffer_count++] = c;
}
}
-static u_char *get_fstr(u_int c, u_int *len)
+static u_char
+*get_fstr(u_int c, u_int *len)
{
u_int i;
@@ -2101,8 +2123,10 @@ static u_char *get_fstr(u_int c, u_int *len)
}
-static void update_leds(int which)
+static void
+update_leds(int which)
{
+ int s;
static u_char xlate_leds[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
/* replace CAPS led with ALTGR led for ALTGR keyboards */
@@ -2112,17 +2136,22 @@ static void update_leds(int which)
else
which &= ~CLKED;
}
- kbd_cmd2(KB_SETLEDS, xlate_leds[which & LED_MASK]);
+ s = spltty();
+ kbd_cmd(KB_SETLEDS);
+ kbd_cmd(xlate_leds[which & LED_MASK]);
+ splx(s);
}
/*
- * scgetc(noblock) : get a character from the keyboard.
- * If noblock = 0 wait until a key is gotten. Otherwise return NOKEY.
+ * scgetc(noblock) - get character from keyboard.
+ * If noblock = 0 wait until a key is pressed.
+ * Else return NOKEY.
*/
-u_int scgetc(int noblock)
+u_int
+scgetc(int noblock)
{
- u_char val, code, release;
+ u_char scancode, keycode;
u_int state, action;
struct key_t *key;
static u_char esc_flag = 0, compose = 0;
@@ -2132,132 +2161,136 @@ next_code:
kbd_wait();
/* First see if there is something in the keyboard port */
if (inb(KB_STAT) & KB_BUF_FULL)
- val = inb(KB_DATA);
+ scancode = inb(KB_DATA);
else if (noblock)
return(NOKEY);
else
goto next_code;
if (cur_console->status & KBD_RAW_MODE)
- return val;
-
- code = val & 0x7F;
- release = val & 0x80;
-
+ return scancode;
+#if ASYNCH
+ if (scancode == KB_ACK || scancode == KB_RESEND) {
+ kbd_reply = scancode;
+ if (noblock)
+ return(NOKEY);
+ goto next_code;
+ }
+#endif
+ keycode = scancode & 0x7F;
switch (esc_flag) {
case 0x00: /* normal scancode */
- switch(code) {
- case 0x38: /* left alt (compose key) */
- if (release && compose) {
+ switch(scancode) {
+ case 0xB8: /* left alt (compose key) */
+ if (compose) {
compose = 0;
if (chr > 255) {
sysbeep(BELL_PITCH, BELL_DURATION);
chr = 0;
}
}
- else {
- if (!compose) {
- compose = 1;
- chr = 0;
- }
+ break;
+ case 0x38:
+ if (!compose) {
+ compose = 1;
+ chr = 0;
}
break;
- case 0x60:
- case 0x61:
- esc_flag = code;
+ case 0xE0:
+ case 0xE1:
+ esc_flag = scancode;
goto next_code;
}
break;
- case 0x60: /* 0xE0 prefix */
+ case 0xE0: /* 0xE0 prefix */
esc_flag = 0;
- switch (code) {
- case 0x1c: /* right enter key */
- code = 0x59;
+ switch (keycode) {
+ case 0x1C: /* right enter key */
+ keycode = 0x59;
break;
- case 0x1d: /* right ctrl key */
- code = 0x5a;
+ case 0x1D: /* right ctrl key */
+ keycode = 0x5A;
break;
case 0x35: /* keypad divide key */
- code = 0x5b;
+ keycode = 0x5B;
break;
case 0x37: /* print scrn key */
- code = 0x5c;
+ keycode = 0x5C;
break;
case 0x38: /* right alt key (alt gr) */
- code = 0x5d;
+ keycode = 0x5D;
break;
case 0x47: /* grey home key */
- code = 0x5e;
+ keycode = 0x5E;
break;
case 0x48: /* grey up arrow key */
- code = 0x5f;
+ keycode = 0x5F;
break;
case 0x49: /* grey page up key */
- code = 0x60;
+ keycode = 0x60;
break;
- case 0x4b: /* grey left arrow key */
- code = 0x61;
+ case 0x4B: /* grey left arrow key */
+ keycode = 0x61;
break;
- case 0x4d: /* grey right arrow key */
- code = 0x62;
+ case 0x4D: /* grey right arrow key */
+ keycode = 0x62;
break;
- case 0x4f: /* grey end key */
- code = 0x63;
+ case 0x4F: /* grey end key */
+ keycode = 0x63;
break;
case 0x50: /* grey down arrow key */
- code = 0x64;
+ keycode = 0x64;
break;
case 0x51: /* grey page down key */
- code = 0x65;
+ keycode = 0x65;
break;
case 0x52: /* grey insert key */
- code = 0x66;
+ keycode = 0x66;
break;
case 0x53: /* grey delete key */
- code = 0x67;
+ keycode = 0x67;
break;
default: /* ignore everything else */
goto next_code;
}
break;
- case 0x61: /* 0xE1 prefix */
+ case 0xE1: /* 0xE1 prefix */
esc_flag = 0;
- if (code == 0x1D)
+ if (keycode == 0x1D)
esc_flag = 0x1D;
goto next_code;
/* NOT REACHED */
case 0x1D: /* pause / break */
esc_flag = 0;
- if (code != 0x45)
+ if (keycode != 0x45)
goto next_code;
- code = 0x68;
+ keycode = 0x68;
break;
}
if (compose) {
- switch (code) {
- case 0x47:
- case 0x48: /* keypad 7,8,9 */
- case 0x49:
- if (!release)
- chr = (code - 0x40) + chr*10;
+ switch (scancode) {
+ /* key pressed process it */
+ case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */
+ chr = (scancode - 0x40) + chr*10;
goto next_code;
- case 0x4b:
- case 0x4c: /* keypad 4,5,6 */
- case 0x4d:
- if (!release)
- chr = (code - 0x47) + chr*10;
+ case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */
+ chr = (scancode - 0x47) + chr*10;
goto next_code;
- case 0x4f:
- case 0x50: /* keypad 1,2,3 */
- case 0x51:
- if (!release)
- chr = (code - 0x4e) + chr*10;
+ case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */
+ chr = (scancode - 0x4E) + chr*10;
goto next_code;
case 0x52: /* keypad 0 */
- if (!release)
- chr *= 10;
+ chr *= 10;
goto next_code;
+
+ /* key release, no interest here */
+ case 0xC7: case 0xC8: case 0xC9: /* keypad 7,8,9 */
+ case 0xCB: case 0xCC: case 0xCD: /* keypad 4,5,6 */
+ case 0xCF: case 0xD0: case 0xD1: /* keypad 1,2,3 */
+ case 0xD2: /* keypad 0 */
+ goto next_code;
+
case 0x38: /* left alt key */
break;
default:
@@ -2273,15 +2306,15 @@ next_code:
state = (shfts ? 1 : 0 ) | (2 * (ctls ? 1 : 0)) | (4 * (alts ? 1 : 0));
if ((!agrs && (cur_console->status & ALKED))
|| (agrs && !(cur_console->status & ALKED)))
- code += ALTGR_OFFSET;
- key = &key_map.key[code];
+ keycode += ALTGR_OFFSET;
+ key = &key_map.key[keycode];
if ( ((key->flgs & FLAG_LOCK_C) && (cur_console->status & CLKED))
|| ((key->flgs & FLAG_LOCK_N) && (cur_console->status & NLKED)) )
state ^= 1;
/* Check for make/break */
action = key->map[state];
- if (release) { /* key released */
+ if (scancode & 0x80) { /* key released */
if (key->spcl & 0x80) {
switch (action) {
case LSH:
@@ -2379,11 +2412,7 @@ next_code:
case NOP:
break;
case RBT:
-#if defined(__FreeBSD__)
shutdown_nice();
-#else
- cpu_reset();
-#endif
break;
case DBG:
#if DDB > 0 /* try to switch to console 0 */
@@ -2443,7 +2472,8 @@ next_code:
}
-int getchar(void)
+int
+getchar(void)
{
u_char thechar;
int s;
@@ -2474,12 +2504,15 @@ int getchar(void)
}
-u_int sgetc(int noblock)
+u_int
+sgetc(int noblock)
{
return (scgetc(noblock) & 0xff);
}
-int pcmmap(dev_t dev, int offset, int nprot)
+
+int
+pcmmap(dev_t dev, int offset, int nprot)
{
if (offset > 0x20000)
return EINVAL;
@@ -2487,11 +2520,12 @@ int pcmmap(dev_t dev, int offset, int nprot)
}
-static void kbd_wait(void)
+static void
+kbd_wait(void)
{
- int i;
+ int i = 1000;
- for (i=0; i<1000; i++) { /* up to 10 msec */
+ while (i--) {
if ((inb(KB_STAT) & KB_READY) == 0)
break;
DELAY (10);
@@ -2499,43 +2533,43 @@ static void kbd_wait(void)
}
-static void kbd_cmd(u_char command)
-{
- kbd_wait();
- outb(KB_DATA, command);
-}
-
-
-static void kbd_cmd2(u_char command, u_char arg)
+static void
+kbd_cmd(u_char command)
{
- int r, s = spltty();
+ int retry = 5;
do {
- kbd_cmd(command);
- r = kbd_reply();
- if (r == KB_ACK) {
- kbd_cmd(arg & 0x7f);
- r = kbd_reply();
+ int i = 100000;
+
+ kbd_wait();
+#if ASYNCH
+ kbd_reply = 0;
+ outb(KB_DATA, command);
+ while (i--) {
+ if (kbd_reply == KB_ACK)
+ return;
+ if (kbd_reply == KB_RESEND)
+ break;
}
- } while (r != KB_ACK);
- splx(s);
-}
-
-
-static int kbd_reply()
-{
- int i;
-
- kbd_wait();
- for (i=0; i<60000; i++) { /* at least 300 msec, 600 msec enough */
- if (inb(KB_STAT) & KB_BUF_FULL)
- return ((u_char) inb(KB_DATA));
- DELAY (10);
- }
- return(-1);
+#else
+ outb(KB_DATA, command);
+ while (i--) {
+ if (inb(KB_STAT) & KB_BUF_FULL) {
+ int val;
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ return;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+#endif
+ } while (retry--);
}
-static void set_mode(scr_stat *scp)
+static void
+set_mode(scr_stat *scp)
{
u_char byte;
int s;
@@ -2579,15 +2613,18 @@ static void set_mode(scr_stat *scp)
}
-static void set_border(int color)
+static void
+set_border(int color)
{
inb(crtc_addr+6); /* reset flip-flop */
outb(ATC, 0x11); outb(ATC, color);
inb(crtc_addr+6); /* reset flip-flop */
- outb(ATC, 0x20); /* enable Palette */
+ outb(ATC, 0x20); /* enable Palette */
}
-static void load_font(int segment, int size, char* font)
+
+static void
+copy_font(int direction, int segment, int size, char* font)
{
int ch, line, s;
u_char val;
@@ -2606,9 +2643,14 @@ static void load_font(int segment, int size, char* font)
outb(GDCIDX, 0x06); outb(GDCREG, 0x05); /* addr = a0000, 64kb */
splx(s);
for (ch=0; ch < 256; ch++)
- for (line=0; line < size; line++)
- *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
- font[(ch*size)+line];
+ for (line=0; line < size; line++)
+ if (direction)
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
+ font[(ch*size)+line];
+ else
+ font[(ch*size)+line] =
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line);
+
/* setup vga for text mode again */
s = splhigh();
inb(crtc_addr+6); /* reset flip/flop */
@@ -2629,7 +2671,8 @@ static void load_font(int segment, int size, char* font)
}
-static void load_palette(void)
+static void
+load_palette(void)
{
int i;
@@ -2641,7 +2684,9 @@ static void load_palette(void)
outb(ATC, 0x20); /* enable palette */
}
-static void save_palette(void)
+
+static void
+save_palette(void)
{
int i;
@@ -2652,7 +2697,8 @@ static void save_palette(void)
}
-static void change_winsize(struct tty *tp, int x, int y)
+static void
+change_winsize(struct tty *tp, int x, int y)
{
if (tp->t_winsize.ws_col != x || tp->t_winsize.ws_row != y) {
tp->t_winsize.ws_col = x;
diff --git a/sys/i386/isa/syscons.c b/sys/i386/isa/syscons.c
index e43f3c1..c7c49c3 100644
--- a/sys/i386/isa/syscons.c
+++ b/sys/i386/isa/syscons.c
@@ -34,19 +34,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from:@(#)syscons.c 1.3 940129
- * $Id: syscons.c,v 1.48 1994/08/13 03:50:16 wollman Exp $
- *
+ * $Id: syscons.c,v 1.1 1994/07/03 20:50:34 sos Exp $
*/
#include "sc.h"
#if NSC > 0
-#if !defined(__FreeBSD__)
-#define FAT_CURSOR
-#endif
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -63,18 +57,21 @@
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/timerreg.h>
+#include <i386/isa/kbdtables.h>
#include <i386/i386/cons.h>
#include <machine/console.h>
#include <machine/psl.h>
#include <machine/frame.h>
#include <machine/pc/display.h>
-#include <i386/isa/iso8859.font>
-#include <i386/isa/kbdtables.h>
#if !defined(NCONS)
#define NCONS 12
#endif
+#if !defined(NO_HARDFONTS)
+#include <i386/isa/iso8859.font>
+#endif
+
/* status flags */
#define LOCK_KEY_MASK 0x0000F
#define LED_MASK 0x00007
@@ -87,15 +84,21 @@
#define VIDEOMEM 0x000A0000
/* misc defines */
-#define MAX_ESC_PAR 3
+#define MAX_ESC_PAR 5
#define TEXT80x25 1
#define TEXT80x50 2
+#define LOAD 1
+#define SAVE 0
#define COL 80
#define ROW 25
#define BELL_DURATION 5
#define BELL_PITCH 800
#define TIMER_FREQ 1193182 /* should be in isa.h */
-#define PCBURST 256
+#define CONSOLE_BUFSIZE 1024
+#define PCBURST 128
+#define FONT_8_LOADED 0x001
+#define FONT_14_LOADED 0x002
+#define FONT_16_LOADED 0x004
/* defines related to hardware addresses */
#define MONO_BASE 0x3B4 /* crt controller base mono */
@@ -164,33 +167,37 @@ static default_attr kernel_default = {
(FG_BLACK | BG_LIGHTGREY) << 8
};
-#define CONSOLE_BUFFER_SIZE 1024
-int console_buffer_count;
-char console_buffer[CONSOLE_BUFFER_SIZE];
-
static scr_stat console[NCONS];
static scr_stat *cur_console = &console[0];
static scr_stat *new_scp, *old_scp;
static term_stat kernel_console;
static default_attr *current_default;
+static int console_buffer_count;
+static char console_buffer[CONSOLE_BUFSIZE];
static int switch_in_progress = 0;
static u_short *crtat = 0;
static u_int crtc_addr = MONO_BASE;
static char crtc_vga = 0;
static u_char shfts = 0, ctls = 0, alts = 0, agrs = 0, metas = 0;
static u_char nlkcnt = 0, clkcnt = 0, slkcnt = 0, alkcnt = 0;
+static char *font_8 = NULL, *font_14 = NULL, *font_16 = NULL;
+static int fonts_loaded = 0;
static char palette[3*256];
static const u_int n_fkey_tab = sizeof(fkey_tab) / sizeof(*fkey_tab);
static int cur_cursor_pos = -1;
static char in_putc = 0;
static char polling = 0;
+#if ASYNCH
+static u_char kbd_reply = 0;
+#endif
static int delayed_next_scr;
static char saved_console = -1; /* saved console number */
-static long scrn_blank_time = 0; /* screen saver timout value */
+static long scrn_blank_time = 0; /* screen saver timeout value */
static int scrn_blanked = 0; /* screen saver active flag */
static int scrn_saver = 0; /* screen saver routine */
static long scrn_time_stamp;
static u_char scr_map[256];
+
extern int hz;
extern struct timeval time;
@@ -234,18 +241,14 @@ static u_char *get_fstr(u_int c, u_int *len);
static void update_leds(int which);
static void kbd_wait(void);
static void kbd_cmd(u_char command);
-static void kbd_cmd2(u_char command, u_char arg);
-static int kbd_reply(void);
static void set_mode(scr_stat *scp);
static void set_border(int color);
-static void load_font(int segment, int size, char* font);
+static void copy_font(int direction, int segment, int size, char* font);
static void save_palette(void);
static void load_palette(void);
static void change_winsize(struct tty *tp, int x, int y);
-
/* available screen savers */
-
static void none_saver(int test);
static void blank_saver(int test);
static void fade_saver(int test);
@@ -266,18 +269,6 @@ static const struct {
#define NUM_SCRN_SAVERS (sizeof(screen_savers) / sizeof(screen_savers[0]))
/* OS specific stuff */
-
-#if defined(NetBSD)
-#define VIRTUAL_TTY(x) pc_tty[x] ? (pc_tty[x]) : (pc_tty[x] = ttymalloc())
-#define CONSOLE_TTY pc_tty[NCONS] ? (pc_tty[NCONS]) : (pc_tty[NCONS] = ttymalloc())
-#define frametype struct trapframe
-#define eflags tf_eflags
-extern u_short *Crtat;
-struct tty *pc_tty[NCONS+1];
-int ttrstrt();
-#endif
-
-#if defined(__FreeBSD__)
#if 0
#define VIRTUAL_TTY(x) (pccons[x] = ttymalloc(pccons[x]))
#define CONSOLE_TTY (pccons[NCONS] = ttymalloc(pccons[NCONS]))
@@ -288,60 +279,71 @@ struct tty *pccons[NCONS+1];
struct tty pccons[NCONS+1];
#endif
#define timeout_t timeout_func_t
-#define frametype struct trapframe
-#define eflags tf_eflags
#define MONO_BUF (KERNBASE+0xB0000)
#define CGA_BUF (KERNBASE+0xB8000)
-#endif
-
-#if defined(__386BSD__) && !defined(__FreeBSD__)
-#define VIRTUAL_TTY(x) &pccons[x]
-#define CONSOLE_TTY &pccons[NCONS]
-#define frametype struct syscframe
-#define eflags sf_eflags
-#define timeout_t caddr_t
-#define MONO_BUF (0xFE0B0000)
-#define CGA_BUF (0xFE0B8000)
-struct tty pccons[NCONS+1];
-#endif
-
-#if defined(__386BSD__) || defined(__FreeBSD__)
-u_short *Crtat = (u_short *)MONO_BUF;
-void consinit(void) {scinit();}
#include "ddb.h"
#if NDDB > 0
#define DDB 1
#endif
-#endif
+u_short *Crtat = (u_short *)MONO_BUF;
+void consinit(void) {scinit();}
struct isa_driver scdriver = {
pcprobe, pcattach, "sc",
};
-int pcprobe(struct isa_device *dev)
+int
+pcprobe(struct isa_device *dev)
{
+ int i, retries = 5;
+ unsigned char val;
+
/* Enable interrupts and keyboard controller */
kbd_wait();
outb(KB_STAT, KB_WRITE);
- kbd_cmd(0x4D);
+ kbd_wait();
+ outb(KB_DATA, KB_MODE);
- /* Start keyboard stuff RESET */
- for (;;) {
- kbd_cmd(KB_RESET);
- if (kbd_reply() == KB_ACK && /* command accepted */
- kbd_reply() == 0xaa) /* self test passed */
- break;
- printf("Keyboard reset failed\n");
-#ifdef KBD_RESET_FAIL_OK
- break;
-#endif
+ /* flush any noise in the buffer */
+ while (inb(KB_STAT) & KB_BUF_FULL) {
+ DELAY(10);
+ (void) inb(KB_DATA);
+ }
+
+ /* Reset keyboard hardware */
+ while (retries--) {
+ kbd_wait();
+ outb(KB_DATA, KB_RESET);
+ for (i=0; i<100000; i++) {
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK || val == KB_ECHO)
+ goto gotres;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+gotres:
+ if (!retries)
+ printf("scprobe: keyboard won't accept RESET command\n");
+ else {
+gotack:
+ DELAY(10);
+ while ((inb(KB_STAT) & KB_BUF_FULL) == 0) DELAY(10);
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ goto gotack;
+ if (val != KB_RESET_DONE)
+ printf("scprobe: keyboard RESET failed %02x\n", val);
}
return (IO_KBDSIZE);
}
-int pcattach(struct isa_device *dev)
+int
+pcattach(struct isa_device *dev)
{
scr_stat *scp;
int start = -1, end = -1, i;
@@ -370,15 +372,28 @@ int pcattach(struct isa_device *dev)
if (crtc_vga) {
get_cursor_shape(&start, &end);
#endif
+#if !defined(NO_HARDFONTS)
+ font_8 = font_8x8;
+ font_14 = font_8x14;
+ font_16 = font_8x16;
+ fonts_loaded = FONT_8_LOADED|FONT_14_LOADED|FONT_16_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
+ copy_font(LOAD, 0, 16, font_16);
+#else
+ font_8 = (char *)malloc(8*256, M_DEVBUF, M_NOWAIT);
+ font_14 = (char *)malloc(14*256, M_DEVBUF, M_NOWAIT);
+ font_16 = (char *)malloc(16*256, M_DEVBUF, M_NOWAIT);
+ copy_font(SAVE, 0, 16, font_16);
+ fonts_loaded = FONT_16_LOADED;
+#endif
save_palette();
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
}
current_default = &user_default;
for (i = 0; i < NCONS; i++) {
scp = &console[i];
- scp->scr_buf = (u_short *)malloc(COL * ROW * 2, M_DEVBUF, M_NOWAIT);
+ scp->scr_buf = (u_short *)malloc(COL * ROW * 2,
+ M_DEVBUF, M_NOWAIT);
scp->mode = TEXT80x25;
scp->term.esc = 0;
scp->term.std_attr = current_default->std_attr;
@@ -391,13 +406,14 @@ int pcattach(struct isa_device *dev)
scp->ysize = ROW;
scp->bell_pitch = BELL_PITCH;
scp->bell_duration = BELL_DURATION;
- scp->status = 0;
+ scp->status = NLKED;
scp->pid = 0;
scp->proc = NULL;
scp->smode.mode = VT_AUTO;
if (i > 0) {
scp->crt_base = scp->crtat = scp->scr_buf;
- fillw(scp->term.cur_attr|scr_map[0x20], scp->scr_buf, COL*ROW);
+ fillw(scp->term.cur_attr|scr_map[0x20],
+ scp->scr_buf, COL*ROW);
}
}
/* get cursor going */
@@ -406,11 +422,13 @@ int pcattach(struct isa_device *dev)
console[0].cursor_end);
#endif
cursor_pos(1);
+ update_leds(console[0].status);
return 0;
}
-static struct tty *get_tty_ptr(dev_t dev)
+static struct tty
+*get_tty_ptr(dev_t dev)
{
int unit = minor(dev);
@@ -422,7 +440,8 @@ static struct tty *get_tty_ptr(dev_t dev)
}
-static scr_stat *get_scr_stat(dev_t dev)
+static scr_stat
+*get_scr_stat(dev_t dev)
{
int unit = minor(dev);
@@ -434,7 +453,8 @@ static scr_stat *get_scr_stat(dev_t dev)
}
-static int get_scr_num()
+static int
+get_scr_num()
{
int i = 0;
@@ -442,7 +462,9 @@ static int get_scr_num()
return i < NCONS ? i : 0;
}
-int pcopen(dev_t dev, int flag, int mode, struct proc *p)
+
+int
+pcopen(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
@@ -453,7 +475,6 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
tp->t_param = pcparam;
tp->t_dev = dev;
if (!(tp->t_state & TS_ISOPEN)) {
- tp->t_state |= TS_WOPEN;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
@@ -470,7 +491,8 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcclose(dev_t dev, int flag, int mode, struct proc *p)
+int
+pcclose(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
struct scr_stat *scp;
@@ -491,7 +513,8 @@ int pcclose(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcread(dev_t dev, struct uio *uio, int flag)
+int
+pcread(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -501,7 +524,8 @@ int pcread(dev_t dev, struct uio *uio, int flag)
}
-int pcwrite(dev_t dev, struct uio *uio, int flag)
+int
+pcwrite(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -511,11 +535,8 @@ int pcwrite(dev_t dev, struct uio *uio, int flag)
}
-/*
- * Got a console interrupt, keyboard action !
- * Catch the character, and see who it goes to.
- */
-void scintr(int unit)
+void
+scintr(int unit)
{
static struct tty *cur_tty;
int c, len;
@@ -556,10 +577,8 @@ void scintr(int unit)
}
-/*
- * Set line parameters
- */
-int pcparam(struct tty *tp, struct termios *t)
+int
+pcparam(struct tty *tp, struct termios *t)
{
int cflag = t->c_cflag;
@@ -571,11 +590,12 @@ int pcparam(struct tty *tp, struct termios *t)
}
-int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
+int
+pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{
int i, error;
struct tty *tp;
- frametype *fp;
+ struct trapframe *fp;
scr_stat *scp;
tp = get_tty_ptr(dev);
@@ -627,17 +647,23 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case CONS_80x50TEXT: /* set 80x50 text mode */
if (!crtc_vga)
return ENXIO;
- scp->mode = TEXT80x50;
- scp->ysize = 50;
- free(scp->scr_buf, M_DEVBUF);
- scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*2,
- M_DEVBUF, M_NOWAIT);
- if (scp != cur_console)
- scp->crt_base = scp->scr_buf;
- set_mode(scp);
- clear_screen(scp);
- change_winsize(tp, scp->xsize, scp->ysize);
- return 0;
+ /* is there a 8x8 font loaded ? */
+ if (fonts_loaded & FONT_8_LOADED) {
+ scp->mode = TEXT80x50;
+ scp->ysize = 50;
+ free(scp->scr_buf, M_DEVBUF);
+ scp->scr_buf =
+ (u_short *)malloc(scp->xsize * scp->ysize * 2,
+ M_DEVBUF, M_NOWAIT);
+ if (scp != cur_console)
+ scp->crt_base = scp->scr_buf;
+ set_mode(scp);
+ clear_screen(scp);
+ change_winsize(tp, scp->xsize, scp->ysize);
+ return 0;
+ }
+ else
+ return EINVAL;
case CONS_GETVERS: /* get version number */
*(int*)data = 0x103; /* version 1.3 */
@@ -750,13 +776,13 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return 0;
case KDENABIO: /* allow io operations */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
return 0;
case KDDISABIO: /* disallow io operations (default) */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
return 0;
case KDSETMODE: /* set current mode of this (virtual) console */
@@ -764,9 +790,9 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KD_TEXT: /* switch to TEXT (known) mode */
/* restore fonts & palette ! */
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
/* FALL THROUGH */
@@ -815,7 +841,10 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KDSETRAD: /* set keyboard repeat & delay rates */
if (*data & 0x80)
return EINVAL;
- kbd_cmd2(KB_SETRAD, *data);
+ i = spltty();
+ kbd_cmd(KB_SETRAD);
+ kbd_cmd(*data);
+ splx(i);
return 0;
case KDSKBMODE: /* set keyboard mode */
@@ -926,48 +955,63 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case PIO_FONT8x8: /* set 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x8, sizeof(font_8x8));
- load_font(1, 8, font_8x8);
+ bcopy(data, font_8, 8*256);
+ fonts_loaded |= FONT_8_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
return 0;
case GIO_FONT8x8: /* get 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x8, data, sizeof(font_8x8));
- return 0;
+ if (fonts_loaded & FONT_8_LOADED) {
+ bcopy(font_8, data, 8*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x14: /* set 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x14, sizeof(font_8x14));
- load_font(2, 14, font_8x14);
+ bcopy(data, font_14, 14*256);
+ fonts_loaded |= FONT_14_LOADED;
+ copy_font(LOAD, 2, 14, font_14);
return 0;
case GIO_FONT8x14: /* get 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x14, data, sizeof(font_8x14));
- return 0;
+ if (fonts_loaded & FONT_14_LOADED) {
+ bcopy(font_14, data, 14*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x16: /* set 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x16, sizeof(font_8x16));
- load_font(0, 16, font_8x16);
+ bcopy(data, font_16, 16*256);
+ fonts_loaded |= FONT_16_LOADED;
+ copy_font(LOAD, 0, 16, font_16);
return 0;
case GIO_FONT8x16: /* get 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x16, data, sizeof(font_8x16));
- return 0;
+ if (fonts_loaded & FONT_16_LOADED) {
+ bcopy(font_16, data, 16*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case CONSOLE_X_MODE_ON: /* just to be compatible */
if (saved_console < 0) {
saved_console = get_scr_num();
switch_scr(minor(dev));
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
scp->status |= UNKNOWN_MODE;
scp->status |= KBD_RAW_MODE;
return 0;
@@ -975,12 +1019,12 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return EAGAIN;
case CONSOLE_X_MODE_OFF:/* just to be compatible */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
scp->status &= ~UNKNOWN_MODE;
@@ -999,7 +1043,7 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
*/
if (data)
sysbeep(TIMER_FREQ/((int*)data)[0],
- ((int*)data)[1]*hz/3000);
+ ((int*)data)[1]*hz/1000);
else
sysbeep(scp->bell_pitch, scp->bell_duration);
return 0;
@@ -1018,7 +1062,8 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
}
-void pcxint(dev_t dev)
+void
+pcxint(dev_t dev)
{
struct tty *tp = get_tty_ptr(dev);
@@ -1032,9 +1077,9 @@ void pcxint(dev_t dev)
}
-void pcstart(struct tty *tp)
+void
+pcstart(struct tty *tp)
{
-#if defined(NetBSD) || defined(__FreeBSD__)
struct clist *rbp;
int i, s, len;
u_char buf[PCBURST];
@@ -1042,7 +1087,7 @@ void pcstart(struct tty *tp)
if (scp->status & SLKED)
return;
- s = spltty(); /* Isn't start always called at spltty? */
+ s = spltty();
if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
tp->t_state |= TS_BUSY;
splx(s);
@@ -1069,58 +1114,11 @@ void pcstart(struct tty *tp)
}
}
splx(s);
-
-#else /* __386BSD__ */
-
- int c, s, len, i;
- scr_stat *scp = get_scr_stat(tp->t_dev);
- u_char buf[PCBURST];
-
- if (scp->status & SLKED)
- return;
- s = spltty();
- if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
- for (;;) {
- if (RB_LEN(tp->t_out) <= tp->t_lowat) {
- if (tp->t_state & TS_ASLEEP) {
- tp->t_state &= ~TS_ASLEEP;
- wakeup((caddr_t)tp->t_out);
- }
- selwakeup(&tp->t_wsel);
- }
- if (RB_LEN(tp->t_out) == 0)
- break;
- if (scp->status & SLKED)
- break;
- len = 0;
- while( len < PCBURST) {
- buf[len++] = getc(tp->t_out);
- if( RB_LEN(tp->t_out) == 0)
- break;
- }
- tp->t_state |= TS_BUSY;
- splx(s);
- for(i=0;i<len;i++)
- ansi_put(scp, buf[i]);
- s = spltty();
- tp->t_state &= ~TS_BUSY;
- }
- tp->t_state |= TS_BUSY;
- if( in_putc == 0) {
- int i;
- for(i=0;i<console_buffer_count;i++) {
- scput(console_buffer[i]);
- }
- console_buffer_count = 0;
- }
- tp->t_state &= ~TS_BUSY;
- }
- splx(s);
-#endif
}
-void pccnprobe(struct consdev *cp)
+void
+pccnprobe(struct consdev *cp)
{
int maj;
@@ -1132,19 +1130,18 @@ void pccnprobe(struct consdev *cp)
/* initialize required fields */
cp->cn_dev = makedev(maj, NCONS);
cp->cn_pri = CN_INTERNAL;
-#if defined(__386BSD__) && !defined(__FreeBSD__)
- cp->cn_tp = CONSOLE_TTY;
-#endif
}
-void pccninit(struct consdev *cp)
+void
+pccninit(struct consdev *cp)
{
scinit();
}
-void pccnputc(dev_t dev, char c)
+void
+pccnputc(dev_t dev, char c)
{
if (c == '\n')
scput('\r');
@@ -1162,7 +1159,8 @@ void pccnputc(dev_t dev, char c)
}
-int pccngetc(dev_t dev)
+int
+pccngetc(dev_t dev)
{
int s = spltty(); /* block scintr while we poll */
int c = scgetc(0);
@@ -1171,11 +1169,15 @@ int pccngetc(dev_t dev)
return(c);
}
-static void none_saver(int test)
+
+static void
+none_saver(int test)
{
}
-static void fade_saver(int test)
+
+static void
+fade_saver(int test)
{
static int count = 0;
int i;
@@ -1205,7 +1207,9 @@ static void fade_saver(int test)
}
}
-static void blank_saver(int test)
+
+static void
+blank_saver(int test)
{
u_char val;
if (test) {
@@ -1220,21 +1224,14 @@ static void blank_saver(int test)
}
}
-static u_long rand_next = 1;
-
-static int rand()
-{
- return ((rand_next = rand_next * 1103515245 + 12345) & 0x7FFFFFFF);
-}
+#define NUM_STARS 50
/*
* Alternate saver that got its inspiration from a well known utility
- * package for an unfamous OS.
+ * package for an inferior^H^H^H^H^H^Hfamous OS.
*/
-
-#define NUM_STARS 50
-
-static void star_saver(int test)
+static void
+star_saver(int test)
{
scr_stat *scp = cur_console;
int cell, i;
@@ -1258,16 +1255,16 @@ static void star_saver(int test)
scrn_blanked = 1;
for(i=0; i<NUM_STARS; i++) {
stars[i][0] =
- rand() % (scp->xsize*scp->ysize);
+ random() % (scp->xsize*scp->ysize);
stars[i][1] = 0;
}
}
- cell = rand() % NUM_STARS;
+ cell = random() % NUM_STARS;
*((u_short*)(Crtat + stars[cell][0])) =
scr_map[pattern[stars[cell][1]]] |
- colors[rand()%sizeof(colors)] << 8;
- if ((stars[cell][1]+=(rand()%4)) >= sizeof(pattern)-1) {
- stars[cell][0] = rand() % (scp->xsize*scp->ysize);
+ colors[random()%sizeof(colors)] << 8;
+ if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
+ stars[cell][0] = random() % (scp->xsize*scp->ysize);
stars[cell][1] = 0;
}
}
@@ -1282,9 +1279,10 @@ static void star_saver(int test)
}
-static void snake_saver(int test)
+static void
+snake_saver(int test)
{
- const char saves[] = {"FreeBSD"};
+ const char saves[] = {"FreeBSD-2.0"};
static u_char *savs[sizeof(saves)-1];
static int dirx, diry;
int f;
@@ -1320,11 +1318,11 @@ static void snake_saver(int test)
f = (savs[0] - (u_char *)Crtat) / 2;
if ((f % scp->xsize) == 0 ||
(f % scp->xsize) == scp->xsize - 1 ||
- (rand() % 50) == 0)
+ (random() % 50) == 0)
dirx = -dirx;
if ((f / scp->xsize) == 0 ||
(f / scp->xsize) == scp->ysize - 1 ||
- (rand() % 20) == 0)
+ (random() % 20) == 0)
diry = -diry;
savs[0] += 2*dirx + 2*diry;
for (f=sizeof(saves)-2; f>=0; f--)
@@ -1341,7 +1339,9 @@ static void snake_saver(int test)
}
}
-static void cursor_shape(int start, int end)
+
+static void
+cursor_shape(int start, int end)
{
outb(crtc_addr, 10);
outb(crtc_addr+1, start & 0xFF);
@@ -1351,7 +1351,8 @@ static void cursor_shape(int start, int end)
#if !defined(FAT_CURSOR)
-static void get_cursor_shape(int *start, int *end)
+static void
+get_cursor_shape(int *start, int *end)
{
outb(crtc_addr, 10);
*start = inb(crtc_addr+1) & 0x1F;
@@ -1361,7 +1362,8 @@ static void get_cursor_shape(int *start, int *end)
#endif
-static void cursor_pos(int force)
+static void
+cursor_pos(int force)
{
int pos;
@@ -1381,7 +1383,8 @@ static void cursor_pos(int force)
}
-static void clear_screen(scr_stat *scp)
+static void
+clear_screen(scr_stat *scp)
{
move_crsr(scp, 0, 0);
fillw(scp->term.cur_attr | scr_map[0x20], scp->crt_base,
@@ -1389,12 +1392,9 @@ static void clear_screen(scr_stat *scp)
}
-static int switch_scr(u_int next_scr)
+static int
+switch_scr(u_int next_scr)
{
- if (in_putc) { /* delay switch if in putc */
- delayed_next_scr = next_scr+1;
- return 0;
- }
if (switch_in_progress &&
(cur_console->proc != pfind(cur_console->pid)))
switch_in_progress = 0;
@@ -1412,7 +1412,10 @@ static int switch_scr(u_int next_scr)
return EINVAL;
}
}
-
+ if (in_putc) { /* delay switch if in putc */
+ delayed_next_scr = next_scr+1;
+ return 0;
+ }
switch_in_progress = 1;
old_scp = cur_console;
new_scp = &console[next_scr];
@@ -1446,7 +1449,8 @@ static int switch_scr(u_int next_scr)
}
-static void exchange_scr(void)
+static void
+exchange_scr(void)
{
struct tty *tp;
@@ -1460,9 +1464,9 @@ static void exchange_scr(void)
bcopy(new_scp->scr_buf, Crtat, new_scp->xsize * new_scp->ysize * 2);
update_leds(new_scp->status);
if ((old_scp->status & UNKNOWN_MODE) && crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
if (old_scp->status & KBD_RAW_MODE || new_scp->status & KBD_RAW_MODE)
@@ -1471,7 +1475,8 @@ static void exchange_scr(void)
}
-static void move_crsr(scr_stat *scp, int x, int y)
+static void
+move_crsr(scr_stat *scp, int x, int y)
{
if (x < 0 || y < 0 || x >= scp->xsize || y >= scp->ysize)
return;
@@ -1480,7 +1485,9 @@ static void move_crsr(scr_stat *scp, int x, int y)
scp->crtat = scp->crt_base + scp->ypos * scp->xsize + scp->xpos;
}
-static void move_up(u_short *s, u_short *d, u_int len)
+
+static void
+move_up(u_short *s, u_short *d, u_int len)
{
s += len;
d += len;
@@ -1488,13 +1495,17 @@ static void move_up(u_short *s, u_short *d, u_int len)
*--d = *--s;
}
-static void move_down(u_short *s, u_short *d, u_int len)
+
+static void
+move_down(u_short *s, u_short *d, u_int len)
{
while (len-- > 0)
*d++ = *s++;
}
-static void scan_esc(scr_stat *scp, u_char c)
+
+static void
+scan_esc(scr_stat *scp, u_char c)
{
static u_char ansi_col[16] =
{0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15};
@@ -1762,39 +1773,45 @@ static void scan_esc(scr_stat *scp, u_char c)
break;
case 'm': /* change attribute */
- if (scp->term.num_param == 0)
- n = 0;
- else
- n = scp->term.param[0];
- switch (n) {
- case 0: /* back to normal */
+ if (scp->term.num_param == 0) {
scp->term.cur_attr = scp->term.std_attr;
break;
- case 1: /* highlight (bold) */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 4: /* highlight (underline) */
- scp->term.cur_attr &= 0x0F00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 5: /* blink */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x8000;
- break;
- case 7: /* reverse video */
- scp->term.cur_attr = scp->term.rev_attr;
- break;
- case 30: case 31: case 32: case 33: /* set fg color */
- case 34: case 35: case 36: case 37:
- scp->term.cur_attr = (scp->term.cur_attr & 0xF0FF)
- | (ansi_col[(n - 30) & 7] << 8);
- break;
- case 40: case 41: case 42: case 43: /* set bg color */
- case 44: case 45: case 46: case 47:
- scp->term.cur_attr = (scp->term.cur_attr & 0x0FFF)
- | (ansi_col[(n - 40) & 7] << 12);
- break;
+ }
+ for (i = 0; i < scp->term.num_param; i++) {
+ switch (n = scp->term.param[i]) {
+ case 0: /* back to normal */
+ scp->term.cur_attr = scp->term.std_attr;
+ break;
+ case 1: /* highlight (bold) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 4: /* highlight (underline) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 5: /* blink */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x8000;
+ break;
+ case 7: /* reverse video */
+ scp->term.cur_attr = scp->term.rev_attr;
+ break;
+ case 30: case 31: /* set fg color */
+ case 32: case 33: case 34:
+ case 35: case 36: case 37:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0xF8FF)
+ | (ansi_col[(n-30) & 7] << 8);
+ break;
+ case 40: case 41: /* set bg color */
+ case 42: case 43: case 44:
+ case 45: case 46: case 47:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0x8FFF)
+ | (ansi_col[(n-40) & 7] << 12);
+ break;
+ }
}
break;
@@ -1923,7 +1940,8 @@ static void scan_esc(scr_stat *scp, u_char c)
}
-static void ansi_put(scr_stat *scp, u_char c)
+static void
+ansi_put(scr_stat *scp, u_char c)
{
if (scp->status & UNKNOWN_MODE)
return;
@@ -1995,7 +2013,9 @@ static void ansi_put(scr_stat *scp, u_char c)
switch_scr(delayed_next_scr - 1);
}
-static void scinit(void)
+
+static void
+scinit(void)
{
u_short volatile *cp = Crtat + (CGA_BUF-MONO_BUF)/sizeof(u_short), was;
unsigned cursorat;
@@ -2046,7 +2066,7 @@ static void scinit(void)
console[0].border = BG_BLACK;;
console[0].xsize = COL;
console[0].ysize = ROW;
- console[0].status = 0;
+ console[0].status = NLKED;
console[0].pid = 0;
console[0].proc = NULL;
console[0].smode.mode = VT_AUTO;
@@ -2063,7 +2083,8 @@ static void scinit(void)
}
-static void scput(u_char c)
+static void
+scput(u_char c)
{
scr_stat *scp = &console[0];
term_stat save;
@@ -2081,13 +2102,14 @@ static void scput(u_char c)
scp->term = save;
--in_putc;
} else {
- if( console_buffer_count < CONSOLE_BUFFER_SIZE)
+ if( console_buffer_count < CONSOLE_BUFSIZE)
console_buffer[console_buffer_count++] = c;
}
}
-static u_char *get_fstr(u_int c, u_int *len)
+static u_char
+*get_fstr(u_int c, u_int *len)
{
u_int i;
@@ -2101,8 +2123,10 @@ static u_char *get_fstr(u_int c, u_int *len)
}
-static void update_leds(int which)
+static void
+update_leds(int which)
{
+ int s;
static u_char xlate_leds[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
/* replace CAPS led with ALTGR led for ALTGR keyboards */
@@ -2112,17 +2136,22 @@ static void update_leds(int which)
else
which &= ~CLKED;
}
- kbd_cmd2(KB_SETLEDS, xlate_leds[which & LED_MASK]);
+ s = spltty();
+ kbd_cmd(KB_SETLEDS);
+ kbd_cmd(xlate_leds[which & LED_MASK]);
+ splx(s);
}
/*
- * scgetc(noblock) : get a character from the keyboard.
- * If noblock = 0 wait until a key is gotten. Otherwise return NOKEY.
+ * scgetc(noblock) - get character from keyboard.
+ * If noblock = 0 wait until a key is pressed.
+ * Else return NOKEY.
*/
-u_int scgetc(int noblock)
+u_int
+scgetc(int noblock)
{
- u_char val, code, release;
+ u_char scancode, keycode;
u_int state, action;
struct key_t *key;
static u_char esc_flag = 0, compose = 0;
@@ -2132,132 +2161,136 @@ next_code:
kbd_wait();
/* First see if there is something in the keyboard port */
if (inb(KB_STAT) & KB_BUF_FULL)
- val = inb(KB_DATA);
+ scancode = inb(KB_DATA);
else if (noblock)
return(NOKEY);
else
goto next_code;
if (cur_console->status & KBD_RAW_MODE)
- return val;
-
- code = val & 0x7F;
- release = val & 0x80;
-
+ return scancode;
+#if ASYNCH
+ if (scancode == KB_ACK || scancode == KB_RESEND) {
+ kbd_reply = scancode;
+ if (noblock)
+ return(NOKEY);
+ goto next_code;
+ }
+#endif
+ keycode = scancode & 0x7F;
switch (esc_flag) {
case 0x00: /* normal scancode */
- switch(code) {
- case 0x38: /* left alt (compose key) */
- if (release && compose) {
+ switch(scancode) {
+ case 0xB8: /* left alt (compose key) */
+ if (compose) {
compose = 0;
if (chr > 255) {
sysbeep(BELL_PITCH, BELL_DURATION);
chr = 0;
}
}
- else {
- if (!compose) {
- compose = 1;
- chr = 0;
- }
+ break;
+ case 0x38:
+ if (!compose) {
+ compose = 1;
+ chr = 0;
}
break;
- case 0x60:
- case 0x61:
- esc_flag = code;
+ case 0xE0:
+ case 0xE1:
+ esc_flag = scancode;
goto next_code;
}
break;
- case 0x60: /* 0xE0 prefix */
+ case 0xE0: /* 0xE0 prefix */
esc_flag = 0;
- switch (code) {
- case 0x1c: /* right enter key */
- code = 0x59;
+ switch (keycode) {
+ case 0x1C: /* right enter key */
+ keycode = 0x59;
break;
- case 0x1d: /* right ctrl key */
- code = 0x5a;
+ case 0x1D: /* right ctrl key */
+ keycode = 0x5A;
break;
case 0x35: /* keypad divide key */
- code = 0x5b;
+ keycode = 0x5B;
break;
case 0x37: /* print scrn key */
- code = 0x5c;
+ keycode = 0x5C;
break;
case 0x38: /* right alt key (alt gr) */
- code = 0x5d;
+ keycode = 0x5D;
break;
case 0x47: /* grey home key */
- code = 0x5e;
+ keycode = 0x5E;
break;
case 0x48: /* grey up arrow key */
- code = 0x5f;
+ keycode = 0x5F;
break;
case 0x49: /* grey page up key */
- code = 0x60;
+ keycode = 0x60;
break;
- case 0x4b: /* grey left arrow key */
- code = 0x61;
+ case 0x4B: /* grey left arrow key */
+ keycode = 0x61;
break;
- case 0x4d: /* grey right arrow key */
- code = 0x62;
+ case 0x4D: /* grey right arrow key */
+ keycode = 0x62;
break;
- case 0x4f: /* grey end key */
- code = 0x63;
+ case 0x4F: /* grey end key */
+ keycode = 0x63;
break;
case 0x50: /* grey down arrow key */
- code = 0x64;
+ keycode = 0x64;
break;
case 0x51: /* grey page down key */
- code = 0x65;
+ keycode = 0x65;
break;
case 0x52: /* grey insert key */
- code = 0x66;
+ keycode = 0x66;
break;
case 0x53: /* grey delete key */
- code = 0x67;
+ keycode = 0x67;
break;
default: /* ignore everything else */
goto next_code;
}
break;
- case 0x61: /* 0xE1 prefix */
+ case 0xE1: /* 0xE1 prefix */
esc_flag = 0;
- if (code == 0x1D)
+ if (keycode == 0x1D)
esc_flag = 0x1D;
goto next_code;
/* NOT REACHED */
case 0x1D: /* pause / break */
esc_flag = 0;
- if (code != 0x45)
+ if (keycode != 0x45)
goto next_code;
- code = 0x68;
+ keycode = 0x68;
break;
}
if (compose) {
- switch (code) {
- case 0x47:
- case 0x48: /* keypad 7,8,9 */
- case 0x49:
- if (!release)
- chr = (code - 0x40) + chr*10;
+ switch (scancode) {
+ /* key pressed process it */
+ case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */
+ chr = (scancode - 0x40) + chr*10;
goto next_code;
- case 0x4b:
- case 0x4c: /* keypad 4,5,6 */
- case 0x4d:
- if (!release)
- chr = (code - 0x47) + chr*10;
+ case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */
+ chr = (scancode - 0x47) + chr*10;
goto next_code;
- case 0x4f:
- case 0x50: /* keypad 1,2,3 */
- case 0x51:
- if (!release)
- chr = (code - 0x4e) + chr*10;
+ case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */
+ chr = (scancode - 0x4E) + chr*10;
goto next_code;
case 0x52: /* keypad 0 */
- if (!release)
- chr *= 10;
+ chr *= 10;
goto next_code;
+
+ /* key release, no interest here */
+ case 0xC7: case 0xC8: case 0xC9: /* keypad 7,8,9 */
+ case 0xCB: case 0xCC: case 0xCD: /* keypad 4,5,6 */
+ case 0xCF: case 0xD0: case 0xD1: /* keypad 1,2,3 */
+ case 0xD2: /* keypad 0 */
+ goto next_code;
+
case 0x38: /* left alt key */
break;
default:
@@ -2273,15 +2306,15 @@ next_code:
state = (shfts ? 1 : 0 ) | (2 * (ctls ? 1 : 0)) | (4 * (alts ? 1 : 0));
if ((!agrs && (cur_console->status & ALKED))
|| (agrs && !(cur_console->status & ALKED)))
- code += ALTGR_OFFSET;
- key = &key_map.key[code];
+ keycode += ALTGR_OFFSET;
+ key = &key_map.key[keycode];
if ( ((key->flgs & FLAG_LOCK_C) && (cur_console->status & CLKED))
|| ((key->flgs & FLAG_LOCK_N) && (cur_console->status & NLKED)) )
state ^= 1;
/* Check for make/break */
action = key->map[state];
- if (release) { /* key released */
+ if (scancode & 0x80) { /* key released */
if (key->spcl & 0x80) {
switch (action) {
case LSH:
@@ -2379,11 +2412,7 @@ next_code:
case NOP:
break;
case RBT:
-#if defined(__FreeBSD__)
shutdown_nice();
-#else
- cpu_reset();
-#endif
break;
case DBG:
#if DDB > 0 /* try to switch to console 0 */
@@ -2443,7 +2472,8 @@ next_code:
}
-int getchar(void)
+int
+getchar(void)
{
u_char thechar;
int s;
@@ -2474,12 +2504,15 @@ int getchar(void)
}
-u_int sgetc(int noblock)
+u_int
+sgetc(int noblock)
{
return (scgetc(noblock) & 0xff);
}
-int pcmmap(dev_t dev, int offset, int nprot)
+
+int
+pcmmap(dev_t dev, int offset, int nprot)
{
if (offset > 0x20000)
return EINVAL;
@@ -2487,11 +2520,12 @@ int pcmmap(dev_t dev, int offset, int nprot)
}
-static void kbd_wait(void)
+static void
+kbd_wait(void)
{
- int i;
+ int i = 1000;
- for (i=0; i<1000; i++) { /* up to 10 msec */
+ while (i--) {
if ((inb(KB_STAT) & KB_READY) == 0)
break;
DELAY (10);
@@ -2499,43 +2533,43 @@ static void kbd_wait(void)
}
-static void kbd_cmd(u_char command)
-{
- kbd_wait();
- outb(KB_DATA, command);
-}
-
-
-static void kbd_cmd2(u_char command, u_char arg)
+static void
+kbd_cmd(u_char command)
{
- int r, s = spltty();
+ int retry = 5;
do {
- kbd_cmd(command);
- r = kbd_reply();
- if (r == KB_ACK) {
- kbd_cmd(arg & 0x7f);
- r = kbd_reply();
+ int i = 100000;
+
+ kbd_wait();
+#if ASYNCH
+ kbd_reply = 0;
+ outb(KB_DATA, command);
+ while (i--) {
+ if (kbd_reply == KB_ACK)
+ return;
+ if (kbd_reply == KB_RESEND)
+ break;
}
- } while (r != KB_ACK);
- splx(s);
-}
-
-
-static int kbd_reply()
-{
- int i;
-
- kbd_wait();
- for (i=0; i<60000; i++) { /* at least 300 msec, 600 msec enough */
- if (inb(KB_STAT) & KB_BUF_FULL)
- return ((u_char) inb(KB_DATA));
- DELAY (10);
- }
- return(-1);
+#else
+ outb(KB_DATA, command);
+ while (i--) {
+ if (inb(KB_STAT) & KB_BUF_FULL) {
+ int val;
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ return;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+#endif
+ } while (retry--);
}
-static void set_mode(scr_stat *scp)
+static void
+set_mode(scr_stat *scp)
{
u_char byte;
int s;
@@ -2579,15 +2613,18 @@ static void set_mode(scr_stat *scp)
}
-static void set_border(int color)
+static void
+set_border(int color)
{
inb(crtc_addr+6); /* reset flip-flop */
outb(ATC, 0x11); outb(ATC, color);
inb(crtc_addr+6); /* reset flip-flop */
- outb(ATC, 0x20); /* enable Palette */
+ outb(ATC, 0x20); /* enable Palette */
}
-static void load_font(int segment, int size, char* font)
+
+static void
+copy_font(int direction, int segment, int size, char* font)
{
int ch, line, s;
u_char val;
@@ -2606,9 +2643,14 @@ static void load_font(int segment, int size, char* font)
outb(GDCIDX, 0x06); outb(GDCREG, 0x05); /* addr = a0000, 64kb */
splx(s);
for (ch=0; ch < 256; ch++)
- for (line=0; line < size; line++)
- *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
- font[(ch*size)+line];
+ for (line=0; line < size; line++)
+ if (direction)
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
+ font[(ch*size)+line];
+ else
+ font[(ch*size)+line] =
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line);
+
/* setup vga for text mode again */
s = splhigh();
inb(crtc_addr+6); /* reset flip/flop */
@@ -2629,7 +2671,8 @@ static void load_font(int segment, int size, char* font)
}
-static void load_palette(void)
+static void
+load_palette(void)
{
int i;
@@ -2641,7 +2684,9 @@ static void load_palette(void)
outb(ATC, 0x20); /* enable palette */
}
-static void save_palette(void)
+
+static void
+save_palette(void)
{
int i;
@@ -2652,7 +2697,8 @@ static void save_palette(void)
}
-static void change_winsize(struct tty *tp, int x, int y)
+static void
+change_winsize(struct tty *tp, int x, int y)
{
if (tp->t_winsize.ws_col != x || tp->t_winsize.ws_row != y) {
tp->t_winsize.ws_col = x;
diff --git a/sys/isa/syscons.c b/sys/isa/syscons.c
index e43f3c1..c7c49c3 100644
--- a/sys/isa/syscons.c
+++ b/sys/isa/syscons.c
@@ -34,19 +34,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from:@(#)syscons.c 1.3 940129
- * $Id: syscons.c,v 1.48 1994/08/13 03:50:16 wollman Exp $
- *
+ * $Id: syscons.c,v 1.1 1994/07/03 20:50:34 sos Exp $
*/
#include "sc.h"
#if NSC > 0
-#if !defined(__FreeBSD__)
-#define FAT_CURSOR
-#endif
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -63,18 +57,21 @@
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/timerreg.h>
+#include <i386/isa/kbdtables.h>
#include <i386/i386/cons.h>
#include <machine/console.h>
#include <machine/psl.h>
#include <machine/frame.h>
#include <machine/pc/display.h>
-#include <i386/isa/iso8859.font>
-#include <i386/isa/kbdtables.h>
#if !defined(NCONS)
#define NCONS 12
#endif
+#if !defined(NO_HARDFONTS)
+#include <i386/isa/iso8859.font>
+#endif
+
/* status flags */
#define LOCK_KEY_MASK 0x0000F
#define LED_MASK 0x00007
@@ -87,15 +84,21 @@
#define VIDEOMEM 0x000A0000
/* misc defines */
-#define MAX_ESC_PAR 3
+#define MAX_ESC_PAR 5
#define TEXT80x25 1
#define TEXT80x50 2
+#define LOAD 1
+#define SAVE 0
#define COL 80
#define ROW 25
#define BELL_DURATION 5
#define BELL_PITCH 800
#define TIMER_FREQ 1193182 /* should be in isa.h */
-#define PCBURST 256
+#define CONSOLE_BUFSIZE 1024
+#define PCBURST 128
+#define FONT_8_LOADED 0x001
+#define FONT_14_LOADED 0x002
+#define FONT_16_LOADED 0x004
/* defines related to hardware addresses */
#define MONO_BASE 0x3B4 /* crt controller base mono */
@@ -164,33 +167,37 @@ static default_attr kernel_default = {
(FG_BLACK | BG_LIGHTGREY) << 8
};
-#define CONSOLE_BUFFER_SIZE 1024
-int console_buffer_count;
-char console_buffer[CONSOLE_BUFFER_SIZE];
-
static scr_stat console[NCONS];
static scr_stat *cur_console = &console[0];
static scr_stat *new_scp, *old_scp;
static term_stat kernel_console;
static default_attr *current_default;
+static int console_buffer_count;
+static char console_buffer[CONSOLE_BUFSIZE];
static int switch_in_progress = 0;
static u_short *crtat = 0;
static u_int crtc_addr = MONO_BASE;
static char crtc_vga = 0;
static u_char shfts = 0, ctls = 0, alts = 0, agrs = 0, metas = 0;
static u_char nlkcnt = 0, clkcnt = 0, slkcnt = 0, alkcnt = 0;
+static char *font_8 = NULL, *font_14 = NULL, *font_16 = NULL;
+static int fonts_loaded = 0;
static char palette[3*256];
static const u_int n_fkey_tab = sizeof(fkey_tab) / sizeof(*fkey_tab);
static int cur_cursor_pos = -1;
static char in_putc = 0;
static char polling = 0;
+#if ASYNCH
+static u_char kbd_reply = 0;
+#endif
static int delayed_next_scr;
static char saved_console = -1; /* saved console number */
-static long scrn_blank_time = 0; /* screen saver timout value */
+static long scrn_blank_time = 0; /* screen saver timeout value */
static int scrn_blanked = 0; /* screen saver active flag */
static int scrn_saver = 0; /* screen saver routine */
static long scrn_time_stamp;
static u_char scr_map[256];
+
extern int hz;
extern struct timeval time;
@@ -234,18 +241,14 @@ static u_char *get_fstr(u_int c, u_int *len);
static void update_leds(int which);
static void kbd_wait(void);
static void kbd_cmd(u_char command);
-static void kbd_cmd2(u_char command, u_char arg);
-static int kbd_reply(void);
static void set_mode(scr_stat *scp);
static void set_border(int color);
-static void load_font(int segment, int size, char* font);
+static void copy_font(int direction, int segment, int size, char* font);
static void save_palette(void);
static void load_palette(void);
static void change_winsize(struct tty *tp, int x, int y);
-
/* available screen savers */
-
static void none_saver(int test);
static void blank_saver(int test);
static void fade_saver(int test);
@@ -266,18 +269,6 @@ static const struct {
#define NUM_SCRN_SAVERS (sizeof(screen_savers) / sizeof(screen_savers[0]))
/* OS specific stuff */
-
-#if defined(NetBSD)
-#define VIRTUAL_TTY(x) pc_tty[x] ? (pc_tty[x]) : (pc_tty[x] = ttymalloc())
-#define CONSOLE_TTY pc_tty[NCONS] ? (pc_tty[NCONS]) : (pc_tty[NCONS] = ttymalloc())
-#define frametype struct trapframe
-#define eflags tf_eflags
-extern u_short *Crtat;
-struct tty *pc_tty[NCONS+1];
-int ttrstrt();
-#endif
-
-#if defined(__FreeBSD__)
#if 0
#define VIRTUAL_TTY(x) (pccons[x] = ttymalloc(pccons[x]))
#define CONSOLE_TTY (pccons[NCONS] = ttymalloc(pccons[NCONS]))
@@ -288,60 +279,71 @@ struct tty *pccons[NCONS+1];
struct tty pccons[NCONS+1];
#endif
#define timeout_t timeout_func_t
-#define frametype struct trapframe
-#define eflags tf_eflags
#define MONO_BUF (KERNBASE+0xB0000)
#define CGA_BUF (KERNBASE+0xB8000)
-#endif
-
-#if defined(__386BSD__) && !defined(__FreeBSD__)
-#define VIRTUAL_TTY(x) &pccons[x]
-#define CONSOLE_TTY &pccons[NCONS]
-#define frametype struct syscframe
-#define eflags sf_eflags
-#define timeout_t caddr_t
-#define MONO_BUF (0xFE0B0000)
-#define CGA_BUF (0xFE0B8000)
-struct tty pccons[NCONS+1];
-#endif
-
-#if defined(__386BSD__) || defined(__FreeBSD__)
-u_short *Crtat = (u_short *)MONO_BUF;
-void consinit(void) {scinit();}
#include "ddb.h"
#if NDDB > 0
#define DDB 1
#endif
-#endif
+u_short *Crtat = (u_short *)MONO_BUF;
+void consinit(void) {scinit();}
struct isa_driver scdriver = {
pcprobe, pcattach, "sc",
};
-int pcprobe(struct isa_device *dev)
+int
+pcprobe(struct isa_device *dev)
{
+ int i, retries = 5;
+ unsigned char val;
+
/* Enable interrupts and keyboard controller */
kbd_wait();
outb(KB_STAT, KB_WRITE);
- kbd_cmd(0x4D);
+ kbd_wait();
+ outb(KB_DATA, KB_MODE);
- /* Start keyboard stuff RESET */
- for (;;) {
- kbd_cmd(KB_RESET);
- if (kbd_reply() == KB_ACK && /* command accepted */
- kbd_reply() == 0xaa) /* self test passed */
- break;
- printf("Keyboard reset failed\n");
-#ifdef KBD_RESET_FAIL_OK
- break;
-#endif
+ /* flush any noise in the buffer */
+ while (inb(KB_STAT) & KB_BUF_FULL) {
+ DELAY(10);
+ (void) inb(KB_DATA);
+ }
+
+ /* Reset keyboard hardware */
+ while (retries--) {
+ kbd_wait();
+ outb(KB_DATA, KB_RESET);
+ for (i=0; i<100000; i++) {
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK || val == KB_ECHO)
+ goto gotres;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+gotres:
+ if (!retries)
+ printf("scprobe: keyboard won't accept RESET command\n");
+ else {
+gotack:
+ DELAY(10);
+ while ((inb(KB_STAT) & KB_BUF_FULL) == 0) DELAY(10);
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ goto gotack;
+ if (val != KB_RESET_DONE)
+ printf("scprobe: keyboard RESET failed %02x\n", val);
}
return (IO_KBDSIZE);
}
-int pcattach(struct isa_device *dev)
+int
+pcattach(struct isa_device *dev)
{
scr_stat *scp;
int start = -1, end = -1, i;
@@ -370,15 +372,28 @@ int pcattach(struct isa_device *dev)
if (crtc_vga) {
get_cursor_shape(&start, &end);
#endif
+#if !defined(NO_HARDFONTS)
+ font_8 = font_8x8;
+ font_14 = font_8x14;
+ font_16 = font_8x16;
+ fonts_loaded = FONT_8_LOADED|FONT_14_LOADED|FONT_16_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
+ copy_font(LOAD, 0, 16, font_16);
+#else
+ font_8 = (char *)malloc(8*256, M_DEVBUF, M_NOWAIT);
+ font_14 = (char *)malloc(14*256, M_DEVBUF, M_NOWAIT);
+ font_16 = (char *)malloc(16*256, M_DEVBUF, M_NOWAIT);
+ copy_font(SAVE, 0, 16, font_16);
+ fonts_loaded = FONT_16_LOADED;
+#endif
save_palette();
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
}
current_default = &user_default;
for (i = 0; i < NCONS; i++) {
scp = &console[i];
- scp->scr_buf = (u_short *)malloc(COL * ROW * 2, M_DEVBUF, M_NOWAIT);
+ scp->scr_buf = (u_short *)malloc(COL * ROW * 2,
+ M_DEVBUF, M_NOWAIT);
scp->mode = TEXT80x25;
scp->term.esc = 0;
scp->term.std_attr = current_default->std_attr;
@@ -391,13 +406,14 @@ int pcattach(struct isa_device *dev)
scp->ysize = ROW;
scp->bell_pitch = BELL_PITCH;
scp->bell_duration = BELL_DURATION;
- scp->status = 0;
+ scp->status = NLKED;
scp->pid = 0;
scp->proc = NULL;
scp->smode.mode = VT_AUTO;
if (i > 0) {
scp->crt_base = scp->crtat = scp->scr_buf;
- fillw(scp->term.cur_attr|scr_map[0x20], scp->scr_buf, COL*ROW);
+ fillw(scp->term.cur_attr|scr_map[0x20],
+ scp->scr_buf, COL*ROW);
}
}
/* get cursor going */
@@ -406,11 +422,13 @@ int pcattach(struct isa_device *dev)
console[0].cursor_end);
#endif
cursor_pos(1);
+ update_leds(console[0].status);
return 0;
}
-static struct tty *get_tty_ptr(dev_t dev)
+static struct tty
+*get_tty_ptr(dev_t dev)
{
int unit = minor(dev);
@@ -422,7 +440,8 @@ static struct tty *get_tty_ptr(dev_t dev)
}
-static scr_stat *get_scr_stat(dev_t dev)
+static scr_stat
+*get_scr_stat(dev_t dev)
{
int unit = minor(dev);
@@ -434,7 +453,8 @@ static scr_stat *get_scr_stat(dev_t dev)
}
-static int get_scr_num()
+static int
+get_scr_num()
{
int i = 0;
@@ -442,7 +462,9 @@ static int get_scr_num()
return i < NCONS ? i : 0;
}
-int pcopen(dev_t dev, int flag, int mode, struct proc *p)
+
+int
+pcopen(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
@@ -453,7 +475,6 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
tp->t_param = pcparam;
tp->t_dev = dev;
if (!(tp->t_state & TS_ISOPEN)) {
- tp->t_state |= TS_WOPEN;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
@@ -470,7 +491,8 @@ int pcopen(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcclose(dev_t dev, int flag, int mode, struct proc *p)
+int
+pcclose(dev_t dev, int flag, int mode, struct proc *p)
{
struct tty *tp = get_tty_ptr(dev);
struct scr_stat *scp;
@@ -491,7 +513,8 @@ int pcclose(dev_t dev, int flag, int mode, struct proc *p)
}
-int pcread(dev_t dev, struct uio *uio, int flag)
+int
+pcread(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -501,7 +524,8 @@ int pcread(dev_t dev, struct uio *uio, int flag)
}
-int pcwrite(dev_t dev, struct uio *uio, int flag)
+int
+pcwrite(dev_t dev, struct uio *uio, int flag)
{
struct tty *tp = get_tty_ptr(dev);
@@ -511,11 +535,8 @@ int pcwrite(dev_t dev, struct uio *uio, int flag)
}
-/*
- * Got a console interrupt, keyboard action !
- * Catch the character, and see who it goes to.
- */
-void scintr(int unit)
+void
+scintr(int unit)
{
static struct tty *cur_tty;
int c, len;
@@ -556,10 +577,8 @@ void scintr(int unit)
}
-/*
- * Set line parameters
- */
-int pcparam(struct tty *tp, struct termios *t)
+int
+pcparam(struct tty *tp, struct termios *t)
{
int cflag = t->c_cflag;
@@ -571,11 +590,12 @@ int pcparam(struct tty *tp, struct termios *t)
}
-int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
+int
+pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{
int i, error;
struct tty *tp;
- frametype *fp;
+ struct trapframe *fp;
scr_stat *scp;
tp = get_tty_ptr(dev);
@@ -627,17 +647,23 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case CONS_80x50TEXT: /* set 80x50 text mode */
if (!crtc_vga)
return ENXIO;
- scp->mode = TEXT80x50;
- scp->ysize = 50;
- free(scp->scr_buf, M_DEVBUF);
- scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*2,
- M_DEVBUF, M_NOWAIT);
- if (scp != cur_console)
- scp->crt_base = scp->scr_buf;
- set_mode(scp);
- clear_screen(scp);
- change_winsize(tp, scp->xsize, scp->ysize);
- return 0;
+ /* is there a 8x8 font loaded ? */
+ if (fonts_loaded & FONT_8_LOADED) {
+ scp->mode = TEXT80x50;
+ scp->ysize = 50;
+ free(scp->scr_buf, M_DEVBUF);
+ scp->scr_buf =
+ (u_short *)malloc(scp->xsize * scp->ysize * 2,
+ M_DEVBUF, M_NOWAIT);
+ if (scp != cur_console)
+ scp->crt_base = scp->scr_buf;
+ set_mode(scp);
+ clear_screen(scp);
+ change_winsize(tp, scp->xsize, scp->ysize);
+ return 0;
+ }
+ else
+ return EINVAL;
case CONS_GETVERS: /* get version number */
*(int*)data = 0x103; /* version 1.3 */
@@ -750,13 +776,13 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return 0;
case KDENABIO: /* allow io operations */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
return 0;
case KDDISABIO: /* disallow io operations (default) */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
return 0;
case KDSETMODE: /* set current mode of this (virtual) console */
@@ -764,9 +790,9 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KD_TEXT: /* switch to TEXT (known) mode */
/* restore fonts & palette ! */
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
/* FALL THROUGH */
@@ -815,7 +841,10 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case KDSETRAD: /* set keyboard repeat & delay rates */
if (*data & 0x80)
return EINVAL;
- kbd_cmd2(KB_SETRAD, *data);
+ i = spltty();
+ kbd_cmd(KB_SETRAD);
+ kbd_cmd(*data);
+ splx(i);
return 0;
case KDSKBMODE: /* set keyboard mode */
@@ -926,48 +955,63 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
case PIO_FONT8x8: /* set 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x8, sizeof(font_8x8));
- load_font(1, 8, font_8x8);
+ bcopy(data, font_8, 8*256);
+ fonts_loaded |= FONT_8_LOADED;
+ copy_font(LOAD, 1, 8, font_8);
return 0;
case GIO_FONT8x8: /* get 8x8 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x8, data, sizeof(font_8x8));
- return 0;
+ if (fonts_loaded & FONT_8_LOADED) {
+ bcopy(font_8, data, 8*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x14: /* set 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x14, sizeof(font_8x14));
- load_font(2, 14, font_8x14);
+ bcopy(data, font_14, 14*256);
+ fonts_loaded |= FONT_14_LOADED;
+ copy_font(LOAD, 2, 14, font_14);
return 0;
case GIO_FONT8x14: /* get 8x14 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x14, data, sizeof(font_8x14));
- return 0;
+ if (fonts_loaded & FONT_14_LOADED) {
+ bcopy(font_14, data, 14*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case PIO_FONT8x16: /* set 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(data, &font_8x16, sizeof(font_8x16));
- load_font(0, 16, font_8x16);
+ bcopy(data, font_16, 16*256);
+ fonts_loaded |= FONT_16_LOADED;
+ copy_font(LOAD, 0, 16, font_16);
return 0;
case GIO_FONT8x16: /* get 8x16 dot font */
if (!crtc_vga)
return ENXIO;
- bcopy(&font_8x16, data, sizeof(font_8x16));
- return 0;
+ if (fonts_loaded & FONT_16_LOADED) {
+ bcopy(font_16, data, 16*256);
+ return 0;
+ }
+ else
+ return ENXIO;
case CONSOLE_X_MODE_ON: /* just to be compatible */
if (saved_console < 0) {
saved_console = get_scr_num();
switch_scr(minor(dev));
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags |= PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags |= PSL_IOPL;
scp->status |= UNKNOWN_MODE;
scp->status |= KBD_RAW_MODE;
return 0;
@@ -975,12 +1019,12 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
return EAGAIN;
case CONSOLE_X_MODE_OFF:/* just to be compatible */
- fp = (frametype *)p->p_md.md_regs;
- fp->eflags &= ~PSL_IOPL;
+ fp = (struct trapframe *)p->p_md.md_regs;
+ fp->tf_eflags &= ~PSL_IOPL;
if (crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
scp->status &= ~UNKNOWN_MODE;
@@ -999,7 +1043,7 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
*/
if (data)
sysbeep(TIMER_FREQ/((int*)data)[0],
- ((int*)data)[1]*hz/3000);
+ ((int*)data)[1]*hz/1000);
else
sysbeep(scp->bell_pitch, scp->bell_duration);
return 0;
@@ -1018,7 +1062,8 @@ int pcioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
}
-void pcxint(dev_t dev)
+void
+pcxint(dev_t dev)
{
struct tty *tp = get_tty_ptr(dev);
@@ -1032,9 +1077,9 @@ void pcxint(dev_t dev)
}
-void pcstart(struct tty *tp)
+void
+pcstart(struct tty *tp)
{
-#if defined(NetBSD) || defined(__FreeBSD__)
struct clist *rbp;
int i, s, len;
u_char buf[PCBURST];
@@ -1042,7 +1087,7 @@ void pcstart(struct tty *tp)
if (scp->status & SLKED)
return;
- s = spltty(); /* Isn't start always called at spltty? */
+ s = spltty();
if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
tp->t_state |= TS_BUSY;
splx(s);
@@ -1069,58 +1114,11 @@ void pcstart(struct tty *tp)
}
}
splx(s);
-
-#else /* __386BSD__ */
-
- int c, s, len, i;
- scr_stat *scp = get_scr_stat(tp->t_dev);
- u_char buf[PCBURST];
-
- if (scp->status & SLKED)
- return;
- s = spltty();
- if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) {
- for (;;) {
- if (RB_LEN(tp->t_out) <= tp->t_lowat) {
- if (tp->t_state & TS_ASLEEP) {
- tp->t_state &= ~TS_ASLEEP;
- wakeup((caddr_t)tp->t_out);
- }
- selwakeup(&tp->t_wsel);
- }
- if (RB_LEN(tp->t_out) == 0)
- break;
- if (scp->status & SLKED)
- break;
- len = 0;
- while( len < PCBURST) {
- buf[len++] = getc(tp->t_out);
- if( RB_LEN(tp->t_out) == 0)
- break;
- }
- tp->t_state |= TS_BUSY;
- splx(s);
- for(i=0;i<len;i++)
- ansi_put(scp, buf[i]);
- s = spltty();
- tp->t_state &= ~TS_BUSY;
- }
- tp->t_state |= TS_BUSY;
- if( in_putc == 0) {
- int i;
- for(i=0;i<console_buffer_count;i++) {
- scput(console_buffer[i]);
- }
- console_buffer_count = 0;
- }
- tp->t_state &= ~TS_BUSY;
- }
- splx(s);
-#endif
}
-void pccnprobe(struct consdev *cp)
+void
+pccnprobe(struct consdev *cp)
{
int maj;
@@ -1132,19 +1130,18 @@ void pccnprobe(struct consdev *cp)
/* initialize required fields */
cp->cn_dev = makedev(maj, NCONS);
cp->cn_pri = CN_INTERNAL;
-#if defined(__386BSD__) && !defined(__FreeBSD__)
- cp->cn_tp = CONSOLE_TTY;
-#endif
}
-void pccninit(struct consdev *cp)
+void
+pccninit(struct consdev *cp)
{
scinit();
}
-void pccnputc(dev_t dev, char c)
+void
+pccnputc(dev_t dev, char c)
{
if (c == '\n')
scput('\r');
@@ -1162,7 +1159,8 @@ void pccnputc(dev_t dev, char c)
}
-int pccngetc(dev_t dev)
+int
+pccngetc(dev_t dev)
{
int s = spltty(); /* block scintr while we poll */
int c = scgetc(0);
@@ -1171,11 +1169,15 @@ int pccngetc(dev_t dev)
return(c);
}
-static void none_saver(int test)
+
+static void
+none_saver(int test)
{
}
-static void fade_saver(int test)
+
+static void
+fade_saver(int test)
{
static int count = 0;
int i;
@@ -1205,7 +1207,9 @@ static void fade_saver(int test)
}
}
-static void blank_saver(int test)
+
+static void
+blank_saver(int test)
{
u_char val;
if (test) {
@@ -1220,21 +1224,14 @@ static void blank_saver(int test)
}
}
-static u_long rand_next = 1;
-
-static int rand()
-{
- return ((rand_next = rand_next * 1103515245 + 12345) & 0x7FFFFFFF);
-}
+#define NUM_STARS 50
/*
* Alternate saver that got its inspiration from a well known utility
- * package for an unfamous OS.
+ * package for an inferior^H^H^H^H^H^Hfamous OS.
*/
-
-#define NUM_STARS 50
-
-static void star_saver(int test)
+static void
+star_saver(int test)
{
scr_stat *scp = cur_console;
int cell, i;
@@ -1258,16 +1255,16 @@ static void star_saver(int test)
scrn_blanked = 1;
for(i=0; i<NUM_STARS; i++) {
stars[i][0] =
- rand() % (scp->xsize*scp->ysize);
+ random() % (scp->xsize*scp->ysize);
stars[i][1] = 0;
}
}
- cell = rand() % NUM_STARS;
+ cell = random() % NUM_STARS;
*((u_short*)(Crtat + stars[cell][0])) =
scr_map[pattern[stars[cell][1]]] |
- colors[rand()%sizeof(colors)] << 8;
- if ((stars[cell][1]+=(rand()%4)) >= sizeof(pattern)-1) {
- stars[cell][0] = rand() % (scp->xsize*scp->ysize);
+ colors[random()%sizeof(colors)] << 8;
+ if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
+ stars[cell][0] = random() % (scp->xsize*scp->ysize);
stars[cell][1] = 0;
}
}
@@ -1282,9 +1279,10 @@ static void star_saver(int test)
}
-static void snake_saver(int test)
+static void
+snake_saver(int test)
{
- const char saves[] = {"FreeBSD"};
+ const char saves[] = {"FreeBSD-2.0"};
static u_char *savs[sizeof(saves)-1];
static int dirx, diry;
int f;
@@ -1320,11 +1318,11 @@ static void snake_saver(int test)
f = (savs[0] - (u_char *)Crtat) / 2;
if ((f % scp->xsize) == 0 ||
(f % scp->xsize) == scp->xsize - 1 ||
- (rand() % 50) == 0)
+ (random() % 50) == 0)
dirx = -dirx;
if ((f / scp->xsize) == 0 ||
(f / scp->xsize) == scp->ysize - 1 ||
- (rand() % 20) == 0)
+ (random() % 20) == 0)
diry = -diry;
savs[0] += 2*dirx + 2*diry;
for (f=sizeof(saves)-2; f>=0; f--)
@@ -1341,7 +1339,9 @@ static void snake_saver(int test)
}
}
-static void cursor_shape(int start, int end)
+
+static void
+cursor_shape(int start, int end)
{
outb(crtc_addr, 10);
outb(crtc_addr+1, start & 0xFF);
@@ -1351,7 +1351,8 @@ static void cursor_shape(int start, int end)
#if !defined(FAT_CURSOR)
-static void get_cursor_shape(int *start, int *end)
+static void
+get_cursor_shape(int *start, int *end)
{
outb(crtc_addr, 10);
*start = inb(crtc_addr+1) & 0x1F;
@@ -1361,7 +1362,8 @@ static void get_cursor_shape(int *start, int *end)
#endif
-static void cursor_pos(int force)
+static void
+cursor_pos(int force)
{
int pos;
@@ -1381,7 +1383,8 @@ static void cursor_pos(int force)
}
-static void clear_screen(scr_stat *scp)
+static void
+clear_screen(scr_stat *scp)
{
move_crsr(scp, 0, 0);
fillw(scp->term.cur_attr | scr_map[0x20], scp->crt_base,
@@ -1389,12 +1392,9 @@ static void clear_screen(scr_stat *scp)
}
-static int switch_scr(u_int next_scr)
+static int
+switch_scr(u_int next_scr)
{
- if (in_putc) { /* delay switch if in putc */
- delayed_next_scr = next_scr+1;
- return 0;
- }
if (switch_in_progress &&
(cur_console->proc != pfind(cur_console->pid)))
switch_in_progress = 0;
@@ -1412,7 +1412,10 @@ static int switch_scr(u_int next_scr)
return EINVAL;
}
}
-
+ if (in_putc) { /* delay switch if in putc */
+ delayed_next_scr = next_scr+1;
+ return 0;
+ }
switch_in_progress = 1;
old_scp = cur_console;
new_scp = &console[next_scr];
@@ -1446,7 +1449,8 @@ static int switch_scr(u_int next_scr)
}
-static void exchange_scr(void)
+static void
+exchange_scr(void)
{
struct tty *tp;
@@ -1460,9 +1464,9 @@ static void exchange_scr(void)
bcopy(new_scp->scr_buf, Crtat, new_scp->xsize * new_scp->ysize * 2);
update_leds(new_scp->status);
if ((old_scp->status & UNKNOWN_MODE) && crtc_vga) {
- load_font(0, 16, font_8x16);
- load_font(1, 8, font_8x8);
- load_font(2, 14, font_8x14);
+ copy_font(LOAD, 0, 16, font_16);
+ copy_font(LOAD, 1, 8, font_8);
+ copy_font(LOAD, 2, 14, font_14);
load_palette();
}
if (old_scp->status & KBD_RAW_MODE || new_scp->status & KBD_RAW_MODE)
@@ -1471,7 +1475,8 @@ static void exchange_scr(void)
}
-static void move_crsr(scr_stat *scp, int x, int y)
+static void
+move_crsr(scr_stat *scp, int x, int y)
{
if (x < 0 || y < 0 || x >= scp->xsize || y >= scp->ysize)
return;
@@ -1480,7 +1485,9 @@ static void move_crsr(scr_stat *scp, int x, int y)
scp->crtat = scp->crt_base + scp->ypos * scp->xsize + scp->xpos;
}
-static void move_up(u_short *s, u_short *d, u_int len)
+
+static void
+move_up(u_short *s, u_short *d, u_int len)
{
s += len;
d += len;
@@ -1488,13 +1495,17 @@ static void move_up(u_short *s, u_short *d, u_int len)
*--d = *--s;
}
-static void move_down(u_short *s, u_short *d, u_int len)
+
+static void
+move_down(u_short *s, u_short *d, u_int len)
{
while (len-- > 0)
*d++ = *s++;
}
-static void scan_esc(scr_stat *scp, u_char c)
+
+static void
+scan_esc(scr_stat *scp, u_char c)
{
static u_char ansi_col[16] =
{0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15};
@@ -1762,39 +1773,45 @@ static void scan_esc(scr_stat *scp, u_char c)
break;
case 'm': /* change attribute */
- if (scp->term.num_param == 0)
- n = 0;
- else
- n = scp->term.param[0];
- switch (n) {
- case 0: /* back to normal */
+ if (scp->term.num_param == 0) {
scp->term.cur_attr = scp->term.std_attr;
break;
- case 1: /* highlight (bold) */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 4: /* highlight (underline) */
- scp->term.cur_attr &= 0x0F00;
- scp->term.cur_attr |= 0x0800;
- break;
- case 5: /* blink */
- scp->term.cur_attr &= 0xFF00;
- scp->term.cur_attr |= 0x8000;
- break;
- case 7: /* reverse video */
- scp->term.cur_attr = scp->term.rev_attr;
- break;
- case 30: case 31: case 32: case 33: /* set fg color */
- case 34: case 35: case 36: case 37:
- scp->term.cur_attr = (scp->term.cur_attr & 0xF0FF)
- | (ansi_col[(n - 30) & 7] << 8);
- break;
- case 40: case 41: case 42: case 43: /* set bg color */
- case 44: case 45: case 46: case 47:
- scp->term.cur_attr = (scp->term.cur_attr & 0x0FFF)
- | (ansi_col[(n - 40) & 7] << 12);
- break;
+ }
+ for (i = 0; i < scp->term.num_param; i++) {
+ switch (n = scp->term.param[i]) {
+ case 0: /* back to normal */
+ scp->term.cur_attr = scp->term.std_attr;
+ break;
+ case 1: /* highlight (bold) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 4: /* highlight (underline) */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x0800;
+ break;
+ case 5: /* blink */
+ scp->term.cur_attr &= 0xFF00;
+ scp->term.cur_attr |= 0x8000;
+ break;
+ case 7: /* reverse video */
+ scp->term.cur_attr = scp->term.rev_attr;
+ break;
+ case 30: case 31: /* set fg color */
+ case 32: case 33: case 34:
+ case 35: case 36: case 37:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0xF8FF)
+ | (ansi_col[(n-30) & 7] << 8);
+ break;
+ case 40: case 41: /* set bg color */
+ case 42: case 43: case 44:
+ case 45: case 46: case 47:
+ scp->term.cur_attr =
+ (scp->term.cur_attr & 0x8FFF)
+ | (ansi_col[(n-40) & 7] << 12);
+ break;
+ }
}
break;
@@ -1923,7 +1940,8 @@ static void scan_esc(scr_stat *scp, u_char c)
}
-static void ansi_put(scr_stat *scp, u_char c)
+static void
+ansi_put(scr_stat *scp, u_char c)
{
if (scp->status & UNKNOWN_MODE)
return;
@@ -1995,7 +2013,9 @@ static void ansi_put(scr_stat *scp, u_char c)
switch_scr(delayed_next_scr - 1);
}
-static void scinit(void)
+
+static void
+scinit(void)
{
u_short volatile *cp = Crtat + (CGA_BUF-MONO_BUF)/sizeof(u_short), was;
unsigned cursorat;
@@ -2046,7 +2066,7 @@ static void scinit(void)
console[0].border = BG_BLACK;;
console[0].xsize = COL;
console[0].ysize = ROW;
- console[0].status = 0;
+ console[0].status = NLKED;
console[0].pid = 0;
console[0].proc = NULL;
console[0].smode.mode = VT_AUTO;
@@ -2063,7 +2083,8 @@ static void scinit(void)
}
-static void scput(u_char c)
+static void
+scput(u_char c)
{
scr_stat *scp = &console[0];
term_stat save;
@@ -2081,13 +2102,14 @@ static void scput(u_char c)
scp->term = save;
--in_putc;
} else {
- if( console_buffer_count < CONSOLE_BUFFER_SIZE)
+ if( console_buffer_count < CONSOLE_BUFSIZE)
console_buffer[console_buffer_count++] = c;
}
}
-static u_char *get_fstr(u_int c, u_int *len)
+static u_char
+*get_fstr(u_int c, u_int *len)
{
u_int i;
@@ -2101,8 +2123,10 @@ static u_char *get_fstr(u_int c, u_int *len)
}
-static void update_leds(int which)
+static void
+update_leds(int which)
{
+ int s;
static u_char xlate_leds[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
/* replace CAPS led with ALTGR led for ALTGR keyboards */
@@ -2112,17 +2136,22 @@ static void update_leds(int which)
else
which &= ~CLKED;
}
- kbd_cmd2(KB_SETLEDS, xlate_leds[which & LED_MASK]);
+ s = spltty();
+ kbd_cmd(KB_SETLEDS);
+ kbd_cmd(xlate_leds[which & LED_MASK]);
+ splx(s);
}
/*
- * scgetc(noblock) : get a character from the keyboard.
- * If noblock = 0 wait until a key is gotten. Otherwise return NOKEY.
+ * scgetc(noblock) - get character from keyboard.
+ * If noblock = 0 wait until a key is pressed.
+ * Else return NOKEY.
*/
-u_int scgetc(int noblock)
+u_int
+scgetc(int noblock)
{
- u_char val, code, release;
+ u_char scancode, keycode;
u_int state, action;
struct key_t *key;
static u_char esc_flag = 0, compose = 0;
@@ -2132,132 +2161,136 @@ next_code:
kbd_wait();
/* First see if there is something in the keyboard port */
if (inb(KB_STAT) & KB_BUF_FULL)
- val = inb(KB_DATA);
+ scancode = inb(KB_DATA);
else if (noblock)
return(NOKEY);
else
goto next_code;
if (cur_console->status & KBD_RAW_MODE)
- return val;
-
- code = val & 0x7F;
- release = val & 0x80;
-
+ return scancode;
+#if ASYNCH
+ if (scancode == KB_ACK || scancode == KB_RESEND) {
+ kbd_reply = scancode;
+ if (noblock)
+ return(NOKEY);
+ goto next_code;
+ }
+#endif
+ keycode = scancode & 0x7F;
switch (esc_flag) {
case 0x00: /* normal scancode */
- switch(code) {
- case 0x38: /* left alt (compose key) */
- if (release && compose) {
+ switch(scancode) {
+ case 0xB8: /* left alt (compose key) */
+ if (compose) {
compose = 0;
if (chr > 255) {
sysbeep(BELL_PITCH, BELL_DURATION);
chr = 0;
}
}
- else {
- if (!compose) {
- compose = 1;
- chr = 0;
- }
+ break;
+ case 0x38:
+ if (!compose) {
+ compose = 1;
+ chr = 0;
}
break;
- case 0x60:
- case 0x61:
- esc_flag = code;
+ case 0xE0:
+ case 0xE1:
+ esc_flag = scancode;
goto next_code;
}
break;
- case 0x60: /* 0xE0 prefix */
+ case 0xE0: /* 0xE0 prefix */
esc_flag = 0;
- switch (code) {
- case 0x1c: /* right enter key */
- code = 0x59;
+ switch (keycode) {
+ case 0x1C: /* right enter key */
+ keycode = 0x59;
break;
- case 0x1d: /* right ctrl key */
- code = 0x5a;
+ case 0x1D: /* right ctrl key */
+ keycode = 0x5A;
break;
case 0x35: /* keypad divide key */
- code = 0x5b;
+ keycode = 0x5B;
break;
case 0x37: /* print scrn key */
- code = 0x5c;
+ keycode = 0x5C;
break;
case 0x38: /* right alt key (alt gr) */
- code = 0x5d;
+ keycode = 0x5D;
break;
case 0x47: /* grey home key */
- code = 0x5e;
+ keycode = 0x5E;
break;
case 0x48: /* grey up arrow key */
- code = 0x5f;
+ keycode = 0x5F;
break;
case 0x49: /* grey page up key */
- code = 0x60;
+ keycode = 0x60;
break;
- case 0x4b: /* grey left arrow key */
- code = 0x61;
+ case 0x4B: /* grey left arrow key */
+ keycode = 0x61;
break;
- case 0x4d: /* grey right arrow key */
- code = 0x62;
+ case 0x4D: /* grey right arrow key */
+ keycode = 0x62;
break;
- case 0x4f: /* grey end key */
- code = 0x63;
+ case 0x4F: /* grey end key */
+ keycode = 0x63;
break;
case 0x50: /* grey down arrow key */
- code = 0x64;
+ keycode = 0x64;
break;
case 0x51: /* grey page down key */
- code = 0x65;
+ keycode = 0x65;
break;
case 0x52: /* grey insert key */
- code = 0x66;
+ keycode = 0x66;
break;
case 0x53: /* grey delete key */
- code = 0x67;
+ keycode = 0x67;
break;
default: /* ignore everything else */
goto next_code;
}
break;
- case 0x61: /* 0xE1 prefix */
+ case 0xE1: /* 0xE1 prefix */
esc_flag = 0;
- if (code == 0x1D)
+ if (keycode == 0x1D)
esc_flag = 0x1D;
goto next_code;
/* NOT REACHED */
case 0x1D: /* pause / break */
esc_flag = 0;
- if (code != 0x45)
+ if (keycode != 0x45)
goto next_code;
- code = 0x68;
+ keycode = 0x68;
break;
}
if (compose) {
- switch (code) {
- case 0x47:
- case 0x48: /* keypad 7,8,9 */
- case 0x49:
- if (!release)
- chr = (code - 0x40) + chr*10;
+ switch (scancode) {
+ /* key pressed process it */
+ case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */
+ chr = (scancode - 0x40) + chr*10;
goto next_code;
- case 0x4b:
- case 0x4c: /* keypad 4,5,6 */
- case 0x4d:
- if (!release)
- chr = (code - 0x47) + chr*10;
+ case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */
+ chr = (scancode - 0x47) + chr*10;
goto next_code;
- case 0x4f:
- case 0x50: /* keypad 1,2,3 */
- case 0x51:
- if (!release)
- chr = (code - 0x4e) + chr*10;
+ case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */
+ chr = (scancode - 0x4E) + chr*10;
goto next_code;
case 0x52: /* keypad 0 */
- if (!release)
- chr *= 10;
+ chr *= 10;
goto next_code;
+
+ /* key release, no interest here */
+ case 0xC7: case 0xC8: case 0xC9: /* keypad 7,8,9 */
+ case 0xCB: case 0xCC: case 0xCD: /* keypad 4,5,6 */
+ case 0xCF: case 0xD0: case 0xD1: /* keypad 1,2,3 */
+ case 0xD2: /* keypad 0 */
+ goto next_code;
+
case 0x38: /* left alt key */
break;
default:
@@ -2273,15 +2306,15 @@ next_code:
state = (shfts ? 1 : 0 ) | (2 * (ctls ? 1 : 0)) | (4 * (alts ? 1 : 0));
if ((!agrs && (cur_console->status & ALKED))
|| (agrs && !(cur_console->status & ALKED)))
- code += ALTGR_OFFSET;
- key = &key_map.key[code];
+ keycode += ALTGR_OFFSET;
+ key = &key_map.key[keycode];
if ( ((key->flgs & FLAG_LOCK_C) && (cur_console->status & CLKED))
|| ((key->flgs & FLAG_LOCK_N) && (cur_console->status & NLKED)) )
state ^= 1;
/* Check for make/break */
action = key->map[state];
- if (release) { /* key released */
+ if (scancode & 0x80) { /* key released */
if (key->spcl & 0x80) {
switch (action) {
case LSH:
@@ -2379,11 +2412,7 @@ next_code:
case NOP:
break;
case RBT:
-#if defined(__FreeBSD__)
shutdown_nice();
-#else
- cpu_reset();
-#endif
break;
case DBG:
#if DDB > 0 /* try to switch to console 0 */
@@ -2443,7 +2472,8 @@ next_code:
}
-int getchar(void)
+int
+getchar(void)
{
u_char thechar;
int s;
@@ -2474,12 +2504,15 @@ int getchar(void)
}
-u_int sgetc(int noblock)
+u_int
+sgetc(int noblock)
{
return (scgetc(noblock) & 0xff);
}
-int pcmmap(dev_t dev, int offset, int nprot)
+
+int
+pcmmap(dev_t dev, int offset, int nprot)
{
if (offset > 0x20000)
return EINVAL;
@@ -2487,11 +2520,12 @@ int pcmmap(dev_t dev, int offset, int nprot)
}
-static void kbd_wait(void)
+static void
+kbd_wait(void)
{
- int i;
+ int i = 1000;
- for (i=0; i<1000; i++) { /* up to 10 msec */
+ while (i--) {
if ((inb(KB_STAT) & KB_READY) == 0)
break;
DELAY (10);
@@ -2499,43 +2533,43 @@ static void kbd_wait(void)
}
-static void kbd_cmd(u_char command)
-{
- kbd_wait();
- outb(KB_DATA, command);
-}
-
-
-static void kbd_cmd2(u_char command, u_char arg)
+static void
+kbd_cmd(u_char command)
{
- int r, s = spltty();
+ int retry = 5;
do {
- kbd_cmd(command);
- r = kbd_reply();
- if (r == KB_ACK) {
- kbd_cmd(arg & 0x7f);
- r = kbd_reply();
+ int i = 100000;
+
+ kbd_wait();
+#if ASYNCH
+ kbd_reply = 0;
+ outb(KB_DATA, command);
+ while (i--) {
+ if (kbd_reply == KB_ACK)
+ return;
+ if (kbd_reply == KB_RESEND)
+ break;
}
- } while (r != KB_ACK);
- splx(s);
-}
-
-
-static int kbd_reply()
-{
- int i;
-
- kbd_wait();
- for (i=0; i<60000; i++) { /* at least 300 msec, 600 msec enough */
- if (inb(KB_STAT) & KB_BUF_FULL)
- return ((u_char) inb(KB_DATA));
- DELAY (10);
- }
- return(-1);
+#else
+ outb(KB_DATA, command);
+ while (i--) {
+ if (inb(KB_STAT) & KB_BUF_FULL) {
+ int val;
+ DELAY(10);
+ val = inb(KB_DATA);
+ if (val == KB_ACK)
+ return;
+ if (val == KB_RESEND)
+ break;
+ }
+ }
+#endif
+ } while (retry--);
}
-static void set_mode(scr_stat *scp)
+static void
+set_mode(scr_stat *scp)
{
u_char byte;
int s;
@@ -2579,15 +2613,18 @@ static void set_mode(scr_stat *scp)
}
-static void set_border(int color)
+static void
+set_border(int color)
{
inb(crtc_addr+6); /* reset flip-flop */
outb(ATC, 0x11); outb(ATC, color);
inb(crtc_addr+6); /* reset flip-flop */
- outb(ATC, 0x20); /* enable Palette */
+ outb(ATC, 0x20); /* enable Palette */
}
-static void load_font(int segment, int size, char* font)
+
+static void
+copy_font(int direction, int segment, int size, char* font)
{
int ch, line, s;
u_char val;
@@ -2606,9 +2643,14 @@ static void load_font(int segment, int size, char* font)
outb(GDCIDX, 0x06); outb(GDCREG, 0x05); /* addr = a0000, 64kb */
splx(s);
for (ch=0; ch < 256; ch++)
- for (line=0; line < size; line++)
- *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
- font[(ch*size)+line];
+ for (line=0; line < size; line++)
+ if (direction)
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line) =
+ font[(ch*size)+line];
+ else
+ font[(ch*size)+line] =
+ *((char *)atdevbase+(segment*0x4000)+(ch*32)+line);
+
/* setup vga for text mode again */
s = splhigh();
inb(crtc_addr+6); /* reset flip/flop */
@@ -2629,7 +2671,8 @@ static void load_font(int segment, int size, char* font)
}
-static void load_palette(void)
+static void
+load_palette(void)
{
int i;
@@ -2641,7 +2684,9 @@ static void load_palette(void)
outb(ATC, 0x20); /* enable palette */
}
-static void save_palette(void)
+
+static void
+save_palette(void)
{
int i;
@@ -2652,7 +2697,8 @@ static void save_palette(void)
}
-static void change_winsize(struct tty *tp, int x, int y)
+static void
+change_winsize(struct tty *tp, int x, int y)
{
if (tp->t_winsize.ws_col != x || tp->t_winsize.ws_row != y) {
tp->t_winsize.ws_col = x;
OpenPOWER on IntegriCloud