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

📄 dm_edit.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 4 页
字号:
    // Display memory.
    memoryDump();
}

/*----------------------------------------------------------------------
 * Scroll lower in memory - This function is called directly from the menu system.
 */

void DM_LowerMemory(void *funcP, char *arg)
{
    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Backup memory pointer.
    viewAddrP -= dumpLength/2;
    // Display memory.
    memoryDump();
}

/*----------------------------------------------------------------------
 * Scroll write in memory - This function is called directly from the menu system.
 */

void DM_WriteMemory(void *funcP, char *arg)
{
    UINT32 paMem;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Check parameters.
    if (!GetParameters(arg, MemEditWrite))
    {
        // Ask user for address.
        printf("Enter address: 0x");
        viewAddrP = (PUINT32)GetHex(8, 52);
        // Ask user for value.
        printf("Enter value: 0x");
        writeValue = GetHex(memoryWidth/4, (43 + memoryWidth/4));
    }

    // Check if this is a valid address
    if (!VirtualToPhysical((PVOID)viewAddrP, (PUINT32)&paMem))
    {
        switch (memoryWidth)
        {
            case 8:    // 8-bits.
            {
                // Get address.
                PUINT8 vaMem8P = (PUINT8)viewAddrP;
                // Store value.
                *vaMem8P = (UINT8)writeValue;
                break;
            }
            
            case 16:   // 16-bits.
            {
                // Get address.
                PUINT16 vaMem16P = (PUINT16)viewAddrP;
                // Store value.
                *vaMem16P = (UINT16)writeValue;
                break;
            }
            case 32:   // 32-bits.
                // Store value.
                *viewAddrP = writeValue;
                break;
        }
    }

    // Display memory.
    memoryDump();
}

/*----------------------------------------------------------------------
 * Set length of memory - This function is called directly from the menu system.
 */

void DM_LengthMemory(void *funcP, char *arg)
{
    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    printf("Dump length value = 0x%X\r\n", dumpLength);

    // Check parameters.
    if (!GetParameters(arg, MemEditLength))
    {
        // Ask user for length.
        printf("Enter number of bytes: 0x");
        dumpLength = GetHex(8, 56);
    }

    printf("New dump length value = 0x%X\r\n", dumpLength);
}

/*----------------------------------------------------------------------
 * Fill memory - This function is called directly from the menu system.
 */

