--- xinu/sys/ttyiin.c 2018/04/24 17:39:04 1.1 +++ xinu/sys/ttyiin.c 2018/04/24 17:40:13 1.1.1.2 @@ -4,107 +4,110 @@ #include #include #include -#include + +/* set up macros for appropriate SLU as spec. by SLUCHIP: + if SLUCHIP==6850, #include slu6850.h, #define TTYIIN ttyiin6850, etc. + if SLUCHIP==7201, #include slu7201.h, #define TTYIIN ttyiin7201, etc. + if SLUCHIP undef.,#include slu.h, #define TTYIIN ttyiin (orig. case) + similarly sluaccess.h, other TTY fns */ +#include /*------------------------------------------------------------------------ * ttyiin -- lower-half tty device driver for input interrupts *------------------------------------------------------------------------ */ -INTPROC ttyiin(iptr) - register struct tty *iptr; /* pointer to tty block */ +INTPROC TTYIIN(ttyp, cptr, error) + register struct tty *ttyp; /* pointer to tty block */ + register struct csr *cptr; /* pointer to cont. & stat. reg */ + register int error; { - register struct csr *cptr; - register int ch, ct; - - cptr = iptr->ioaddr; - ch=cptr->crbuf; - if (ch & SLUERMASK) - return; /* discard if error */ - ch &= SLUCHMASK; - if (iptr->imode == IMRAW) { - if (scount(iptr->isem) >= IBUFLEN) { - return; /* discard if no space */ - } - iptr->ibuff[iptr->ihead++] = ch; - if (iptr->ihead >= IBUFLEN) /* wrap buffer pointer */ - iptr->ihead = 0; - signal(iptr->isem); + register int ch; + Bool cerr; + int ct; + +#ifdef DEBUG +/* kprintf("ttyiin(%x, %x)\n", ttyp, cptr); + */ +#endif + ch = slugetch(cptr); + if (ttyp->imode == IMRAW) { + if (scount(ttyp->isem) >= IBUFLEN) + return; + if (error) /* character error */ + ttyp->ibuff[ttyp->ihead++] = ch | IOCHERR; + else + ttyp->ibuff[ttyp->ihead++] = ch; + if (ttyp->ihead >= IBUFLEN) /* wrap buffer pointer */ + ttyp->ihead = 0; + signal(ttyp->isem); } else { /* cbreak | cooked mode */ - if ( ch == RETURN && iptr->icrlf ) + cerr = error ? IOCHERR : 0; + ch &= SLUCHMASK; + if ( ch == RETURN && ttyp->icrlf ) ch = NEWLINE; - if (iptr->iintr && ch == iptr->iintrc) { - send(iptr->iintpid, INTRMSG); - eputc(ch, iptr, cptr); - return; - } - if (iptr->oflow) { - if (ch == iptr->ostart) { - iptr->oheld = FALSE; - cptr->ctstat = SLUENABLE; + if (ttyp->oflow) { + if (ch == ttyp->ostart) { + ttyp->oheld = FALSE; return; } - if (ch == iptr->ostop) { - iptr->oheld = TRUE; + if (ch == ttyp->ostop) { + ttyp->oheld = TRUE; return; } } - iptr->oheld = FALSE; - if (iptr->imode == IMCBREAK) { /* cbreak mode */ - if (scount(iptr->isem) >= IBUFLEN) { - eputc(iptr->ifullc,iptr,cptr); + ttyp->oheld = FALSE; + if (ttyp->imode == IMCBREAK) { /* cbreak mode */ + if (scount(ttyp->isem) >= IBUFLEN) { + eputc(ttyp->ifullc,ttyp,cptr); return; } - iptr->ibuff[iptr->ihead++] = ch; - if (iptr->ihead >= IBUFLEN) - iptr->ihead = 0; - if (iptr->iecho) - echoch(ch,iptr,cptr); - if (scount(iptr->isem) < IBUFLEN) - signal(iptr->isem); + ttyp->ibuff[ttyp->ihead++] = ch | cerr; + if (ttyp->ihead >= IBUFLEN) + ttyp->ihead = 0; + if (ttyp->iecho) + echoch(ch,ttyp,cptr); + if (scount(ttyp->isem) < IBUFLEN) + signal(ttyp->isem); } else { /* cooked mode */ - if (ch == iptr->ikillc && iptr->ikill) { - iptr->ihead -= iptr->icursor; - if (iptr->ihead < 0) - iptr->ihead += IBUFLEN; - iptr->icursor = 0; - eputc(RETURN,iptr,cptr); - eputc(NEWLINE,iptr,cptr); + if (ch == ttyp->ikillc && ttyp->ikill) { + ttyp->ihead -= ttyp->icursor; + if (ttyp->ihead < 0) + ttyp->ihead += IBUFLEN; + ttyp->icursor = 0; + eputc(RETURN,ttyp,cptr); + eputc(NEWLINE,ttyp,cptr); return; } - if (ch == iptr->ierasec && iptr->ierase) { - if (iptr->icursor > 0) { - iptr->icursor--; - erase1(iptr,cptr); + if (ch == ttyp->ierasec && ttyp->ierase) { + if (ttyp->icursor > 0) { + ttyp->icursor--; + erase1(ttyp,cptr); } return; } - if (ch == NEWLINE || ch == RETURN || - (iptr->ieof && ch == iptr->ieofc)) { - if (iptr->iecho) { - echoch(ch,iptr,cptr); - if (ch == iptr->ieofc) - echoch(NEWLINE,iptr,cptr); - } - iptr->ibuff[iptr->ihead++] = ch; - if (iptr->ihead >= IBUFLEN) - iptr->ihead = 0; - ct = iptr->icursor+1; /* +1 for \n or \r*/ - iptr->icursor = 0; - signaln(iptr->isem,ct); + if (ch == NEWLINE || ch == RETURN) { + if (ttyp->iecho) + echoch(ch,ttyp,cptr); + ttyp->ibuff[ttyp->ihead++] = ch | cerr; + if (ttyp->ihead >= IBUFLEN) + ttyp->ihead = 0; + ct = ttyp->icursor+1; /* +1 for \n or \r*/ + ttyp->icursor = 0; + signaln(ttyp->isem,ct); return; } - ct = scount(iptr->isem); + ct = scount(ttyp->isem); ct = ct < 0 ? 0 : ct; - if ((ct + iptr->icursor) >= IBUFLEN-1) { - eputc(iptr->ifullc,iptr,cptr); + if ((ct + ttyp->icursor) >= IBUFLEN-1) { + eputc(ttyp->ifullc,ttyp,cptr); return; } - if (iptr->iecho) - echoch(ch,iptr,cptr); - iptr->icursor++; - iptr->ibuff[iptr->ihead++] = ch; - if (iptr->ihead >= IBUFLEN) - iptr->ihead = 0; + if (ttyp->iecho) + echoch(ch,ttyp,cptr); + ttyp->icursor++; + ttyp->ibuff[ttyp->ihead++] = ch | cerr; + if (ttyp->ihead >= IBUFLEN) + ttyp->ihead = 0; } } } @@ -113,57 +116,65 @@ INTPROC ttyiin(iptr) * erase1 -- erase one character honoring erasing backspace *------------------------------------------------------------------------ */ -LOCAL erase1(iptr,cptr) - struct tty *iptr; +LOCAL erase1(ttyp,cptr) + register struct tty *ttyp; register struct csr *cptr; { - char ch; + register char ch; + +#ifdef DEBUG + kprintf("erase1(%x, %x)\n", ttyp, cptr); +#endif - if (--(iptr->ihead) < 0) - iptr->ihead += IBUFLEN; - ch = iptr->ibuff[iptr->ihead]; - if (iptr->iecho) { + if (--(ttyp->ihead) < 0) + ttyp->ihead += IBUFLEN; + ch = ttyp->ibuff[ttyp->ihead]; + if (ttyp->iecho) { if (ch < BLANK || ch == 0177) { - if (iptr->evis) { - eputc(BACKSP,iptr,cptr); - if (iptr->ieback) { - eputc(BLANK,iptr,cptr); - eputc(BACKSP,iptr,cptr); + if (ttyp->evis) { + eputc(BACKSP,ttyp,cptr); + if (ttyp->ieback) { + eputc(BLANK,ttyp,cptr); + eputc(BACKSP,ttyp,cptr); } } - eputc(BACKSP,iptr,cptr); - if (iptr->ieback) { - eputc(BLANK,iptr,cptr); - eputc(BACKSP,iptr,cptr); + eputc(BACKSP,ttyp,cptr); + if (ttyp->ieback) { + eputc(BLANK,ttyp,cptr); + eputc(BACKSP,ttyp,cptr); } } else { - eputc(BACKSP,iptr,cptr); - if (iptr->ieback) { - eputc(BLANK,iptr,cptr); - eputc(BACKSP,iptr,cptr); + eputc(BACKSP,ttyp,cptr); + if (ttyp->ieback) { + eputc(BLANK,ttyp,cptr); + eputc(BACKSP,ttyp,cptr); } } - } else - cptr->ctstat = SLUENABLE; + } else { + slutenable(cptr); /* restart output */ + } } /*------------------------------------------------------------------------ * echoch -- echo a character with visual and ocrlf options *------------------------------------------------------------------------ */ -LOCAL echoch(ch, iptr, cptr) - char ch; /* character to echo */ - register struct tty *iptr; /* ptr to I/O block for this dev*/ +LOCAL echoch(ch, ttyp, cptr) + register char ch; /* character to echo */ + register struct tty *ttyp; /* pointer to I/O block for dev */ register struct csr *cptr; /* csr address for this devptr */ { - if ((ch==NEWLINE||ch==RETURN)&&iptr->ecrlf) { - eputc(RETURN,iptr,cptr); - eputc(NEWLINE,iptr,cptr); - } else if ((chevis) { - eputc(UPARROW,iptr,cptr); - eputc(ch+0100,iptr,cptr); /* make it printable */ +#ifdef DEBUG +/* kprintf("echoch(%c,%x,%x)\n", ch, ttyp, cptr); */ +#endif + if ((ch==NEWLINE||ch==RETURN)&&ttyp->ecrlf) { + eputc(RETURN,ttyp,cptr); + eputc(NEWLINE,ttyp,cptr); + } else if ((ch < BLANK || ch == 0177) && ttyp->evis) { + eputc(UPARROW,ttyp,cptr); + eputc(ch+0100,ttyp,cptr); /* make it printable */ } else { - eputc(ch,iptr,cptr); + eputc(ch,ttyp,cptr); } } @@ -171,13 +182,16 @@ LOCAL echoch(ch, iptr, cptr) * eputc - put one character in the echo queue *------------------------------------------------------------------------ */ -LOCAL eputc(ch,iptr,cptr) - char ch; - register struct tty *iptr; +LOCAL eputc(ch,ttyp,cptr) + register char ch; + register struct tty *ttyp; register struct csr *cptr; { - iptr->ebuff[iptr->ehead++] = ch; - if (iptr->ehead >= EBUFLEN) - iptr->ehead = 0; - cptr->ctstat = SLUENABLE; +#ifdef DEBUG +/* kprintf("eputc(%c,%x,%x)\n", ch, ttyp, cptr); */ +#endif + ttyp->ebuff[ttyp->ehead++] = ch; + if (ttyp->ehead >= EBUFLEN) + ttyp->ehead = 0; + slutenable(cptr); /* restart output */ }