VirtualBox

Changeset 76 in kStuff


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

xtide-utils: ataid fixes. new delay method.

Location:
hacks/xtide
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • hacks/xtide/ataid.c

    r75 r76  
    4545
    4646
     47static void AtaPrintIdString(const char *pszPrefix, uint16_t const *pawStr, unsigned cWords, const char *pszSuffix)
     48{
     49    unsigned i;
     50
     51    fputs(pszPrefix, stdout);
     52
     53    putchar('\'');
     54    for (i = 0; i < cWords; i++)
     55    {
     56        int j;
     57        for (j = 8; j >= 0; j -= 8)
     58        {
     59            uint8_t b = (uint8_t)(pawStr[i] >> j);
     60            if (b < UINT8_C(0x7f) || b >= UINT8_C(0x20))
     61                putchar(b);
     62            else
     63                printf("\\x%02x", b);
     64        }
     65    }
     66    putchar('\'');
     67
     68    fputs(pszSuffix, stdout);
     69}
     70
     71
    4772int main(int argc, char **argv)
    4873{
     
    5984     */
    6085    /* Word[0]: */
    61     printf("[0]=%#06x", g_awIdentify[0]);
    62     if ((g_awIdentify[0] >> 7) & 1)
    63         fputs(" removable-media", stdout);
    64     if ((g_awIdentify[0] >> 6) & 1)
    65         fputs(" not-removable", stdout);
    66     if ((g_awIdentify[0] >> 2) & 1)
    67         fputs(" bit2-maybe-incomplete!", stdout);
    68     if ((g_awIdentify[0] >> 15) & 1)
    69         fputs(" not-ATA-device!", stdout);
    70     putchar('\n');
    71 
    72     printf("[  1]=%#06x - obsolete logical cylinders         %d\n", g_awIdentify[1], g_awIdentify[1]);
    73     printf("[  2]=%#06x (reserved / vendor specific)\n", g_awIdentify[2]);
    74     printf("[  3]=%#06x - obsolete logical heads             %d\n", g_awIdentify[3], g_awIdentify[3]);
    75     printf("[  4]=%#06x - vendor specific / retired\n", g_awIdentify[4]);
    76     printf("[  5]=%#06x - vendor specific / retired\n", g_awIdentify[5]);
    77     printf("[  6]=%#06x - obsolete logical sectors per track %d\n", g_awIdentify[6], g_awIdentify[6]);
    78     printf("[  7]=%#06x - vendor specific / reserved for CompactFlash\n", g_awIdentify[7]);
    79     printf("[  8]=%#06x - vendor specific / reserved for CompactFlash\n", g_awIdentify[8]);
    80     printf("[  9]=%#06x - vendor specific / retired\n", g_awIdentify[9]);
    81     printf("[ 10:19]     - serial number     '%.20s'\n", &g_awIdentify[10]);
    82     printf("[ 20]=%#06x - vendor specific / obsolete\n", g_awIdentify[20]);
    83     printf("[ 21]=%#06x - vendor specific / obsolete\n", g_awIdentify[21]);
    84     printf("[ 22]=%#06x - obsolete ECC/vendor bytes for READ/WRITE LONG %d\n", g_awIdentify[22], g_awIdentify[22]);
    85     printf("[ 23:26]     - firmware revision '%.8s'\n", &g_awIdentify[23]);
    86     printf("[ 27:46]     - model number      '%.40s'\n", &g_awIdentify[27]);
    87 
    88     printf("[ 47]=%#06x - READ/WRITE MULTIPLE ", g_awIdentify[47]);
    89     if ((g_awIdentify[47] & 0xff) == 0)
     86    i = 0;
     87    printf("[%3u]=%#06x", i, g_awIdentify[i]);
     88    if ((g_awIdentify[i] >> 7) & 1)     fputs(" removable-media", stdout);
     89    if ((g_awIdentify[i] >> 6) & 1)     fputs(" not-removable", stdout);
     90    if ((g_awIdentify[i] >> 2) & 1)     fputs(" bit2-maybe-incomplete!", stdout);
     91    if ((g_awIdentify[i] >> 15) & 1)    fputs(" not-ATA-device!", stdout);
     92    putchar('\n');
     93
     94    i = 1; printf("[%3u]=%#06x - obsolete logical cylinders:         %d\n", i, g_awIdentify[i], g_awIdentify[i]);
     95    i = 2; printf("[%3u]=%#06x (reserved / vendor specific)\n",             i, g_awIdentify[i]);
     96    i = 3; printf("[%3u]=%#06x - obsolete logical heads:             %d\n", i, g_awIdentify[i], g_awIdentify[i]);
     97    i = 4; printf("[%3u]=%#06x (vendor specific / retired)\n",              i, g_awIdentify[i]);
     98    i = 5; printf("[%3u]=%#06x (vendor specific / retired)\n",              i, g_awIdentify[i]);
     99    i = 6; printf("[%3u]=%#06x - obsolete logical sectors per track: %d\n", i, g_awIdentify[i], g_awIdentify[i]);
     100    i = 7; printf("[%3u]=%#06x (vendor specific / reserved for CompactFlash)\n", i, g_awIdentify[i]);
     101    i = 8; printf("[%3u]=%#06x (vendor specific / reserved for CompactFlash)\n", i, g_awIdentify[i]);
     102    i = 9; printf("[%3u]=%#06x (vendor specific / retired)\n",              i, g_awIdentify[i]);
     103    i = 10; AtaPrintIdString("[ 10:19]     - serial number:        ", &g_awIdentify[i], 10, "\n");
     104    i = 20; printf("[%3u]=%#06x (vendor specific / obsolete)\n",            i, g_awIdentify[i]);
     105    i = 21; printf("[%3u=%#06x (vendor specific / obsolete)\n",             i, g_awIdentify[i]);
     106    i = 22; printf("[=%#06x - obsolete ECC/vendor bytes for READ/WRITE LONG %d\n", i, g_awIdentify[i], g_awIdentify[i]);
     107    i = 23; AtaPrintIdString("[ 23:26]     - firmware revision:    ", &g_awIdentify[i], 4, "\n");
     108    i = 27; AtaPrintIdString("[ 27:46]     - model number:         ", &g_awIdentify[i], 20, "\n");
     109
     110    i = 47; printf("[%3u]=%#06x - READ/WRITE MULTIPLE ",                    i, g_awIdentify[i]);
     111    if ((g_awIdentify[i] & 0xff) == 0)
    90112        fputs("not implemented", stdout);
    91     else if ((g_awIdentify[47] & 0xff) == 0)
     113    else
    92114        printf("max %d sectors", g_awIdentify[47] & 0xff);
    93     if ((g_awIdentify[47] >> 8) == 0x80)
     115    if ((g_awIdentify[i] >> 8) == 0x80)
    94116        fputs(", ATA-4 top value", stdout);
    95117    else
     
    97119    putchar('\n');
    98120
    99     printf("[ 48]=%#06x - trusted computing group bits ", g_awIdentify[48]);
    100     if ((g_awIdentify[48] & UINT16_C(0xc001)) == UINT16_C(0x4001))
    101         printf("%#x\n", g_awIdentify[48] & UINT16_C(0x3ffe));
     121    i = 48; printf("[%3u]=%#06x - trusted computing group bits ",           i, g_awIdentify[i]);
     122    if ((g_awIdentify[i] & UINT16_C(0xc001)) == UINT16_C(0x4001))
     123        printf("%#x\n", g_awIdentify[i] & UINT16_C(0x3ffe));
    102124    else
    103125        fputs("not present\n", stdout);
    104126
    105     printf("[ 49]=%#06x - capabilities:", g_awIdentify[49]);
    106     if (g_awIdentify[49] & UINT16_C(0x0100))
    107         fputs(" DMA", stdout);
    108     if (g_awIdentify[49] & UINT16_C(0x0200))
    109         fputs(" LBA", stdout);
    110     if (g_awIdentify[49] & UINT16_C(0x0400))
    111         fputs(" IORDY-disable", stdout);
    112     if (g_awIdentify[49] & UINT16_C(0x0800))
    113         fputs(" IORDY-supported", stdout);
    114     if (g_awIdentify[49] & UINT16_C(0x1000))
    115         fputs(" rsvd12", stdout);
    116     if (g_awIdentify[49] & UINT16_C(0x2000))
    117         fputs(" ata2-standby-timer", stdout);
    118     if (g_awIdentify[49] & UINT16_C(0x4000))
    119         fputs(" rsvd14", stdout);
    120     if (g_awIdentify[49] & UINT16_C(0x8000))
    121         fputs(" rsvd15", stdout);
    122     if (g_awIdentify[49] & UINT16_C(0x00ff))
    123         printf(" vendor07=%#x", g_awIdentify[49] & UINT16_C(0x00ff));
    124     putchar('\n');
    125 
    126     printf("[ 50]=%#06x - capabilities:", g_awIdentify[50]);
    127     if ((g_awIdentify[50] & UINT16_C(0xc000)) == UINT16_C(0x4000))
    128     {
    129         if (g_awIdentify[50] & 1)
    130             fputs(" vendor-standby-timer-min", stdout);
    131         if (g_awIdentify[50] & 2)
    132             fputs(" obsolete1", stdout);
    133         if (g_awIdentify[50] & UINT16_C(0x3ffc))
    134             printf(" reserved=%#x", g_awIdentify[50] & UINT16_C(0x3ffc));
     127    i = 49; printf("[%3u]=%#06x - capabilities:",                           i, g_awIdentify[i]);
     128    if (g_awIdentify[i] & UINT16_C(0x0100))     fputs(" DMA", stdout);
     129    if (g_awIdentify[i] & UINT16_C(0x0200))     fputs(" LBA", stdout);
     130    if (g_awIdentify[i] & UINT16_C(0x0400))     fputs(" IORDY-disable", stdout);
     131    if (g_awIdentify[i] & UINT16_C(0x0800))     fputs(" IORDY-supported", stdout);
     132    if (g_awIdentify[i] & UINT16_C(0x1000))     fputs(" rsvd12", stdout);
     133    if (g_awIdentify[i] & UINT16_C(0x2000))     fputs(" ata2-standby-timer", stdout);
     134    if (g_awIdentify[i] & UINT16_C(0x4000))     fputs(" rsvd14", stdout);
     135    if (g_awIdentify[i] & UINT16_C(0x8000))     fputs(" rsvd15", stdout);
     136    if (g_awIdentify[i] & UINT16_C(0x00ff))     printf(" vendor07=%#x", g_awIdentify[i] & UINT16_C(0x00ff));
     137    putchar('\n');
     138
     139    i = 50; printf("[%3u]=%#06x - capabilities:",                           i, g_awIdentify[i]);
     140    if ((g_awIdentify[i] & UINT16_C(0xc000)) == UINT16_C(0x4000))
     141    {
     142        if (g_awIdentify[i] & 1)                fputs(" vendor-standby-timer-min", stdout);
     143        if (g_awIdentify[i] & 2)                fputs(" obsolete1", stdout);
     144        if (g_awIdentify[i] & UINT16_C(0x3ffc)) printf(" reserved=%#x", g_awIdentify[i] & UINT16_C(0x3ffc));
    135145        putchar('\n');
    136146    }
     
    161171    printf(" free-fall-sensitivity=%#x\n", g_awIdentify[53] >> 8);
    162172
    163     printf("[ 54]=%#06x - obsolete current logical cylinders         %d", g_awIdentify[54]);
     173    i = 54; printf("[%3u]=%#06x - obsolete current logical cylinders         %d", i, g_awIdentify[i], g_awIdentify[i]);
    164174    if (g_awIdentify[54] > 16383)
    165175        fputs(" (high!)", stdout);
    166176    putchar('\n');
    167177
    168     printf("[ 55]=%#06x - obsolete current logical heads             %d", g_awIdentify[55]);
     178    i = 55; printf("[%3u]=%#06x - obsolete current logical heads             %d", i, g_awIdentify[i], g_awIdentify[i]);
    169179    if (g_awIdentify[55] > 16)
    170180        fputs(" (high!)", stdout);
    171181    putchar('\n');
    172182
    173     printf("[ 56]=%#06x - obsolete current logical sectors per track %d", g_awIdentify[56]);
     183    i = 56; printf("[%3u]=%#06x - obsolete current logical sectors per track %d", i, g_awIdentify[i], g_awIdentify[i]);
    174184    if (g_awIdentify[56] > 63)
    175185        fputs(" (high!)", stdout);
     
    229239    printf("[ 67]=%#06x - minimum PIO cycle time without IORDY               %d ns\n", g_awIdentify[67], g_awIdentify[67]);
    230240    printf("[ 68]=%#06x - minimum PIO cycle time with IORDY                  %d ns\n", g_awIdentify[68], g_awIdentify[68]);
    231     printf("[ 69]=%#06x - reserved\n", g_awIdentify[69]);
    232     printf("[ 70]=%#06x - reserved\n", g_awIdentify[70]);
    233     printf("[ 71]=%#06x - reserved for identify packet device\n", g_awIdentify[71]);
    234     printf("[ 72]=%#06x - reserved for identify packet device\n", g_awIdentify[72]);
    235     printf("[ 73]=%#06x - reserved for identify packet device\n", g_awIdentify[73]);
    236     printf("[ 74]=%#06x - reserved for identify packet device\n", g_awIdentify[74]);
     241    printf("[ 69]=%#06x (reserved)\n", g_awIdentify[69]);
     242    printf("[ 70]=%#06x (reserved)\n", g_awIdentify[70]);
     243    printf("[ 71]=%#06x (reserved for identify packet device)\n", g_awIdentify[71]);
     244    printf("[ 72]=%#06x (reserved for identify packet device)\n", g_awIdentify[72]);
     245    printf("[ 73]=%#06x (reserved for identify packet device)\n", g_awIdentify[73]);
     246    printf("[ 74]=%#06x (reserved for identify packet device)\n", g_awIdentify[74]);
    237247
    238248    printf("[ 75]=%#06x - queue depth %d", g_awIdentify[75], (g_awIdentify[75] & 0x1f) + 1);
     
    263273        fputs(" probably not SATA\n", stdout);
    264274
    265     printf("[ 77]=%#06x - reserved for SATA\n", g_awIdentify[77]);
     275    printf("[ 77]=%#06x (reserved for SATA)\n", g_awIdentify[77]);
    266276
    267277    printf("[ 78]=%#06x - SATA features supported: ", g_awIdentify[78]);
     
    315325            if (g_awIdentify[80] & (UINT16_C(0x0001) << i))
    316326                printf(" ata%u", i);
     327        putchar('\n');
    317328    }
    318329    else
    319330        fputs(" not specified\n", stdout);
    320331
    321     printf("[ 81]=%#06x - Minor version number: %d", g_awIdentify[81], g_awIdentify[81]);
     332    printf("[ 81]=%#06x - Minor version number: %d\n", g_awIdentify[81], g_awIdentify[81]);
    322333
    323334    printf("[ 82]=%#06x - Supports: ", g_awIdentify[82]);
    324     if (g_awIdentify[82] & UINT16_C(0x0001))    fputs(" smart", stdout);
    325     if (g_awIdentify[82] & UINT16_C(0x0002))    fputs(" security", stdout);
    326     if (g_awIdentify[82] & UINT16_C(0x0004))    fputs(" obsolete2", stdout);
    327     if (g_awIdentify[82] & UINT16_C(0x0008))    fputs(" mand-power-management", stdout);
    328     if (!(g_awIdentify[82] & UINT16_C(0x0010))) fputs(" no-packet", stdout);
    329     if (g_awIdentify[82] & UINT16_C(0x0020))    fputs(" volatile-write-cache", stdout);
    330     if (g_awIdentify[82] & UINT16_C(0x0040))    fputs(" look-ahead", stdout);
    331     if (g_awIdentify[82] & UINT16_C(0x0080))    fputs(" release-intr", stdout);
    332     if (g_awIdentify[82] & UINT16_C(0x0100))    fputs(" service-intr", stdout);
    333     if (!(g_awIdentify[82] & UINT16_C(0x0200))) fputs(" no-device-reset", stdout);
    334     if (g_awIdentify[82] & UINT16_C(0x0400))    fputs(" hpa", stdout);
    335     if (g_awIdentify[82] & UINT16_C(0x0800))    fputs(" obsolete11", stdout);
    336     if (g_awIdentify[82] & UINT16_C(0x1000))    fputs(" write-buffer", stdout);
    337     if (g_awIdentify[82] & UINT16_C(0x2000))    fputs(" read-buffer", stdout);
    338     if (g_awIdentify[82] & UINT16_C(0x4000))    fputs(" nop", stdout);
    339     if (g_awIdentify[82] & UINT16_C(0x8000))    fputs(" obsolete15", stdout);
    340     putchar('\n');
     335    if ((g_awIdentify[83] & UINT16_C(0xc000)) == UINT16_C(0x4000)) /* yes, 83; see 7.16.7.38 in ata8. */
     336    {
     337        if (g_awIdentify[82] & UINT16_C(0x0001))    fputs(" smart", stdout);
     338        if (g_awIdentify[82] & UINT16_C(0x0002))    fputs(" security", stdout);
     339        if (g_awIdentify[82] & UINT16_C(0x0004))    fputs(" obsolete2", stdout);
     340        if (g_awIdentify[82] & UINT16_C(0x0008))    fputs(" mand-power-management", stdout);
     341        if (!(g_awIdentify[82] & UINT16_C(0x0010))) fputs(" no-packet", stdout);
     342        if (g_awIdentify[82] & UINT16_C(0x0020))    fputs(" volatile-write-cache", stdout);
     343        if (g_awIdentify[82] & UINT16_C(0x0040))    fputs(" look-ahead", stdout);
     344        if (g_awIdentify[82] & UINT16_C(0x0080))    fputs(" release-intr", stdout);
     345        if (g_awIdentify[82] & UINT16_C(0x0100))    fputs(" service-intr", stdout);
     346        if (!(g_awIdentify[82] & UINT16_C(0x0200))) fputs(" no-device-reset", stdout);
     347        if (g_awIdentify[82] & UINT16_C(0x0400))    fputs(" hpa", stdout);
     348        if (g_awIdentify[82] & UINT16_C(0x0800))    fputs(" obsolete11", stdout);
     349        if (g_awIdentify[82] & UINT16_C(0x1000))    fputs(" write-buffer", stdout);
     350        if (g_awIdentify[82] & UINT16_C(0x2000))    fputs(" read-buffer", stdout);
     351        if (g_awIdentify[82] & UINT16_C(0x4000))    fputs(" nop", stdout);
     352        if (g_awIdentify[82] & UINT16_C(0x8000))    fputs(" obsolete15", stdout);
     353        putchar('\n');
     354    }
     355    else
     356        fputs(" not specified\n", stdout);
    341357
    342358    printf("[ 83]=%#06x - Supports: ", g_awIdentify[83]);
     
    470486    printf("[ 92]=%#06x - master password ID:      %d\n", g_awIdentify[92], g_awIdentify[92]);
    471487
    472     printf("[ 93]=%#06x - hardware reset result:", g_awIdentify[92], g_awIdentify[92]);
     488    printf("[ 93]=%#06x - hardware reset result:", g_awIdentify[93], g_awIdentify[93]);
    473489    if ((g_awIdentify[93] & UINT16_C(0xc000)) == UINT16_C(0x4000))
    474490    {
     
    509525           *(uint64_t *)&g_awIdentify[100], *(uint64_t *)&g_awIdentify[100]);
    510526    printf("[104]=%#06x - streaming transfer time, PIO:      %d\n", g_awIdentify[104], g_awIdentify[104]);
    511     printf("[105]=%#06x - reserved\n", g_awIdentify[105]);
     527    printf("[105]=%#06x (reserved)\n", g_awIdentify[105]);
    512528    if ((g_awIdentify[106] & UINT16_C(0xc000)) == UINT16_C(0x4000))
    513529    {
     
    523539
    524540    printf("[107]=%#06x - Inter-seek delay for acoustic testing\n", g_awIdentify[107]);
    525     printf("[108:111]    - World wide name:     %#llx\n", *(uint64_t *)&g_awIdentify[107]);
     541    printf("[108:111]    - World wide name:     %#llx\n", *(uint64_t *)&g_awIdentify[108]);
    526542    for (i = 112; i <= 116; i++)
    527         printf("[%u]=%#06x - reserved\n", i, g_awIdentify[i]);
     543        printf("[%u]=%#06x (reserved)\n", i, g_awIdentify[i]);
    528544    printf("[117:118]    - Logical sector size: %lu bytes (%#lx)\n",
    529545           *(uint32_t *)&g_awIdentify[117], *(uint32_t *)&g_awIdentify[117]);
     
    531547        printf("[%u]=%#06x - todo\n", i, g_awIdentify[i]);
    532548    for (i = 121; i <= 126; i++)
    533         printf("[%u]=%#06x - reserved\n", i, g_awIdentify[i]);
     549        printf("[%u]=%#06x (reserved)\n", i, g_awIdentify[i]);
    534550    printf("[127]=%#06x - obsolete\n", g_awIdentify[127]);
    535551    printf("[128]=%#06x - security status - todo\n", g_awIdentify[128]);
     
    538554    printf("[160]=%#06x - CFA power mode - todo\n", g_awIdentify[160]);
    539555    for (i = 161; i <= 167; i++)
    540         printf("[%u]=%#06x - reserved for CompactFlash guys\n", i, g_awIdentify[i]);
    541     printf("[168]=%#06x - Device nominal form factor - todo\n", g_awIdentify[160]);
     556        printf("[%u]=%#06x (reserved for the CompactFlash guys)\n", i, g_awIdentify[i]);
     557    printf("[168]=%#06x - Device nominal form factor - todo\n", g_awIdentify[168]);
    542558    for (i = 169; i <= 175; i++)
    543         printf("[%u]=%#06x - reserved\n", i, g_awIdentify[i]);
    544     printf("[176:205]    - current media string: '%.60s'\n", i, &g_awIdentify[176]);
     559        printf("[%u]=%#06x (reserved)\n", i, g_awIdentify[i]);
     560    AtaPrintIdString("[176:205]    - current media string: ", &g_awIdentify[176], 30, "\n");
    545561    printf("[206]=%#06x - SCT command transport - todo\n", g_awIdentify[206]);
    546     printf("[207]=%#06x - reserved for CE-ATA - todo\n", g_awIdentify[207]);
    547     printf("[208]=%#06x - reserved for CE-ATA - todo\n", g_awIdentify[208]);
    548     printf("[209]=%#06x - logical block alignment - todo\n", g_awIdentify[206]);
     562    printf("[207]=%#06x (reserved for CE-ATA)\n", g_awIdentify[207]);
     563    printf("[208]=%#06x (reserved for CE-ATA)\n", g_awIdentify[208]);
     564    printf("[209]=%#06x - logical block alignment - todo\n", g_awIdentify[209]);
    549565    printf("[210:211]    - Write-Read-Verify sector count mode 3: %lu (%#lx)\n",
    550566           *(uint32_t *)&g_awIdentify[210], *(uint32_t *)&g_awIdentify[210]);
     
    555571           *(uint32_t *)&g_awIdentify[215], *(uint32_t *)&g_awIdentify[215]);
    556572    printf("[217]=%#06x - Nominal media rotation rate: %u\n", g_awIdentify[217], g_awIdentify[217]);
    557     printf("[218]=%#06x - reserved\n", g_awIdentify[218]);
     573    printf("[218]=%#06x (reserved)\n", g_awIdentify[218]);
    558574    printf("[219]=%#06x - NV cache options - todo\n", g_awIdentify[219]);
    559575    printf("[220]=%#06x - Current write-read-verify mode - todo\n", g_awIdentify[220]);
    560     printf("[221]=%#06x - reserved\n", g_awIdentify[221]);
     576    printf("[221]=%#06x (reserved)\n", g_awIdentify[221]);
    561577    printf("[222]=%#06x - Transport major version number - todo\n", g_awIdentify[222]);
    562578    printf("[223]=%#06x - Transport minor version number: %u\n", g_awIdentify[223], g_awIdentify[223]);
    563579    for (i = 224; i <= 233; i++)
    564         printf("[%u]=%#06x - reserved for CE-ATA\n", i, g_awIdentify[i]);
     580        printf("[%u]=%#06x (reserved for CE-ATA)\n", i, g_awIdentify[i]);
    565581    printf("[234]=%#06x - Min 512 bytes blocks per download microcode mode 3: %u\n", g_awIdentify[234], g_awIdentify[234]);
    566582    printf("[235]=%#06x - Max 512 bytes blocks per download microcode mode 3: %u\n", g_awIdentify[235], g_awIdentify[235]);
    567583    for (i = 236; i <= 254; i++)
    568         printf("[%u]=%#06x - reserved\n", i, g_awIdentify[i]);
     584        printf("[%u]=%#06x (reserved)\n", i, g_awIdentify[i]);
    569585
    570586    printf("[255]=%#06x - Integrity word: ", g_awIdentify[255]);
  • 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)
  • hacks/xtide/atalib.h

    r75 r76  
    103103#define ATA_FV_XFERMODE_MWDMA_MODE_XXX_FLAG          UINT8_C(0x20)
    104104
     105
     106#define ATA_PIT_FREQ                        UINT32_C(1193182)
     107void AtaDelayPitTicks(uint8_t cTicks);
     108#pragma aux AtaDelayPitTicks = \
     109    "pushf" \
     110    "cli" \
     111    "in     al, 40h" \
     112    "mov    ch, al" /* ch = prev */ \
     113 "again:" \
     114    "nop" \
     115    "in     al, 40h" \
     116    "sub    ch, al" /* ch = ticks elapsed */ \
     117    "sub    cl, ch" /* check if ticks left is <= ticks elapsed; update ticks left. */ \
     118    "mov    ch, al" /* ch = prev tick count */ \
     119    "ja     again" \
     120    "popf" \
     121    parm [cl] \
     122    modify exact [ax cx];
     123
    105124/** Delay a bit by reading PIC mask. Should take 4-5 bus cycles,
    106125 * and thus be more than the required 400ns delay on old computers. */
    107 #define ATA_DELAY_400NS()   do { inp(0x21); } while (0)
     126#if 0
     127# define ATA_DELAY_400NS()   do { inp(0x21); } while (0)
     128# define ATA_DELAY_5US()     \
     129    do { ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); \
     130         ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); \
     131         ATA_DELAY_400NS(); ATA_DELAY_400NS(); ATA_DELAY_400NS(); \
     132    } while (0)
     133#else
     134# define ATA_DELAY_400NS()   AtaDelayPitTicks(1)
     135# define ATA_DELAY_5US()     AtaDelayPitTicks(6)
     136#endif
     137
    108138
    109139extern uint16_t g_cHeads;
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