Changeset 76 in kStuff for hacks/xtide/atalib.c
- Timestamp:
- Dec 28, 2015 1:37:00 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hacks/xtide/atalib.c
r75 r76 62 62 63 63 64 uint16_t AtaReadPitCounter0(void); 65 #pragma aux AtaReadPitCounter0 = \ 66 "pushf" \ 67 "cli" \ 68 "mov al, 4" /* chan0, latch access[, mode 2, 16-bit] */ \ 69 "out 43h, al" \ 70 "in al, 40h" \ 71 "mov ah, al" \ 72 "in al, 40h" \ 73 "xchg ah, al" \ 74 "popf" \ 75 value [ax] \ 76 modify exact [ax]; 77 78 uint8_t AtaReadPitCounter0Lsb(void); 79 #pragma aux AtaReadPitCounter0Lsb = \ 80 "in al, 40h" \ 81 value [al] \ 82 modify exact [al]; 83 84 85 void AtaDelayMicroSecs(uint8_t cMicroSecs) 86 { 87 /* 88 * ASSUME PIT chan 0 is not in mode 3 and running at 18Hz (reload 64K). 89 * 90 * ASSUME we won't be spending too many microsecs here, so we won't do 91 * an extremely accurate job converting PIT ticks to microseconds. Given 92 * the frequency of 1193182 HZ, that is a period of 838ns, we count each 93 * PIT tick as a microsecond but adding a leap period every 8 rounds 94 * (should've been 6, but 8 is cheaper to calculate). 95 */ 96 uint16_t uPrev = AtaReadPitCounter0(); 97 uint16_t const cTicksNeeded = cMicroSecs + (cMicroSecs >> 3); 98 uint32_t cTicksElapsed = 0; 99 while (cTicksElapsed < cTicksNeeded) 100 { 101 uint16_t uNow = AtaReadPitCounter0(); 102 cTicksElapsed += uPrev - uNow; 103 uPrev = uNow; 104 } 105 } 106 107 108 #if 0 /* currently implemented as inline assembly */ 109 void AtaDelayPitTicks(uint8_t cTicks) 110 { 111 /* 112 * ASSUME PIT channel 0 is in mode 2. 113 * ASSUME PIT channel 0 is in LSB read mode. 114 * ASSUME PIT channel 0 is reloading a multiple of 256. 115 * ASSUME PIT channel 0 is not currently latched. 116 * ASSUME PIT channel 0 is in binary mode (not BCD). 117 */ 118 uint8_t uPrev = AtaReadPitCounter0Lsb(); 119 for (;;) 120 { 121 uint8_t uNow = AtaReadPitCounter0Lsb(); 122 uint8_t cElapsed = uPrev - uNow; 123 if (cElapsed >= cTicks) 124 break; 125 cElapsed -= cTicks; 126 uPrev = uNow; 127 } 128 } 129 #endif 130 131 132 64 133 size_t AtaPrintStatus(FILE *pOut, uint8_t bSts) 65 134 { … … 465 534 466 535 /* Set the reset flat. */ 467 outp(ATA_REG_CONTROL(g_uBasePort), ATA_CTL_SRST );536 outp(ATA_REG_CONTROL(g_uBasePort), ATA_CTL_SRST | ATA_CTL_IEN); 468 537 /** @todo This still needs work - it doesn't work when ERR is set. */ 469 538 470 539 /* Wait for the busy flag response. */ 471 for (bSts = 0; bSts < 20; bSts++) 472 ATA_DELAY_400NS(); 540 ATA_DELAY_5US(); 473 541 while (!(bSts = inp(ATA_REG_STATUS(g_uBasePort))) & ATA_STS_BUSY) 474 542 ATA_DELAY_400NS(); 475 543 476 /* Clear the reset flag . */477 outp(ATA_REG_CONTROL(g_uBasePort), 0);544 /* Clear the reset flag, keeping ints disabled. */ 545 outp(ATA_REG_CONTROL(g_uBasePort), ATA_CTL_IEN); 478 546 ATA_DELAY_400NS(); 479 547 … … 495 563 if (g_fSupportsSetFeature8BitData) 496 564 { 497 if (g_f8BitData )565 if (g_f8BitData == 1 || g_f8BitData == 3) 498 566 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_EN_8BIT_DATA, 0); 567 else if (g_f8BitData == 0) 568 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0); 499 569 else 500 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0);570 rc = 0; 501 571 if (rc != 0) 502 572 return rc; … … 567 637 if (g_fSupportsSetFeature8BitData) 568 638 { 569 if (g_f8BitData )639 if (g_f8BitData == 1 || g_f8BitData == 3) 570 640 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_EN_8BIT_DATA, 0); 641 else if (g_f8BitData == 0) 642 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0); 571 643 else 572 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0);644 rc = 0; 573 645 if (rc != 0) 574 646 { … … 619 691 printf("Device %#x at %#x/%#x: %u cylinders, %u heads, %u sectors, %s data\n", 620 692 g_bDevice, g_uBasePort, g_uCtrlPort, g_cCylinders, g_cHeads, g_cSectorsPerTrack, 621 g_f8BitData ? "8-bit" : "16-bit");693 g_f8BitData == 1 ? "8-bit" : g_f8BitData == 3 ? "8/16-bit" : g_f8BitData == 0 ? "16-bit(!)" : "16-bit"); 622 694 623 695 /* Figure 5-9 in SanDisk Manual Rev 12.0: */ … … 743 815 || strcmp(pszArg, "-16") == 0) 744 816 f8BitData = 0; 817 else if (strcmp(pszArg, "--16-bit-data-no-change") == 0) 818 f8BitData = UINT8_MAX; 745 819 else if (strcmp(pszArg, "--reset") == 0) 746 820 fReset = 1; 747 821 else if (strcmp(pszArg, "--no-reset") == 0) 748 822 fReset = 0; 749 else if (strcmp(pszArg, "--ide") == 0) 823 else if ( strcmp(pszArg, "--ide") == 0 824 || strcmp(pszArg, "--ide-primary") == 0) 750 825 { 751 826 /* Normal IDE, primary. */ … … 753 828 uCtrlPort = 0x3f0; 754 829 cShiftPort = 0; 755 f8BitData = 0; 830 f8BitData = UINT8_MAX; 831 } 832 else if (strcmp(pszArg, "--ide-secondary") == 0) 833 { 834 /* Normal IDE, secondary. */ 835 uBasePort = 0x170; 836 uCtrlPort = 0x370; 837 cShiftPort = 0; 838 f8BitData = UINT8_MAX; 756 839 } 757 840 else if (strcmp(pszArg, "--xt-cf") == 0)
Note:
See TracChangeset
for help on using the changeset viewer.