📄 adviotrc.c
字号:
//********************************************************************
// ATA LOW LEVEL I/O DRIVER -- ADVIOTRC.C
//
// by Hale Landis (hlandis@ata-atapi.com)
//
// There is no copyright and there are no restrictions on the use
// of this ATA Low Level I/O Driver code. It is distributed to
// help other programmers understand how the ATA device interface
// works and it is distributed without any warranty. Use this
// code at your own risk.
//
// Compile with one of the Borland C or C++ compilers.
//
// This C source contains the low level I/O trace functions.
//********************************************************************
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include "advio.h"
//**************************************************************
// Common trace data
//**************************************************************
// trace dump buffer returned by trc_err_dump2()
// trc_cht_dump2() and trc_llt_dump2()
static unsigned char trcDmpBuf[200];
// buffer used to assemble print lines
static unsigned char prtBuf[64];
//**************************************************************
// Common Trace Functions
//**************************************************************
// function to return command type (protocol)
static unsigned char * typeNames[] =
{
//123456789012 (max 12 chars)
"NONE",
"ATA DmaIn",
"ATA DmaOut",
"ATA ND",
"ATA PDI",
"ATA PDO",
"ATA SR",
"ATAPI DmaIn",
"ATAPI DmaOut",
"ATAPI ND",
"ATAPI PDI",
"ATAPI PDO",
"????"
} ;
unsigned char * trc_get_type_name( unsigned char ct )
{
return typeNames[ ct ];
}
//**************************************************************
// table used to initialize cmd code ndx table
// this is used for fast lookup of cmd names
// and can be used to implement other arrays
// of information per cmd code.
static unsigned char cmdCodeLst[] =
{
0x00, // entry for unknown cmd codes
0x03 , 0x08 , 0x10 , 0x20 , 0x24 , 0x25 , 0x26 , 0x29, // 1 to 8
0x30 , 0x34 , 0x35 , 0x36 , 0x38 , 0x39 , 0x3C , 0x40, // 9 to 16
0x42 , 0x50 , 0x70 , 0x87 , 0x90 , 0x91 , 0x94 , 0x95, // 17 to 24
0x96 , 0x97 , 0x98 , 0x99 , 0xA0 , 0xA1 , 0xb0 , 0xC0, // 25 to 32
0xC4 , 0xC5 , 0xC6 , 0xC7 , 0xC8 , 0xCA , 0xCC , 0xCD, // 33 to 40
0xE0 , 0xE1 , 0xE2 , 0xE3 , 0xE4 , 0xE5 , 0xE6 , 0xE7, // 41 to 48
0xE8 , 0xEA , 0xEC , 0xEF // 49 to 52
} ;
#if TRC_NUM_CMDS != sizeof( cmdCodeLst )
#error TRC_NUM_CMDS is incorrect !
#endif
// command name lookup table
static unsigned char * cmdNames[] =
{
"? Cmd Name ?", // 0x00 0=unknown cmd codes
"CFA REQUEST EXT ERR CODE" , // 0x03 1
"DEVICE RESET" , // 0x08 2
"RECALIBRATE" , // 0x10 3
"READ SECTORS" , // 0x20 4
"READ SECTORS EXT" , // 0x24 5
"READ DMA EXT" , // 0x25 6
"READ DMA QUEUED EXT" , // 0x26 7
"READ MULTIPLE EXT" , // 0x29 8
"WRITE SECTORS" , // 0x30 9
"WRITE SECTORS EXT" , // 0x34 10
"WRITE DMA EXT" , // 0x35 11
"WRITE DMA QUEUED EXT" , // 0x36 12
"CFA WRITE SECTORS WO ERASE" , // 0x38 13
"WRITE MULTIPLE EXT" , // 0x39 14
"WRITE VERIFY" , // 0x3C 15
"READ VERIFY SECTORS" , // 0x40 16
"READ VERIFY SECTORS EXT" , // 0x42 17
"FORMAT TRACK" , // 0x50 18
"SEEK" , // 0x70 19
"CFA TRANSLATE SECTOR" , // 0x87 20
"EXECUTE DEVICE DIAGNOSTIC" , // 0x90 21
"INITIALIZE DEVICE PARAMETERS" , // 0x91 22
"STANDBY IMMEDIATE" , // 0x94 23
"IDLE IMMEDIATE" , // 0x95 24
"STANDBY" , // 0x96 25
"IDLE" , // 0x97 26
"CHECK POWER MODE" , // 0x98 27
"SLEEP" , // 0x99 28
"PACKET" , // 0xA0 29
"IDENTIFY PACKET DEVICE" , // 0xA1 30
"SMART", // 0xb0 31
"CFA ERASE SECTORS" , // 0xC0 32
"READ MULTIPLE" , // 0xC4 33
"WRITE MULTIPLE" , // 0xC5 34
"SET MULTIPLE MODE" , // 0xC6 35
"READ DMA QUEUED" , // 0xC7 36
"READ DMA" , // 0xC8 37
"WRITE DMA" , // 0xCA 38
"WRITE DMA QUEUED" , // 0xCC 39
"CFA WRITE MULTIPLE WO ERASE" , // 0xCD 40
"STANDBY IMMEDIATE" , // 0xE0 41
"IDLE IMMEDIATE" , // 0xE1 42
"STANDBY" , // 0xE2 43
"IDLE" , // 0xE3 44
"READ BUFFER" , // 0xE4 45
"CHECK POWER MODE" , // 0xE5 46
"SLEEP" , // 0xE6 47
"FLUSH CACHE" , // 0xE7 48
"WRITE BUFFER" , // 0xE8 49
"FLUSH CACHE EXT" , // 0xEA 50
"IDENTIFY DEVICE" , // 0xEC 51
"SET FEATURES" , // 0xEF 52
} ;
// cmd code to cmd ndx table - see macro TRC_CMD_NDX() in ADVIO.H.
unsigned char trc_CmdCodeNdx[256];
// function to initialize trc_CmdCodeNdx[]
static void init_cmd_ndx_tbl( void );
static void init_cmd_ndx_tbl( void )
{
int ndx;
for ( ndx = 0; ndx < sizeof( cmdCodeLst ); ndx ++ )
trc_CmdCodeNdx[cmdCodeLst[ndx]] = ndx;
// note: unknown cmd codes will have an ndx of 0.
}
// function to return the cmd name for a cmd code.
unsigned char * trc_get_cmd_name( unsigned int cc )
{
if ( trc_CmdCodeNdx[CMD_READ_SECTORS] == 0 ) // 1st call initialization
init_cmd_ndx_tbl();
if ( cc == CMD_SRST ) // soft reset
return "SOFT RESET";
return cmdNames[TRC_CC2NDX(cc)]; // code->ndx->name
}
//**************************************************************
// ATA status names lookup table and lookup function
static struct
{
unsigned char bitPos;
unsigned char * bitName;
} ataStatusNames[] =
{
0x80 , "BSY " ,
0x40 , "DRDY " ,
0x20 , "DF " ,
0x10 , "DSC " ,
0x08 , "DRQ " ,
0x04 , "CORR " ,
0x02 , "IDX " ,
0x01 , "ERR "
} ;
static unsigned char ataStatusNameBuf[48];
unsigned char * trc_get_st_bit_name( unsigned char st )
{
int ndx;
if ( st & 0x80 )
st = 0x80;
* ataStatusNameBuf = 0;
for ( ndx = 0; ndx < 8; ndx ++ )
{
if ( st & ataStatusNames[ndx].bitPos )
strcat( ataStatusNameBuf, ataStatusNames[ndx].bitName );
}
return ataStatusNameBuf;
}
//**************************************************************
// ATA error names lookup table and lookup function
static struct
{
unsigned char bitPos;
unsigned char * bitName;
} ataErrorNames[] =
{
0x80 , "BBK:ICRC " ,
0x40 , "UNC " ,
0x20 , "MC " ,
0x10 , "IDNF " ,
0x08 , "MCR " ,
0x04 , "ABRT " ,
0x02 , "TK0NF " ,
0x01 , "AMNF "
} ;
static unsigned char ataErrorNameBuf[48];
unsigned char * trc_get_er_bit_name( unsigned char er )
{
int ndx;
* ataErrorNameBuf = 0;
for ( ndx = 0; ndx < 8; ndx ++ )
{
if ( er & ataErrorNames[ndx].bitPos )
strcat( ataErrorNameBuf, ataErrorNames[ndx].bitName );
}
return ataErrorNameBuf;
}
//**************************************************************
// error name lookup table and lookup function
static struct
{
int errCode;
unsigned char * errName;
} errNames[] =
{
1 , "Soft Reset timed out polling for device 0 to set BSY=0" ,
2 , "Soft Reset timed out polling device 1" ,
3 , "Soft Reset timed out polling for device 1 to set BSY=0" ,
11 , "Selected device is hung - reset required" ,
12 , "Device selection timed out polling for BSY=0 DRQ=0" ,
21 , "Non-Data command ended with bad status" ,
22 , "Non-Data command timed out waiting for an interrupt" ,
23 , "Non-Data command timed out polling for BSY=0" ,
24 , "Exec Dev Diag command timed out polling device 1" ,
31 , "PIO Data In command terminated by error status" ,
32 , "Device should be ready to transfer data but DRQ=0" ,
33 , "PIO Data In command ended with bad status" ,
34 , "PIO Data In command timed out waiting for an interrupt" ,
35 , "PIO Data In command timed out polling for BSY=0" ,
41 , "PIO Data Out command terminated by error status" ,
42 , "Device should be ready to transfer data but DRQ=0" ,
43 , "PIO Data Out command ended with bad status" ,
44 , "PIO Data Out command timed out waiting for an interrupt" ,
45 , "PIO Data Out command timed out polling for BSY=0" ,
46 , "Extra interrupt at start of a PIO Data Out command" ,
47 , "PIO Data Out command timed out polling for BSY=0" ,
51 , "Timeout waiting for BSY=0/DRQ=1 for cmd packet transfer" ,
52 , "Bad status at command packet transfer time" ,
53 , "Timeout waiting for interrupt for data packet transfer" ,
54 , "Timeout polling for BSY=0/DRQ=1 for a data packet" ,
55 , "Bad status at data packet transfer time" ,
56 , "Timout waiting for final interrupt at end of command" ,
57 , "Timeout polling for final BSY=0 at end of command" ,
58 , "Bad status at end of command" ,
59 , "Byte count for data packet is zero" ,
61 , "Buffer overrun (host buffer too small)" ,
70 , "No DMA channel is setup" ,
71 , "End of command without complete data transfer" ,
72 , "Timeout waiting for 1st transfer to complete" ,
73 , "Timeout waiting for command to complete" ,
74 , "Bad status at end of command" ,
75 , "Timeout waiting for BSY=0/DRQ=1 for cmd packet transfer" ,
76 , "Bad status at command packet transfer time" ,
77 , "ATA command code is not C8H or CAH" ,
78 , "End of command with BMCR/BMIDE Error=1" ,
0 , "" // end of table
} ;
unsigned char * trc_get_err_name( int ec )
{
int ndx = 0;
while ( * errNames[ndx].errName )
{
if ( ec == errNames[ndx].errCode )
return errNames[ndx].errName;
ndx ++ ;
}
return "";
}
//**************************************************************
static struct
{
unsigned int pErrCode;
unsigned char * pErrName;
} pErrNames[] =
{
FAILBIT0 , "slow setting BSY=1 or DRQ=1 after A0 cmd" ,
FAILBIT1 , "got interrupt before cmd packet xfer" ,
FAILBIT2 , "SC wrong at cmd packet xfer time" ,
FAILBIT3 , "byte count wrong at cmd packet xfer time" ,
FAILBIT4 , "SC (CD bit) wrong at data packet xfer time" ,
FAILBIT5 , "SC (IO bit) wrong at data packet xfer time" ,
FAILBIT6 , "byte count wrong at data packet xfer time" ,
FAILBIT7 , "byte count odd at data packet xfer time" ,
FAILBIT8 , "SC (CD and IO bits) wrong at end of cmd" ,
FAILBIT9 , "fail bit 9" ,
FAILBIT10 , "fail bit 10" ,
FAILBIT11 , "fail bit 11" ,
FAILBIT12 , "fail bit 12" ,
FAILBIT13 , "fail bit 13" ,
FAILBIT14 , "fail bit 14" ,
FAILBIT15 , "extra interrupts detected"
} ;
//**************************************************************
// Display of previous command
//**************************************************************
// command or reset error display data
static int errDmpLine;
static int errDmpLine2;
//**************************************************************
// start the display of a command or reset error display
void trc_err_dump1( void )
{
errDmpLine = 1;
errDmpLine2 = 0;
}
//**************************************************************
// return one line of a command or reset error display,
// returns NULL at end
unsigned char * trc_err_dump2( void )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -