VirtualBox

Changeset 76 in kStuff for hacks/xtide/atalib.c


Ignore:
Timestamp:
Dec 28, 2015 1:37:00 AM (9 years ago)
Author:
bird
Message:

xtide-utils: ataid fixes. new delay method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hacks/xtide/atalib.c

    r75 r76  
    6262
    6363
     64uint16_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
     78uint8_t AtaReadPitCounter0Lsb(void);
     79#pragma aux AtaReadPitCounter0Lsb = \
     80    "in  al, 40h" \
     81    value [al] \
     82    modify exact [al];
     83
     84
     85void 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 */
     109void 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
    64133size_t AtaPrintStatus(FILE *pOut, uint8_t bSts)
    65134{
     
    465534
    466535    /* 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);
    468537/** @todo This still needs work - it doesn't work when ERR is set. */
    469538
    470539    /* Wait for the busy flag response. */
    471     for (bSts = 0; bSts < 20; bSts++)
    472         ATA_DELAY_400NS();
     540    ATA_DELAY_5US();
    473541    while (!(bSts = inp(ATA_REG_STATUS(g_uBasePort))) & ATA_STS_BUSY)
    474542        ATA_DELAY_400NS();
    475543
    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);
    478546    ATA_DELAY_400NS();
    479547
     
    495563    if (g_fSupportsSetFeature8BitData)
    496564    {
    497         if (g_f8BitData)
     565        if (g_f8BitData == 1 || g_f8BitData == 3)
    498566            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);
    499569        else
    500             rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0);
     570            rc = 0;
    501571        if (rc != 0)
    502572            return rc;
     
    567637        if (g_fSupportsSetFeature8BitData)
    568638        {
    569             if (g_f8BitData)
     639            if (g_f8BitData == 1 || g_f8BitData == 3)
    570640                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);
    571643            else
    572                 rc = AtaSetFeature(g_bDevice, ATA_FEATURE_DI_8BIT_DATA, 0);
     644                rc = 0;
    573645            if (rc != 0)
    574646            {
     
    619691        printf("Device %#x at %#x/%#x: %u cylinders, %u heads, %u sectors, %s data\n",
    620692               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");
    622694
    623695        /* Figure 5-9 in SanDisk Manual Rev 12.0: */
     
    743815                 || strcmp(pszArg, "-16") == 0)
    744816            f8BitData = 0;
     817        else if (strcmp(pszArg, "--16-bit-data-no-change") == 0)
     818            f8BitData = UINT8_MAX;
    745819        else if (strcmp(pszArg, "--reset") == 0)
    746820            fReset = 1;
    747821        else if (strcmp(pszArg, "--no-reset") == 0)
    748822            fReset = 0;
    749         else if (strcmp(pszArg, "--ide") == 0)
     823        else if (   strcmp(pszArg, "--ide") == 0
     824                 || strcmp(pszArg, "--ide-primary") == 0)
    750825        {
    751826            /* Normal IDE, primary. */
     
    753828            uCtrlPort  = 0x3f0;
    754829            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;
    756839        }
    757840        else if (strcmp(pszArg, "--xt-cf") == 0)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette