Annotation of kernel/bsd/dev/ppc/cons.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* 
        !            26:  * Copyright (c) 1987, 1988 NeXT, Inc.
        !            27:  *
        !            28:  * HISTORY
        !            29:  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
        !            30:  *     Integrated POSIX support
        !            31:  *
        !            32:  * 12-Aug-87  John Seamons (jks) at NeXT
        !            33:  *     Ported to NeXT.
        !            34:  */ 
        !            35: 
        !            36: /*
        !            37:  * Indirect driver for console.
        !            38:  */
        !            39: #import <sys/param.h>
        !            40: #import <sys/systm.h>
        !            41: #import <sys/conf.h>
        !            42: #import <sys/ioctl.h>
        !            43: #import <sys/tty.h>
        !            44: #import <sys/proc.h>
        !            45: #import <sys/uio.h>
        !            46: #import <bsd/dev/ppc/cons.h>
        !            47: 
        !            48: struct tty     cons;
        !            49: struct tty     *constty;               /* current console device */
        !            50: 
        !            51: /*ARGSUSED*/
        !            52: int
        !            53: cnopen(dev, flag, devtype, pp)
        !            54:        dev_t dev;
        !            55:        int flag, devtype;
        !            56:        struct proc *pp;
        !            57: {
        !            58:        dev_t device;
        !            59: 
        !            60:        if (constty)
        !            61:            device = constty->t_dev;
        !            62:        else
        !            63:            device = cons.t_dev;
        !            64:        return ((*cdevsw[major(device)].d_open)(device, flag, devtype, pp));
        !            65: }
        !            66: 
        !            67: /*ARGSUSED*/
        !            68: int
        !            69: cnclose(dev, flag, mode, pp)
        !            70:        dev_t dev;
        !            71:        int flag, mode;
        !            72:        struct proc *pp;
        !            73: {
        !            74:        dev_t device;
        !            75: 
        !            76:        if (constty)
        !            77:            device = constty->t_dev;
        !            78:        else
        !            79:            device = cons.t_dev;
        !            80:        return ((*cdevsw[major(device)].d_close)(device, flag, mode, pp));
        !            81: }
        !            82: 
        !            83: /*ARGSUSED*/
        !            84: int
        !            85: cnread(dev, uio, ioflag)
        !            86:        dev_t dev;
        !            87:        struct uio *uio;
        !            88:        int ioflag;
        !            89: {
        !            90:        dev_t device;
        !            91: 
        !            92:        if (constty)
        !            93:            device = constty->t_dev;
        !            94:        else
        !            95:            device = cons.t_dev;
        !            96:        return ((*cdevsw[major(device)].d_read)(device, uio, ioflag));
        !            97: }
        !            98: 
        !            99: /*ARGSUSED*/
        !           100: int
        !           101: cnwrite(dev, uio, ioflag)
        !           102:        dev_t dev;
        !           103:        struct uio *uio;
        !           104:        int ioflag;
        !           105: {
        !           106:     dev_t device;
        !           107: 
        !           108:        if (constty)
        !           109:            device = constty->t_dev;
        !           110:        else
        !           111:            device = cons.t_dev;
        !           112:     return ((*cdevsw[major(device)].d_write)(device, uio, ioflag));
        !           113: }
        !           114: 
        !           115: /*ARGSUSED*/
        !           116: int
        !           117: cnioctl(dev, cmd, addr, flag, p)
        !           118:        dev_t dev;
        !           119:        int cmd;
        !           120:        caddr_t addr;
        !           121:        int flag;
        !           122:        struct proc *p;
        !           123: {
        !           124:        dev_t device;
        !           125: 
        !           126:        if (constty)
        !           127:            device = constty->t_dev;
        !           128:        else
        !           129:            device = cons.t_dev;
        !           130:        /*
        !           131:         * Superuser can always use this to wrest control of console
        !           132:         * output from the "virtual" console.
        !           133:         */
        !           134:        if (cmd == TIOCCONS && constty) {
        !           135:                int error = suser(p->p_ucred, (u_short *) NULL);
        !           136:                if (error)
        !           137:                        return (error);
        !           138:                constty = NULL;
        !           139:                return (0);
        !           140:        }
        !           141:        return ((*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p));
        !           142: }
        !           143: 
        !           144: /*ARGSUSED*/
        !           145: int
        !           146: cnselect(dev, flag, p)
        !           147:        dev_t dev;
        !           148:        int flag;
        !           149:        struct proc *p;
        !           150: {
        !           151:        dev_t device;
        !           152: 
        !           153:        if (constty)
        !           154:            device = constty->t_dev;
        !           155:        else
        !           156:            device = cons.t_dev;
        !           157:        return ((*cdevsw[major(device)].d_select)(device, flag, p));
        !           158: }
        !           159: 
        !           160: int
        !           161: cngetc()
        !           162: {
        !           163:        dev_t device;
        !           164: 
        !           165:        if (constty)
        !           166:            device = constty->t_dev;
        !           167:        else
        !           168:            device = cons.t_dev;
        !           169:        return ((*cdevsw[major(device)].d_getc)(device));
        !           170: }
        !           171: 
        !           172: /*ARGSUSED*/
        !           173: int
        !           174: cnputc(c)
        !           175:        char c;
        !           176: {
        !           177:        dev_t device;
        !           178: 
        !           179:        if (constty)
        !           180:            device = constty->t_dev;
        !           181:        else
        !           182:            device = cons.t_dev;
        !           183:        return ((*cdevsw[major(device)].d_putc)(device, c));
        !           184: }
        !           185: 
        !           186: #if    NCPUS > 1
        !           187: slave_cnenable()
        !           188: {
        !           189:        /* FIXME: what to do here? */
        !           190: }
        !           191: #endif NCPUS > 1
        !           192: 
        !           193: /* Send a debug char to modem port */
        !           194: #define LINE   1
        !           195: extern int scc_putc(int unit, int line, int c);
        !           196: extern int scc_getc(int unit, int line, boolean_t wait, boolean_t raw);
        !           197: 
        !           198: void
        !           199: czputc(char c)
        !           200: {
        !           201:     if (c == '\n')
        !           202:                (void) scc_putc(0 /* ignored */, LINE, '\r');
        !           203: 
        !           204:     (void) scc_putc(0 /* ignored */, LINE, c);
        !           205: }
        !           206: 
        !           207: #include <stdarg.h>
        !           208: #include <sys/subr_prf.h>
        !           209: 
        !           210: void
        !           211: kprintf( const char *format, ...)
        !           212: {
        !           213:     extern int kdp_flag;
        !           214: 
        !           215:     if( kdp_flag & 2) {
        !           216: 
        !           217:        char buffer[256];
        !           218:        char *sptr = buffer;
        !           219:        char *cptr = buffer;
        !           220:        va_list ap;
        !           221:        
        !           222:        va_start(ap, format);
        !           223:        prf(format, ap, TOSTR, (struct tty *)&sptr);
        !           224:        va_end(ap);
        !           225:     
        !           226:        while( cptr != sptr)
        !           227:            czputc( *cptr++);
        !           228:     }
        !           229: }
        !           230: 

unix.superglobalmegacorp.com

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