home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / x386 / x386Init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-20  |  9.1 KB  |  327 lines

  1. /*
  2.  * $XConsortium: x386Init.c,v 1.2 91/08/20 15:39:58 gildea Exp $
  3.  *
  4.  * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of Thomas Roell not be used in
  11.  * advertising or publicity pertaining to distribution of the software without
  12.  * specific, written prior permission.  Thomas Roell makes no representations
  13.  * about the suitability of this software for any purpose.  It is provided
  14.  * "as is" without express or implied warranty.
  15.  *
  16.  * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  18.  * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  22.  * PERFORMANCE OF THIS SOFTWARE.
  23.  */
  24.  
  25. #include "X.h"
  26. #include "Xmd.h"
  27. #include "input.h"
  28. #include "servermd.h"
  29. #include "scrnintstr.h"
  30. #include "site.h"
  31.  
  32. #include "compiler.h"
  33.  
  34. #include "x386Procs.h"
  35. #include "x386OSD.h"
  36.  
  37. #ifdef XTESTEXT1
  38. #include "atKeynames.h"
  39. extern int xtest_command_key;
  40. #endif /* XTESTEXT1 */
  41.  
  42. extern ScrnInfoRec vga256InfoRec;
  43. extern ScrnInfoRec vga16InfoRec;
  44. extern ScrnInfoRec wgaInfoRec;
  45. extern ScrnInfoRec xgaInfoRec;
  46.  
  47. ScrnInfoPtr x386Screens[] = {
  48.   
  49.   &vga256InfoRec,
  50. #ifdef notyet
  51.   &vga16InfoRec, 
  52.   &wgaInfoRec,
  53.   &xgaInfoRec,
  54. #endif
  55. };
  56.  
  57. int         x386MaxScreens = sizeof(x386Screens) / sizeof(ScrnInfoPtr);
  58. x386InfoRec x386Info;
  59. int         x386ScreenIndex;
  60.  
  61.  
  62. /*
  63.  * InitOutput --
  64.  *    Initialize screenInfo for all actually accessible framebuffers.
  65.  *      That includes vt-manager setup, querying all possible devices and
  66.  *      collecting the pixmap formats.
  67.  */
  68.  
  69. void
  70. InitOutput(pScreenInfo, argc, argv)
  71.      ScreenInfo    *pScreenInfo;
  72.      int         argc;
  73.      char        **argv;
  74. {
  75.   int                    i, j, index, fd;
  76.   struct vt_mode         VT;
  77.   char                   vtname1[10],vtname2[10];
  78.   static int             numFormats = 0;
  79.   static PixmapFormatRec formats[MAXFORMATS];
  80.   static unsigned long   generation = 0;
  81.    
  82.  
  83.   if (serverGeneration == 1) {
  84.  
  85.     ErrorF("X386 Version 1.2 / X Windows System\n");
  86.     ErrorF("(protocol Version %d, revision %d, vendor release %d)\n\n",
  87.        X_PROTOCOL, X_PROTOCOL_REVISION, VENDOR_RELEASE );
  88.  
  89.     /*
  90.      * setup the virtual terminal manager
  91.      */
  92.     if ((fd = open("/dev/console",O_WRONLY,0)) <0) 
  93.       FatalError("Cannot open /dev/console\n");
  94.  
  95.     if (ioctl(fd, VT_OPENQRY, &x386Info.vtno) < 0 || x386Info.vtno == -1) 
  96.       FatalError("Cannot find a free VT\n");
  97.  
  98.     close(fd);
  99.  
  100.     sprintf(vtname1,"/dev/vc%02d",x386Info.vtno); /* ESIX */
  101.     sprintf(vtname2,"/dev/vt%02d",x386Info.vtno); /* rest of the world */
  102.  
  103.     if ( (x386Info.consoleFd = open(vtname1, O_RDWR | O_NDELAY, 0)) < 0 &&
  104.      (x386Info.consoleFd = open(vtname2, O_RDWR | O_NDELAY, 0)) < 0 )
  105.       FatalError("Cannot open %s (%s)\n",vtname2, vtname1);
  106.     
  107.     if (ioctl(x386Info.consoleFd, VT_GETMODE, &VT) < 0) 
  108.       FatalError ("VT_GETMODE failed\n");
  109.     
  110.     signal(SIGUSR1, x386VTRequest);
  111.     
  112.     VT.mode = VT_PROCESS;
  113.     VT.relsig = SIGUSR1;
  114.     VT.acqsig = SIGUSR1;
  115.     if (ioctl(x386Info.consoleFd, VT_SETMODE, &VT) < 0) 
  116.       FatalError ("VT_SETMODE VT_PROCESS failed\n");
  117.     
  118.     if (ioctl(x386Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
  119.       FatalError ("KDSETMODE KD_GRAPHICS failed\n");
  120.  
  121.  
  122.     x386Config();
  123.  
  124.     /*
  125.      * collect all possible formats
  126.      */
  127.     formats[0].depth = 1;
  128.     formats[0].bitsPerPixel = 1;
  129.     formats[0].scanlinePad = BITMAP_SCANLINE_PAD;
  130.   
  131.     for ( i=0; i < x386MaxScreens && x386Screens[i]->configured; i++ )
  132.       { 
  133.     /*
  134.      * add new pixmap format
  135.      */
  136.     for ( j=0; j <= numFormats; j++ ) {
  137.       
  138.       if (formats[j].depth == x386Screens[i]->depth &&
  139.           formats[j].bitsPerPixel == x386Screens[i]->bitsPerPixel)
  140.         break; /* found */
  141.       
  142.       if ( j == numFormats ) {
  143.         formats[j].depth = x386Screens[i]->depth;
  144.         formats[j].bitsPerPixel = x386Screens[i]->bitsPerPixel;
  145.         formats[j].scanlinePad = BITMAP_SCANLINE_PAD;
  146.         numFormats++;
  147.         if ( numFormats > MAXFORMATS )
  148.           FatalError( "WSGO!! Too many formats! Exiting\n" );
  149.         
  150.         break; /* added */
  151.       }
  152.     }
  153.       }
  154.   }
  155.  
  156.   /*
  157.    * now force to get the VT
  158.    */
  159.   if (ioctl(x386Info.consoleFd, VT_ACTIVATE, x386Info.vtno) != 0)
  160.     ErrorF("VT_ACTIVATE failed\n");
  161.   if (ioctl(x386Info.consoleFd, VT_WAITACTIVE, x386Info.vtno) != 0)
  162.     ErrorF("VT_WAITACTIVE failed\n");
  163.  
  164.  
  165.   /*
  166.    * Use the previous collected parts to setup pScreenInfo
  167.    */
  168.   pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  169.   pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  170.   pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  171.   pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  172.   pScreenInfo->numPixmapFormats = numFormats;
  173.   for ( i=0; i < numFormats; i++ ) pScreenInfo->formats[i] = formats[i];
  174.  
  175.   if (generation != serverGeneration)
  176.     {
  177.       x386ScreenIndex = AllocateScreenPrivateIndex();
  178.       generation = serverGeneration;
  179.     }
  180.  
  181.  
  182.   for ( i=0; i < x386MaxScreens && x386Screens[i]->configured; i++ )
  183.     {    
  184.       /*
  185.        * On a server-reset, we have explicitely to remap all stuff ...
  186.        * (At startuptime this is implicitely done by probing the device
  187.        */
  188.       if (serverGeneration != 1) (x386Screens[i]->EnterLeaveVT)(ENTER);
  189.       index = AddScreen(x386Screens[i]->Init, argc, argv);
  190.       if (index > -1)
  191.     screenInfo.screens[index]->devPrivates[x386ScreenIndex].ptr
  192.       = (pointer)x386Screens[i];
  193.  
  194.       /*
  195.        * Here we have to let the driver getting access of the VT. Note that
  196.        * this doesn't mean that the graphics board may access automatically
  197.        * the monitor. If the monitor is shared this is done in x386CrossScreen!
  198.        */
  199.       if (!x386Info.sharedMonitor) (x386Screens[i]->EnterLeaveMonitor)(ENTER);
  200.     }
  201.  
  202.   RegisterBlockAndWakeupHandlers(x386Block, x386Wakeup, (void *)0);
  203. }
  204.  
  205.  
  206.  
  207. /*
  208.  * InitInput --
  209.  *      Initialize all supported input devices...what else is there
  210.  *      besides pointer and keyboard? Two DeviceRec's are allocated and
  211.  *      registered as the system pointer and keyboard devices.
  212.  */
  213.  
  214. void
  215. InitInput(argc, argv)
  216.      int           argc;
  217.      char          **argv;
  218. {
  219.   x386Info.vtRequestsPending = FALSE;
  220.   x386Info.inputPending = FALSE;
  221. #ifdef XTESTEXT1
  222.   xtest_command_key = KEY_SysReqest + MIN_KEYCODE;
  223. #endif /* XTESTEXT1 */
  224.  
  225.   x386Info.pKeyboard = AddInputDevice(x386Info.kbdProc, TRUE); 
  226.   x386Info.pPointer =  AddInputDevice(x386Info.mseProc, TRUE);
  227.   RegisterKeyboardDevice(x386Info.pKeyboard); 
  228.   RegisterPointerDevice(x386Info.pPointer); 
  229.  
  230.   miRegisterPointerDevice(screenInfo.screens[0], x386Info.pPointer);
  231.   mieqInit (x386Info.pKeyboard, x386Info.pPointer);
  232. }
  233.  
  234.  
  235.  
  236. /*
  237.  * ddxGiveUp --
  238.  *      Device dependent cleanup. Called by by dix before normal server death.
  239.  *      For SYSV386 we must switch the terminal back to normal mode. No error-
  240.  *      checking here, since there should be restored as much as possible.
  241.  */
  242.  
  243. void
  244. ddxGiveUp()
  245. {
  246.   struct vt_mode   VT;
  247.  
  248.   ioctl(x386Info.consoleFd, VT_ACTIVATE, x386Info.vtno);
  249.   ioctl(x386Info.consoleFd, VT_WAITACTIVE, 0);
  250.   ioctl(x386Info.consoleFd, KDSETMODE, KD_TEXT);  /* Back to text mode  ... */
  251.   if (ioctl(x386Info.consoleFd, VT_GETMODE, &VT) != -1)
  252.     {
  253.       VT.mode = VT_AUTO;
  254.       ioctl(x386Info.consoleFd, VT_SETMODE, &VT); /* set default vt handling */
  255.     }
  256.  
  257.   close(x386Info.consoleFd);                    /* make the vt-manager happy */
  258. }
  259.  
  260.  
  261.  
  262. /*
  263.  * AbortDDX --
  264.  *      DDX - specific abort routine.  Called by AbortServer(). The attempt is
  265.  *      made to restore all original setting of the displays. Also all devices
  266.  *      are closed.
  267.  */
  268.  
  269. void
  270. AbortDDX()
  271. {
  272.   int i;
  273.  
  274.   /*
  275.    * try to deinitialize all input devices
  276.    */
  277.   if (x386Info.pPointer) (x386Info.mseProc)(x386Info.pPointer, DEVICE_CLOSE);
  278.   if (x386Info.pKeyboard) (x386Info.kbdProc)(x386Info.pKeyboard, DEVICE_CLOSE);
  279.  
  280.   /*
  281.    * try to restore the original video state
  282.    */
  283.   for ( i=0; i < screenInfo.numScreens; i++ )
  284.     (X386SCRNINFO(screenInfo.screens[i])->EnterLeaveVT)( LEAVE );
  285.  
  286.   /*
  287.    * This is needed for a abnormal server exit, since the normal exit stuff
  288.    * MUST also be performed (i.e. the vt must be left in a defined state)
  289.    */
  290.   ddxGiveUp();
  291. }
  292.  
  293.  
  294.  
  295. /*
  296.  * ddxProcessArgument --
  297.  *    Process device-dependent command line args. Returns 0 if argument is
  298.  *      not device dependent, otherwise Count of number of elements of argv
  299.  *      that are part of a device dependent commandline option.
  300.  */
  301.  
  302. /* ARGSUSED */
  303. int
  304. ddxProcessArgument (argc, argv, i)
  305.      int argc;
  306.      char *argv[];
  307.      int i;
  308. {
  309.   return 0;
  310. }
  311.  
  312.  
  313. /*
  314.  * ddxUseMsg --
  315.  *    Print out correct use of device dependent commandline options.
  316.  *      Maybe the user now knows what really to do ...
  317.  */
  318.  
  319. void
  320. ddxUseMsg()
  321. {
  322.   ErrorF("\n");
  323.   ErrorF("\n");
  324.   ErrorF("Device Dependent Usage\n");
  325.   ErrorF("\n");
  326. }
  327.