tty_t * line2tty(devminor_t line) { /* Convert a terminal line to tty_table pointer */ tty_t* tp; /* /dev/log goes to /dev/console, and both may be redirected. */ if (line == CONS_MINOR || line == LOG_MINOR) line = consoleline; if (line == VIDEO_MINOR) { return(NULL); } else if ((line - CONS_MINOR) < NR_CONS) { tp = tty_addr(line - CONS_MINOR); } else if ((line - RS232_MINOR) < NR_RS_LINES) { tp = tty_addr(line - RS232_MINOR + NR_CONS); } else { tp = NULL; } if (tp != NULL && !tty_active(tp)) tp = NULL; return(tp); }
tty_t * line2tty(devminor_t line) { /* Convert a terminal line to tty_table pointer */ tty_t* tp; if ((line - TTYPX_MINOR) < NR_PTYS) { tp = tty_addr(line - TTYPX_MINOR); } else if ((line - PTYPX_MINOR) < NR_PTYS) { tp = tty_addr(line - PTYPX_MINOR); } else if ((line - UNIX98_MINOR) < NR_PTYS * 2) { tp = tty_addr((line - UNIX98_MINOR) >> 1); } else {
/*===========================================================================* * tty_task * *===========================================================================*/ PUBLIC void tty_task() { /* Main routine of the terminal task. */ message tty_mess; /* buffer for all incoming messages */ register struct tty_struct *tp; tty_init(); while (TRUE) { receive(ANY, &tty_mess); if (!isttyline(tty_mess.TTY_LINE)) { tty_mess.m_type = -1; /* force error */ tty_mess.TTY_LINE = 0; /* so hardware ints can get through */ } tp = tty_addr(tty_mess.TTY_LINE); switch(tty_mess.m_type) { case HARD_INT: do_int(); break; case TTY_READ: do_read(tp, &tty_mess); break; case TTY_WRITE: do_write(tp, &tty_mess); break; case TTY_IOCTL: do_ioctl(tp, &tty_mess); break; case TTY_SETPGRP: do_setpgrp(tp, &tty_mess); break; case CANCEL: do_cancel(tp, &tty_mess); break; default: tty_reply(TASK_REPLY, tty_mess.m_source, tty_mess.PROC_NR, EINVAL); } if (saved == TRUE && tty_mess.m_source == save_mess.m_source) { saved = FALSE; tty_reply(save_mess.m_type, save_mess.m_source, save_mess.REP_PROC_NR, save_mess.REP_STATUS); } } }
/*===========================================================================* * tty_task * *===========================================================================*/ PUBLIC void tty_task() { /* Main routine of the terminal task. */ message tty_mess; /* buffer for all incoming messages */ register tty_t *tp; unsigned line; /* Initialize the terminal lines. */ for (tp = FIRST_TTY; tp < END_TTY; tp++) tty_init(tp); /* Display the Minix startup banner. */ printf("Minix %s.%s Copyright 1997 Prentice-Hall, Inc.\n\n", OS_RELEASE, OS_VERSION); #if (CHIP == INTEL) /* Real mode, or 16/32-bit protected mode? */ #if _WORD_SIZE == 4 printf("Executing in 32-bit protected mode\n\n"); #else printf("Executing in %s mode\n\n", protected_mode ? "16-bit protected" : "real"); #endif #endif while (TRUE) { /* Handle any events on any of the ttys. */ for (tp = FIRST_TTY; tp < END_TTY; tp++) { if (tp->tty_events) handle_events(tp); } receive(ANY, &tty_mess); /* A hardware interrupt is an invitation to check for events. */ if (tty_mess.m_type == HARD_INT) continue; /* Check the minor device number. */ line = tty_mess.TTY_LINE; if ((line - CONS_MINOR) < NR_CONS) { tp = tty_addr(line - CONS_MINOR); } else if (line == LOG_MINOR) { tp = tty_addr(0); } else if ((line - RS232_MINOR) < NR_RS_LINES) { tp = tty_addr(line - RS232_MINOR + NR_CONS); } else if ((line - TTYPX_MINOR) < NR_PTYS) { tp = tty_addr(line - TTYPX_MINOR + NR_CONS + NR_RS_LINES); } else if ((line - PTYPX_MINOR) < NR_PTYS) { tp = tty_addr(line - PTYPX_MINOR + NR_CONS + NR_RS_LINES); do_pty(tp, &tty_mess); continue; /* this is a pty, not a tty */ } else { tp = NULL; } /* If the device doesn't exist or is not configured return ENXIO. */ if (tp == NULL || !tty_active(tp)) { tty_reply(TASK_REPLY, tty_mess.m_source, tty_mess.PROC_NR, ENXIO); continue; } /* Execute the requested function. */ switch (tty_mess.m_type) { case DEV_READ: do_read(tp, &tty_mess); break; case DEV_WRITE: do_write(tp, &tty_mess); break; case DEV_IOCTL: do_ioctl(tp, &tty_mess); break; case DEV_OPEN: do_open(tp, &tty_mess); break; case DEV_CLOSE: do_close(tp, &tty_mess); break; case CANCEL: do_cancel(tp, &tty_mess); break; default: tty_reply(TASK_REPLY, tty_mess.m_source, tty_mess.PROC_NR, EINVAL); } } }