⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.cpp

📁 这是运行在windows ce 4.2 版本下的关于硬盘加载的驱动程序
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include <windows.h>
#include <debug.h>

#ifdef DEBUG
DBGPARAM dpCurSettings = {
    TEXT("ATAPI"), {
    TEXT("Init"),TEXT("Deinit"),TEXT("Main"),TEXT("I/O"),
    TEXT("PCMCIA"),TEXT("PCI"),TEXT("IOCTL"),TEXT("CDROM"),
    TEXT("DMA"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),
    TEXT("Warning"),TEXT("Error"),TEXT("Helper"), TEXT("Current") },
#if 1
    ZONEMASK_IOCTL | 
    ZONEMASK_DMA | 
    ZONEMASK_INIT | 
    ZONEMASK_HELPER | 
    ZONEMASK_DEINIT | 
    ZONEMASK_PCMCIA | 
    ZONEMASK_PCI | 
    ZONEMASK_MAIN | 
    ZONEMASK_IO | 
    ZONEMASK_CDROM | 
    ZONEMASK_ERROR |
    ZONEMASK_CURRENT |
//#else    
    ZONEMASK_ERROR |
    ZONEMASK_INIT
#endif    
};

void DumpRegKey( DWORD dwZone, PTSTR szKey, HKEY hKey)
{
    DWORD dwIndex=0;
    WCHAR szValueName[MAX_PATH];
    DWORD dwValueNameSize = MAX_PATH;
    BYTE pValueData[256];
    DWORD dwType;
    DWORD dwValueDataSize = sizeof(pValueData);
    DEBUGMSG( dwZone, (TEXT("Dumping registry for key %s \r\n"), szKey));
    while(ERROR_SUCCESS == RegEnumValue( hKey, dwIndex, szValueName, &dwValueNameSize, NULL, &dwType, pValueData, &dwValueDataSize)) {
        if (REG_SZ == dwType) {
            DEBUGMSG( dwZone, (TEXT("\t\t%s = %s\r\n"), szValueName, (LPWSTR)pValueData));
        } else
        if (REG_DWORD == dwType) {
            DEBUGMSG( dwZone, (TEXT("\t\t%s = %08X\r\n"), szValueName, *(PDWORD)pValueData));
        } else
        if (REG_MULTI_SZ == dwType) {
            PWSTR pValueTemp = (PWSTR)pValueData;
            DEBUGMSG( dwZone, (TEXT("\t\t%s :\r\n"), szValueName));
            while(*pValueTemp) {
                DEBUGMSG( dwZone, (TEXT("\t\t\t%s\r\n"), (LPWSTR)pValueTemp));
                pValueTemp += (wcslen(pValueTemp)+1);
            }
        }
        dwIndex++;
        dwValueDataSize = sizeof(pValueData);
        dwValueNameSize = MAX_PATH;
    }
}

static VOID FormatSBCS(PUCHAR p, PTSTR pT, DWORD len)
{
    while (len)
    {
        if ((*p > 0x20) && (*p < 0x7F))
        {
            *pT = (TCHAR)*p;
        }
        else
        {
            *pT = (TCHAR)'.';
        }
        pT++;
        p++;
        len--;
    }
    *pT = 0;        // Terminate the string
}       // FormatSBCS


