⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adviotrc.c

📁 pc机上经由pci连接的ata和atapi设备驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
{

   if ( ADP->flg == TRC_FLAG_EMPTY )
      return NULL;
   if ( errDmpLine == 1 )
   {
      errDmpLine = 2;
      if ( ADP->flg == TRC_FLAG_SRST )
         sprintf( trcDmpBuf, "ATA Reset: SR = %s (%s)",
                             trc_get_cmd_name( CMD_SRST ),
                             trc_get_type_name( ADP->ct ) );
      else
      if ( ADP->flg == TRC_FLAG_ATAPI )
         sprintf( trcDmpBuf, "PACKET Command: %02X = %s (%s)",
                             ADP->cmd,
                             trc_get_cmd_name( ADP->cmd ),
                             trc_get_type_name( ADP->ct ) );
      else
         sprintf( trcDmpBuf, "ATA Command: %02X = %s (%s)",
                             ADP->cmd,
                             trc_get_cmd_name( ADP->cmd ),
                             trc_get_type_name( ADP->ct ) );

      return trcDmpBuf;
   }
   if ( errDmpLine == 2 )
   {
      errDmpLine = 3;
      if ( ADP->flg == TRC_FLAG_ATA )
      {
         if ( ADP->lbaSize == LBA48 )
         {
            // LBA48 before and after
            sprintf( trcDmpBuf, "LBA48 SC %ld %lXH, "
                                "before %lu.%lu %lX.%lXH, "
                                "after %lu.%lu %lX.%lXH",
                                 ADP->ns, ADP->ns,
                                 ADP->lbaHigh1, ADP->lbaLow1,
                                 ADP->lbaHigh1, ADP->lbaLow1,
                                 ADP->lbaHigh2, ADP->lbaLow2,
                                 ADP->lbaHigh2, ADP->lbaLow2 );
         }
         else
         if ( ADP->lbaSize == LBA28 )
         {
            // LBA28 before and after
            sprintf( trcDmpBuf, "LBA28 SC %ld %lXH, "
                                "before %lu %lXH, "
                                "after %lu %lXH",
                                 ADP->ns, ADP->ns,
                                 ADP->lbaLow1, ADP->lbaLow1,
                                 ADP->lbaLow2, ADP->lbaLow2 );
         }
         else
         {
            // CHS before and after
            unsigned int cyl1, head1, sect1;
            unsigned int cyl2, head2, sect2;

            cyl1  = (unsigned int) ( ADP->ch1 << 8 ) | ADP->cl1;
            head1 = (unsigned int) ADP->dh1 & 0x0f;
            sect1 = (unsigned int) ADP->sn1;
            cyl2  = (unsigned int) ( ADP->ch2 << 8 ) | ADP->cl2;
            head2 = (unsigned int) ADP->dh2 & 0x0f;
            sect2 = (unsigned int) ADP->sn2;
            sprintf( trcDmpBuf, "CHS SC %ld %lXH, "
                                "before %u.%u.%u %X.%X.%XH, "
                                "after %u.%u.%u %X.%X.%XH ",
                                 ADP->ns, ADP->ns,
                                 cyl1, head1, sect1, cyl1, head1, sect1,
                                 cyl2, head2, sect2, cyl2, head2, sect2 );
         }
         return trcDmpBuf;
      }
      if ( ADP->flg == TRC_FLAG_ATAPI )
      {
         if ( ADP->reg_atapi_cp_size == 12 )
         {
            sprintf( trcDmpBuf, "CDB %02X %02X %02X %02X  "
                                    "%02X %02X %02X %02X  "
                                    "%02X %02X %02X %02X ",
                     ADP->reg_atapi_cp_data[0], ADP->reg_atapi_cp_data[1],
                     ADP->reg_atapi_cp_data[2], ADP->reg_atapi_cp_data[3],
                     ADP->reg_atapi_cp_data[4], ADP->reg_atapi_cp_data[5],
                     ADP->reg_atapi_cp_data[6], ADP->reg_atapi_cp_data[7],
                     ADP->reg_atapi_cp_data[8], ADP->reg_atapi_cp_data[9],
                     ADP->reg_atapi_cp_data[10], ADP->reg_atapi_cp_data[11] );
         }
         else
         {
            sprintf( trcDmpBuf, "CDB %02X %02X %02X %02X  "
                                    "%02X %02X %02X %02X  "
                                    "%02X %02X %02X %02X  "
                                    "%02X %02X %02X %02X ",
                     ADP->reg_atapi_cp_data[0], ADP->reg_atapi_cp_data[1],
                     ADP->reg_atapi_cp_data[2], ADP->reg_atapi_cp_data[3],
                     ADP->reg_atapi_cp_data[4], ADP->reg_atapi_cp_data[5],
                     ADP->reg_atapi_cp_data[6], ADP->reg_atapi_cp_data[7],
                     ADP->reg_atapi_cp_data[8], ADP->reg_atapi_cp_data[9],
                     ADP->reg_atapi_cp_data[10], ADP->reg_atapi_cp_data[11],
                     ADP->reg_atapi_cp_data[12], ADP->reg_atapi_cp_data[13],
                     ADP->reg_atapi_cp_data[14], ADP->reg_atapi_cp_data[15] );
         }
         return trcDmpBuf;
      }
   }
   if ( errDmpLine == 3 )
   {
      errDmpLine = 4;
      sprintf( trcDmpBuf, "Driver ErrCode: %d %s ",
                          ADP->ec, trc_get_err_name( ADP->ec ) );
      return trcDmpBuf;
   }
   if ( errDmpLine == 4 )
   {
      errDmpLine = 5;
      if ( ADP->to )
      {
         sprintf( trcDmpBuf, "                   "
                             "Driver timed out (see low level trace for details) !" );
         return trcDmpBuf;
      }
   }
   if ( errDmpLine == 5 )
   {
      errDmpLine = 6;
      sprintf( trcDmpBuf, "Bytes transferred: %ld (%lXH); DRQ packets: %ld (%lXH) ",
                        ADP->totalBytesXfer, ADP->totalBytesXfer,
                        ADP->drqPackets, ADP->drqPackets );
      return trcDmpBuf;
   }
   if ( errDmpLine == 6 )
   {
      errDmpLine = 7;
      sprintf( trcDmpBuf, "Device Status: %02X = %s ", ADP->st2,
                        trc_get_st_bit_name( ADP->st2 ) );
      return trcDmpBuf;
   }
   if ( errDmpLine == 7 )
   {
      errDmpLine = 8;
      sprintf( trcDmpBuf, "Device  Error: %02X = %s ", ADP->er2,
                         trc_get_er_bit_name( ADP->er2 ) );
      return trcDmpBuf;
   }
   if ( errDmpLine == 8 )
   {
      errDmpLine = 9;
      sprintf( trcDmpBuf, "ATA Intf Regs: FR  ER  SC  SN  CL  CH  DH  CM  ST  AS  DC " );
      return trcDmpBuf;
   }
   if ( errDmpLine == 9 )
   {
      errDmpLine = 10;
      if ( ADP->flg == TRC_FLAG_SRST )
         sprintf( trcDmpBuf, "   Cmd Params: "
                  // fr  er  sc  sn  cl  ch  dh  cm  st  as  dc
                    "--  --  --  --  --  --  --  --  --  --  04 " );
      else
         sprintf( trcDmpBuf, "   Cmd Params: "
                  //  fr   er   sc    sn    cl    ch    dh    cm   st  as   dc
                    "%02X  --  %02X  %02X  %02X  %02X  %02X  %02X  --  --  %02X ",
                     ADP->fr1 & 0x00ff,
                     ADP->sc1 & 0x00ff,
                     ADP->sn1,
                     ADP->cl1, ADP->ch1, ADP->dh1,
                     ADP->cmd, ADP->dc1 );
      return trcDmpBuf;
   }
   if ( errDmpLine == 10 )
   {
      errDmpLine = 11;
      sprintf( trcDmpBuf, "    After Cmd: "
                  // fr   er    sc    sn    cl    ch    dh   cm   st    as   dc
                    "--  %02X  %02X  %02X  %02X  %02X  %02X  --  %02X  %02X  -- ",
                     ADP->er2, ADP->sc2 & 0x00ff,
                     ADP->sn2, ADP->cl2, ADP->ch2,
                     ADP->dh2, ADP->st2, ADP->as2 );
      return trcDmpBuf;
   }
   if ( ( errDmpLine == 11 ) &&  ADP->failbits )
   {
      errDmpLine = 12;
      errDmpLine2 = 0;
      sprintf( trcDmpBuf, "  ATA/ATAPI protocol errors bits (%04XH):",
                          ADP->failbits );
      return trcDmpBuf;
   }
   if ( errDmpLine == 12 )
   {
      while ( ( errDmpLine2 < 16 )
              &&
              ( ! ( ADP->failbits & pErrNames[errDmpLine2].pErrCode ) )
            )
         errDmpLine2 ++ ;
      if ( errDmpLine2 < 16 )
      {
         sprintf( trcDmpBuf, "      - %s", pErrNames[errDmpLine2].pErrName );
         errDmpLine2 ++ ;
         return trcDmpBuf;
      }
   }
   return NULL;
}

