Changeset 74 in kStuff
- Timestamp:
- Dec 21, 2015 12:40:51 AM (9 years ago)
- Location:
- hacks/xtide
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
hacks/xtide/atalib.c
r73 r74 43 43 uint16_t g_uBasePort; 44 44 uint16_t g_uCtrlPort; 45 uint 16_t g_uPortShift;45 uint8_t g_cPortShift; 46 46 uint8_t g_bDevice; 47 47 uint8_t g_fUseLbaMode = 1; … … 201 201 cb >>= 1; 202 202 203 if (f8BitData )203 if (f8BitData == 1) 204 204 { 205 205 while (cb-- > 0) … … 223 223 224 224 cb >>= 1; 225 if (f8BitData )225 if (f8BitData == 1) 226 226 { 227 227 while (cb-- > 0) … … 363 363 outp(ATA_REG_CYLINDER_HIGH(g_uBasePort), 0); 364 364 365 bSts = AtaSubmitCommandAndWaitForData(ATA_CMD_WRITE_ SECTORS);365 bSts = AtaSubmitCommandAndWaitForData(ATA_CMD_WRITE_BUFFER); 366 366 if (bSts & ATA_STS_ERR) 367 367 return AtaError(bSts, "writing buffer (#1)"); … … 466 466 /* Set the reset flat. */ 467 467 outp(ATA_REG_CONTROL(g_uBasePort), ATA_CTL_SRST); 468 /** @todo This still needs work - it doesn't work when ERR is set. */ 468 469 469 470 /* Wait for the busy flag response. */ 470 ATA_DELAY_400NS();471 ATA_DELAY_400NS();471 for (bSts = 0; bSts < 20; bSts++) 472 ATA_DELAY_400NS(); 472 473 while (!(bSts = inp(ATA_REG_STATUS(g_uBasePort))) & ATA_STS_BUSY) 473 474 ATA_DELAY_400NS(); … … 521 522 } 522 523 523 int AtaInit(uint16_t uBasePort, uint16_t uCtrlPort, uint8_t uPortShift, uint8_t bDevice, uint8_t f8BitData)524 int AtaInit(uint16_t uBasePort, uint16_t uCtrlPort, uint8_t cPortShift, uint8_t bDevice, uint8_t f8BitData) 524 525 { 525 526 int rc; … … 528 529 g_uBasePort = uBasePort; 529 530 g_uCtrlPort = uCtrlPort; 530 g_ uPortShift = uPortShift;531 g_cPortShift = cPortShift; 531 532 g_bDevice = bDevice; 532 533 g_f8BitData = f8BitData; … … 539 540 inp(ATA_REG_STATUS(g_uBasePort)); 540 541 bSts = inp(ATA_REG_STATUS(g_uBasePort)); 541 bStsAlt = inp(ATA_REG_ALT_STATUS(g_u BasePort));542 bStsAlt = inp(ATA_REG_ALT_STATUS(g_uCtrlPort)); 542 543 if (bSts != bStsAlt || bSts == 0xff) 543 544 { 544 545 fprintf(stderr, "Status register differs or is 0xff\n"); 545 fprintf(stderr, " status=");546 AtaPrintStatus(std out, bSts);546 fprintf(stderr, " port %#05x status=", ATA_REG_STATUS(g_uBasePort)); 547 AtaPrintStatus(stderr, bSts); 547 548 fprintf(stderr, "\n"); 548 fprintf(stderr, " alt status=");549 AtaPrintStatus(std out, bStsAlt);549 fprintf(stderr, " port %#05x alt status=", ATA_REG_ALT_STATUS(g_uCtrlPort)); 550 AtaPrintStatus(stderr, bStsAlt); 550 551 fprintf(stderr, "\n"); 551 552 return -1; … … 619 620 620 621 /* Figure 5-9 in SanDisk Manual Rev 12.0: */ 621 if ( (g_awIdentify[83] & UINT16_C(0xc00)) == UINT16_C(0x4000) 622 && (g_awIdentify[84] & UINT16_C(0xc00)) == UINT16_C(0x4000)) 622 printf("debug: word82=%#x word83=%#x word84=%#x\n", g_awIdentify[82], g_awIdentify[83], g_awIdentify[84]); 623 if ( g_awIdentify[82] != 0 && g_awIdentify[82] != UINT16_C(0xffff) 624 && g_awIdentify[83] != 0 && g_awIdentify[83] != UINT16_C(0xffff) 625 && g_awIdentify[84] != 0 && g_awIdentify[84] != UINT16_C(0xffff) 626 && (g_awIdentify[83] & UINT16_C(0xc000)) == UINT16_C(0x4000) 627 && (g_awIdentify[84] & UINT16_C(0xc000)) == UINT16_C(0x4000) ) 623 628 { 624 629 g_fSupportsWriteBuffer = (g_awIdentify[82] & UINT16_C(0x1000)) != 0; … … 628 633 g_fSupportsWriteBuffer == 1 ? "have" : g_fSupportsWriteBuffer == 0 ? "no" : "uncertain", 629 634 g_fSupportsReadBuffer == 1 ? "have" : g_fSupportsReadBuffer == 0 ? "no" : "uncertain"); 635 break; 630 636 } 631 637 … … 729 735 || strcmp(pszArg, "-8") == 0) 730 736 f8BitData = 1; 737 else if ( strcmp(pszArg, "--8-bit-data-plus") == 0 738 || strcmp(pszArg, "-8+") == 0) 739 f8BitData = 3; 731 740 else if ( strcmp(pszArg, "--16-bit-data") == 0 732 741 || strcmp(pszArg, "-16") == 0) 733 742 f8BitData = 0; 743 else if (strcmp(pszArg, "--ide") == 0) 744 { 745 /* Normal IDE, primary. */ 746 uBasePort = 0x1f0; 747 uCtrlPort = 0x3f0; 748 cShiftPort = 0; 749 f8BitData = 0; 750 } 751 else if (strcmp(pszArg, "--xt-cf") == 0) 752 { 753 /* Lo-tech CF-lite. */ 754 uBasePort = 0x300; 755 uCtrlPort = 0x310; 756 cShiftPort = 1; 757 f8BitData = 1; 758 } 734 759 } 735 760 -
hacks/xtide/atalib.h
r73 r74 29 29 30 30 /* The necessary I/O ports, indexed by "bus". */ 31 #define ATA_PORT_SHIFT 1/* For XT-CF trick */31 #define ATA_PORT_SHIFT (g_cPortShift) /* For XT-CF trick */ 32 32 #define ATA_REG_DATA(a_uBasePort) (a_uBasePort) 33 33 #define ATA_REG_FEATURES(a_uBasePort) ((a_uBasePort) + (1 << ATA_PORT_SHIFT)) -
hacks/xtide/atarwbuf.c
r73 r74 29 29 #include <io.h> 30 30 #include <conio.h> 31 #include <time.h> 31 32 32 33 #include "atalib.h" … … 40 41 int rc; 41 42 unsigned i; 43 uint32_t cSectors; 44 clock_t tsStart; 45 clock_t cTicksElapsed; 42 46 43 47 rc = AtaInitFromArgv(1, argc, argv); … … 64 68 } 65 69 70 /* 71 * Do some performance testing. 72 */ 73 /* read */ 74 cSectors = 0; 75 cTicksElapsed = clock(); 76 do 77 tsStart = clock(); 78 while (tsStart == cTicksElapsed); 79 do 80 { 81 rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/); 82 if (rc == 0) 83 rc = AtaReadBuffer(s_abBuf2, 0 /*fExtraChecks*/); 84 if (rc != 0) 85 return 1; 86 cSectors += 2; 87 cTicksElapsed = clock() - tsStart; 88 } while (cTicksElapsed < CLOCKS_PER_SEC * 2); 89 cSectors >>= 1; 90 printf("Read: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors); 91 92 /* write */ 93 cSectors = 0; 94 cTicksElapsed = clock(); 95 do 96 tsStart = clock(); 97 while (tsStart == cTicksElapsed); 98 do 99 { 100 rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/); 101 if (rc == 0) 102 rc = AtaWriteBuffer(s_abBuf1, 0 /*fExtraChecks*/); 103 if (rc != 0) 104 return 1; 105 cSectors += 2; 106 cTicksElapsed = clock() - tsStart; 107 } while (cTicksElapsed < CLOCKS_PER_SEC * 2); 108 cSectors >>= 1; 109 printf("Write: %lu bytes/sec (%u sec/s)\n", cSectors * 512, cSectors); 110 111 66 112 return 0; 67 113 } 68 114 69
Note:
See TracChangeset
for help on using the changeset viewer.