by shigemk2

当面は技術的なことしか書かない

sgtty

sgtty

dmr/tty.c

gttyとsttyの実際の処理

/*
 * Stuff common to stty and gtty.
 * Check legality and switch out to individual
 * device routine.
 * v  is 0 for stty; the parameters are taken from u.u_arg[].
 * c  is non-zero for gtty and is the place in which the device
 * routines place their information.
 */
sgtty(v)
int *v;
{
    register struct file *fp;
    register struct inode *ip;

    if ((fp = getf(u.u_ar0[R0])) == NULL)
        return;
    ip = fp->f_inode;
    if ((ip->i_mode&IFMT) != IFCHR) {
        u.u_error = ENOTTY;
        return;
    }
    /* 端末設定デバイスドライバを呼び出す */
    (*cdevsw[ip->i_addr[0].d_major].d_sgtty)(ip->i_addr[0], v);
}

klsgtty

dmr/kl.c

klsgtty(dev, v)
int *v;
{
    register struct tty *tp;

    tp = &kl11[dev.d_minor];
    ttystty(tp, v);
}

ttystty

実際にtty構造体への書き込みと読み出しを行う dmr/tty.c

引数avでモードの切り替えを行っている

/*
 * Common code for gtty and stty functions on typewriters.
 * If v is non-zero then gtty is being done and information is
 * passed back therein;
 * if it is zero stty is being done and the input information is in the
 * u_arg array.
 */
ttystty(atp, av)
int *atp, *av;
{
    register  *tp, *v;

    tp = atp;
    if(v = av) {
        /* 重要な処理はココ */
        *v++ = tp->t_speeds;
        v->lobyte = tp->t_erase;
        v->hibyte = tp->t_kill;
        v[1] = tp->t_flags;
        /* 戻り値にあまり意味は無い */
        return(1);
    }
    wflushtty(tp);
    v = u.u_arg;
    /* 重要な処理はココ */
    tp->t_speeds = *v++;
    tp->t_erase = v->lobyte;
    tp->t_kill = v->hibyte;
    tp->t_flags = v[1];
    return(0);
}