--- Gnu-Mach/i386/i386at/com.c 2020/09/02 04:44:38 1.1.1.2 +++ Gnu-Mach/i386/i386at/com.c 2020/09/02 04:49:24 1.1.1.4 @@ -24,14 +24,18 @@ * the rights to redistribute these changes. */ -#include #if NCOM > 0 +#include +#include + #include #include +#include +#include #include #include -#include +#include #include #include @@ -39,17 +43,13 @@ #include #include #include +#include +#include #include -#include -#include - -extern void timeout(), ttrstrt(); +#include -int comprobe(), comintr(), comstart(), commctl(); -void comattach(); static void comparam(); -int comstop(), comgetstat(), comsetstat(); static vm_offset_t com_std[NCOM] = { 0 }; struct bus_device *cominfo[NCOM]; @@ -63,14 +63,12 @@ boolean_t comfifo[NCOM]; boolean_t comtimer_active; int comtimer_state[NCOM]; -#if RCLINE >= 0 #define RCBAUD B9600 +static int rcline = -1; static struct bus_device *comcndev; -int comcnprobe(struct consdev *cp); -int comcninit(struct consdev *cp); -int comcngetc(dev_t dev, int wait); -int comcnputc(dev_t dev, int c); -#endif + +/* XX */ +extern char *kernel_cmdline; #ifndef PORTSELECTOR #define ISPEED B9600 @@ -147,7 +145,7 @@ comprobe_general(struct bus_device *dev, type = "82450 or 16450"; outb(FIFO_CTL(addr), iFIFOENA | iFIFO14CH); /* Enable fifo */ if ((inb(FIFO_CTL(addr)) & iFIFO14CH) != 0) - { /* Was it successfull */ + { /* Was it successful */ /* if both bits are not set then broken xx550 */ if ((inb(FIFO_CTL(addr)) & iFIFO14CH) == iFIFO14CH) { @@ -171,12 +169,11 @@ comprobe_general(struct bus_device *dev, * all of bus_device_init */ int -comprobe(int port, struct bus_device *dev) +comprobe(vm_offset_t port, struct bus_ctlr *dev) { - return comprobe_general(dev, /*noisy*/ 0); + return comprobe_general((struct bus_device *)dev, /*noisy*/ 0); } -#if RCLINE >= 0 /* * Probe routine for use by the console */ @@ -186,13 +183,19 @@ comcnprobe(struct consdev *cp) struct bus_device *b; int maj, unit, pri; +#define CONSOLE_PARAMETER " console=com" + u_char *console = (u_char *) strstr(kernel_cmdline, CONSOLE_PARAMETER); + + if (console) + mach_atoi(console + strlen(CONSOLE_PARAMETER), &rcline); + maj = 0; unit = -1; pri = CN_DEAD; for (b = bus_device_init; b->driver; b++) if (strcmp(b->name, "com") == 0 - && b->unit == RCLINE + && b->unit == rcline && comprobe_general(b, /*quiet*/ 0)) { /* Found one */ @@ -204,8 +207,9 @@ comcnprobe(struct consdev *cp) cp->cn_dev = makedev(maj, unit); cp->cn_pri = pri; + + return 0; } -#endif /* @@ -221,7 +225,7 @@ comattach(struct bus_device *dev) u_short addr = dev->address; take_dev_irq(dev); - printf(", port = %x, spl = %d, pic = %d. (DOS COM%d)", + printf(", port = %lx, spl = %ld, pic = %d. (DOS COM%d)", dev->address, dev->sysdep, dev->sysdep1, unit+1); /* comcarrier[unit] = addr->flags;*/ @@ -236,7 +240,6 @@ comattach(struct bus_device *dev) } } -#if RCLINE >= 0 /* * Attach/init routine for console. This isn't called by * configure_bus_device which sets the alive, adaptor, and minfo @@ -258,7 +261,7 @@ comcninit(struct consdev *cp) outb(LINE_CTL(addr), iDLAB); outb(BAUD_LSB(addr), divisorreg[RCBAUD] & 0xff); outb(BAUD_MSB(addr), divisorreg[RCBAUD] >>8); - outb(LINE_CTL(addr), i7BITS|iPEN); + outb(LINE_CTL(addr), i8BITS); outb(INTR_ENAB(addr), 0); outb(MODEM_CTL(addr), iDTR|iRTS|iOUT2); @@ -278,8 +281,8 @@ comcninit(struct consdev *cp) } } + return 0; } -#endif /* * Probe for COM after autoconfiguration. @@ -316,7 +319,7 @@ boolean_t com_reprobe( } io_return_t comopen( - int dev, + dev_t dev, int flag, io_req_t ior) { @@ -328,13 +331,15 @@ io_return_t comopen( io_return_t result; if (unit >= NCOM) - return ENXIO; /* no such device */ + return D_NO_SUCH_DEVICE; /* no such device */ if ((isai = cominfo[unit]) == 0 || isai->alive == 0) { /* * Try to probe it again */ if (!com_reprobe(unit)) - return ENXIO; + return D_NO_SUCH_DEVICE; + if ((isai = cominfo[unit]) == 0 || isai->alive == 0) + return D_NO_SUCH_DEVICE; } tp = &com_tty[unit]; @@ -382,7 +387,7 @@ io_return_t comopen( if (!comtimer_active) { comtimer_active = TRUE; - comtimer(); + comtimer(NULL); } s = spltty(); @@ -395,8 +400,8 @@ io_return_t comopen( return result; } -io_return_t comclose(dev, flag) -int dev; +void comclose(dev, flag) +dev_t dev; int flag; { struct tty *tp = &com_tty[minor(dev)]; @@ -411,18 +416,18 @@ int flag; if (comfifo[minor(dev)] != 0) outb(INTR_ID(addr), 0x00); /* Disable fifos */ } - return 0; + return; } io_return_t comread(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_read(&com_tty[minor(dev)], ior); } io_return_t comwrite(dev, ior) -int dev; +dev_t dev; io_req_t ior; { return char_write(&com_tty[minor(dev)], ior); @@ -432,7 +437,7 @@ io_return_t comportdeath(dev, port) dev_t dev; mach_port_t port; { - return (tty_portdeath(&com_tty[minor(dev)], port)); + return (tty_portdeath(&com_tty[minor(dev)], (ipc_port_t)port)); } io_return_t @@ -440,7 +445,7 @@ comgetstat(dev, flavor, data, count) dev_t dev; int flavor; int *data; /* pointer to OUT array */ -unsigned int *count; /* out */ +natural_t *count; /* out */ { io_return_t result = D_SUCCESS; int unit = minor(dev); @@ -459,11 +464,11 @@ unsigned int *count; /* out */ } io_return_t -comsetstat(dev, flavor, data, count) -dev_t dev; -int flavor; -int * data; -unsigned int count; +comsetstat( + dev_t dev, + int flavor, + int * data, + natural_t count) { io_return_t result = D_SUCCESS; int unit = minor(dev); @@ -488,10 +493,10 @@ unsigned int count; return (D_SUCCESS); } -comintr(unit) -int unit; +void +comintr(int unit) { - register struct tty *tp = &com_tty[unit]; + struct tty *tp = &com_tty[unit]; u_short addr = cominfo[unit]->address; static char comoverrun = 0; char c, line, intr_id; @@ -513,10 +518,35 @@ int unit; case RECi: case CTIi: /* Character timeout indication */ if (tp->t_state&TS_ISOPEN) { + int escape = 0; while ((line = inb(LINE_STAT(addr))) & iDR) { c = inb(TXRX(addr)); - ttyinput(c, tp); + + if (c == 0x1b) { + escape = 1; + continue; + } + +#if MACH_KDB + if (escape && c == 'D'-('A'-1)) + /* ctrl-alt-d pressed, + invoke debugger */ + kdb_kintr(); + else +#endif /* MACH_KDB */ + if (escape) { + ttyinput(0x1b, tp); + ttyinput(c, tp); + } + else + ttyinput(c, tp); + + escape = 0; } + + if (escape) + /* just escape */ + ttyinput(0x1b, tp); } else tt_open_wakeup(tp); break; @@ -527,7 +557,7 @@ int unit; ((tp->t_flags&(EVENP|ODDP)) == EVENP || (tp->t_flags&(EVENP|ODDP)) == ODDP)) { /* parity error */; - } else if (line&iOR && !comoverrun) { + } else if (line_stat&iOR && !comoverrun) { printf("com%d: overrun\n", unit); comoverrun = 1; } else if (line_stat & (iFE | iBRKINTR)) { @@ -539,8 +569,7 @@ int unit; } static void -comparam(unit) -register int unit; +comparam(int unit) { struct tty *tp = &com_tty[unit]; u_short addr = (int)tp->t_addr; @@ -586,6 +615,7 @@ register int unit; splx(s); } +void comparm(int unit, int baud, int intr, int mode, int modem) { u_short addr = (u_short)(cominfo[unit]->address); @@ -607,16 +637,17 @@ comparm(int unit, int baud, int intr, in int comst_1, comst_2, comst_3, comst_4, comst_5 = 14; -int -comstart(tp) -struct tty *tp; +void +comstart(struct tty *tp) { - char nch; + int nch; +#if 0 int i; +#endif if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP|TS_BUSY)) { comst_1++; - return(0); + return; } if ((!queue_empty(&tp->t_delayed_write)) && (tp->t_outq.c_cc <= TTLOWAT(tp))) { @@ -625,7 +656,7 @@ comst_2++; } if (!tp->t_outq.c_cc) { comst_3++; - return(0); + return; } #if 0 @@ -645,22 +676,24 @@ comst_4++; } #else nch = getc(&tp->t_outq); + if (nch == -1) + return; if ((nch & 0200) && ((tp->t_flags & LITOUT) == 0)) { - timeout(ttrstrt, (char *)tp, (nch & 0x7f) + 6); + timeout((timer_func_t *)ttrstrt, (char *)tp, (nch & 0x7f) + 6); tp->t_state |= TS_TIMEOUT; comst_4++; - return(0); + return; } outb(TXRX((int)tp->t_addr), nch); tp->t_state |= TS_BUSY; #endif - return(0); } /* Check for stuck xmitters */ int comtimer_interval = 5; -comtimer() +void +comtimer(void * param) { spl_t s = spltty(); struct tty *tp = com_tty; @@ -674,7 +707,7 @@ comtimer() if (++comtimer_state[i] < 2) continue; /* Its stuck */ -printf("Tty %x was stuck\n", tp); +printf("Tty %p was stuck\n", tp); nch = getc(&tp->t_outq); outb(TXRX((int)tp->t_addr), nch); } @@ -686,8 +719,10 @@ printf("Tty %x was stuck\n", tp); /* * Set receive modem state from modem status register. */ -fix_modem_state(unit, modem_stat) -int unit, modem_stat; +void +fix_modem_state( + int unit, + int modem_stat) { int stat = 0; @@ -707,6 +742,7 @@ int unit, modem_stat; /* * Modem change (input signals) */ +void commodem_intr( int unit, int stat) @@ -736,15 +772,16 @@ commodem_intr( /* * Set/get modem bits */ +int commctl( - register struct tty *tp, - int bits, - int how) + struct tty *tp, + int bits, + int how) { spl_t s; int unit; vm_offset_t dev_addr; - register int b; + int b = 0; /* Suppress gcc warning */ unit = minor(tp->t_dev); @@ -802,9 +839,10 @@ commctl( return commodem[unit]; } -comstop(tp, flags) -register struct tty *tp; -int flags; +void +comstop( + struct tty *tp, + int flags) { if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0) tp->t_state |= TS_FLUSH; @@ -815,16 +853,16 @@ int flags; * Code to be called from debugger. * */ -void compr_addr(addr) +void compr_addr(vm_offset_t addr) { /* The two line_stat prints may show different values, since * touching some of the registers constitutes changing them. */ - printf("LINE_STAT(%x) %x\n", + printf("LINE_STAT(%lu) %x\n", LINE_STAT(addr), inb(LINE_STAT(addr))); - printf("TXRX(%x) %x, INTR_ENAB(%x) %x, INTR_ID(%x) %x, LINE_CTL(%x) %x,\n\ -MODEM_CTL(%x) %x, LINE_STAT(%x) %x, MODEM_STAT(%x) %x\n", + printf("TXRX(%lu) %x, INTR_ENAB(%lu) %x, INTR_ID(%lu) %x, LINE_CTL(%lu) %x,\n\ +MODEM_CTL(%lu) %x, LINE_STAT(%lu) %x, MODEM_STAT(%lu) %x\n", TXRX(addr), inb(TXRX(addr)), INTR_ENAB(addr), inb(INTR_ENAB(addr)), INTR_ID(addr), inb(INTR_ID(addr)), @@ -834,7 +872,7 @@ MODEM_CTL(%x) %x, LINE_STAT(%x) %x, MODE MODEM_STAT(addr),inb(MODEM_STAT(addr))); } -int compr(unit) +int compr(int unit) { compr_addr(cominfo[unit]->address); return(0); @@ -854,7 +892,6 @@ comgetc(int unit) return c; } -#if RCLINE >= 0 /* * Routines for the console */ @@ -871,6 +908,8 @@ comcnputc(dev_t dev, int c) if (c == '\n') comcnputc(dev, '\r'); outb(addr, c); + + return 0; } int @@ -886,6 +925,5 @@ comcngetc(dev_t dev, int wait) c = inb(TXRX(addr)); return c & 0x7f; } -#endif /* RCLINE */ #endif /* NCOM */