X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/88a7a62ac37860454424240400aa10e0319144c7..1eebc1a70802d2bd87f4a95eba439778ff6803ae:/usr/src/sys/kern/tty_subr.c diff --git a/usr/src/sys/kern/tty_subr.c b/usr/src/sys/kern/tty_subr.c index edd9a2ba56..44d708addd 100644 --- a/usr/src/sys/kern/tty_subr.c +++ b/usr/src/sys/kern/tty_subr.c @@ -1,11 +1,17 @@ -/* tty_subr.c 4.20 83/05/27 */ +/* + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + * + * @(#)tty_subr.c 7.3 (Berkeley) %G% + */ -#include "../h/param.h" -#include "../h/systm.h" -#include "../h/conf.h" -#include "../h/buf.h" -#include "../h/tty.h" -#include "../h/clist.h" +#include "param.h" +#include "systm.h" +#include "buf.h" +#include "ioctl.h" +#include "tty.h" +#include "clist.h" char cwaiting; @@ -18,7 +24,7 @@ getc(p) register struct cblock *bp; register int c, s; - s = spl5(); + s = spltty(); if (p->c_cc <= 0) { c = -1; p->c_cc = 0; @@ -27,7 +33,7 @@ getc(p) c = *p->c_cf++ & 0377; if (--p->c_cc<=0) { bp = (struct cblock *)(p->c_cf-1); - bp = (struct cblock *) ((int)bp & ~CROUND); + bp = (struct cblock *)((int)bp & ~CROUND); p->c_cf = NULL; p->c_cl = NULL; bp->c_next = cfreelist; @@ -51,10 +57,9 @@ getc(p) } } splx(s); - return(c); + return (c); } -#ifdef notdef /* * copy clist to buffer. * return number of bytes moved. @@ -65,24 +70,31 @@ q_to_b(q, cp, cc) { register struct cblock *bp; register int s; + register nc; char *acp; if (cc <= 0) - return(0); - s = spl5(); + return (0); + s = spltty(); if (q->c_cc <= 0) { q->c_cc = 0; q->c_cf = q->c_cl = NULL; splx(s); - return(0); + return (0); } acp = cp; - cc++; - while (--cc) { - *cp++ = *q->c_cf++; - if (--q->c_cc <= 0) { - bp = (struct cblock *)(q->c_cf-1); + while (cc) { + nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND); + nc = MIN(nc, cc); + nc = MIN(nc, q->c_cc); + (void) bcopy(q->c_cf, cp, (unsigned)nc); + q->c_cf += nc; + q->c_cc -= nc; + cc -= nc; + cp += nc; + if (q->c_cc <= 0) { + bp = (struct cblock *)(q->c_cf - 1); bp = (struct cblock *)((int)bp & ~CROUND); q->c_cf = q->c_cl = NULL; bp->c_next = cfreelist; @@ -108,9 +120,8 @@ q_to_b(q, cp, cc) } } splx(s); - return(cp-acp); + return (cp-acp); } -#endif /* * Return count of contiguous characters @@ -123,7 +134,7 @@ ndqb(q, flag) register cc; int s; - s = spl5(); + s = spltty(); if (q->c_cc <= 0) { cc = -q->c_cc; goto out; @@ -149,11 +160,9 @@ ndqb(q, flag) } out: splx(s); - return(cc); + return (cc); } - - /* * Flush cc bytes from q. */ @@ -165,10 +174,9 @@ ndflush(q, cc) char *end; int rem, s; - s = spl5(); - if (q->c_cc <= 0) { + s = spltty(); + if (q->c_cc <= 0) goto out; - } while (cc>0 && q->c_cc) { bp = (struct cblock *)((int)q->c_cf & ~CROUND); if ((int)bp == (((int)q->c_cl-1) & ~CROUND)) { @@ -219,11 +227,11 @@ putc(c, p) register char *cp; register s; - s = spl5(); + s = spltty(); if ((cp = p->c_cl) == NULL || p->c_cc < 0 ) { if ((bp = cfreelist) == NULL) { splx(s); - return(-1); + return (-1); } cfreelist = bp->c_next; cfreecount -= CBSIZE; @@ -233,7 +241,7 @@ putc(c, p) bp = (struct cblock *)cp - 1; if ((bp->c_next = cfreelist) == NULL) { splx(s); - return(-1); + return (-1); } bp = bp->c_next; cfreelist = bp->c_next; @@ -245,11 +253,9 @@ putc(c, p) p->c_cc++; p->c_cl = cp; splx(s); - return(0); + return (0); } - - /* * copy buffer to clist. * return number of bytes not transfered. @@ -261,14 +267,13 @@ b_to_q(cp, cc, q) { register char *cq; register struct cblock *bp; - register s, acc; + register s, nc; + int acc; if (cc <= 0) - return(0); + return (0); acc = cc; - - - s = spl5(); + s = spltty(); if ((cq = q->c_cl) == NULL || q->c_cc < 0) { if ((bp = cfreelist) == NULL) goto out; @@ -280,7 +285,7 @@ b_to_q(cp, cc, q) while (cc) { if (((int)cq & CROUND) == 0) { - bp = (struct cblock *) cq - 1; + bp = (struct cblock *)cq - 1; if ((bp->c_next = cfreelist) == NULL) goto out; bp = bp->c_next; @@ -289,14 +294,17 @@ b_to_q(cp, cc, q) bp->c_next = NULL; cq = bp->c_info; } - *cq++ = *cp++; - cc--; + nc = MIN(cc, sizeof (struct cblock) - ((int)cq & CROUND)); + (void) bcopy(cp, cq, (unsigned)nc); + cp += nc; + cq += nc; + cc -= nc; } out: q->c_cl = cq; - q->c_cc += acc-cc; + q->c_cc += acc - cc; splx(s); - return(cc); + return (cc); } /* @@ -331,7 +339,7 @@ unputc(p) register int c, s; struct cblock *obp; - s = spl5(); + s = spltty(); if (p->c_cc <= 0) c = -1; else { @@ -365,59 +373,140 @@ unputc(p) /* * Put the chars in the from que * on the end of the to que. - * - * SHOULD JUST USE q_to_b AND THEN b_to_q HERE. */ catq(from, to) struct clist *from, *to; { - register c; - - while ((c = getc(from)) >= 0) - (void) putc(c, to); + char bbuf[CBSIZE*4]; + register s, c; + + s = spltty(); + if (to->c_cc == 0) { + *to = *from; + from->c_cc = 0; + from->c_cf = NULL; + from->c_cl = NULL; + splx(s); + return; + } + splx(s); + while (from->c_cc > 0) { + c = q_to_b(from, bbuf, sizeof bbuf); + (void) b_to_q(bbuf, c, to); + } } +#ifdef unneeded /* - * Integer (short) get/put - * using clists + * Integer (short) get/put using clists. */ -typedef short word_t; -union chword { - word_t word; - struct { - char Ch[sizeof (word_t)]; - } Cha; -#define ch Cha.Ch -}; +typedef u_short word_t; getw(p) register struct clist *p; { - register int i; - union chword x; + register int s, c; + register struct cblock *bp; - if (p->c_cc < sizeof (word_t)) - return (-1); - for (i = 0; i < sizeof (word_t); i++) - x.ch[i] = getc(p); - return (x.word); + if (p->c_cc <= 1) + return(-1); + if (p->c_cc & 01) { + c = getc(p); +#if BYTE_ORDER == LITTLE_ENDIAN + return (c | (getc(p)<<8)); +#else + return (getc(p) | (c<<8)); +#endif + } + s = spltty(); +#if BYTE_ORDER == LITTLE_ENDIAN + c = (((u_char *)p->c_cf)[0] << 8) | ((u_char *)p->c_cf)[1]; +#else + c = (((u_char *)p->c_cf)[1] << 8) | ((u_char *)p->c_cf)[0]; +#endif + p->c_cf += sizeof (word_t); + p->c_cc -= sizeof (word_t); + if (p->c_cc <= 0) { + bp = (struct cblock *)(p->c_cf-1); + bp = (struct cblock *)((int)bp & ~CROUND); + p->c_cf = NULL; + p->c_cl = NULL; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup(&cwaiting); + cwaiting = 0; + } + } else if (((int)p->c_cf & CROUND) == 0) { + bp = (struct cblock *)(p->c_cf); + bp--; + p->c_cf = bp->c_next->c_info; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup(&cwaiting); + cwaiting = 0; + } + } + splx(s); + return (c); } putw(c, p) register struct clist *p; + word_t c; { register s; - register int i; - union chword x; + register struct cblock *bp; + register char *cp; - s = spl5(); + s = spltty(); if (cfreelist==NULL) { splx(s); return(-1); } - x.word = c; - for (i = 0; i < sizeof (word_t); i++) - (void) putc(x.ch[i], p); + if (p->c_cc & 01) { +#if BYTE_ORDER == LITTLE_ENDIAN + (void) putc(c, p); + (void) putc(c>>8, p); +#else + (void) putc(c>>8, p); + (void) putc(c, p); +#endif + } else { + if ((cp = p->c_cl) == NULL || p->c_cc < 0 ) { + if ((bp = cfreelist) == NULL) { + splx(s); + return (-1); + } + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + p->c_cf = cp = bp->c_info; + } else if (((int)cp & CROUND) == 0) { + bp = (struct cblock *)cp - 1; + if ((bp->c_next = cfreelist) == NULL) { + splx(s); + return (-1); + } + bp = bp->c_next; + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + cp = bp->c_info; + } +#if defined(vax) + *(word_t *)cp = c; +#else + ((u_char *)cp)[0] = c>>8; + ((u_char *)cp)[1] = c; +#endif + p->c_cl = cp + sizeof (word_t); + p->c_cc += sizeof (word_t); + } splx(s); return (0); } +#endif unneeded