void DM_FillMemory(void *funcP, char *arg)
{
    UINT32 paMem;
    PVOID memP;
    PUINT32 defFlashP = NULL;
    PUINT32 altFlashP = NULL;
    BOOL writeDefFlash = FALSE;
    BOOL writeAltFlash = FALSE;
    UINT32 block;
    UINT32 count;
    UINT status;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Check parameters.
    if (!GetParameters(arg, MemEditFill))
    {
        // Ask user for address.
        printf("Enter fill address: 0x");
        viewAddrP = (PUINT32)GetHex(8, 55);
        // Ask user for fill length.
        printf("Enter fill length: 0x");
        fillLength = GetHex(8, 54);
        // Ask user for value.
        printf("Enter value: 0x");
        writeValue = GetHex(memoryWidth/4, (43 + memoryWidth/4));
    }

    // Get virtual address of flash.
    PhysicalToVirtual(BOARD_BOOT_FLASH_BASE, 0, (PVOID)&defFlashP);
    PhysicalToVirtual(BOARD_APP_FLASH_BASE, 0, (PVOID)&altFlashP);

    // Check if request to write to the default flash.
    if (((UINT)viewAddrP >= (UINT)defFlashP) &&
        ((UINT)viewAddrP < ((UINT)defFlashP + 0x02000000)))
    {
        // Set flag indicating flash destination.
        writeDefFlash = TRUE;
    }

    // Check if request to write to the default flash.
    if (((UINT)viewAddrP >= (UINT)altFlashP) &&
        ((UINT)viewAddrP < ((UINT)altFlashP + 0x02000000)))
    {
        // Set flag indicating flash destination.
        writeAltFlash = TRUE;
    }

    if (writeDefFlash || writeAltFlash)
    {
        memP = (PUINT)0x70480000;
    }
    else
    {
        memP = viewAddrP;
    }

    // Check if this is a valid address
    if ((!VirtualToPhysical((PVOID)memP, (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)((UINT)memP + fillLength), (PUINT32)&paMem)))
    {
        // Fill memory with the specified value.
        memset(memP, writeValue, fillLength);

        // Check if request to write to flash
        if (writeDefFlash || writeAltFlash)
        {
            // Calculate the number of blocks to write.
            count = fillLength/512 + 1;

            if (writeDefFlash)
            {
                // Get pointer to flash DCS.
                flashCtxP = &contexts[Flash_Default_Index];
                // Setup the flash driver.
                status = flashCtxP->FlashHWSetupFnP(flashCtxP);
                // Calculate block number.
                block = ((UINT)viewAddrP - (UINT)defFlashP) / 512;
                // Write block to flash.
                status = flashCtxP->FlashWriteFnP(flashCtxP,
                                                  block,
                                                  (PCHAR)memP,
                                                  count);
                // Shutdown the flash driver.
                flashCtxP->FlashHWShutdownFnP(flashCtxP);
            }
            else
            {
                // Get pointer to flash DCS.
                flashCtxP = &contexts[Flash_Alternate_Index];
                // Setup the flash driver.
                status = flashCtxP->FlashHWSetupFnP(flashCtxP);
                // Calculate block number.
                block = ((UINT)viewAddrP - (UINT)altFlashP) / 512;
                // Write block to flash.
                status = flashCtxP->FlashWriteFnP(flashCtxP,
                                                  block,
                                                  (PCHAR)memP,
                                                  count);
                // Shutdown the flash driver.
                flashCtxP->FlashHWShutdownFnP(flashCtxP);
            }
        }

        // Display memory.
        memoryDump();
    }
    else
    {
        printf("Invalid address: %08x\r\n", (UINT32)memP);
    }
}

/*----------------------------------------------------------------------
 * Copy memory - This function is called directly from the menu system.
 */

