added my responsibility for the `cpm' port
[unix-history] / sys / i386 / isa / pccons.c
index f68c34b..ca5621f 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)pccons.c      5.11 (Berkeley) 5/21/91
  * SUCH DAMAGE.
  *
  *     from: @(#)pccons.c      5.11 (Berkeley) 5/21/91
- *     $Id$
+ *     $Id: pccons.c,v 1.16 1994/05/03 19:38:49 davidg Exp $
  */
 
 /*
  */
 
 /*
@@ -63,7 +63,7 @@
 int pc_xmode;
 #endif /* XSERVER */
 
 int pc_xmode;
 #endif /* XSERVER */
 
-struct tty pccons;
+struct tty *pccons;
 
 struct pcconsoftc {
        char    cs_flags;
 
 struct pcconsoftc {
        char    cs_flags;
@@ -97,15 +97,13 @@ static struct video_state {
        char    color;  /* color or mono display */
 } vs;
 
        char    color;  /* color or mono display */
 } vs;
 
-int pcprobe(), pcattach();
+static int pcprobe(struct isa_device *);
+static int pcattach(struct isa_device *);
 
 struct isa_driver pcdriver = {
        pcprobe, pcattach, "pc",
 };
 
 
 struct isa_driver pcdriver = {
        pcprobe, pcattach, "pc",
 };
 
-/* block cursor so wfj does not go blind on laptop hunting for
-       the verdamnt cursor -wfj */
-#define        FAT_CURSOR
 
 #define        COL             80
 #define        ROW             25
 
 #define        COL             80
 #define        ROW             25
@@ -118,7 +116,7 @@ struct      isa_driver pcdriver = {
 
 static unsigned int addr_6845 = MONO_BASE;
 u_short *Crtat = (u_short *)MONO_BUF;
 
 static unsigned int addr_6845 = MONO_BASE;
 u_short *Crtat = (u_short *)MONO_BUF;
-static openf;
+static int openf;
 
 char *sgetc(int);
 static char    *more_chars;
 
 char *sgetc(int);
 static char    *more_chars;
@@ -133,12 +131,15 @@ static    int     char_count;
 #define        CN_TIMERVAL     (hz)            /* frequency at which to check cons */
 #define        CN_TIMO         (2*60)          /* intervals to allow for output char */
 
 #define        CN_TIMERVAL     (hz)            /* frequency at which to check cons */
 #define        CN_TIMO         (2*60)          /* intervals to allow for output char */
 
-int    pcstart();
-int    pcparam();
-int    ttrstrt();
-char   partab[];
+void   pcstart(struct tty *);
+int    pcparam(struct tty *, struct termios *);
+extern char partab[];
+static void cursor(caddr_t, int);
+static void sput(int /*u_char*/, int /*u_char*/);
+static void pc_xmode_on(void);
+static void pc_xmode_off(void);
 
 
-extern pcopen(dev_t, int, int, struct proc *);
+int pcopen(int /*dev_t*/, int, int, struct proc *);
 /*
  * Wait for CP to accept last CP command sent
  * before setting up next command.
 /*
  * Wait for CP to accept last CP command sent
  * before setting up next command.
@@ -201,8 +202,9 @@ int kbd_response()
 /*
  * these are both bad jokes
  */
 /*
  * these are both bad jokes
  */
+int
 pcprobe(dev)
 pcprobe(dev)
-struct isa_device *dev;
+       struct isa_device *dev;
 {
        int again = 0;
        int response;
 {
        int again = 0;
        int response;
@@ -258,8 +260,9 @@ struct isa_device *dev;
        return (IO_KBDSIZE);
 }
 
        return (IO_KBDSIZE);
 }
 
+int
 pcattach(dev)
 pcattach(dev)
-struct isa_device *dev;
+       struct isa_device *dev;
 {
        u_short *cp = Crtat + (CGA_BUF-MONO_BUF)/CHR;
        u_short was;
 {
        u_short *cp = Crtat + (CGA_BUF-MONO_BUF)/CHR;
        u_short was;
@@ -267,12 +270,14 @@ struct isa_device *dev;
        if (vs.color == 0)
                printf("pc%d: type monochrome\n",dev->id_unit);
        else    printf("pc%d: type color\n",dev->id_unit);
        if (vs.color == 0)
                printf("pc%d: type monochrome\n",dev->id_unit);
        else    printf("pc%d: type color\n",dev->id_unit);
-       cursor(0);
+       cursor(0, 0);
+       return 0;
 }
 
 /* ARGSUSED */
 }
 
 /* ARGSUSED */
+int
 #ifdef __STDC__
 #ifdef __STDC__
-pcopen(dev_t dev, int flag, int mode, struct proc *p)
+pcopen(int /*dev_t*/ dev, int flag, int mode, struct proc *p)
 #else
 pcopen(dev, flag, mode, p)
        dev_t dev;
 #else
 pcopen(dev, flag, mode, p)
        dev_t dev;
@@ -284,13 +289,12 @@ pcopen(dev, flag, mode, p)
 
        if (minor(dev) != 0)
                return (ENXIO);
 
        if (minor(dev) != 0)
                return (ENXIO);
-       tp = &pccons;
+       tp = pccons = ttymalloc(pccons);
        tp->t_oproc = pcstart;
        tp->t_param = pcparam;
        tp->t_dev = dev;
        openf++;
        if ((tp->t_state & TS_ISOPEN) == 0) {
        tp->t_oproc = pcstart;
        tp->t_param = pcparam;
        tp->t_dev = dev;
        openf++;
        if ((tp->t_state & TS_ISOPEN) == 0) {
-               tp->t_state |= TS_WOPEN;
                ttychars(tp);
                tp->t_iflag = TTYDEF_IFLAG;
                tp->t_oflag = TTYDEF_OFLAG;
                ttychars(tp);
                tp->t_iflag = TTYDEF_IFLAG;
                tp->t_oflag = TTYDEF_OFLAG;
@@ -302,33 +306,42 @@ pcopen(dev, flag, mode, p)
        } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
                return (EBUSY);
        tp->t_state |= TS_CARR_ON;
        } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
                return (EBUSY);
        tp->t_state |= TS_CARR_ON;
-       return ((*linesw[tp->t_line].l_open)(dev, tp));
+       return ((*linesw[tp->t_line].l_open)(dev, tp, 0));
 }
 
 }
 
+int
 pcclose(dev, flag, mode, p)
        dev_t dev;
        int flag, mode;
        struct proc *p;
 {
 pcclose(dev, flag, mode, p)
        dev_t dev;
        int flag, mode;
        struct proc *p;
 {
-       (*linesw[pccons.t_line].l_close)(&pccons, flag);
-       ttyclose(&pccons);
+       (*linesw[pccons->t_line].l_close)(pccons, flag);
+       ttyclose(pccons);
+#ifdef broken /* session holds a ref to the tty; can't deallocate */
+       ttyfree(pccons);
+       pccons = (struct tty *)NULL;
+#endif
        return(0);
 }
 
 /*ARGSUSED*/
        return(0);
 }
 
 /*ARGSUSED*/
+int
 pcread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 pcread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
 {
-       return ((*linesw[pccons.t_line].l_read)(&pccons, uio, flag));
+       return ((*linesw[pccons->t_line].l_read)(pccons, uio, flag));
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
+int
 pcwrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 pcwrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
 {
-       return ((*linesw[pccons.t_line].l_write)(&pccons, uio, flag));
+       return ((*linesw[pccons->t_line].l_write)(pccons, uio, flag));
 }
 
 /*
 }
 
 /*
@@ -336,8 +349,9 @@ pcwrite(dev, uio, flag)
  * the console processor wants to give us a character.
  * Catch the character, and see who it goes to.
  */
  * the console processor wants to give us a character.
  * Catch the character, and see who it goes to.
  */
-pcrint(dev, irq, cpl)
-       dev_t dev;
+void
+pcrint(unit)
+       int unit;
 {
        int c;
        char *cp;
 {
        int c;
        char *cp;
@@ -348,7 +362,7 @@ pcrint(dev, irq, cpl)
        if (pcconsoftc.cs_flags & CSF_POLLING)
                return;
 #ifdef KDB
        if (pcconsoftc.cs_flags & CSF_POLLING)
                return;
 #ifdef KDB
-       if (kdbrintr(c, &pccons))
+       if (kdbrintr(c, pccons))
                return;
 #endif
        if (!openf)
                return;
 #endif
        if (!openf)
@@ -356,11 +370,11 @@ pcrint(dev, irq, cpl)
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
        /* send at least one character, because cntl-space is a null */
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
        /* send at least one character, because cntl-space is a null */
-       (*linesw[pccons.t_line].l_rint)(*cp++ & 0xff, &pccons);
+       (*linesw[pccons->t_line].l_rint)(*cp++ & 0xff, pccons);
 #endif /* XSERVER */
 
        while (*cp)
 #endif /* XSERVER */
 
        while (*cp)
-               (*linesw[pccons.t_line].l_rint)(*cp++ & 0xff, &pccons);
+               (*linesw[pccons->t_line].l_rint)(*cp++ & 0xff, pccons);
 }
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
 }
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
@@ -369,11 +383,14 @@ pcrint(dev, irq, cpl)
 #define CONSOLE_X_BELL _IOW('t',123,int[2])
 #endif /* XSERVER */
 
 #define CONSOLE_X_BELL _IOW('t',123,int[2])
 #endif /* XSERVER */
 
+int
 pcioctl(dev, cmd, data, flag)
        dev_t dev;
 pcioctl(dev, cmd, data, flag)
        dev_t dev;
+       int cmd;
        caddr_t data;
        caddr_t data;
+       int flag;
 {
 {
-       register struct tty *tp = &pccons;
+       register struct tty *tp = pccons;
        register error;
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
        register error;
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
@@ -411,6 +428,7 @@ int pcconsintr = 1;
  * Got a console transmission interrupt -
  * the console processor wants another character.
  */
  * Got a console transmission interrupt -
  * the console processor wants another character.
  */
+void
 pcxint(dev)
        dev_t dev;
 {
 pcxint(dev)
        dev_t dev;
 {
@@ -419,14 +437,15 @@ pcxint(dev)
 
        if (!pcconsintr)
                return;
 
        if (!pcconsintr)
                return;
-       pccons.t_state &= ~TS_BUSY;
+       pccons->t_state &= ~TS_BUSY;
        pcconsoftc.cs_timo = 0;
        pcconsoftc.cs_timo = 0;
-       if (pccons.t_line)
-               (*linesw[pccons.t_line].l_start)(&pccons);
+       if (pccons->t_line)
+               (*linesw[pccons->t_line].l_start)(pccons);
        else
        else
-               pcstart(&pccons);
+               pcstart(pccons);
 }
 
 }
 
+void
 pcstart(tp)
        register struct tty *tp;
 {
 pcstart(tp)
        register struct tty *tp;
 {
@@ -436,20 +455,11 @@ pcstart(tp)
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
                goto out;
        do {
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
                goto out;
        do {
-       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);
-               }
-               if (tp->t_wsel) {
-                       selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
-                       tp->t_wsel = 0;
-                       tp->t_state &= ~TS_WCOLL;
-               }
-       }
-       if (RB_LEN(&tp->t_out) == 0)
+       if (tp->t_state & (TS_SO_OCOMPLETE | TS_SO_OLOWAT) || tp->t_wsel)
+               ttwwakeup(tp);
+       if (RB_LEN(tp->t_out) == 0)
                goto out;
                goto out;
-       c = getc(&tp->t_out);
+       c = getc(tp->t_out);
        tp->t_state |= TS_BUSY;                         /* 21 Aug 92*/
        splx(s);
        sput(c, 0);
        tp->t_state |= TS_BUSY;                         /* 21 Aug 92*/
        splx(s);
        sput(c, 0);
@@ -460,6 +470,7 @@ out:
        splx(s);
 }
 
        splx(s);
 }
 
+void
 pccnprobe(cp)
        struct consdev *cp;
 {
 pccnprobe(cp)
        struct consdev *cp;
 {
@@ -472,11 +483,12 @@ pccnprobe(cp)
 
        /* initialize required fields */
        cp->cn_dev = makedev(maj, 0);
 
        /* initialize required fields */
        cp->cn_dev = makedev(maj, 0);
-       cp->cn_tp = &pccons;
+       cp->cn_tp = pccons;
        cp->cn_pri = CN_INTERNAL;
 }
 
 /* ARGSUSED */
        cp->cn_pri = CN_INTERNAL;
 }
 
 /* ARGSUSED */
+void
 pccninit(cp)
        struct consdev *cp;
 {
 pccninit(cp)
        struct consdev *cp;
 {
@@ -489,6 +501,7 @@ pccninit(cp)
 static __color;
 
 /* ARGSUSED */
 static __color;
 
 /* ARGSUSED */
+void
 pccnputc(dev, c)
        dev_t dev;
        char c;
 pccnputc(dev, c)
        dev_t dev;
        char c;
@@ -501,6 +514,7 @@ pccnputc(dev, c)
 /*
  * Print a character on console.
  */
 /*
  * Print a character on console.
  */
+void
 pcputchar(c, tp)
        char c;
        register struct tty *tp;
 pcputchar(c, tp)
        char c;
        register struct tty *tp;
@@ -511,6 +525,7 @@ pcputchar(c, tp)
 
 
 /* ARGSUSED */
 
 
 /* ARGSUSED */
+int
 pccngetc(dev)
        dev_t dev;
 {
 pccngetc(dev)
        dev_t dev;
 {
@@ -529,6 +544,7 @@ pccngetc(dev)
        return (*cp);
 }
 
        return (*cp);
 }
 
+int
 pcgetchar(tp)
        register struct tty *tp;
 {
 pcgetchar(tp)
        register struct tty *tp;
 {
@@ -546,6 +562,7 @@ pcgetchar(tp)
 /*
  * Set line parameters
  */
 /*
  * Set line parameters
  */
+int
 pcparam(tp, t)
        register struct tty *tp;
        register struct termios *t;
 pcparam(tp, t)
        register struct tty *tp;
        register struct termios *t;
@@ -580,8 +597,10 @@ pcpoll(onoff)
 
 static u_short *crtat = 0;
 
 
 static u_short *crtat = 0;
 
-cursor(int a)
-{      int pos = crtat - Crtat;
+static void
+cursor(caddr_t rock, int arg2)
+{
+       int pos = crtat - Crtat;
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
        if (!pc_xmode) {
 
 #ifdef XSERVER                                         /* 15 Aug 92*/
        if (!pc_xmode) {
@@ -595,8 +614,8 @@ cursor(int a)
        outb(addr_6845+1, 0);
        outb(addr_6845, 11);
        outb(addr_6845+1, 18);
        outb(addr_6845+1, 0);
        outb(addr_6845, 11);
        outb(addr_6845+1, 18);
-#endif FAT_CURSOR
-       if (a == 0)
+#endif /* FAT_CURSOR */
+       if (rock == 0)
                timeout(cursor, 0, hz/10);
 #ifdef XSERVER                                         /* 15 Aug 92*/
        }
                timeout(cursor, 0, hz/10);
 #ifdef XSERVER                                         /* 15 Aug 92*/
        }
@@ -612,19 +631,22 @@ static u_char shift_down, ctrl_down, alt_down, caps, num, scroll;
 /* translate ANSI color codes to standard pc ones */
 static char fgansitopc[] =
 {      FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
 /* translate ANSI color codes to standard pc ones */
 static char fgansitopc[] =
 {      FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
-       FG_MAGENTA, FG_CYAN, FG_LIGHTGREY};
+       FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
+};
 
 static char bgansitopc[] =
 {      BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
 
 static char bgansitopc[] =
 {      BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
-       BG_MAGENTA, BG_CYAN, BG_LIGHTGREY};
+       BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
+};
 
 /*
  *   sput has support for emulation of the 'pc3' termcap entry.
  *   if ka, use kernel attributes.
  */
 
 /*
  *   sput has support for emulation of the 'pc3' termcap entry.
  *   if ka, use kernel attributes.
  */
+static void
 sput(c,  ka)
 sput(c,  ka)
-u_char c;
-u_char ka;
+       u_char c;
+       u_char ka;
 {
 
        int sc = 1;     /* do scroll check */
 {
 
        int sc = 1;     /* do scroll check */
@@ -679,7 +701,8 @@ u_char ka;
                }
                vs.kern_bg_at = BG_BLACK;
 
                }
                vs.kern_bg_at = BG_BLACK;
 
-               fillw(((vs.bg_at|vs.fg_at)<<8)|' ', crtat, COL*ROW-cursorat);
+               fillw(((vs.bg_at|vs.fg_at)<<8)|' ', crtat,
+                     COL*ROW-cursorat);
        }
 
        /* which attributes do we use? */
        }
 
        /* which attributes do we use? */
@@ -725,7 +748,9 @@ u_char ka;
                if (vs.esc) {
                        if (vs.ebrac) {
                                switch(c) {
                if (vs.esc) {
                        if (vs.ebrac) {
                                switch(c) {
-                                       int pos;
+                                       int pos, posy, count;
+                                       u_short *src, *dst;
+
                                case 'm':
                                        if (!vs.cx) vs.so = 0;
                                        else vs.so = 1;
                                case 'm':
                                        if (!vs.cx) vs.so = 0;
                                        else vs.so = 1;
@@ -823,18 +848,51 @@ u_char ka;
                                        break;
                                case 'S':  /* scroll up cx lines */
                                        if (vs.cx <= 0) vs.cx = 1;
                                        break;
                                case 'S':  /* scroll up cx lines */
                                        if (vs.cx <= 0) vs.cx = 1;
-                                       bcopy(Crtat+vs.ncol*vs.cx, Crtat, vs.ncol*(vs.nrow-vs.cx)*CHR);
-                                       fillw((at <<8)+' ', Crtat+vs.ncol*(vs.nrow-vs.cx), vs.ncol*vs.cx);
-                                       /* crtat -= vs.ncol*vs.cx; /* XXX */
+                                       posy = (crtat - Crtat) / vs.ncol;
+                                       if (vs.cx > posy)
+                                               vs.cx = posy;
+                                       bcopyw(Crtat+vs.ncol*vs.cx, Crtat, vs.ncol*(vs.nrow-vs.cx)*CHR);
+                                       fillw((at <<8)+' ',
+                                               (Crtat + vs.ncol * (vs.nrow - vs.cx)),
+                                               vs.ncol * vs.cx);
+                                       /* crtat -= vs.ncol*vs.cx;*/ /* XXX */
                                        vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
                                        break;
                                case 'T':  /* scroll down cx lines */
                                        if (vs.cx <= 0) vs.cx = 1;
                                        vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
                                        break;
                                case 'T':  /* scroll down cx lines */
                                        if (vs.cx <= 0) vs.cx = 1;
-                                       bcopy(Crtat, Crtat+vs.ncol*vs.cx, vs.ncol*(vs.nrow-vs.cx)*CHR);
+                                       posy = (crtat - Crtat) / vs.ncol;
+                                       if (vs.cx > vs.nrow - posy)
+                                               vs.cx = vs.nrow - posy;
+                                       bcopyw(Crtat, Crtat+vs.ncol*vs.cx, vs.ncol*(vs.nrow-vs.cx)*CHR);
                                        fillw((at <<8)+' ', Crtat, vs.ncol*vs.cx);
                                        fillw((at <<8)+' ', Crtat, vs.ncol*vs.cx);
-                                       /* crtat += vs.ncol*vs.cx; /* XXX */
+                                       /* crtat += vs.ncol*vs.cx;*/ /* XXX */
                                        vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
                                        break;
                                        vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
                                        break;
+                               case 'L':       /* Insert cx lines */
+                                       if (vs.cx <= 0) vs.cx = 1;
+                                       posy = (crtat - Crtat) / vs.ncol;
+                                       if (vs.cx > vs.nrow - posy)
+                                               vs.cx = vs.nrow - posy;
+                                       src = Crtat + posy * vs.ncol;
+                                       dst = src + vs.cx * vs.ncol;
+                                       count = vs.nrow - (posy + vs.cx);
+                                       bcopyw(src, dst, count * vs.ncol * CHR);
+                                       fillw((at <<8)+' ', src, vs.cx * vs.ncol);
+                                       vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
+                                       break;
+                               case 'M':       /* Delete cx lines */
+                                       if (vs.cx <= 0) vs.cx = 1;
+                                       posy = (crtat - Crtat) / vs.ncol;
+                                       if (vs.cx > vs.nrow - posy)
+                                               vs.cx = vs.nrow - posy;
+                                       dst = Crtat + posy * vs.ncol;
+                                       src = dst + vs.cx * vs.ncol;
+                                       count = vs.nrow - (posy + vs.cx);
+                                       bcopyw(src, dst, count * vs.ncol * CHR);
+                                       src = dst + count * vs.ncol;
+                                       fillw((at <<8)+' ', src, vs.cx * vs.ncol);
+                                       vs.esc = 0; vs.ebrac = 0; vs.eparm = 0;
+                                       break;
                                case ';': /* Switch params in cursor def */
                                        vs.eparm = 1;
                                        break;
                                case ';': /* Switch params in cursor def */
                                        vs.eparm = 1;
                                        break;
@@ -920,13 +978,13 @@ u_char ka;
        }
        if (sc && crtat >= Crtat+vs.ncol*vs.nrow) { /* scroll check */
                if (openf) do (void)sgetc(1); while (scroll);
        }
        if (sc && crtat >= Crtat+vs.ncol*vs.nrow) { /* scroll check */
                if (openf) do (void)sgetc(1); while (scroll);
-               bcopy(Crtat+vs.ncol, Crtat, vs.ncol*(vs.nrow-1)*CHR);
+               bcopyw(Crtat+vs.ncol, Crtat, vs.ncol*(vs.nrow-1)*CHR);
                fillw ((at << 8) + ' ', Crtat + vs.ncol*(vs.nrow-1),
                        vs.ncol);
                crtat -= vs.ncol;
        }
        if (ka)
                fillw ((at << 8) + ' ', Crtat + vs.ncol*(vs.nrow-1),
                        vs.ncol);
                crtat -= vs.ncol;
        }
        if (ka)
-               cursor(1);
+               cursor((caddr_t)1, 0);
 }
 
 
 }
 
 
@@ -1352,7 +1410,7 @@ static Scan_def   scan_codes[] =
 };
 
 
 };
 
 
-
+void
 update_led()
 {
        int response;
 update_led()
 {
        int response;
@@ -1393,7 +1451,9 @@ update_led()
  *   noblock  ==  0  wait  until a key is gotten. Otherwise return a
  *    if no characters are present 0.
  */
  *   noblock  ==  0  wait  until a key is gotten. Otherwise return a
  *    if no characters are present 0.
  */
-char *sgetc(noblock)
+char *
+sgetc(noblock)
+       int noblock;
 {
        u_char          dt;
        unsigned        key;
 {
        u_char          dt;
        unsigned        key;
@@ -1476,14 +1536,20 @@ loop:
 #endif /* !XSERVER*/
        }
 
 #endif /* !XSERVER*/
        }
 
+       /*
+        *   Check for cntl-alt-del
+        */
+       if ((dt == 83) && ctrl_down && alt_down)
+               cpu_reset();
+
 #include "ddb.h"
 #if NDDB > 0
        /*
         *   Check for cntl-alt-esc
         */
        if ((dt == 1) && ctrl_down && alt_down) {
 #include "ddb.h"
 #if NDDB > 0
        /*
         *   Check for cntl-alt-esc
         */
        if ((dt == 1) && ctrl_down && alt_down) {
-               Debugger();
-               dt |= 0x80;     /* discard esc (ddb discarded ctrl-alt) */
+               Debugger("manual escape to debugger");
+               goto loop;
        }
 #endif
 
        }
 #endif
 
@@ -1626,6 +1692,7 @@ loop:
 #define del    0177    
 #define cntld  4
 
 #define del    0177    
 #define cntld  4
 
+int
 getchar()
 {
        char    thechar;
 getchar()
 {
        char    thechar;
@@ -1694,6 +1761,7 @@ dprintf(flgs, fmt /*, va_alist */)
        __color = 0;
 }
 
        __color = 0;
 }
 
+void
 consinit() {}
 
 /* -hv- 22-Apr-93: to make init_main more portable */
 consinit() {}
 
 /* -hv- 22-Apr-93: to make init_main more portable */
@@ -1714,7 +1782,7 @@ void cons_normal()
 
 int pcmmap(dev_t dev, int offset, int nprot)
 {
 
 int pcmmap(dev_t dev, int offset, int nprot)
 {
-       if (offset > 0x20000)
+       if (offset > 0x20000 - PAGE_SIZE)
                return -1;
        return i386_btop((0xa0000 + offset));
 }
                return -1;
        return i386_btop((0xa0000 + offset));
 }
@@ -1723,30 +1791,32 @@ int pcmmap(dev_t dev, int offset, int nprot)
 #include "machine/psl.h"
 #include "machine/frame.h"
 
 #include "machine/psl.h"
 #include "machine/frame.h"
 
-pc_xmode_on ()
+static void
+pc_xmode_on (void)
 {
 {
-       struct syscframe *fp;
+       struct trapframe *fp;
 
        if (pc_xmode)
                return;
        pc_xmode = 1;
 
 
        if (pc_xmode)
                return;
        pc_xmode = 1;
 
-       fp = (struct syscframe *)curproc->p_regs;
-       fp->sf_eflags |= PSL_IOPL;
+       fp = (struct trapframe *)curproc->p_regs;
+       fp->tf_eflags |= PSL_IOPL;
 }
 
 }
 
+static void
 pc_xmode_off ()
 {
 pc_xmode_off ()
 {
-       struct syscframe *fp;
+       struct trapframe *fp;
 
        if (pc_xmode == 0)
                return;
        pc_xmode = 0;
 
 
        if (pc_xmode == 0)
                return;
        pc_xmode = 0;
 
-       cursor(0);
+       cursor(0, 0);
 
 
-       fp = (struct syscframe *)curproc->p_regs;
-       fp->sf_eflags &= ~PSL_IOPL;
+       fp = (struct trapframe *)curproc->p_regs;
+       fp->tf_eflags &= ~PSL_IOPL;
 }
 #endif /* XSERVER*/
 
 }
 #endif /* XSERVER*/