//**************************************************************
// Command History Trace
//**************************************************************

// command types to trace, see TRC_TYPE_xxx in advio.h and
// see trc_cht_types() below.

static unsigned int chtTypes = 0xffff; // default is trace all cmd types

static unsigned char * chtTypeName[] =
   { "?????",
     "DR   ", "DW   ",
     "ND   ", "PDI  ", "PDO  ",
     "RESET",
     "DPR  ", "DPW  ",
     "PN   ", "PR   ", "PW   " } ;

//**************************************************************

// set the commands types that are traced,
// see TRC_TYPE_xxx in advio.h and chtTypes above.

void trc_cht_types( int type )

{

   if ( type < 1 )
      chtTypes = 0x0000;   // trace nothing
   else
      if ( type > 15 )
         chtTypes = 0xffff;   // trace all
      else
         chtTypes |= 0x0001 << type;  // selective
}

//**************************************************************

static int chtDmpLine;
static int chtDmpNdx = 0;

//**************************************************************

// place an command or reset entry into
// the command history trace buffer

void trc_cht( void )

{
   int ndx;
   struct CHT far * ep;

   if ( ! ( ( 0x0001 << ADP->ct ) & chtTypes ) )
      return;

   ep = ADP->chtBuf + ADP->chtCur;

   // entry type, entry flag, command code, etc
   ep->flg = ADP->flg;
   ep->ct  = ADP->ct ;
   ep->cmd = ADP->cmd;
   ep->ns = ADP->ns;
   ep->mc = ADP->mc;
   ep->fr1 = ADP->fr1;
   ep->dh1 = ADP->dh1;
   // starting CHS/LBA
   ep->lbaSize = ADP->lbaSize;
   ep->cyl  = ( ADP->ch1 << 8 ) | ADP->cl1;
   ep->head = ADP->dh1 & 0x0f;
   ep->sect = ADP->sn1;
   ep->lbaLow1 = ADP->lbaLow1;
   // ending status and driver error codes
   ep->st2 = ADP->st2;
   ep->er2 = ADP->er2;
   ep->ec  = ADP->ec ;
   ep->to  = ADP->to ;
   // ATAPI CDB size and CDB data
   ep->cdbSize = ADP->reg_atapi_cp_size;
   for ( ndx = 0; ndx < ADP->reg_atapi_cp_size; ndx ++ )
      ep->cdbBuf[ndx] = ADP->reg_atapi_cp_data[ndx];

   // move to next entry
   ADP->chtCur ++ ;
   if ( ADP->chtCur >= ADP->chtSize )
      ADP->chtCur = 0;
}

