1.1 --- a/test/testide.c Wed Dec 20 11:24:16 2006 +0000
1.2 +++ b/test/testide.c Thu Dec 21 10:14:24 2006 +0000
1.5 - * $Id: testide.c,v 1.3 2006-12-20 11:24:16 nkeynes Exp $
1.6 + * $Id: testide.c,v 1.4 2006-12-21 10:14:24 nkeynes Exp $
1.8 * IDE interface test cases. Covers all (known) IDE registers in the
1.9 * 5F7000 - 5F74FF range including DMA, but does not cover any GD-Rom
1.11 #define IDE_COMMAND IDE_BASE+0x09C
1.12 #define IDE_ACTIVATE IDE_BASE+0x4E4
1.14 +#define IDE_DISC IDE_LBA0
1.15 #define IDE_DEVCONTROL IDE_ALTSTATUS
1.16 #define IDE_ERROR IDE_FEATURE
1.17 #define IDE_STATUS IDE_COMMAND
1.19 { IDE_ALTSTATUS, 0x58,
1.27 { IDE_ALTSTATUS, 0xD0,
1.36 IDE_STATUS, 0x50, 0, 0 };
1.38 -int send_packet_command( char *cmd )
1.39 +int send_packet_command( const char *cmd )
1.41 unsigned short *spkt = (unsigned short *)cmd;
1.43 @@ -187,12 +186,92 @@
1.47 +int read_pio( char *buf, int expected_length ) {
1.48 + uint32_t ready_regs[] = {
1.49 + IDE_ALTSTATUS, 0x58,
1.52 + IDE_LBA1, expected_length & 0xFF,
1.53 + IDE_LBA2, (expected_length >> 8),
1.59 + unsigned short *bufptr = (unsigned short *)buf;
1.60 + unsigned int length = 0, avail;
1.63 + CHECK_REGS( ready_regs );
1.64 + for( i=0; i<expected_length; i+=2 ) {
1.65 + *bufptr++ = word_read(IDE_DATA);
1.70 + ready_regs[1] = 0x50;
1.71 + ready_regs[5] = 0x03;
1.72 + ready_regs[13] = 0x50;
1.73 + CHECK_REGS( ready_regs );
1.77 +#define IDE_TEST_PACKET_OK( c,e,l ) if( ide_test_packet_ok( __FILE__, __LINE__, __func__, c, e, l ) != 0 ) { return -1; }
1.78 +int ide_test_packet_ok( const char *file, int line, const char *func,
1.79 + const char *cmd, char *expect, int expect_len )
1.81 + char buf[expect_len];
1.82 + int status = send_packet_command(cmd);
1.83 + if( status != 0 ) {
1.86 + status = byte_read( IDE_ALTSTATUS );
1.87 + if( status & 1 ) { /* Error */
1.88 + status = ide_get_sense_code();
1.89 + fprintf( stderr, "Assertion failed at %s:%d %s(): Unexpected error %04X\n",
1.90 + file, line, func, status );
1.94 + status = read_pio( buf, expect_len );
1.95 + if( status != 0 ) {
1.98 + if( expect != NULL && memcmp( expect, buf, expect_len ) != 0 ) {
1.99 + fprintf(stderr, "Assertion failed at %s:%d %s(): Results differ from expected:\n",file,line,func );
1.100 + fwrite_diff( stderr, expect, expect_len, buf, expect_len );
1.106 +#define IDE_TEST_PACKET_ERROR( c,e ) if( ide_test_packet_error( __FILE__, __LINE__, __func__, c, e ) != 0 ) { return -1; }
1.107 +int ide_test_packet_error( char *file, int line, char *func,
1.108 + char *cmd, int expect_error )
1.110 + uint32_t error_regs[] =
1.111 + { IDE_ALTSTATUS, 0x51,
1.112 + IDE_ERROR, (expect_error & 0x0F)<<4,
1.115 + IDE_STATUS, 0x51, 0, 0 };
1.116 + uint32_t error_code;
1.117 + int status = send_packet_command(cmd);
1.118 + if( status != 0 ) {
1.121 + CHECK_REGS(error_regs);
1.122 + error_code = ide_get_sense_code();
1.123 + CHECK_IEQUALS( expect_error, error_code );
1.129 uint32_t abort_regs[] = {
1.130 IDE_ALTSTATUS, 0x51,
1.137 @@ -204,7 +283,6 @@
1.138 IDE_ALTSTATUS, 0x00,
1.145 @@ -216,7 +294,6 @@
1.146 IDE_ALTSTATUS, 0x50,
1.153 @@ -228,7 +305,6 @@
1.154 IDE_ALTSTATUS, 0x50,
1.161 @@ -236,6 +312,8 @@
1.165 +/************************** Interface Tests *******************************/
1.168 * Test enable/disable of the IDE interface via port
1.170 @@ -352,13 +430,14 @@
1.171 CHECK_REGS( packet_data_ready_regs );
1.172 *spkt++ = word_read(IDE_DATA);
1.173 *spkt++ = word_read(IDE_DATA);
1.174 - CHECK_REGS( post_packet_data_regs );
1.175 +// CHECK_REGS( post_packet_data_regs );
1.178 CHECK_REGS( packet_complete_regs );
1.180 if( memcmp( result, expect_ident, 12 ) != 0 ) {
1.181 fwrite_diff( stderr, expect_ident, 12, result, 12 );
1.186 @@ -387,10 +466,62 @@
1.190 +/***************************** GD-Rom Tests **********************************/
1.192 +int test_read_toc()
1.194 + char cmd[12] = { 0x14,0,0,0x00, 0x0C,0,0,0, 0,0,0,0 };
1.195 + char expect[12] = { 0x41, 0,0, 0x96, 0x41, 0, 0x2E, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF };
1.197 + IDE_TEST_PACKET_OK( cmd, expect, 12 );
1.202 + * Test interaction of Read CD (0x30) with Status (0x40,1)
1.204 +int test_status1()
1.206 + char cmd[12] = { 0x40, 0x01, 0, 0, 16,0,0,0, 0,0,0,0 };
1.207 + char read1cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4C, 0, 0, 0, 0, 0,1,0 };
1.208 + char expect1[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,1,0,0, 0x2E,0x4D,0,0 };
1.209 + char read2cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4D, 0, 0, 0, 0, 0,1,0 };
1.210 + char expect2[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,4,0,0, 0x2E,0x50,0,0 };
1.211 + char read3cmd[12] = { 0x30, 0x28, 0, 0x2E, 0x4E, 0, 0, 0, 0, 0,1,0 };
1.212 + char expect3[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,5,0,0, 0x2E,0x51,0,0 };
1.213 + char expect4[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,2,0,0, 0x2E,0x4E,0,0 };
1.214 + char read5cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x01, 0, 0, 0, 0, 0,1,0 };
1.215 + char expect5[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0,0xB6,0,0, 0x2F,0x02,0,0 };
1.216 + char read6cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x50, 0, 0, 0, 0, 0,1,0 };
1.217 + char expect6[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0x01,0x05,0,0, 0x2F,0x51,0,0 };
1.218 + char read7cmd[12] = { 0x30, 0x28, 0, 0x2F, 0x51, 0, 0, 0, 0, 0,1,0 };
1.219 + char expect7[16] = { 0,0x15,0,0x0E, 0x41,2,1,0, 0x01,0x06,0,0, 0x2F,0x52,0,0 };
1.222 + IDE_TEST_PACKET_OK(read1cmd, NULL, 2048);
1.223 + IDE_TEST_PACKET_OK(cmd, expect1, 14 );
1.224 + IDE_TEST_PACKET_OK(read2cmd, NULL, 2048);
1.225 + IDE_TEST_PACKET_OK(cmd, expect2, 14 );
1.226 + IDE_TEST_PACKET_OK(read3cmd, NULL, 2048);
1.227 + IDE_TEST_PACKET_OK(cmd, expect3, 14 );
1.228 + IDE_TEST_PACKET_OK(read2cmd, NULL, 2048);
1.229 + IDE_TEST_PACKET_OK(cmd, expect4, 14 );
1.230 + IDE_TEST_PACKET_OK(read5cmd, NULL, 2048);
1.231 + IDE_TEST_PACKET_OK(cmd, expect5, 14 );
1.232 + IDE_TEST_PACKET_OK(read6cmd, NULL, 2048);
1.233 + IDE_TEST_PACKET_OK(cmd, expect6, 14 );
1.238 +/********************************* Main **************************************/
1.240 typedef int (*test_func_t)();
1.242 test_func_t test_fns[] = { test_enable, test_reset, test_packet,
1.243 - test_dma, test_dma_abort, NULL };
1.244 + test_dma, test_dma_abort,
1.246 + test_status1, NULL };
1.250 @@ -401,6 +532,7 @@
1.251 for( i=0; test_fns[i] != NULL; i++ ) {
1.253 if( test_fns[i]() != 0 ) {
1.254 + fprintf( stderr, "Test %d failed\n", i+1 );