Changeset 74 for hacks/xtide/atalib.c


Ignore:
Timestamp:
Dec 21, 2015, 1:40:51 AM (10 years ago)
Author:
bird
Message:

xtide util hacking, included bios patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hacks/xtide/atalib.c

    r73 r74  
    4343uint16_t g_uBasePort;
    4444uint16_t g_uCtrlPort;
    45 uint16_t g_uPortShift;
     45uint8_t  g_cPortShift;
    4646uint8_t  g_bDevice;
    4747uint8_t  g_fUseLbaMode = 1;
     
    201201    cb >>= 1;
    202202
    203     if (f8BitData)
     203    if (f8BitData == 1)
    204204    {
    205205        while (cb-- > 0)
     
    223223
    224224    cb >>= 1;
    225     if (f8BitData)
     225    if (f8BitData == 1)
    226226    {
    227227        while (cb-- > 0)
     
    363363    outp(ATA_REG_CYLINDER_HIGH(g_uBasePort),    0);
    364364
    365     bSts = AtaSubmitCommandAndWaitForData(ATA_CMD_WRITE_SECTORS);
     365    bSts = AtaSubmitCommandAndWaitForData(ATA_CMD_WRITE_BUFFER);
    366366    if (bSts & ATA_STS_ERR)
    367367        return AtaError(bSts, "writing buffer (#1)");
     
    466466    /* Set the reset flat. */
    467467    outp(ATA_REG_CONTROL(g_uBasePort), ATA_CTL_SRST);
     468/** @todo This still needs work - it doesn't work when ERR is set. */
    468469
    469470    /* 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();
    472473    while (!(bSts = inp(ATA_REG_STATUS(g_uBasePort))) & ATA_STS_BUSY)
    473474        ATA_DELAY_400NS();
     
    521522}
    522523
    523 int AtaInit(uint16_t uBasePort, uint16_t uCtrlPort, uint8_t uPortShift, uint8_t bDevice, uint8_t f8BitData)
     524int AtaInit(uint16_t uBasePort, uint16_t uCtrlPort, uint8_t cPortShift, uint8_t bDevice, uint8_t f8BitData)
    524525{
    525526    int rc;
     
    528529    g_uBasePort  = uBasePort;
    529530    g_uCtrlPort  = uCtrlPort;
    530     g_uPortShift = uPortShift;
     531    g_cPortShift = cPortShift;
    531532    g_bDevice    = bDevice;
    532533    g_f8BitData  = f8BitData;
     
    539540    inp(ATA_REG_STATUS(g_uBasePort));
    540541    bSts    = inp(ATA_REG_STATUS(g_uBasePort));
    541     bStsAlt = inp(ATA_REG_ALT_STATUS(g_uBasePort));
     542    bStsAlt = inp(ATA_REG_ALT_STATUS(g_uCtrlPort));
    542543    if (bSts != bStsAlt || bSts == 0xff)
    543544    {
    544545        fprintf(stderr, "Status register differs or is 0xff\n");
    545         fprintf(stderr, "     status=");
    546         AtaPrintStatus(stdout, bSts);
     546        fprintf(stderr, " port %#05x    status=", ATA_REG_STATUS(g_uBasePort));
     547        AtaPrintStatus(stderr, bSts);
    547548        fprintf(stderr, "\n");
    548         fprintf(stderr, " alt status=");
    549         AtaPrintStatus(stdout, bStsAlt);
     549        fprintf(stderr, " port %#05x alt status=", ATA_REG_ALT_STATUS(g_uCtrlPort));
     550        AtaPrintStatus(stderr, bStsAlt);
    550551        fprintf(stderr, "\n");
    551552        return -1;
     
    619620
    620621        /* 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))
     622printf("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) )
    623628        {
    624629            g_fSupportsWriteBuffer = (g_awIdentify[82] & UINT16_C(0x1000)) != 0;
     
    628633               g_fSupportsWriteBuffer == 1 ? "have" : g_fSupportsWriteBuffer == 0 ? "no" : "uncertain",
    629634               g_fSupportsReadBuffer  == 1 ? "have" : g_fSupportsReadBuffer  == 0 ? "no" : "uncertain");
     635        break;
    630636    }
    631637
     
    729735                 || strcmp(pszArg, "-8") == 0)
    730736            f8BitData = 1;
     737        else if (   strcmp(pszArg, "--8-bit-data-plus") == 0
     738                 || strcmp(pszArg, "-8+") == 0)
     739            f8BitData = 3;
    731740        else if (   strcmp(pszArg, "--16-bit-data") == 0
    732741                 || strcmp(pszArg, "-16") == 0)
    733742            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        }
    734759    }
    735760
Note: See TracChangeset for help on using the changeset viewer.