00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <string.h>
00015
00016 #include <kernel/IdeLow.h>
00017 #include <kernel/Ide.h>
00018 #include <kernel/IdeTimer.h>
00019 #include <kernel/video.h>
00020
00021 #include <kernel/IdeDebug.h>
00022
00023 static byte hex_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
00024
00025
00026 CmdNames_Struct CmdNames[] =
00027 {
00028 {HDC_CMD_CFA_ERASE_SECTORS , "CFA ERASE SECTORS" } ,
00029 {HDC_CMD_CFA_REQUEST_EXT_ERR_CODE , "CFA REQUEST EXT ERR CODE" } ,
00030 {HDC_CMD_CFA_TRANSLATE_SECTOR , "CFA TRANSLATE SECTOR" } ,
00031 {HDC_CMD_CFA_WRITE_MULTIPLE_WO_ERASE , "CFA WRITE MULTIPLE WO ERASE" } ,
00032 {HDC_CMD_CFA_WRITE_SECTORS_WO_ERASE , "CFA WRITE SECTORS WO ERASE" } ,
00033 {HDC_CMD_CHECK_POWER_MODE1 , "CHECK POWER MODE" } ,
00034 {HDC_CMD_CHECK_POWER_MODE2 , "CHECK POWER MODE" } ,
00035 {HDC_CMD_DEVICE_RESET , "DEVICE RESET" } ,
00036 {HDC_CMD_EXECUTE_DEVICE_DIAGNOSTIC , "EXECUTE DEVICE DIAGNOSTIC" } ,
00037 {HDC_CMD_FLUSH_CACHE , "FLUSH CACHE" } ,
00038 {HDC_CMD_FORMAT_TRACK , "FORMAT TRACK" } ,
00039 {HDC_CMD_IDENTIFY_DEVICE , "IDENTIFY DEVICE" } ,
00040 {HDC_CMD_IDENTIFY_PACKET_DEVICE , "IDENTIFY PACKET DEVICE" } ,
00041 {HDC_CMD_IDLE1 , "IDLE" } ,
00042 {HDC_CMD_IDLE2 , "IDLE" } ,
00043 {HDC_CMD_IDLE_IMMEDIATE1 , "IDLE IMMEDIATE" } ,
00044 {HDC_CMD_IDLE_IMMEDIATE2 , "IDLE IMMEDIATE" } ,
00045 {HDC_CMD_INITIALIZE_DRIVE_PARAMETERS , "INITIALIZE DEVICE PARAMETERS" } ,
00046 {HDC_CMD_NOP , "NOP" } ,
00047 {HDC_CMD_PACKET , "PACKET" } ,
00048 {HDC_CMD_READ_BUFFER , "READ BUFFER" } ,
00049 {HDC_CMD_READ_DMA_QUEUED , "READ DMA QUEUED" } ,
00050 {HDC_CMD_READ_DMA , "READ DMA" } ,
00051 {HDC_CMD_READ_MULTIPLE , "READ MULTIPLE" } ,
00052 {HDC_CMD_READ_SECTORS , "READ SECTORS" } ,
00053 {HDC_CMD_READ_VERIFY_SECTORS , "READ VERIFY SECTORS" } ,
00054 {HDC_CMD_RECALIBRATE , "RECALIBRATE" } ,
00055 {HDC_CMD_SEEK , "SEEK" } ,
00056 {HDC_CMD_SET_FEATURES , "SET FEATURES" } ,
00057 {HDC_CMD_SET_MULTIPLE_MODE , "SET MULTIPLE MODE" } ,
00058 {HDC_CMD_SLEEP1 , "SLEEP" } ,
00059 {HDC_CMD_SLEEP2 , "SLEEP" } ,
00060 {HDC_CMD_STANDBY1 , "STANDBY" } ,
00061 {HDC_CMD_STANDBY2 , "STANDBY" } ,
00062 {HDC_CMD_STANDBY_IMMEDIATE1 , "STANDBY IMMEDIATE" } ,
00063 {HDC_CMD_STANDBY_IMMEDIATE2 , "STANDBY IMMEDIATE" } ,
00064 {HDC_CMD_WRITE_BUFFER , "WRITE BUFFER" } ,
00065 {HDC_CMD_WRITE_DMA , "WRITE DMA" } ,
00066 {HDC_CMD_WRITE_DMA_QUEUED , "WRITE DMA QUEUED" } ,
00067 {HDC_CMD_WRITE_MULTIPLE , "WRITE MULTIPLE" } ,
00068 {HDC_CMD_WRITE_SECTORS , "WRITE SECTORS" } ,
00069 {HDC_CMD_WRITE_VERIFY , "WRITE VERIFY" } ,
00070 {0x00 , ""}
00071 } ;
00072
00073 static ErrNames_Struct ErrNames[] =
00074 {
00075 {1 , "Soft Reset timed out polling for device 0 to set BSY=0" },
00076 {2 , "Soft Reset timed out polling device 1 to access register"},
00077 {3 , "Soft Reset timed out polling for device 1 to set BSY=0" },
00078 {4 , "Soft Reset timed out polling for device 0 and 1" },
00079
00080 {11 , "Device selection timed out polling for BSY=0" },
00081 {12 , "Device selection timed out polling for RDY=1" },
00082
00083 {21 , "Non-Data command ended with bad status" },
00084 {22 , "Non-Data command timed out waiting for an interrupt" },
00085 {23 , "Non-Data command timed out polling for BSY=0" },
00086 {24 , "Exec Dev Diag command timed out polling device 1" },
00087
00088 {31 , "PIO Data In command terminated by error status" },
00089 {32 , "Device should be ready to transfer data but DRQ=0" },
00090 {33 , "PIO Data In command ended with bad status" },
00091 {34 , "PIO Data In command timed out waiting for an interrupt" },
00092 {35 , "PIO Data In command timed out polling for BSY=0" },
00093
00094 {41 , "PIO Data Out command terminated by error status" },
00095 {42 , "Device should be ready to transfer data but DRQ=0" },
00096 {43 , "PIO Data Out command ended with bad status" },
00097 {44 , "PIO Data Out command timed out waiting for an interrupt"},
00098 {45 , "PIO Data Out command timed out polling for BSY=0" },
00099 {46 , "Extra interrupt at start of a PIO Data Out command" },
00100 {47 , "PIO Data Out command timed out polling for BSY=0" },
00101
00102 {51 , "Timeout waiting for BSY=0/DRQ=1 for cmd packet transfer"},
00103 {52 , "Bad status at command packet transfer time" },
00104 {53 , "Timeout waiting for interrupt for data packet transfer" },
00105 {54 , "Timeout polling for BSY=0/DRQ=1 for a data packet" },
00106 {55 , "Bad status at data packet transfer time" },
00107 {56 , "Timout waiting for final interrupt at end of command" },
00108 {57 , "Timeout polling for final BSY=0 at end of command" },
00109 {58 , "Bad status at end of command" },
00110 {59 , "Buffer overrun (host buffer too small)" },
00111 {60 , "Byte count for data packet is zero" },
00112
00113 {70 , "No DMA channel is setup" },
00114 {71 , "End of command without complete data transfer" },
00115 {72 , "Timeout waiting for 1st transfer to complete" },
00116 {73 , "Timeout waiting for command to complete" },
00117 {74 , "Bad status at end of command" },
00118 {75 , "Timeout waiting for BSY=0/DRQ=1 for cmd packet transfer"},
00119 {76 , "Bad status at command packet transfer time" },
00120 {77 , "ATA command code is not C8H or CAH" },
00121
00122 {80 , "No tag available now" },
00123 {81 , "Timeout polling for SERV=1" },
00124 {0x00 , ""}
00125 } ;
00126
00127
00128
00129
00130
00131
00132 char * GetIdeErrorMessage(int Err)
00133 {
00134 int i=0;
00135 while (ErrNames[i].ErrCode != 0x00 && ErrNames[i].ErrCode != Err)
00136 i++;
00137
00138 return ErrNames[i].ErrName;
00139 }
00140
00141
00142
00143
00144
00145
00146 void ShowIdeErrorMessage(int Err,int Dump)
00147 {
00148 int i=0;
00149 int j=0;
00150
00151 if (Err!=0x00)
00152 {
00153 while (ErrNames[i].ErrCode != 0x00 && ErrNames[i].ErrCode != Err)
00154 i++;
00155
00156 kprintf("\n\rIde Driver Error: ");
00157
00158 if (ErrNames[i].ErrCode != 0x00)
00159 kprintf("%s",ErrNames[j].ErrName);
00160 else
00161
00162 kprintf("Unknow Error");
00163
00164 if (Dump)
00165 ShowIdeRegisterDump();
00166 }
00167 }
00168
00169
00170
00171
00172 void ShowIdeRegisterDump()
00173 {
00174 kprintf("\n\rIDE REGISTER DUMP");
00175
00176 kprintf("\n\rSTATUS =0x");
00177 PrintByteHex(InPortAta(CC_ASTAT));
00178 gotoxy(20,-1);
00179 kprintf("ERROR =0x");
00180 PrintByteHex(InPortAta(CC_ERR));
00181
00182 kprintf("\n\rSEC CNT =0x");
00183 PrintByteHex(InPortAta(CC_SECC));
00184 gotoxy(20,-1);
00185 kprintf("SEC NUM =0x");
00186 PrintByteHex(InPortAta(CC_SECN));
00187
00188 kprintf("\n\rCYL LOW =0x");
00189 PrintByteHex(InPortAta(CC_CYLL));
00190 gotoxy(20,-1);
00191 kprintf("CYL HIGH=0x");
00192 PrintByteHex(InPortAta(CC_CYLH));
00193 gotoxy(40,-1);
00194 kprintf("DEV HEAD=0x");
00195 PrintByteHex(InPortAta(CC_DEVH));
00196
00197 kprintf("\n\r");
00198 }
00199
00200 void PrintByteHex(byte Data)
00201 {
00202 kputchar(hex_table[(Data>>4) & 0xF]);
00203 kputchar(hex_table[(Data) & 0xF]);
00204 }
00205
00206 void ShowMatrixData(char * DataBuffer,int Col,int BytePerCol,int RowToWait,int Len, int Mode)
00207 {
00208 int i=0;
00209 int j=0;
00210 int z=0;
00211 int RowCount=0;
00212 int CrtWidth=k_get_crt_width();
00213
00214 while(i<Len)
00215 {
00216 RowCount++;
00217 kprintf("\n\r");
00218 j=0;
00219
00220 while (i<Len && j<Col)
00221 {
00222 gotoxy(j*(CrtWidth/Col),-1);
00223 kprintf("[");
00224 PrintByteHex( (byte)i );
00225 kprintf("]");
00226 z=0;
00227
00228
00229 while (i<Len && z<BytePerCol)
00230 {
00231 switch (Mode)
00232 {
00233 case DBG_SHOWMAT_ASCII:
00234 kprintf("%c",DataBuffer[i]);
00235 break;
00236 case DBG_SHOWMAT_HEX:
00237 default:
00238 kprintf(" ");
00239 PrintByteHex(DataBuffer[i]);
00240 break;
00241 }
00242 z++;
00243 i++;
00244 }
00245 j++;
00246 }
00247 if ( (i<Len) && ((RowCount % RowToWait) == 0) )
00248 WaitKeyPress(MSG_PRESSKEY);
00249 }
00250 }
00251