home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 July / APC47-2.ISO / mac / macsbug / macsbug.hqx / MacsBug 6.5.4a6 / Building dcmds / C Samples / Drvr.c next >
Encoding:
C/C++ Source or Header  |  1998-09-22  |  7.9 KB  |  362 lines

  1. /*
  2.     File:        Drvr.c
  3.  
  4.     Contains:    This is the Unit Table dcmd.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglass
  9.  
  10.     Copyright:    ⌐ 1988,1993-1998 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.     File Ownership:
  13.  
  14.         DRI:                Jim Murphy
  15.  
  16.         Other Contact:        Dave Lyons
  17.  
  18.         Technology:            MacsBug
  19.  
  20.     Writers:
  21.  
  22.         (JM3)    Jim Murphy
  23.         (fau)    Fernando Urbina
  24.         (DAL)    Dave Lyons
  25.  
  26.     Change History (most recent first):
  27.  
  28.         <10>      8/3/98    JM3        Use lomem accessors so we can nuke the include of SysEqu.h.
  29.          <9>     7/14/98    DAL        Cosmetic.
  30.          <8>     5/27/98    fau        Version 3.0.2:  Changed the storage field to display the
  31.                                     "storage" for 68K drivers and the driver version for native
  32.                                     drivers (in hex).  Updated the help string accordingly.
  33.          <7>     6/17/97    DAL        -b = busy only. Version 3.0.1.
  34.          <6>   25-Jan-96    JM3        Updated the sample build commands to be current.
  35.          <5>    10/27/95    DAL        Draw "-nil-" instead of empty-string for nil DRVR handles
  36.                                     (merged in from Scott Douglass' source).
  37.          <4>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  38.          <3>     3/14/94    DAL        Re-layed-out the columns: removed Window and made room for
  39.                                     everything to be nice on 13" monitors. Made the "that's strange"
  40.                                     message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
  41.                                     Hoon is happy.
  42.          <2>     9/14/93    DAL        made the driver name column wider
  43.  
  44.     Modification history:
  45.          7Dec88 sad        show driver version
  46.         29Nov88 sad        revised for new dcmd names
  47.         13Oct88 sad        written from file.c
  48.  
  49.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  50.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  51.     the Linker.
  52.  
  53.     C Drvr.c
  54.     Link -o Drvr -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Drvr.c.o"    ╢
  55.         "{Libraries}Runtime.o"
  56.     BuildDcmd Drvr 193 -format3
  57.     Echo 'include "Drvr";'    |    Rez -a -o "{SystemFolder}Debugger Prefs"
  58.  
  59. */
  60.  
  61. #include <MacTypes.h>
  62. #include <MacMemory.h>
  63. #include <Devices.h>
  64. #include <DriverFamilyMatching.h>
  65. #include <LowMem.h>
  66.  
  67. #include "dcmd.h"
  68. #include "put.h"
  69.  
  70.  
  71. typedef struct DRVR
  72. {
  73.     short drvrFlags;
  74.     short drvrDelay;
  75.     short drvrEMask;
  76.     short drvrMenu;
  77.     short drvrOpen;
  78.     short drvrPrime;
  79.     short drvrCtl;
  80.     short drvrStatus;
  81.     short drvrClose;
  82.     Str255 drvrName;
  83. } DRVR;
  84.  
  85.  
  86. static void DrawHdr()
  87. {
  88. //                    0         1         2         3         4         5         6         7         8         9
  89. //                    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
  90.     dcmdDrawLine("\pdRef dNum Driver                      Flg  Ver   qHead  Stor/Ver Dely  Drvr at DCE at");
  91. }
  92.  
  93. #define kColumnNameEnd         37
  94. #define kColumnVersionEnd    46
  95. #define kColumnQHeadEnd        54
  96. #define kColumnStorageEnd    64
  97. #define kColumnDriverAtEnd    78
  98. #define kColumnDCEAtEnd        85
  99.  
  100.  
  101. static void DrawDCE(short dref, AuxDCE* dcep)
  102. {
  103.     DRVR*    drvrp;
  104.  
  105.     PutUHexWord(dref);
  106.     PutSpace();
  107.     PutUHexWord(~dref);
  108.     PutSpace();
  109.     if (dcep->dCtlFlags & 0x40)
  110.     {
  111.         if (dcep->dCtlDriver)
  112.         {
  113.             drvrp = * (DRVR **) dcep->dCtlDriver;
  114.             if (drvrp)
  115.                 PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  116.             else
  117.                 PutPStrTruncTo("\p-purged-", kColumnNameEnd);
  118.         }
  119.         else
  120.         {
  121.             PutPStrTruncTo("\p-nil-", kColumnNameEnd);
  122.         };
  123.     }
  124.     else
  125.     {
  126.         if (dcep->dCtlDriver)
  127.         {
  128.             drvrp = (DRVR*)dcep->dCtlDriver;
  129.             PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  130.         }
  131.         else
  132.         {
  133.             PutPStrTruncTo("\p-nil-", kColumnNameEnd);
  134.         };
  135.     };
  136.     PutSpace();
  137.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  138.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  139.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  140.     PutSpace();
  141.     PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd);            // version
  142.     PutSpace();
  143.     PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd);            // qHead
  144.     PutSpace();
  145.     
  146.     if ( dcep->dCtlFlags & (1<<3) )  // Is_Native
  147.     {
  148.         DriverDescriptionPtr    descPtr = (DriverDescriptionPtr) dcep->dCtlOwner;
  149.  
  150.         PutUHexZTo( descPtr->driverType.version.majorRev, 2, kColumnStorageEnd-6);
  151.         PutChar('.');
  152.         PutUHexZTo( descPtr->driverType.version.minorAndBugRev, 2, kColumnStorageEnd-3);
  153.         
  154.         switch (descPtr->driverType.version.stage)
  155.         {
  156.             case 0x40:
  157.                 PutChar('a');
  158.                 break;
  159.             case 0x60:
  160.                 PutChar('b');
  161.                 break;
  162.             case 0x80:
  163.                 PutChar('f');
  164.                 break;
  165.             case 0x20:
  166.                 PutChar('d');
  167.                 break;
  168.             default:
  169.                 PutChar('?');
  170.                 break;
  171.         }
  172.     
  173.         PutUHexZTo( descPtr->driverType.version.nonRelRev, 2, kColumnStorageEnd);
  174.  
  175.     }
  176.     else
  177.     {
  178.         PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd);            // Storage
  179.     }
  180.     PutSpace();
  181.     PutUHexWord((unsigned long) dcep->dCtlDelay);
  182.     PutSpace();
  183.     PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
  184.     PutSpace();
  185.     PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
  186.     PutLine();
  187.  
  188.     // For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
  189.     // the dCtlRefNum is $FFFB (don't whine about it)
  190.  
  191.     if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
  192.     {
  193.         PutPStr("\p   that is strange:  dCtlRefNum = ");
  194.         PutUHexWord(dcep->dCtlRefNum);
  195.         PutLine();
  196.     }
  197. } // DrawDCE
  198.  
  199.  
  200. pascal void DoDrvrCommand(dcmdBlock* paramPtr)
  201. {
  202.     Boolean    doOne = false;
  203.     Boolean    busyOnly = false;
  204.     long    dref;
  205.     short    NumDCEs;
  206.  
  207.     dcmdSwapWorlds();
  208.  
  209.     dcmdDrawLine("\pDisplaying Driver Control Entries");
  210.  
  211.     // Get low-memory values after dcmdSwapWorlds().
  212.  
  213.     NumDCEs = LMGetUnitTableEntryCount();
  214.  
  215.     if ( dcmdPeekAtNextChar() == '-' )
  216.     {
  217.         short oldPos = dcmdGetPosition();
  218.         short ch;
  219.  
  220.         dcmdGetNextChar();        // eat the "-"
  221.         
  222.         ch = dcmdGetNextChar();
  223.  
  224.         if ( ch == 'b' || ch == 'B' )
  225.             busyOnly = true;
  226.         else
  227.             dcmdSetPosition( oldPos );
  228.     }
  229.  
  230.     if ( !busyOnly )
  231.         (void) dcmdGetNextExpression(&dref, &doOne);
  232.  
  233.     if (doOne)    // info on one specific driver
  234.     {
  235.         short dnum;
  236.  
  237.         dref = (short) dref;
  238.  
  239.         if (dref < 0)
  240.         {
  241.             dnum = ~dref;
  242.         }
  243.         else
  244.         {
  245.             dnum = dref;
  246.             dref = ~dref;
  247.         }
  248.  
  249.         if (dnum > NumDCEs)
  250.         {
  251.             PutPStr("\pBad refnum ");
  252.             PutUHexWord(dref);
  253.             PutSpace();
  254.             PutUHexWord(~dref);
  255.             PutLine();
  256.         }
  257.         else
  258.         {
  259.             AuxDCE** dceh = ((AuxDCE***)LMGetUTableBase())[dnum];
  260.             if (dceh)
  261.             {
  262.                 DrawHdr();
  263.                 DrawDCE(dref,*dceh);
  264.             }
  265.             else
  266.             {
  267.                 PutPStr("\pDriver ");
  268.                 PutUHexWord(dref);
  269.                 PutSpace();
  270.                 PutUHexWord(~dref);
  271.                 PutPStr("\p is not installed");
  272.                 PutLine();
  273.             }
  274.         }
  275.     }
  276.     else        // no driver number specified on command line
  277.     {
  278.         short DCEsUsed = 0;
  279.         short dnum;
  280.         AuxDCE*** dcehp;
  281.         Boolean foundOne = false;
  282.         for(dnum = 0, dcehp = (AuxDCE***) LMGetUTableBase(); dnum < NumDCEs; dnum++, dcehp++)
  283.         {
  284.             if (*dcehp)
  285.             {
  286.                 if (busyOnly && (**dcehp)->dCtlQHdr.qHead == 0)
  287.                     continue;
  288.  
  289.                 DCEsUsed++;
  290.                 if (!foundOne)
  291.                 {
  292.                     DrawHdr();
  293.                     foundOne = true;
  294.                 }
  295.                 DrawDCE(~dnum,**dcehp);
  296.             }
  297.  
  298.             if (paramPtr->aborted)
  299.                 break;
  300.         }
  301.  
  302.         if ( !paramPtr->aborted )
  303.         {
  304.             if ( busyOnly )
  305.             {
  306.                 if ( !foundOne )
  307.                 {
  308.                     PutPStr("\pNo drivers are busy.");
  309.                     PutLine();
  310.                 }
  311.             }
  312.             else
  313.             {
  314.                 PutUDec(NumDCEs);
  315.                 PutPStr("\p Unit Table entries, ");
  316.                 PutUDec(DCEsUsed);
  317.                 PutPStr("\p in use, ");
  318.                 PutUDec(NumDCEs - DCEsUsed);
  319.                 PutPStr("\p free");
  320.                 PutLine();
  321.             }
  322.         }
  323.     }    
  324.  
  325.     dcmdSwapWorlds();
  326. } // DoDrvrCommand
  327.  
  328.  
  329. pascal void CommandEntry(dcmdBlock* paramPtr)
  330. {
  331.  
  332.     static const Str255 usageStr = "\p[refNum|num] | -b";
  333.  
  334.     switch (paramPtr->request)
  335.     {
  336.         case dcmdInit:
  337.             break;
  338.  
  339.         case dcmdHelp:
  340.             dcmdDrawLine("\pDisplays driver information for the given refNum or all installed");
  341.             dcmdDrawLine("\pdrivers. Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  342.             dcmdDrawLine("\pStor/Ver field shows the storage for 68k drivers and the version");
  343.             dcmdDrawLine("\pfor native drivers.");
  344.             dcmdDrawLine("\p  drvr -b  shows only the drivers that are busy.");
  345.             break;
  346.  
  347.         case dcmdGetInfo:
  348.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03028000; // version 3.0.2 final
  349.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  350.             break;
  351.  
  352.         case dcmdDoIt:
  353.             DoDrvrCommand(paramPtr);
  354.             break;
  355.  
  356.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  357.  
  358.         default:
  359.             break;
  360.     }
  361. } // CommandEntry
  362.