📄 ataiotrc.c
字号:
if ( reg_cmd_info.cmd == CMD_PACKET )
{
if ( reg_atapi_cp_size == 12 )
sprintf( trcDmpBuf, " ATAPI CDB: %02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X ",
reg_atapi_cp_data[0], reg_atapi_cp_data[1],
reg_atapi_cp_data[2], reg_atapi_cp_data[3],
reg_atapi_cp_data[4], reg_atapi_cp_data[5],
reg_atapi_cp_data[6], reg_atapi_cp_data[7],
reg_atapi_cp_data[8], reg_atapi_cp_data[9],
reg_atapi_cp_data[10], reg_atapi_cp_data[11] );
else
sprintf( trcDmpBuf, " ATAPI CDB: %02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X ",
reg_atapi_cp_data[0], reg_atapi_cp_data[1],
reg_atapi_cp_data[2], reg_atapi_cp_data[3],
reg_atapi_cp_data[4], reg_atapi_cp_data[5],
reg_atapi_cp_data[6], reg_atapi_cp_data[7],
reg_atapi_cp_data[8], reg_atapi_cp_data[9],
reg_atapi_cp_data[10], reg_atapi_cp_data[11],
reg_atapi_cp_data[12], reg_atapi_cp_data[13],
reg_atapi_cp_data[14], reg_atapi_cp_data[15] );
return trcDmpBuf;
}
}
if ( errDmpLine == 3 )
{
errDmpLine = 4;
sprintf( trcDmpBuf, "Driver ErrCode: %d %s ",
reg_cmd_info.ec, trc_get_err_name( reg_cmd_info.ec ) );
return trcDmpBuf;
}
if ( errDmpLine == 4 )
{
errDmpLine = 5;
if ( reg_cmd_info.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) ",
reg_cmd_info.totalBytesXfer, reg_cmd_info.totalBytesXfer,
reg_cmd_info.drqPackets, reg_cmd_info.drqPackets );
return trcDmpBuf;
}
if ( errDmpLine == 6 )
{
errDmpLine = 7;
sprintf( trcDmpBuf, " Device Status: %02X = %s ", reg_cmd_info.st2,
trc_get_st_bit_name( reg_cmd_info.st2 ) );
return trcDmpBuf;
}
if ( errDmpLine == 7 )
{
errDmpLine = 8;
sprintf( trcDmpBuf, " Device Error: %02X = %s ", reg_cmd_info.er2,
trc_get_er_bit_name( reg_cmd_info.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 ( reg_cmd_info.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 ",
reg_cmd_info.fr1, reg_cmd_info.sc1, reg_cmd_info.sn1,
reg_cmd_info.cl1, reg_cmd_info.ch1, reg_cmd_info.dh1,
reg_cmd_info.cmd, reg_cmd_info.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 -- ",
reg_cmd_info.er2, reg_cmd_info.sc2, reg_cmd_info.sn2,
reg_cmd_info.cl2, reg_cmd_info.ch2, reg_cmd_info.dh2,
reg_cmd_info.st2, reg_cmd_info.as2 );
return trcDmpBuf;
}
if ( ( errDmpLine == 11 ) && reg_cmd_info.failbits )
{
errDmpLine = 12;
errDmpLine2 = 0;
sprintf( trcDmpBuf, " ATA/ATAPI protocol errors bits (%04XH):",
reg_cmd_info.failbits );
return trcDmpBuf;
}
if ( errDmpLine == 12 )
{
while ( ( errDmpLine2 < 16 )
&&
( ! ( reg_cmd_info.failbits & pErrNames[errDmpLine2].pErrCode ) )
)
errDmpLine2 ++ ;
if ( errDmpLine2 < 16 )
{
sprintf( trcDmpBuf, " - %s", pErrNames[errDmpLine2].pErrName );
errDmpLine2 ++ ;
return trcDmpBuf;
}
}
return NULL;
}
//**********************************************************
// command types to trace, see TRC_TYPE_xxx in ataio.h and
// see trc_cht_types() below.
static unsigned int chtTypes = 0xffff; // default is trace all cmd types
// command history trace buffer
#define MAX_CHT 100
static struct
{
unsigned char flg; // see TRC_FLAG_xxx in ataio.h
unsigned char ct; // see TRC_TYPE_xxx in ataio.h
unsigned char cmd; // command code or cdb size
unsigned char fr1; // feature reg before or cdb byte 0
unsigned char sc1; // sec cnt before or cdb byte 1
unsigned char sn1; // sec num before or cdb continued
unsigned char cl1; // cyl low before
unsigned char ch1; // cyl high before
unsigned char dh1; // device head before
unsigned char dc1; // device control before
unsigned char ec; // detailed error code
unsigned char to; // not zero if time out error
unsigned char st2; // status reg after
unsigned char as2; // alt status reg after
unsigned char er2; // error reg after
unsigned char sc2; // sec cnt after
unsigned char sn2; // sec num after
unsigned char cl2; // cyl low after
unsigned char ch2; // cyl high after
unsigned char dh2; // device head after
} chtBuf[MAX_CHT];
static int chtCur = 0;
static int chtDmpLine = 0;
static int chtDmpNdx = 0;
//**************************************************************
// set the commands types that are traced,
// see TRC_TYPE_xxx in ataio.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
}
//**************************************************************
// place an command or reset entry into
// the command history trace buffer
void trc_cht( void )
{
if ( ! ( ( 0x0001 << reg_cmd_info.ct ) & chtTypes ) )
return;
chtBuf[chtCur].flg = reg_cmd_info.flg;
chtBuf[chtCur].ct = reg_cmd_info.ct ;
chtBuf[chtCur].cmd = reg_cmd_info.cmd;
chtBuf[chtCur].fr1 = reg_cmd_info.fr1;
chtBuf[chtCur].sc1 = reg_cmd_info.sc1;
chtBuf[chtCur].sn1 = reg_cmd_info.sn1;
chtBuf[chtCur].cl1 = reg_cmd_info.cl1;
chtBuf[chtCur].ch1 = reg_cmd_info.ch1;
chtBuf[chtCur].dh1 = reg_cmd_info.dh1;
chtBuf[chtCur].dc1 = reg_cmd_info.dc1;
chtBuf[chtCur].ec = reg_cmd_info.ec ;
chtBuf[chtCur].to = reg_cmd_info.to ;
chtBuf[chtCur].st2 = reg_cmd_info.st2;
chtBuf[chtCur].as2 = reg_cmd_info.as2;
chtBuf[chtCur].er2 = reg_cmd_info.er2;
chtBuf[chtCur].sc2 = reg_cmd_info.sc2;
chtBuf[chtCur].sn2 = reg_cmd_info.sn2;
chtBuf[chtCur].cl2 = reg_cmd_info.cl2;
chtBuf[chtCur].ch2 = reg_cmd_info.ch2;
chtBuf[chtCur].dh2 = reg_cmd_info.dh2;
chtCur ++ ;
if ( chtCur >= MAX_CHT )
chtCur = 0;
}
//**************************************************************
// place an atapi command packet entry into
// the command history trace buffer
void trc_cht_pkt( void )
{
int ndx;
unsigned char * cp1;
unsigned char * cp2;
if ( ! ( ( 0x0001 << reg_cmd_info.ct ) & chtTypes ) )
return;
chtBuf[chtCur].flg = TRC_FLAG_CDB;
chtBuf[chtCur].ct = TRC_TYPE_PND;
chtBuf[chtCur].cmd = reg_atapi_cp_size;
cp1 = reg_atapi_cp_data;
cp2 = & chtBuf[chtCur].fr1;
for ( ndx = 0; ndx < reg_atapi_cp_size; ndx ++ )
{
* cp2 = * cp1;
cp2 ++ ;
cp1 ++ ;
}
chtCur ++ ;
if ( chtCur >= MAX_CHT )
chtCur = 0;
}
//**************************************************************
// clear the command history trace buffer
void trc_cht_dump0( void )
{
for ( chtCur = 0; chtCur < MAX_CHT; chtCur ++ )
chtBuf[chtCur].flg = TRC_FLAG_EMPTY;
chtCur = 0;
}
//**************************************************************
// start a dump of the command history trace buffer
void trc_cht_dump1( void )
{
chtDmpLine = 0;
chtDmpNdx = chtCur + 1;
if ( chtDmpNdx >= MAX_CHT )
chtDmpNdx = 0;
}
//**************************************************************
// return one line of the command history trace buffer,
// returns NULL at end.
unsigned char * trc_cht_dump2( void )
{
unsigned long lba;
unsigned char * cp;
chtDmpLine ++ ;
if ( chtDmpLine == 1 ) // 1st line is 1st line of heading
{
//0 1 2 3 4 5 6 7 7
//12345678901234567890123456789012345678901234567890123456789012345678901234567
strcpy( trcDmpBuf, "<--------- registers before ------> <---------- registers after ------> <--->" );
return trcDmpBuf;
}
if ( chtDmpLine == 2 ) // 2nd line is 2nd line of heading
{
//0 1 2 3 4 5 6 7 7
//12345678901234567890123456789012345678901234567890123456789012345678901234567
strcpy( trcDmpBuf, "CM FR SC SN ChCl DH DC CHS--or--LBA ST AS ER SC SN ChCl DH CHS--or--LBA EC TO" );
return trcDmpBuf;
}
while ( 1 )
{
if ( chtDmpNdx == chtCur )
return NULL;
if ( chtBuf[chtDmpNdx].flg != TRC_FLAG_EMPTY )
break;
chtDmpNdx ++ ;
if ( chtDmpNdx >= MAX_CHT )
chtDmpNdx = 0;
}
if ( chtBuf[chtDmpNdx].flg == TRC_FLAG_CDB )
{
cp = & chtBuf[chtDmpNdx].fr1;
if ( chtBuf[chtDmpNdx].cmd == 12 )
sprintf( trcDmpBuf, " ATAPI CDB: %02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X ",
* ( cp + 0 ), * ( cp + 1 ),
* ( cp + 2 ), * ( cp + 3 ),
* ( cp + 4 ), * ( cp + 5 ),
* ( cp + 6 ), * ( cp + 7 ),
* ( cp + 8 ), * ( cp + 9 ),
* ( cp + 10 ), * ( cp + 11 ) );
else
sprintf( trcDmpBuf, " ATAPI CDB: %02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X "
"%02X%02X %02X%02X ",
* ( cp + 0 ), * ( cp + 1 ),
* ( cp + 2 ), * ( cp + 3 ),
* ( cp + 4 ), * ( cp + 5 ),
* ( cp + 6 ), * ( cp + 7 ),
* ( cp + 8 ), * ( cp + 9 ),
* ( cp + 10 ), * ( cp + 11 ),
* ( cp + 12 ), * ( cp + 13 ),
* ( cp + 14 ), * ( cp + 15 ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -