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); }
static void ___cprintf(char* fmt, ...) { #ifdef DEBUG va_list list; va_start(list, fmt); char text[128]; memset(text, 0, 128); vsnprintf(text, 128, fmt, list); va_end(list); //tty_puts_native(tty_find(0), text); //tty_new_line(tty_find(0)); /* Write directly to the log file */ tty_t active = tty_active(); if(active && active->codes_logged) { klog_write(code_log, text, strlen(text)); char nl = '\n'; klog_write(code_log, &nl, 1); } #endif }
/*===========================================================================* * 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); } } }