void DM_CopyMemory(void *funcP, char *arg)
{
    UINT32 paMem;
    PUINT32 defFlashP = NULL;
    PUINT32 altFlashP = NULL;
    BOOL writeDefFlash = FALSE;
    BOOL writeAltFlash = FALSE;
    UINT32 block;
    UINT32 count;
    UINT status;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Check parameters.
    if (!GetParameters(arg, MemEditCopy))
    {
        // Ask user for address.
        printf("Enter source address: 0x");
        srcAddrP = (PCHAR)GetHex(8, 56);
        printf("Enter destination address: 0x");
        destAddrP = (PCHAR)GetHex(8, 58);
        // Ask user for copy length.
        printf("Enter copy length: 0x");
        copyLength = GetHex(8, 54);
    }

    // Get virtual address of flash.
    PhysicalToVirtual(BOARD_BOOT_FLASH_BASE, 0, (PVOID)&defFlashP);
    PhysicalToVirtual(BOARD_APP_FLASH_BASE, 0, (PVOID)&altFlashP);

    // Check if request to write to the default flash.
    if (((UINT)destAddrP >= (UINT)defFlashP) &&
        ((UINT)destAddrP < ((UINT)defFlashP + 0x02000000)))
    {
        // Set flag indicating flash destination.
        writeDefFlash = TRUE;
    }

    // Check if request to write to the default flash.
    if (((UINT)destAddrP >= (UINT)altFlashP) &&
        ((UINT)destAddrP < ((UINT)altFlashP + 0x02000000)))
    {
        // Set flag indicating flash destination.
        writeAltFlash = TRUE;
    }

    // Check if this is a valid address
    if ((!VirtualToPhysical((PVOID)srcAddrP, (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)((UINT)srcAddrP + copyLength), (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)destAddrP, (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)((UINT)destAddrP + copyLength), (PUINT32)&paMem)))
    {
        // Check if destination is flash.
        if (!writeDefFlash && !writeAltFlash)
        {
            // Copy the block.
            memcpy(destAddrP, srcAddrP, copyLength);
        }

        // Update the pointer to display.
        viewAddrP = (PUINT32)destAddrP;

        // Check if request to write to flash
        if (writeDefFlash || writeAltFlash)
        {
            // Calculate the number of blocks to write.
            count = fillLength/512 + 1;

            if (writeDefFlash)
            {
                // Get pointer to flash DCS.
                flashCtxP = &contexts[Flash_Default_Index];
                // Setup the flash driver.
                status = flashCtxP->FlashHWSetupFnP(flashCtxP);
                // Calculate block number.
                block = ((UINT)destAddrP - (UINT)defFlashP) / 512;
                // Write block to flash.
                status = flashCtxP->FlashWriteFnP(flashCtxP,
                                                  block,
                                                  (PCHAR)srcAddrP,
                                                  count);
                // Shutdown the flash driver.
                flashCtxP->FlashHWShutdownFnP(flashCtxP);
            }
            else
            {
                // Get pointer to flash DCS.
                flashCtxP = &contexts[Flash_Alternate_Index];
                // Setup the flash driver.
                status = flashCtxP->FlashHWSetupFnP(flashCtxP);
                // Calculate block number.
                block = ((UINT)destAddrP - (UINT)altFlashP) / 512;
                // Write block to flash.
                status = flashCtxP->FlashWriteFnP(flashCtxP,
                                                  block,
                                                  (PCHAR)srcAddrP,
                                                  count);
                // Shutdown the flash driver.
                flashCtxP->FlashHWShutdownFnP(flashCtxP);
            }
        }

        // Display memory.
        memoryDump();
    }
    else
    {
        printf("Invalid address: %08x\r\n", (UINT32)destAddrP);
    }
}

/*----------------------------------------------------------------------
 * Compare memory - This function is called directly from the menu system.
 */

void DM_CompareMemory(void *funcP, char *arg)
{
    UINT32 paMem;
    PVOID memP;
    UINT x;

    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    // Check parameters.
    if (!GetParameters(arg, MemEditCompare))
    {
        // Ask user for address.
        printf("Enter source address: 0x");
        srcAddrP = (PCHAR)GetHex(8, 56);
        printf("Enter destination address: 0x");
        destAddrP = (PCHAR)GetHex(8, 58);
        // Ask user for copy length.
        printf("Enter compare length: 0x");
        compareLength = GetHex(8, 56);
    }

    // Check for valid addresses.
    if ((!VirtualToPhysical((PVOID)srcAddrP, (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)((UINT)srcAddrP + compareLength), (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)destAddrP, (PUINT32)&paMem)) &&
        (!VirtualToPhysical((PVOID)((UINT)destAddrP + compareLength), (PUINT32)&paMem)))
    {
        // Save pointer to destination.
        memP = destAddrP;

        // Compare the block.
        for (x = 0; x < compareLength; srcAddrP++, destAddrP++, x++)
        {
            if (*srcAddrP != *destAddrP)
            {
                printf("Mismatch at %08x/%02x and %08x/%02x\r\n",
                       (UINT32)srcAddrP, *srcAddrP, (UINT32)destAddrP, *destAddrP);
                break;
            }
        }

        if (x == compareLength)
        {
            printf("No difference found!\r\n");
        }
        // Update the pointer to display.
        viewAddrP = (PUINT32)memP;

        // Display memory.
        memoryDump();
    }
    else
    {
        printf("Invalid address: source: %08x destination: %08x\r\n",
               (UINT32)srcAddrP, (UINT32)destAddrP);
    }
}

void DM_WidthMemory(void *menuP, char *arg)
{
    // Disable the menus from being displayed.
    gMenuEnabled = FALSE;

    printf("Memory width = %d bits\r\n", memoryWidth);

    // Check parameters.

⌨️ 快捷键说明

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