home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mips / mipsInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  13.7 KB  |  651 lines

  1. /*
  2.  * $XConsortium: mipsInit.c,v 1.5 91/07/18 22:58:20 keith Exp $
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  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 MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #ident    "$Header: mipsInit.c,v 1.5 91/07/18 22:58:20 keith Exp $"
  24.  
  25. #include <sys/types.h>
  26. #include <sysv/sys/cpu_board.h>
  27. #include <sysv/sys/lock.h>
  28. #ifndef NOSIGNALS
  29. #include <sysv/sys/signal.h>
  30. #endif NOSIGNALS
  31. #undef FID
  32.  
  33. #include "X.h"
  34. #include "Xproto.h"
  35. #include "keysym.h"
  36. #include "input.h"
  37. #include "cursor.h"
  38. #include "colormapst.h"
  39. #include "scrnintstr.h"
  40. #include "servermd.h"
  41. #include "mipointer.h"
  42.  
  43. #include "mips.h"
  44. #include "mipsFb.h"
  45. #include "mipsIo.h"
  46. #include "mipsKbd.h"
  47. #include "mipsMouse.h"
  48.  
  49. int mipsSysType;
  50.  
  51. extern int    mipsMouseProc(), mipsKeybdProc();
  52.  
  53. extern int      defaultColorVisualClass;
  54. extern int monitorResolution;
  55. int        DDXnoreset = 0;
  56. int        DDXxled1 = 0;
  57. int        DDXxled2 = 0;
  58. int        DDXxled3 = 0;
  59. static int mipsScreenTypeWanted;
  60. int mipsMonitorSize;
  61. static int mipsNoFBHW;
  62. static int mipsNoFBCache;
  63. static char *blackPixelName = "black";
  64. static char *whitePixelName = "white";
  65.  
  66. #if NETWORK_KEYBD
  67. extern char    *netKeybdAddr;
  68. #endif /* NETWORK_KEYBD */
  69. #if EMULATE_COLOR || EMULATE_MONO
  70. int        DDXemulate = 0;
  71. #endif /* EMULATE_COLOR || EMULATE_MONO */
  72. #if PIXIE
  73. int        pixie = 0;
  74. #endif /* PIXIE */
  75.  
  76. /* Globals for io */
  77.  
  78. DevicePtr    pPointer;
  79. DevicePtr    pKeyboard;
  80. volatile extern int    mipsIOReady;
  81.  
  82. MipsScreenRec mipsScreen[MAXSCREENS];
  83.  
  84. extern Bool mipsMap2030();
  85. extern Bool mipsMap3230c();
  86. extern Bool mipsMap3230m();
  87.  
  88. static Bool (*mipsMapProc[][3])() = {
  89.     0,
  90.     mipsMap2030,
  91.     0,        /* 2030 mono */
  92.     0,
  93.     mipsMap3230c,
  94.     mipsMap3230m,
  95. };
  96.  
  97. /*
  98.  * We don't have real frame buffer devices, so as a hack
  99.  * we always use unit 0 for the color screen and unit 1 for
  100.  * the mono screen
  101.  */
  102. #define COLOR_UNIT    0
  103. #define MONO_UNIT    1
  104.  
  105. /* supported pixmap formats */
  106. static PixmapFormatRec formats[] = {
  107.     {8, 8, BITMAP_SCANLINE_PAD},
  108.     {1, 1, BITMAP_SCANLINE_PAD},
  109. };
  110. #define NUMFORMATS    sizeof(formats)/sizeof(formats[0])
  111.  
  112. extern void mipsInstallColormap();
  113. extern void mipsUninstallColormap();
  114. extern int mipsListInstalledColormaps();
  115. extern void mipsStoreColors();
  116. Bool mipsScreenInit();
  117. static Bool mipsSaveScreen();
  118. static Bool mipsCloseScreen();
  119.  
  120. /* Open output to the screen framebuffer */
  121. InitOutput(screenInfo, argc, argv)
  122.     ScreenInfo *screenInfo;
  123.     int argc;
  124.     char **argv;
  125. {
  126.     int i;
  127.  
  128.     systemType();
  129.  
  130.     screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  131.     screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  132.     screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  133.     screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  134.  
  135.     screenInfo->numPixmapFormats = 1;
  136.     screenInfo->formats[0] = formats[0];
  137.  
  138.     if (mipsScreenTypeWanted)
  139.         MipsScreenNumToPriv(0)->type = mipsScreenTypeWanted;
  140.     else {
  141.         MipsScreenNumToPriv(COLOR_UNIT)->type = MIPS_SCRTYPE_COLOR;
  142.         MipsScreenNumToPriv(MONO_UNIT)->type = MIPS_SCRTYPE_MONO;
  143.     }
  144.  
  145.     for (i = 0; i < MAXSCREENS; i++) {
  146.         MipsScreenPtr pm = MipsScreenNumToPriv(i);
  147.         Bool(*fun)();
  148.  
  149.         if (pm->type == MIPS_SCRTYPE_DISABLED)
  150.             continue;
  151.  
  152.         pm->unit = i;
  153.  
  154.         if (!(fun = mipsMapProc[mipsSysType][pm->type]) ||
  155.             !(*fun)(pm))
  156.             continue;
  157.  
  158.         if (monitorResolution)
  159.             pm->dpi = monitorResolution;
  160.  
  161.         if (mipsNoFBCache)
  162.             pm->fbnorm = pm->fbnocache;
  163.  
  164.         if (mipsNoFBHW)
  165.             pm->cap = 0;
  166.  
  167.         if (pm->bitsPerPixel > 1) {
  168.             screenInfo->numPixmapFormats = 2;
  169.             screenInfo->formats[1] = formats[1];
  170.         }
  171.  
  172.         (void) AddScreen(mipsScreenInit, argc, argv);
  173.     }
  174. }
  175.  
  176. /*ARGSUSED*/
  177. Bool
  178. mipsScreenInit(index, pScreen, argc, argv)
  179.     int index;
  180.     ScreenPtr pScreen;
  181.     int argc;
  182.     char *argv[];
  183. {
  184.     MipsScreenPtr pm = MipsScreenNumToPriv(index);
  185.     int fbtype = pm->type;
  186.     Bool (*fun)();
  187.     extern Bool cfbScreenInit();
  188.     extern Bool mfbScreenInit();
  189.     extern Bool mipsCreateDefColormap();
  190.     
  191.     fun = fbtype == MIPS_SCRTYPE_COLOR ?
  192.         cfbScreenInit : mfbScreenInit;
  193.     if (!(*fun)(pScreen, (pointer) pm->fbnorm,
  194.         pm->scr_width, pm->scr_height,
  195.         pm->dpi, pm->dpi,
  196.         pm->fb_width))
  197.         return FALSE;
  198.  
  199.     if (fbtype == MIPS_SCRTYPE_COLOR) {
  200. #ifndef STATIC_COLOR
  201.         pScreen->InstallColormap = mipsInstallColormap;
  202.         pScreen->UninstallColormap = mipsUninstallColormap;
  203.         pScreen->ListInstalledColormaps = mipsListInstalledColormaps;
  204.         pScreen->StoreColors = mipsStoreColors;
  205. #endif /* STATIC_COLOR */
  206.         if (pm->depth == 4)
  207.             mipsFixScreen4(pScreen);
  208.     }
  209.     else {
  210.         pScreen->whitePixel =   1;
  211.         pScreen->blackPixel =   0;
  212.     }
  213.  
  214.     pm->CloseScreen = pScreen->CloseScreen;
  215.     pScreen->CloseScreen = mipsCloseScreen;
  216.     pScreen->SaveScreen = mipsSaveScreen;
  217.     (void) mipsSaveScreen(pScreen, SCREEN_SAVER_FORCER);
  218.  
  219. #ifdef X11R4
  220.     {
  221.         extern miPointerCursorFuncRec mipsPointerCursorFuncs;
  222.  
  223.         if (!miDCInitialize(pScreen, &mipsPointerCursorFuncs))
  224.             return FALSE;
  225.     }
  226. #else /* X11R4 */
  227.     if (!mipsCursorInit(pm, pScreen))
  228.         return FALSE;
  229. #endif /* X11R4 */
  230.  
  231.     return mipsCreateDefColormap(index, pScreen,
  232.         whitePixelName, blackPixelName);
  233. }
  234.  
  235. static
  236. systemType()
  237. {
  238.     switch (cpubd()) {
  239.     case BRDTYPE_R3030:
  240.         mipsSysType = RS3230;
  241.         break;
  242.  
  243.     case BRDTYPE_I2000:
  244.     case BRDTYPE_I2000S:
  245.     default:
  246.         mipsSysType = RS2030;
  247.         break;
  248.     }
  249. }
  250.  
  251. static Bool
  252. mipsSaveScreen(pScreen, on)
  253.     ScreenPtr pScreen;
  254.     Bool on;
  255. {
  256.     MipsScreenPtr pm = MipsScreenToPriv(pScreen);
  257.  
  258.     if (on != SCREEN_SAVER_ON)
  259.         lastEventTime = GetTimeInMillis();
  260.  
  261.     if (pm->Blank)
  262.         (*pm->Blank)(pm, on);
  263.  
  264.     return TRUE;
  265. }
  266.  
  267. static Bool
  268. mipsCloseScreen(i, pScreen)
  269.     int        i;
  270.     ScreenPtr    pScreen;
  271. {
  272.     MipsScreenPtr   pm = MipsScreenToPriv(pScreen);
  273.     Bool        ret;
  274.  
  275. #ifdef SYSV
  276.     (void) sigseg (SIGPOLL, SIG_IGN);
  277. #else
  278.     (void) signal (SIGPOLL, SIG_IGN);
  279. #endif
  280.     pScreen->CloseScreen = pm->CloseScreen;
  281.     ret = (*pScreen->CloseScreen) (i, pScreen);
  282.     (void) (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF);
  283.     return ret;
  284. }
  285.  
  286. /* Open input from the mouse and keyboard */
  287.  
  288. /* ARGSUSED */
  289. void
  290. InitInput(argc, argv)
  291. int argc;
  292. char *argv[];
  293. {
  294.     extern int    sigIOfunc();
  295.     static int    zero = 0;
  296.  
  297.     initKeybd();
  298.  
  299.     pPointer = AddInputDevice(mipsMouseProc, TRUE);
  300.     pKeyboard = AddInputDevice(mipsKeybdProc, TRUE);
  301.  
  302.     RegisterPointerDevice(pPointer);
  303.     RegisterKeyboardDevice(pKeyboard);
  304.     miRegisterPointerDevice(screenInfo.screens[0], pPointer);
  305.  
  306. #ifdef X11R4
  307.     SetInputCheck(&zero, &mipsIOReady);
  308. #else /* X11R4 */
  309.     if (!mieqInit(pKeyboard, pPointer))
  310.     return;
  311. #endif /* X11R4 */
  312.  
  313. #ifdef SYSV
  314.     (void) sigset(SIGPOLL, sigIOfunc);
  315. #else /* SYSV */
  316.     (void) signal(SIGPOLL, sigIOfunc);
  317. #endif /* SYSV */
  318. }
  319.  
  320. /* DDX - specific abort routine.  Called by AbortServer(). */
  321.  
  322. void
  323. AbortDDX()
  324. {
  325.     MipsScreenPtr pm;
  326.  
  327.     for (pm = MipsScreenNumToPriv(0);
  328.         pm < MipsScreenNumToPriv(MAXSCREENS); pm++)
  329.         if (pm->Close)
  330.             (*pm->Close)(pm);
  331. }
  332.  
  333. /* Called by GiveUp(). */
  334.  
  335. void
  336. ddxGiveUp()
  337. {
  338.     AbortDDX();
  339. }
  340.  
  341. #define    BAD_ARG    (-66)    /* convenient invalid argument */
  342.  
  343. /* Process command line arguments specific to mips Xserver */
  344. int
  345. ddxProcessArgument(argc, argv, i)
  346.     int argc;
  347.     char *argv[];
  348.     int i;
  349. {
  350.     int v;
  351.     static void BadUse();
  352.  
  353.     argv += i;
  354.     argc -= i;
  355.  
  356.     if (matcharg(argv[0], "-bp") == 0) {
  357.         if (argc < 2)
  358.             BadUse();
  359.         blackPixelName = argv[1];
  360.         return 2;
  361.     }
  362.     if (matcharg(argv[0], "-wp") == 0) {
  363.         if (argc < 2)
  364.             BadUse();
  365.         whitePixelName = argv[1];
  366.         return 2;
  367.     }
  368. #ifdef X11R4
  369.     if (matcharg(argv[0], "-mb") == 0) {
  370.         extern int motionBufferSize;
  371.  
  372.         if (argc < 2)
  373.             BadUse();
  374.         v = atoi(argv[1]);
  375.         if (v < 0)
  376.             v = 0;
  377.         if (v > 1024)
  378.             v = 1024;
  379.         motionBufferSize = v;
  380.         return 2;
  381.     }
  382. #endif /* X11R4 */
  383.     if (matcharg(argv[0], "-pl*ock") == 0) {
  384.         (void) plock(PROCLOCK);
  385.         return 1;
  386.     }
  387.     if (matcharg(argv[0], "-tl*ock") == 0) {
  388.         (void) plock(TXTLOCK);
  389.         return 1;
  390.     }
  391.     if (matcharg(argv[0], "-dl*ock") == 0) {
  392.         (void) plock(DATLOCK);
  393.         return 1;
  394.     }
  395.     if (matcharg(argv[0], "-ni*ce") == 0) {
  396.         if (argc < 2)
  397.             BadUse();
  398.         (void) nice(atoi(argv[1]));
  399.         return 2;
  400.     }
  401.     if (matcharg(argv[0], "-nor*eset") == 0) {
  402.         DDXnoreset = 1;
  403.         return 1;
  404.     }
  405.     if (matcharg(argv[0], "-xled1") == 0) {
  406.         DDXxled1 = 1;
  407.         return 1;
  408.     }
  409.     if (matcharg(argv[0], "-xled2") == 0) {
  410.         DDXxled2 = 1;
  411.         return 1;
  412.     }
  413.     if (matcharg(argv[0], "-xled3") == 0) {
  414.         DDXxled3 = 1;
  415.         return 1;
  416.     }
  417.     if (matcharg(argv[0], "-vi*sual") == 0) {
  418.         if (argc < 2)
  419.             BadUse();
  420.  
  421.         if ((v = matchargs(argv[1], BAD_ARG,
  422.             "d*efault", -1,
  423.             "staticg*ray", StaticGray,
  424.             "g*rayscale", GrayScale,
  425.             "staticc*olor", StaticColor,
  426.             "p*seudocolor", PseudoColor,
  427.             (char *) 0)) == BAD_ARG)
  428.             BadUse();
  429.  
  430.         defaultColorVisualClass = v;
  431.         return 2;
  432.     }
  433.     if (matcharg(argv[0], "-en*able") == 0) {
  434.         if (argc < 2)
  435.             BadUse();
  436.         if ((v = matchargs(argv[1], BAD_ARG,
  437.             "c*olor", MIPS_SCRTYPE_COLOR,
  438.             "m*onochrome", MIPS_SCRTYPE_MONO,
  439.             (char *) 0)) == BAD_ARG)
  440.             BadUse();
  441.         mipsScreenTypeWanted = v;
  442.         return 2;
  443.     }
  444.     if (matcharg(argv[0], "-mo*nochrome") == 0) {
  445.         mipsScreenTypeWanted = MIPS_SCRTYPE_MONO;
  446.         return 1;
  447.     }
  448.     if (matcharg(argv[0], "-1*9inch") == 0) {
  449.         mipsMonitorSize = 1;
  450.         return 1;
  451.     }
  452.     if (matcharg(argv[0], "-noca*che") == 0) {
  453.         mipsNoFBCache = 1;
  454.         return 1;
  455.     }
  456.     if (matcharg(argv[0], "-nohw") == 0) {
  457.         mipsNoFBHW = 1;
  458.         return 1;
  459.     }
  460.     if (matcharg(argv[0], "-k*eyboard") == 0) {
  461.         if (argc < 2)
  462.             BadUse();
  463.         if ((v = matchargs(argv[1], BAD_ARG,
  464.             "de*fault", DEFAULT_KEYBOARD,
  465. #ifdef AT_KEYBOARD
  466.             "at", AT_KEYBOARD,
  467. #endif                /* AT_KEYBOARD */
  468. #ifdef XT_KEYBOARD
  469.             "xt", XT_KEYBOARD,
  470. #endif                /* XT_KEYBOARD */
  471. #ifdef UNIX1_KEYBOARD
  472.             "unix", UNIX1_KEYBOARD,
  473. #endif                /* UNIX1_KEYBOARD */
  474.             (char *) 0)) == BAD_ARG)
  475.             BadUse();
  476.         keybdPriv.type = v;
  477.  
  478.         if (argc < 3 || argv[2][0] == '-')
  479.             return 2;
  480.             
  481.         keybdPriv.unit = atoi(argv[2]);
  482.         return 3;
  483.     }
  484.     if (matcharg(argv[0], "-po*inter") == 0) {
  485.         if (argc < 2)
  486.             BadUse();
  487.         if ((v = matchargs(argv[1], BAD_ARG,
  488.             "de*fault", MIPS_MOUSE_DEFAULT,
  489.             "m*", MIPS_MOUSE_MOUSEMAN,
  490.             (char *) 0)) == BAD_ARG)
  491.             BadUse();
  492.         mousePriv.type = v;
  493.  
  494.         if (argc < 3 || argv[2][0] == '-')
  495.             return 2;
  496.             
  497.         mousePriv.unit = atoi(argv[2]);
  498.  
  499.         if (argc < 4 || argv[3][0] == '-')
  500.             return 3;
  501.  
  502.         mousePriv.baud = atoi(argv[3]);
  503.  
  504.         if (argc < 5 || argv[4][0] == '-')
  505.             return 4;
  506.  
  507.         mousePriv.rate = atoi(argv[5]);
  508.  
  509.         return 5;
  510.     }
  511. #if NETWORK_KEYBD
  512.     if (matcharg(argv[0], "-ne*tkeybd") == 0) {
  513.         if (argc < 2)
  514.             BadUse();
  515.         netKeybdAddr = argv[1];
  516.         return 2;
  517.     }
  518. #endif                /* NETWORK_KEYBD */
  519. #if EMULATE_COLOR || EMULATE_MONO
  520.     if (matcharg(argv[0], "-em*ulate") == 0) {
  521.         DDXemulate = 1;
  522.         return 1;
  523.     }
  524. #endif                /* EMULATE_COLOR || EMULATE_MONO */
  525. #if PIXIE
  526.     if (matcharg(argv[0], "-pi*xie") == 0) {
  527.         pixie = 1;
  528.         return 1;
  529.     }
  530. #endif                /* PIXIE */
  531.     return 0;
  532. }
  533.  
  534. /* print use message and quit */
  535. static void
  536. BadUse()
  537. {
  538.     extern void UseMsg();
  539.  
  540.     UseMsg();
  541.     exit(1);
  542. }
  543.  
  544. /* Print use message for command line arguments specific to mips Xserver */
  545.  
  546. static char *usetext[] = {
  547. "-bp color        set default black-pixel color\n\
  548. -wp color        set default white-pixel color\n\
  549. -plock            process lock the server\n\
  550. -tlock            text lock the server\n\
  551. -dlock            data lock the server\n\
  552. -nice incr        change the scheduling priority of the server\n\
  553. -noreset        do not reset server on last client close\n\
  554. -xled1            use LED for xled1 instead of Scroll Lock\n\
  555. -xled2            use LED for xled2 instead of Caps Lock\n\
  556. -xled3            use LED for xled3 instead of Num Lock\n\
  557. -visual PseudoColor|StaticColor|GrayScale|StaticGray\n\
  558.             use grayscale/color visual on the color screen\n\
  559. -enable color|mono    enable the color and/or mono screens\n\
  560. -19inch            set color screen dpi for 19\" monitor\n\
  561. -keyboard Default|AT|XT|UNIX [unit#]\n\
  562.             select type of keyboard to use\n\
  563. -pointer Default|Mouseman [unit#] [baud] [sample_rate]\n\
  564.             select type of pointer device to use",
  565. #ifdef X11R4
  566. "-mb size        size of motion buffer (0-1024, default 100)\n",
  567. #endif /* X11R4 */
  568. #if NETWORK_KEYBD
  569. "-netkeybd net-addr    connect to keyboard at network address",
  570. #endif /* NETWORK_KEYBD */
  571. #if EMULATE_COLOR || EMULATE_MONO
  572. "-emulate        emulate color or mono screens",
  573. #endif /* EMULATE_COLOR || EMULATE_MONO */
  574. #if PIXIE
  575. "-pixie            enable use of pixie analysis",
  576. #endif /* PIXIE */
  577.     0
  578. };
  579.  
  580. void
  581. ddxUseMsg()
  582. {
  583.     char **p;
  584.  
  585.     for (p = usetext; *p; p++)
  586.         ErrorF("%s\n", *p);
  587. }
  588.  
  589. /*
  590.  * match argument against list of keywords
  591.  * "*" in keyword allows prefix match
  592.  */
  593.  
  594. #include <varargs.h>
  595. #include <ctype.h>
  596.  
  597. /* arg, bad val, key, ret val, key, ret val, 0 */
  598. /*VARARGS*/
  599. static int
  600. matchargs(va_alist)
  601. va_dcl
  602. {
  603.     va_list ap;
  604.     char *arg, *key;
  605.     int ret;
  606.  
  607.     va_start(ap);
  608.     arg = va_arg(ap, char *);
  609.     ret = va_arg(ap, int);
  610.  
  611.     while (key = va_arg(ap, char *)) {
  612.         int val = va_arg(ap, int);
  613.         char *ac = arg;
  614.         int star = 0;
  615.  
  616.         for (;;) {
  617.             char k = *key++, a = *ac++;
  618.  
  619.             if (isascii(a) && isupper(a))
  620.                 a = tolower(a);
  621.  
  622.             /* XXX once we've seen the star we have
  623.             to remember abbrevs are OK */
  624.             if (k == '*') {
  625.                 star = 1;
  626.                 if (a == 0) {
  627.                     ret = val;
  628.                     break;
  629.                 }
  630.                 ac--;
  631.                 continue;
  632.             }
  633.             if (a != k && !star)
  634.                 break;
  635.             if (a == 0) {
  636.                 ret = val;
  637.                 break;
  638.             }
  639.         }
  640.     }
  641.     va_end(ap);
  642.     return ret;
  643. }
  644.  
  645. static int
  646. matcharg(arg, key)
  647.     char *arg, *key;
  648. {
  649.     return matchargs(arg, -1, key, 0, (char *) 0);
  650. }
  651.