void AtaPrintIdentify(IDENTIFY_DATA *pId)
{
    DWORD i;
    PUCHAR pCh ;
    
    TCHAR OutBuf[128];
    PTSTR pOut;
    PUSHORT tempS;
    UCHAR tempByte;
    ULONG j,k,n;
    TCHAR tch[100];
    
    i=n = sizeof(IDENTIFY_DATA);
    pOut = OutBuf;
    pCh = (PUCHAR) pId;
    pOut += wsprintf(pOut, TEXT("[%3d] "), (n-i));
    while (i) {
        if ((n-i)> 0){
                pOut = OutBuf;
            pOut += wsprintf(pOut, TEXT("[%3d] "), (n-i)/2);
        }
        k = (i < 16) ? i : 16;
        for (j = 0; j < k; j++) {
            pOut += wsprintf(pOut, TEXT("%2x "), pCh[j]);
        }
        if (k < 16) {           // align last line
            for (j = 0; j < 16 - k; j++) {
                pOut += wsprintf(pOut, TEXT("   "));
            }
        }
        for (j = 0; j < k; j++) {
            if ((pCh[j] < ' ') || (pCh[j] > '~')) {
                pOut += wsprintf(pOut, TEXT("."));
            } else {
                pOut += wsprintf(pOut, TEXT("%c"), pCh[j]);
            }
        }
        DEBUGMSG( ZONE_INIT, (TEXT("%s\r\n"), OutBuf));
        
        i -= k;
        pCh += k;
    }
    DEBUGMSG( ZONE_INIT, (TEXT("ATDISK: Identify Data -\r\n")));
    
    DEBUGMSG( ZONE_INIT, (TEXT("General configuration = %x\r\n"),pId->GeneralConfiguration ));
    
    //
    // Byte flip model number, revision, and serial number string.
    //
    tempS = pId->ModelNumber;
    for (k=0; k<20; k++) {
        tempByte = (UCHAR)(tempS[k] & 0x00FF);
        tempS[k] = tempS[k] >> 8;
        tempS[k] |= tempByte << 8;
    }
    
    tempS = pId->FirmwareRevision;
    for (k=0; k<4; k++) {
        tempByte = (UCHAR)(tempS[k] & 0x00FF);
        tempS[k] = tempS[k] >> 8;
        tempS[k] |= tempByte << 8;
    }
    
    tempS = pId->SerialNumber;
    for (k=0; k<10; k++) {
        tempByte = (UCHAR)(tempS[k] & 0x00FF);
        tempS[k] = tempS[k] >> 8;
        tempS[k] |= tempByte << 8;
    }

    FormatSBCS((PUCHAR)&pId->SerialNumber[0], tch, 20);
    DEBUGMSG( ZONE_INIT, (TEXT("Serial number: %s\r\n"), tch));
    
    if (pId->BufferType == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer type unspecified\r\n")));
    }
    if (pId->BufferType == 1) {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer type single port - no simultaneous transfer\r\n")));
    }
    if (pId->BufferType == 2) {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer type dual port - simultaneous transfer capable\r\n")));
    }
    if (pId->BufferType == 3) {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer type dual port - simultaneous transfer capable - read cache\r\n")));
    }
    if (pId->BufferType >= 4) {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer type reserved\r\n")));
    }
    if (pId->BufferSectorSize == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Unspecified buffer size\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Buffer size in sectors: %d\r\n"),pId->BufferSectorSize));
    }
    if (pId->NumberOfEccBytes == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Number of Ecc bytes is unspecified\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Number of Ecc bytes or r/w long: %d\r\n"),pId->NumberOfEccBytes));
    }
    
    FormatSBCS((PUCHAR)&pId->FirmwareRevision[0], tch, 8);
    DEBUGMSG( ZONE_INIT, (TEXT("Firmware revision: %s\r\n"), tch));
    FormatSBCS((PUCHAR)&pId->ModelNumber[0], tch, 40);
    DEBUGMSG( ZONE_INIT, (TEXT("Model number: %s\r\n"), tch));
    
    if (pId->MaximumBlockTransfer == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Read/Write multiple not implmeneted\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Maximum sectors/interrupt on read/write multiple: %d\r\n"), pId->MaximumBlockTransfer));
    }   
    if (pId->DoubleWordIo == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Can not perform double word IO\r\n")));
    } else if (pId->DoubleWordIo == 1) {
        DEBUGMSG( ZONE_INIT, (TEXT("Can perform double word IO\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Unknown doubleword specifier\r\n")));
    }
    
    if (pId->Capabilities & 0x0200) {
        DEBUGMSG( ZONE_INIT, (TEXT("LBA mode supported\r\n")));

    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("LBA mode NOT supported\r\n")));
    }
    
    if (pId->Capabilities & 0x0100) {
        DEBUGMSG( ZONE_INIT, (TEXT("DMA supported\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("DMA NOT supported\r\n")));
    }
    
    DEBUGMSG( ZONE_INIT, (TEXT("PIO cycle timing mode: %x\r\n"),pId->PioCycleTimingMode));
    DEBUGMSG( ZONE_INIT, (TEXT("DMA cycle timing mode: %x\r\n"),pId->DmaCycleTimingMode));
    
    if ((pId->TranslationFieldsValid & 1) == 0) {
        DEBUGMSG( ZONE_INIT, (TEXT("Current size fields MAY be valid\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Current size fields ARE valid\r\n")));
    }
    
    DEBUGMSG( ZONE_INIT, (TEXT("Current number of cylinders: %d\r\n"), pId->NumberOfCurrentCylinders));
    
    DEBUGMSG( ZONE_INIT, (TEXT("Current number of heads: %d\r\n"), pId->NumberOfCurrentHeads));
    DEBUGMSG( ZONE_INIT, (TEXT("Current number of sectors/track: %d\r\n"), pId->CurrentSectorsPerTrack));
    DEBUGMSG( ZONE_INIT, (TEXT("Current sector capacity: %d\r\n"), pId->CurrentSectorCapacity));
    DEBUGMSG( ZONE_INIT, (TEXT("Sectors per interrupt with r/w multiple: %d\r\n"), pId->MultiSectorCount));
    if (pId->MultiSectorSettingValid & 1) {
        DEBUGMSG( ZONE_INIT, (TEXT("Multi sector setting valid\r\n")));
    } else {
        DEBUGMSG( ZONE_INIT, (TEXT("Multi sector setting is INVALID\r\n")));
    }
    DEBUGMSG( ZONE_INIT, (TEXT("Total user addressable sectors: %d\r\n"), pId->TotalUserAddressableSectors));
    DEBUGMSG( ZONE_INIT, (TEXT("Single word dma modes supported: %x\r\n"), pId->SingleDmaModesSupported));
    DEBUGMSG( ZONE_INIT, (TEXT("Single word transfer mode active: %x\r\n"), pId->SingleDmaTransferActive));
    DEBUGMSG( ZONE_INIT, (TEXT("Multi word dma modes supported: %x\r\n"), pId->MultiDmaModesSupported));

    DEBUGMSG( ZONE_INIT, (TEXT("Ultra dma modes supported: %x\r\n"), pId-> UltraDMASupport));

    DEBUGMSG( ZONE_INIT, (TEXT("Ultra dma transfer mode active: %x\r\n"), pId-> UltraDMAActive));   

    DEBUGMSG( ZONE_INIT, (TEXT("MediaStatusNotification: %x\r\n"), pId-> MediaStatusNotification)); // 126

    DEBUGMSG( ZONE_INIT, (TEXT("ATAPI Version Number: %ld.%ld\r\n"), pId->MajorVersionNumber, pId->MinorVersionNumber));

    DEBUGMSG( ZONE_INIT, (TEXT("Security Status: %04X\r\n"), pId->SecurityStatus));

    DEBUGMSG( ZONE_INIT, (TEXT("CFAPowerMode1: %04X\r\n"), pId->CFAPowerMode1));

    DEBUGMSG( ZONE_INIT, (TEXT("ATDISK:ATAIssueIdentify done\r\n")));
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -