Annotation of Net2/arch/hp300/hpux/hpux_tty.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 University of Utah.
        !             3:  * Copyright (c) 1990 The Regents of the University of California.
        !             4:  * All rights reserved.
        !             5:  *
        !             6:  * This code is derived from software contributed to Berkeley by
        !             7:  * the Systems Programming Group of the University of Utah Computer
        !             8:  * Science Department.
        !             9:  *
        !            10:  * Redistribution and use in source and binary forms, with or without
        !            11:  * modification, are permitted provided that the following conditions
        !            12:  * are met:
        !            13:  * 1. Redistributions of source code must retain the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer.
        !            15:  * 2. Redistributions in binary form must reproduce the above copyright
        !            16:  *    notice, this list of conditions and the following disclaimer in the
        !            17:  *    documentation and/or other materials provided with the distribution.
        !            18:  * 3. All advertising materials mentioning features or use of this software
        !            19:  *    must display the following acknowledgement:
        !            20:  *     This product includes software developed by the University of
        !            21:  *     California, Berkeley and its contributors.
        !            22:  * 4. Neither the name of the University nor the names of its contributors
        !            23:  *    may be used to endorse or promote products derived from this software
        !            24:  *    without specific prior written permission.
        !            25:  *
        !            26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            36:  * SUCH DAMAGE.
        !            37:  *
        !            38:  * from: Utah $Hdr: hpux_tty.c 1.1 90/07/09$
        !            39:  *
        !            40:  *     @(#)hpux_tty.c  7.9 (Berkeley) 5/30/91
        !            41:  */
        !            42: 
        !            43: /*
        !            44:  * stty/gtty/termio emulation stuff
        !            45:  */
        !            46: #ifdef HPUXCOMPAT
        !            47: 
        !            48: #include "param.h"
        !            49: #include "systm.h"
        !            50: #include "filedesc.h"
        !            51: #include "ioctl.h"
        !            52: #include "tty.h"
        !            53: #include "proc.h"
        !            54: #include "file.h"
        !            55: #include "conf.h"
        !            56: #include "buf.h"
        !            57: #include "kernel.h"
        !            58: 
        !            59: #include "hpux.h"
        !            60: #include "hpux_termio.h"
        !            61: 
        !            62: /*
        !            63:  * Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
        !            64:  */
        !            65: hpuxtermio(fp, com, data, p)
        !            66:        struct file *fp;
        !            67:        caddr_t data;
        !            68:        struct proc *p;
        !            69: {
        !            70:        struct termios tios;
        !            71:        int line, error, (*ioctlrout)();
        !            72:        register struct hpuxtermio *tiop;
        !            73: 
        !            74:        ioctlrout = fp->f_ops->fo_ioctl;
        !            75:        tiop = (struct hpuxtermio *)data;
        !            76:        switch (com) {
        !            77:        case HPUXTCGETA:
        !            78:                /*
        !            79:                 * Get BSD terminal state
        !            80:                 */
        !            81:                bzero(data, sizeof(struct hpuxtermio));
        !            82:                if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
        !            83:                        break;
        !            84:                /*
        !            85:                 * Set iflag.
        !            86:                 * Same through ICRNL, no BSD equivs for IUCLC, IENQAK
        !            87:                 */
        !            88:                tiop->c_iflag = tios.c_iflag & 0x1ff;
        !            89:                if (tios.c_iflag & IXON)
        !            90:                        tiop->c_iflag |= TIO_IXON;
        !            91:                if (tios.c_iflag & IXOFF)
        !            92:                        tiop->c_iflag |= TIO_IXOFF;
        !            93:                if (tios.c_iflag & IXANY)
        !            94:                        tiop->c_iflag |= TIO_IXANY;
        !            95:                /*
        !            96:                 * Set oflag.
        !            97:                 * No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
        !            98:                 * or any of the delays.
        !            99:                 */
        !           100:                if (tios.c_oflag & OPOST)
        !           101:                        tiop->c_oflag |= TIO_OPOST;
        !           102:                if (tios.c_oflag & ONLCR)
        !           103:                        tiop->c_oflag |= TIO_ONLCR;
        !           104:                if (tios.c_oflag & OXTABS)
        !           105:                        tiop->c_oflag |= TIO_TAB3;
        !           106:                /*
        !           107:                 * Set cflag.
        !           108:                 * Baud from ospeed, rest from cflag.
        !           109:                 */
        !           110:                tiop->c_cflag = bsdtohpuxbaud(tios.c_ospeed);
        !           111:                switch (tios.c_cflag & CSIZE) {
        !           112:                case CS5:
        !           113:                        tiop->c_cflag |= TIO_CS5; break;
        !           114:                case CS6:
        !           115:                        tiop->c_cflag |= TIO_CS6; break;
        !           116:                case CS7:
        !           117:                        tiop->c_cflag |= TIO_CS7; break;
        !           118:                case CS8:
        !           119:                        tiop->c_cflag |= TIO_CS8; break;
        !           120:                }
        !           121:                if (tios.c_cflag & CSTOPB)
        !           122:                        tiop->c_cflag |= TIO_CSTOPB;
        !           123:                if (tios.c_cflag & CREAD)
        !           124:                        tiop->c_cflag |= TIO_CREAD;
        !           125:                if (tios.c_cflag & PARENB)
        !           126:                        tiop->c_cflag |= TIO_PARENB;
        !           127:                if (tios.c_cflag & PARODD)
        !           128:                        tiop->c_cflag |= TIO_PARODD;
        !           129:                if (tios.c_cflag & HUPCL)
        !           130:                        tiop->c_cflag |= TIO_HUPCL;
        !           131:                if (tios.c_cflag & CLOCAL)
        !           132:                        tiop->c_cflag |= TIO_CLOCAL;
        !           133:                /*
        !           134:                 * Set lflag.
        !           135:                 * No BSD equiv for XCASE.
        !           136:                 */
        !           137:                if (tios.c_lflag & ECHOE)
        !           138:                        tiop->c_lflag |= TIO_ECHOE;
        !           139:                if (tios.c_lflag & ECHOK)
        !           140:                        tiop->c_lflag |= TIO_ECHOK;
        !           141:                if (tios.c_lflag & ECHO)
        !           142:                        tiop->c_lflag |= TIO_ECHO;
        !           143:                if (tios.c_lflag & ECHONL)
        !           144:                        tiop->c_lflag |= TIO_ECHONL;
        !           145:                if (tios.c_lflag & ISIG)
        !           146:                        tiop->c_lflag |= TIO_ISIG;
        !           147:                if (tios.c_lflag & ICANON)
        !           148:                        tiop->c_lflag |= TIO_ICANON;
        !           149:                if (tios.c_lflag & NOFLSH)
        !           150:                        tiop->c_lflag |= TIO_NOFLSH;
        !           151:                /*
        !           152:                 * Line discipline
        !           153:                 */
        !           154:                line = 0;
        !           155:                (void) (*ioctlrout)(fp, TIOCGETD, (caddr_t)&line, p);
        !           156:                tiop->c_line = line;
        !           157:                /*
        !           158:                 * Set editing chars
        !           159:                 */
        !           160:                tiop->c_cc[HPUXVINTR] = tios.c_cc[VINTR];
        !           161:                tiop->c_cc[HPUXVQUIT] = tios.c_cc[VQUIT];
        !           162:                tiop->c_cc[HPUXVERASE] = tios.c_cc[VERASE];
        !           163:                tiop->c_cc[HPUXVKILL] = tios.c_cc[VKILL];
        !           164:                if (tiop->c_lflag & TIO_ICANON) {
        !           165:                        tiop->c_cc[HPUXVEOF] = tios.c_cc[VEOF];
        !           166:                        tiop->c_cc[HPUXVEOL] = tios.c_cc[VEOL];
        !           167:                } else {
        !           168:                        tiop->c_cc[HPUXVMIN] = tios.c_cc[VMIN];
        !           169:                        tiop->c_cc[HPUXVTIME] = tios.c_cc[VTIME];
        !           170:                }
        !           171:                break;
        !           172: 
        !           173:        case HPUXTCSETA:
        !           174:        case HPUXTCSETAW:
        !           175:        case HPUXTCSETAF:
        !           176:                /*
        !           177:                 * Get old characteristics and determine if we are a tty.
        !           178:                 */
        !           179:                if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
        !           180:                        break;
        !           181:                /*
        !           182:                 * Set iflag.
        !           183:                 * Same through ICRNL, no HP-UX equiv for IMAXBEL
        !           184:                 */
        !           185:                tios.c_iflag &= ~(IXON|IXOFF|IXANY|0x1ff);
        !           186:                tios.c_iflag |= tiop->c_iflag & 0x1ff;
        !           187:                if (tiop->c_iflag & TIO_IXON)
        !           188:                        tios.c_iflag |= IXON;
        !           189:                if (tiop->c_iflag & TIO_IXOFF)
        !           190:                        tios.c_iflag |= IXOFF;
        !           191:                if (tiop->c_iflag & TIO_IXANY)
        !           192:                        tios.c_iflag |= IXANY;
        !           193:                /*
        !           194:                 * Set oflag.
        !           195:                 * No HP-UX equiv for ONOEOT
        !           196:                 */
        !           197:                tios.c_oflag &= ~(OPOST|ONLCR|OXTABS);
        !           198:                if (tiop->c_oflag & TIO_OPOST)
        !           199:                        tios.c_oflag |= OPOST;
        !           200:                if (tiop->c_oflag & TIO_ONLCR)
        !           201:                        tios.c_oflag |= ONLCR;
        !           202:                if (tiop->c_oflag & TIO_TAB3)
        !           203:                        tios.c_oflag |= OXTABS;
        !           204:                /*
        !           205:                 * Set cflag.
        !           206:                 * No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
        !           207:                 */
        !           208:                tios.c_cflag &=
        !           209:                        ~(CSIZE|CSTOPB|CREAD|PARENB|PARODD|HUPCL|CLOCAL);
        !           210:                switch (tiop->c_cflag & TIO_CSIZE) {
        !           211:                case TIO_CS5:
        !           212:                        tios.c_cflag |= CS5; break;
        !           213:                case TIO_CS6:
        !           214:                        tios.c_cflag |= CS6; break;
        !           215:                case TIO_CS7:
        !           216:                        tios.c_cflag |= CS7; break;
        !           217:                case TIO_CS8:
        !           218:                        tios.c_cflag |= CS8; break;
        !           219:                }
        !           220:                if (tiop->c_cflag & TIO_CSTOPB)
        !           221:                        tios.c_cflag |= CSTOPB;
        !           222:                if (tiop->c_cflag & TIO_CREAD)
        !           223:                        tios.c_cflag |= CREAD;
        !           224:                if (tiop->c_cflag & TIO_PARENB)
        !           225:                        tios.c_cflag |= PARENB;
        !           226:                if (tiop->c_cflag & TIO_PARODD)
        !           227:                        tios.c_cflag |= PARODD;
        !           228:                if (tiop->c_cflag & TIO_HUPCL)
        !           229:                        tios.c_cflag |= HUPCL;
        !           230:                if (tiop->c_cflag & TIO_CLOCAL)
        !           231:                        tios.c_cflag |= CLOCAL;
        !           232:                /*
        !           233:                 * Set lflag.
        !           234:                 * No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
        !           235:                 * IEXTEN treated as part of ICANON
        !           236:                 */
        !           237:                tios.c_lflag &= ~(ECHOE|ECHOK|ECHO|ISIG|ICANON|IEXTEN|NOFLSH);
        !           238:                if (tiop->c_lflag & TIO_ECHOE)
        !           239:                        tios.c_lflag |= ECHOE;
        !           240:                if (tiop->c_lflag & TIO_ECHOK)
        !           241:                        tios.c_lflag |= ECHOK;
        !           242:                if (tiop->c_lflag & TIO_ECHO)
        !           243:                        tios.c_lflag |= ECHO;
        !           244:                if (tiop->c_lflag & TIO_ECHONL)
        !           245:                        tios.c_lflag |= ECHONL;
        !           246:                if (tiop->c_lflag & TIO_ISIG)
        !           247:                        tios.c_lflag |= ISIG;
        !           248:                if (tiop->c_lflag & TIO_ICANON)
        !           249:                        tios.c_lflag |= (ICANON|IEXTEN);
        !           250:                if (tiop->c_lflag & TIO_NOFLSH)
        !           251:                        tios.c_lflag |= NOFLSH;
        !           252:                /*
        !           253:                 * Set editing chars.
        !           254:                 * No HP-UX equivs of VEOL2/VWERASE/VREPRINT/VSUSP/VDSUSP
        !           255:                 * VSTOP/VLNEXT/VDISCARD/VMIN/VTIME/VSTATUS/VERASE2
        !           256:                 */
        !           257:                tios.c_cc[VINTR] = tiop->c_cc[HPUXVINTR];
        !           258:                tios.c_cc[VQUIT] = tiop->c_cc[HPUXVQUIT];
        !           259:                tios.c_cc[VERASE] = tiop->c_cc[HPUXVERASE];
        !           260:                tios.c_cc[VKILL] = tiop->c_cc[HPUXVKILL];
        !           261:                if (tios.c_lflag & ICANON) {
        !           262:                        tios.c_cc[VEOF] = tiop->c_cc[HPUXVEOF];
        !           263:                        tios.c_cc[VEOL] = tiop->c_cc[HPUXVEOL];
        !           264:                } else {
        !           265:                        tios.c_cc[VMIN] = tiop->c_cc[HPUXVMIN];
        !           266:                        tios.c_cc[VTIME] = tiop->c_cc[HPUXVTIME];
        !           267:                }
        !           268:                /*
        !           269:                 * Set the new stuff
        !           270:                 */
        !           271:                if (com == HPUXTCSETA)
        !           272:                        com = TIOCSETA;
        !           273:                else if (com == HPUXTCSETAW)
        !           274:                        com = TIOCSETAW;
        !           275:                else
        !           276:                        com = TIOCSETAF;
        !           277:                error = (*ioctlrout)(fp, com, (caddr_t)&tios, p);
        !           278:                if (error == 0) {
        !           279:                        /*
        !           280:                         * Set line discipline
        !           281:                         */
        !           282:                        line = tiop->c_line;
        !           283:                        (void) (*ioctlrout)(fp, TIOCSETD, (caddr_t)&line, p);
        !           284:                        /*
        !           285:                         * Set non-blocking IO if VMIN == VTIME == 0.
        !           286:                         * Should handle the other cases as well.  It also
        !           287:                         * isn't correct to just turn it off as it could be
        !           288:                         * on as the result of a fcntl operation.
        !           289:                         * XXX - wouldn't need to do this at all if VMIN/VTIME
        !           290:                         * were implemented.
        !           291:                         */
        !           292:                        line = (tiop->c_cc[HPUXVMIN] == 0 &&
        !           293:                                tiop->c_cc[HPUXVTIME] == 0);
        !           294:                        if (line)
        !           295:                                fp->f_flag |= FNONBLOCK;
        !           296:                        else
        !           297:                                fp->f_flag &= ~FNONBLOCK;
        !           298:                        (void) (*ioctlrout)(fp, FIONBIO, (caddr_t)&line, p);
        !           299:                }
        !           300:                break;
        !           301: 
        !           302:        default:
        !           303:                error = EINVAL;
        !           304:                break;
        !           305:        }
        !           306:        return(error);
        !           307: }
        !           308: 
        !           309: bsdtohpuxbaud(bsdspeed)
        !           310:        long bsdspeed;
        !           311: {
        !           312:        switch (bsdspeed) {
        !           313:        case B0:     return(TIO_B0);
        !           314:        case B50:    return(TIO_B50);
        !           315:        case B75:    return(TIO_B75);
        !           316:        case B110:   return(TIO_B110);
        !           317:        case B134:   return(TIO_B134);
        !           318:        case B150:   return(TIO_B150);
        !           319:        case B200:   return(TIO_B200);
        !           320:        case B300:   return(TIO_B300);
        !           321:        case B600:   return(TIO_B600);
        !           322:        case B1200:  return(TIO_B1200);
        !           323:        case B1800:  return(TIO_B1800);
        !           324:        case B2400:  return(TIO_B2400);
        !           325:        case B4800:  return(TIO_B4800);
        !           326:        case B9600:  return(TIO_B9600);
        !           327:        case B19200: return(TIO_B19200);
        !           328:        case B38400: return(TIO_B38400);
        !           329:        default:     return(TIO_B0);
        !           330:        }
        !           331: }
        !           332: 
        !           333: hpuxtobsdbaud(hpuxspeed)
        !           334:        int hpuxspeed;
        !           335: {
        !           336:        static char hpuxtobsdbaudtab[32] = {
        !           337:                B0,     B50,    B75,    B110,   B134,   B150,   B200,   B300,
        !           338:                B600,   B0,     B1200,  B1800,  B2400,  B0,     B4800,  B0,
        !           339:                B9600,  B19200, B38400, B0,     B0,     B0,     B0,     B0,
        !           340:                B0,     B0,     B0,     B0,     B0,     B0,     EXTA,   EXTB
        !           341:        };
        !           342: 
        !           343:        return(hpuxtobsdbaudtab[hpuxspeed & TIO_CBAUD]);
        !           344: }
        !           345: 
        !           346: /* #ifdef COMPAT */
        !           347: ohpuxgtty(p, uap, retval)
        !           348:        struct proc *p;
        !           349:        struct args {
        !           350:                int     fdes;
        !           351:                caddr_t cmarg;
        !           352:        } *uap;
        !           353:        int *retval;
        !           354: {
        !           355: 
        !           356:        return (getsettty(p, uap->fdes, HPUXTIOCGETP, uap->cmarg));
        !           357: }
        !           358: 
        !           359: ohpuxstty(p, uap, retval)
        !           360:        struct proc *p;
        !           361:        struct args {
        !           362:                int     fdes;
        !           363:                caddr_t cmarg;
        !           364:        } *uap;
        !           365:        int *retval;
        !           366: {
        !           367: 
        !           368:        return (getsettty(p, uap->fdes, HPUXTIOCSETP, uap->cmarg));
        !           369: }
        !           370: 
        !           371: /*
        !           372:  * Simplified version of ioctl() for use by
        !           373:  * gtty/stty and TIOCGETP/TIOCSETP.
        !           374:  */
        !           375: getsettty(p, fdes, com, cmarg)
        !           376:        struct proc *p;
        !           377:        int fdes, com;
        !           378:        caddr_t cmarg;
        !           379: {
        !           380:        register struct filedesc *fdp = p->p_fd;
        !           381:        register struct file *fp;
        !           382:        struct hpuxsgttyb hsb;
        !           383:        struct sgttyb sb;
        !           384:        int error;
        !           385: 
        !           386:        if (((unsigned)fdes) >= fdp->fd_nfiles ||
        !           387:            (fp = fdp->fd_ofiles[fdes]) == NULL)
        !           388:                return (EBADF);
        !           389:        if ((fp->f_flag & (FREAD|FWRITE)) == 0)
        !           390:                return (EBADF);
        !           391:        if (com == HPUXTIOCSETP) {
        !           392:                if (error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb))
        !           393:                        return (error);
        !           394:                sb.sg_ispeed = hsb.sg_ispeed;
        !           395:                sb.sg_ospeed = hsb.sg_ospeed;
        !           396:                sb.sg_erase = hsb.sg_erase;
        !           397:                sb.sg_kill = hsb.sg_kill;
        !           398:                sb.sg_flags = hsb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
        !           399:                if (hsb.sg_flags & V7_XTABS)
        !           400:                        sb.sg_flags |= XTABS;
        !           401:                if (hsb.sg_flags & V7_HUPCL)
        !           402:                        (void)(*fp->f_ops->fo_ioctl)
        !           403:                                (fp, TIOCHPCL, (caddr_t)0, p);
        !           404:                com = TIOCSETP;
        !           405:        } else {
        !           406:                bzero((caddr_t)&hsb, sizeof hsb);
        !           407:                com = TIOCGETP;
        !           408:        }
        !           409:        error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb, p);
        !           410:        if (error == 0 && com == TIOCGETP) {
        !           411:                hsb.sg_ispeed = sb.sg_ispeed;
        !           412:                hsb.sg_ospeed = sb.sg_ospeed;
        !           413:                hsb.sg_erase = sb.sg_erase;
        !           414:                hsb.sg_kill = sb.sg_kill;
        !           415:                hsb.sg_flags = sb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
        !           416:                if (sb.sg_flags & XTABS)
        !           417:                        hsb.sg_flags |= V7_XTABS;
        !           418:                error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
        !           419:        }
        !           420:        return (error);
        !           421: }
        !           422: /* #endif */
        !           423: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.