also @ TechSpot: 'Supercapacitor' could fully charge your phone in less than 30 seconds

Get HDD (SATA) identify data problem

Discussion in 'Software Apps' started by robinsuen, May 13, 2012.

Post New Reply
  1. robinsuen Newcomer, in training

    I want to get HDD(set as AHCI) identifydata 256 words,
    But still have problem. How to change the following program?
    Any help can be very appreciated.

    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<dos.h>
    #include<math.h>
    typedef unsigned char BYTE;
    typedef unsigned int WORD;
    typedef unsigned long DWORD;
    WORD wRevBuf[256];
    //----------------------------------------------------------
    //Get Sata Base address
    WORD getSataBase(BYTE bus, BYTE dev, BYTE fun, BYTE reg)
    {
    DWORD pciaddr;δΊ†)
    // bus:0 dev:31 fun:2, reg
    pciaddr = (1L << 31) + ((DWORD)bus << 16)+((DWORD)dev << 11)
    + ((WORD)fun << 8)+ (reg & 0xFC);
    asm {
    mov eax,pciaddr
    mov dx,0CF8h //config space control address
    out dx,eax
    mov dx,0CFCh //conf space data address
    in eax, dx
    }
    return _AX;
    }
    //----------------------------------------------------------
    //get 256 word from HDD verifydata
    void getHDD_VerifyData(void)
    {
    int I;
    WORD wBAR;
    wBAR = getSataBase(0, 0X1F, 2, 0x10) & 0xFFFE;
    //offset 10h, wBAR is 0xF0B0
    //offset 18h, wBAR is 0xF090
    //using Ru.exe, can know the wBAR result is right value.

    printf("wBAR: %08x\n", wBAR);


    //outportb(wBAR, 0);
    //outportb(wBAR+1, 0);
    //outportb(wBAR+2, 0);
    //outportb(wBAR+3, 0);
    //outportb(wBAR+4, 0);
    //outportb(wBAR+5, 0);
    //outportb(wBAR+6, 0xA0);
    outportb(wBAR+7, 0xEC);
    for (I=0; I<256; I++)
    wRevBuf = inport(wBAR);
    }
    //----------------------------------------------------------
    void main(int argc, char* argv[])
    {

    BYTE dat;
    /*
    printf("0x10 Addr: %08x\n", getSataBase(0, 0X1F, 2, 0x10));
    printf("0x14 Addr: %08x\n", getSataBase(0, 0X1F, 2, 0x14));
    printf("0x18 Addr: %08x\n", getSataBase(0, 0X1F, 2, 0x18));
    printf("0x1c Addr: %08x\n", getSataBase(0, 0X1F, 2, 0x1c));
    */
    getHDD_VerifyData();

    //display 256 word
    printf(" ");
    for (int I=0; I<16; I++)
    printf("%04X ", I);
    printf("\n");
    for (int y=0; y<16; y++)
    {
    if (y == 7) system("pause");
    printf("%02x ", y*16);
    for (int I=0; I<16; I++)
    {
    printf("%04X ", wRevBuf[y*16+I]);
    }
    printf("\n");
    }
    }