~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Minix Cross Reference
Minix/kernel/sunconsole.c


  1 static char rcsid[] = "$Id: sunconsole.c,v 1.4 1996/08/01 02:08:48 paul Exp $";
  2 
  3 /*
  4  * The file contains the code for transferring Minix's terminal output into
  5  * SunOS.  The entry points for this file are:
  6  *     - scr_init - sets up output for the specified terminal line
  7  *     - putk - called by printk to print a character to the console.
  8  *     - handup - a handup has occurred for a terminal line.
  9  *
 10  * scr_init puts pointers to cons_write and cons_echo into tty structs,
 11  * so cons_write and cons_echo are indirectly callable from outside.
 12  */
 13  
 14 #include "kernel.h"
 15 #include <termios.h>
 16 #include "proc.h"
 17 #include <minix/callnr.h>
 18 #include <minix/com.h>
 19 #include "tty.h"
 20 #include <signal.h>
 21 #include <sun/syscall.h>
 22 
 23 #define CONSOLE         0
 24 
 25 /*
 26  * Local functions.
 27  */
 28 static void cons_write(tty_t *tp);
 29 static void cons_echo(tty_t *tp, int c);
 30 static void out_char(tty_t *tp, char c);
 31 
 32 /*
 33  * Function: scr_init
 34  * Parameter: tp - tty struct whose line is being initialised.
 35  */
 36 void scr_init(tty_t *tp)
 37 {
 38     /* Initialize the keyboard driver. */
 39     kb_init(tp);
 40 
 41     /* Output functions. */
 42     tp->tty_devwrite = cons_write;
 43     tp->tty_echo = cons_echo;
 44 }
 45 
 46 
 47 /*
 48  * Function: cons_write
 49  * Parameter: tp - tty to write to (it data is queued for it)
 50  *
 51  * If there is data to output, and output is not inhibited, than all
 52  * queued data is output.  Terminal 0 uses TERMINAL_FD for input and
 53  * TERMINAL_FD + 1 for output; terminal 1 uses TERMINAL_FD + 2 for input
 54  * and TERMINAL_FD + 3 for output and so on.  That is why the output
 55  * descriptor for terminal n is TERMINAL_FD + 2n + 1.
 56  */
 57 static void cons_write(tty_t *tp)
 58 {
 59     int count;
 60     char buf[64];
 61     phys_bytes user_phys;
 62 
 63     /*
 64      * Check quickly for nothing to do, so this can be called often without
 65      * unmodular tests elsewhere.
 66      */
 67     if ((count = tp->tty_outleft) == 0 || tp->tty_inhibited) return;
 68   
 69     do {
 70         if (count > sizeof(buf)) count = sizeof(buf);
 71         user_phys = proc_vir2phys(proc_addr(tp->tty_outproc), tp->tty_out_vir);
 72         phys_copy(user_phys, vir2phys(buf), (phys_bytes) count);
 73 
 74         SunOS(SYS_write, TERMINAL_FD + 1 + tty_line(tp) * 2, buf, count);
 75         
 76         tp->tty_out_vir += count;
 77         tp->tty_outcum += count;
 78         tp->tty_outleft -= count;
 79 
 80     } while ((count = tp->tty_outleft) != 0 && !tp->tty_inhibited);
 81 
 82     /*
 83      * Reply to the writer if all output is finished.
 84      */
 85     if (tp->tty_outleft == 0) {
 86         tty_reply(tp->tty_outrepcode, tp->tty_outcaller, tp->tty_outproc,
 87                   tp->tty_outcum);
 88         tp->tty_outcum = 0;
 89     }
 90 }
 91  
 92 
 93 /*
 94  * Function: cons_echo
 95  * Parameters: tp - tty struct for terminal to write to
 96  *             c - character to write to tp
 97  */
 98 static void cons_echo(tty_t *tp, int c)
 99 {
100     out_char(tp, c);
101 }
102 
103 
104 /*
105  * Function: putk
106  * Parameter: c - character to write
107  *
108  * Write character c to the system console.  If newline is being written,
109  * output a carriage return first.  
110  *
111  * This procedure is used by the version of printf() that is linked with
112  * the kernel itself.  The one in the library sends a message to FS, which is
113  * not what is needed for printing within the kernel.
114  */
115 void putk(char c)
116 {
117     if (c) {
118         if (c == '\n') out_char(&tty_table[CONSOLE], (int) '\r');
119         out_char(&tty_table[CONSOLE], (int) c);
120     }
121 }
122 
123 
124 /*
125  * Function: out_char
126  * Parameters: tp - tty struct for terminal to write to
127  *             c - character to write to tp
128  *
129  * Output a single character to a terminal.  See above for discussion of
130  * calculation of the fd to specify.
131  */
132 
133 static void out_char(tty_t *tp, char c)
134 {
135     SunOS(SYS_write, TERMINAL_FD + 1 + tty_line(tp) * 2, &c, 1);
136 }
137 
138 
139 /*
140  * Function: hangup
141  * Parameter: connum - terminal number
142  *
143  * When a remote smx user exits from their terminal program, a special code is
144  * sent and we must close the two file descriptors and kill all of the
145  * session's processes.
146  */
147  
148 void hangup(int connum)
149 {
150     struct tty *tp = &tty_table[connum];
151 
152     scr_init(tp);
153     sigchar(tp, SIGHUP);
154 }
155 
156 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.