//**************************************************************

// initialize command history trace buffer

void trc_cht_dump0( void )

{
   int ndx;
   struct CHT far * ep;

   for ( ndx = 0; ndx < ADP->chtSize; ndx ++ )
   {
      ep = ADP->chtBuf + ndx;
      ep->flg = TRC_FLAG_EMPTY;
   }
   ADP->chtCur = 0;
}

//**************************************************************

// start a dump of the command history trace buffer

void trc_cht_dump1( void )

{

   chtDmpLine = 1;
   chtDmpNdx = ADP->chtCur + 1;
   if ( chtDmpNdx >= ADP->chtSize )
      chtDmpNdx = 0;
}

//**************************************************************

// return one line of the command history trace buffer,
// returns NULL at end.
//
// lines are formated in the style of ATADEMO commands.
// there are three ATADEMO commands per line (DEV, LBAx,
// and the I/O command). The three values at the end of the
// line (following the //) are the driver result error code,
// driver timeout flag, status register and error register.

static unsigned char esStr[24];
static unsigned char atStr[24];
static unsigned char saStr[24];
static unsigned char mcStr[24];

unsigned char * trc_cht_dump2( void )

{
   struct CHT far * ep;

   if ( chtDmpLine == 1 )     // 1st line is 1st heading line
   {
      strcpy( trcDmpBuf,
        //0        1         2         3         4         5         6         7
        //123456789012345678901234567890123456789012345678901234567890123456789012
        //DEV n, LBAnn, ttttt xxH xxxxH nnnnn nnnnnnnnn    nnn ; nn nn xxH xxH
         "Dev n, LBAnn, Type- Cmd FR--- SC--- LBA--------- MC- ; EC TO ST- ER-" );
      chtDmpLine = 2;
      return trcDmpBuf;
   }
   if ( chtDmpLine == 2 )     // 2nd line is 2nd heading line
   {
      strcpy( trcDmpBuf,
        //0        1         2         3         4         5         6         7
        //123456789012345678901234567890123456789012345678901234567890123456789012
        //DEV n, CHS,   ttttt xxH xxxxH nnnnn ccccc hh sss nnn ; nn nn xxH xxH
         "Dev n, CHS,   Type- Cmd FR--- SC--- Cyl-- Hd Sec MC- ; EC TO ST- ER-" );
      chtDmpLine = 3;
      return trcDmpBuf;
   }

   // search for oldest entry
   while ( 1 )
   {
      if ( chtDmpNdx == ADP->chtCur )
         return NULL;
      ep = ADP->chtBuf + chtDmpNdx;
      if ( ep->flg != TRC_FLAG_EMPTY )
         break;
      chtDmpNdx ++ ;
      if ( chtDmpNdx >= ADP->chtSize )
         chtDmpNdx = 0;
   }

   // return one trace table entry...
   sprintf( esStr, " ; %2d %2d %02XH %02XH",
                   ep->ec,
                   ep->to,
                   ep->st2,
                   ep->er2 );
   if ( ep->flg == TRC_FLAG_SRST )
   {
      // TRC_TYPE_ASR -> DEV n, LBAnn, RESET ; nn nn xxH xxH

      //0        1         2         3         4         5         6         7

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -