home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / uxkern / cons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  3.8 KB  |  207 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    cons.c,v $
  29.  * Revision 2.1  92/04/21  17:10:52  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*
  36.  * Console output.  Handles aliasing other ttys to console.
  37.  */
  38.  
  39. #include <second_server.h>
  40.  
  41. #include <sys/param.h>
  42. #include <sys/types.h>
  43. #include <sys/ioctl.h>
  44. #include <sys/tty.h>
  45. #include <sys/conf.h>
  46. #include <sys/systm.h>
  47. #include <sys/errno.h>
  48. #include <sys/file.h>
  49. #include <sys/synch.h>
  50.  
  51. #include <uxkern/device_utils.h>
  52.  
  53. struct tty    cons_tty;
  54. struct tty    *cons_tp = &cons_tty;
  55.  
  56. dev_t            cons_dev_number = NODEV;
  57. mach_port_t        console_port;
  58. extern mach_port_t    device_server_port;
  59.  
  60. extern struct tty *tty_find_tty();
  61.  
  62. #if    SECOND_SERVER
  63. extern    int    second_server;
  64. #endif    /* SECOND_SERVER */
  65.  
  66. cons_initialization()
  67. {
  68.     bzero(cons_tp, sizeof (struct tty));
  69. }
  70.  
  71. cons_open(dev, flag)
  72.     dev_t    dev;
  73.     int    flag;
  74. {
  75.     register int error;
  76.     register int major_num;
  77.  
  78. #if    SECOND_SERVER
  79.     if (second_server) {
  80.         return second_cons_open(dev, flag);
  81.     }
  82. #endif    /* SECOND_SERVER */
  83.  
  84.     if (cons_dev_number == NODEV) {
  85.         /*
  86.          * Look for console.
  87.          */
  88.         for (major_num = 0; major_num < nchrdev; major_num++) {
  89.         if (!strcmp(cdevsw[major_num].d_name, "console")) {
  90.             cons_dev_number = makedev(major_num, 0);
  91.             break;
  92.         }
  93.         }
  94.         if (cons_dev_number == NODEV) {
  95.         panic("no console configured");
  96.         }
  97.     }
  98.  
  99.     error = tty_open(cons_dev_number, flag);
  100.  
  101.     cons_tp = tty_find_tty(cons_dev_number);
  102.  
  103. #if    0
  104.     /* TTYLOC */
  105.     if (cons_tp->t_ttyloc.tlc_hostid == 0) {
  106.         cons_tp->t_ttyloc.tlc_hostid = TLC_MYHOST;
  107.         cons_tp->t_ttyloc.tlc_ttyid  = TLC_CONSOLE;
  108.     }
  109. #endif    0
  110.  
  111.     return (error);
  112. }
  113.  
  114. /* to satisfy console redirection */
  115. cons_write(dev, uio, flag)
  116.     dev_t    dev;
  117.     struct uio *uio;
  118. {
  119.     return (tty_write(dev, uio, flag));
  120. }
  121.  
  122. /* to satisfy console redirection */
  123. cons_ioctl(dev, cmd, data, flag)
  124.     dev_t    dev;
  125.     int    cmd;
  126.     caddr_t    data;
  127.     int    flag;
  128. {
  129.     return (tty_ioctl(dev, cmd, data, flag));
  130. }
  131.  
  132. mach_port_t
  133. cons_port(dev)
  134.     dev_t    dev;
  135. {
  136.     return cons_tp->t_device_port;
  137. }
  138.  
  139. #define    CONS_BUF_SIZE    1024
  140. char    cons_buf[CONS_BUF_SIZE];
  141. int    cons_buf_pos = 0;
  142.  
  143. cnputc(c)
  144.     int    c;
  145. {
  146.     int s;
  147.  
  148. #if    SECOND_SERVER
  149.     if (second_server) {
  150.         second_cnputc(c);
  151.         return;
  152.     }
  153. #endif    /* SECOND_SERVER */
  154.  
  155.     s = spltty();
  156.     cons_buf[cons_buf_pos++] = c;
  157.     if (cons_buf_pos >= CONS_BUF_SIZE)
  158.         cnflush();
  159.  
  160.     if (c == '\n')
  161.         cnputc('\r');
  162.     (void) splx(s);
  163. }
  164.  
  165. cnflush()
  166. {
  167.     unsigned int cw;
  168.     int s;
  169.  
  170. #if    SECOND_SERVER
  171.     if (second_server) {
  172.         return;
  173.     }
  174. #endif    /* SECOND_SERVER */
  175.  
  176.     s = spltty();
  177.     (void) device_write_inband(cons_tp->t_device_port,
  178.             0, 0,
  179.             &cons_buf[0], cons_buf_pos,
  180.             &cw);
  181.     cons_buf_pos = 0;
  182.     (void) splx(s);
  183. }
  184.  
  185. console_init()
  186. {
  187.     kern_return_t    rc;
  188.  
  189. #if    SECOND_SERVER
  190.     if (second_server) {
  191.         return;
  192.     }
  193. #endif    /* SECOND_SERVER */
  194.  
  195.     /*
  196.      * Open the console
  197.      */
  198.     rc = device_open(device_server_port,
  199.              D_READ|D_WRITE,
  200.              "console",
  201.              &console_port);
  202.     if (rc != KERN_SUCCESS)
  203.         panic("console_init");
  204.  
  205. }
  206.  
  207.