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