Example #1
0
void CFlashram::DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len)
{
    uint8_t FlipBuffer[0x10000];

    switch (m_FlashFlag)
    {
    case FLASHRAM_MODE_READ:
        if (!m_File.IsOpen() && !LoadFlashram())
        {
            return;
        }
        if (len > sizeof(FlipBuffer))
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: DmaFromFlashram FlipBuffer to small (len: %d)", __FUNCTION__, len).c_str());
            }
            len = sizeof(FlipBuffer);
        }
        if ((len & 3) != 0)
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: Unaligned flash ram read ???", __FUNCTION__).c_str());
            }
            return;
        }
        memset(FlipBuffer, 0, sizeof(FlipBuffer));
        StartOffset = StartOffset << 1;
        m_File.Seek(StartOffset, CFile::begin);
        m_File.Read(FlipBuffer, len);

        for (int32_t count = m_File.GetLength(); count < len; count++)
        {
            FlipBuffer[count] = 0xFF;
        }

        for (int32_t count = 0; count < len; count += 4)
        {
            *(uint32_t *)(dest + count) = *(uint32_t *)&FlipBuffer[count];
        }
        break;
    case FLASHRAM_MODE_STATUS:
        if (StartOffset != 0 && len != 8)
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: Reading m_FlashStatus not being handled correctly\nStart: %X len: %X", __FUNCTION__, StartOffset, len).c_str());
            }
        }
        *((uint32_t *)(dest)+0) = (uint32_t)((m_FlashStatus >> 32) & 0xFFFFFFFF);
        *((uint32_t *)(dest)+1) = (uint32_t)(m_FlashStatus & 0xFFFFFFFF);
        break;
    default:
        if (bHaveDebugger())
        {
            g_Notify->DisplayError(stdstr_f("%s: Start: %X, Offset: %X len: %X", __FUNCTION__, dest - g_MMU->Rdram(), StartOffset, len).c_str());
        }
    }
}
Example #2
0
void CFlashram::DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len)
{
    uint8_t FlipBuffer[0x10000];
    uint32_t count;

    switch (m_FlashFlag)
    {
    case FLASHRAM_MODE_READ:
        if (m_hFile == NULL)
        {
            if (!LoadFlashram())
            {
                return;
            }
        }
        if (len > 0x10000)
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: DmaFromFlashram FlipBuffer to small (len: %d)", __FUNCTION__, len).c_str());
            }
            len = 0x10000;
        }
        if ((len & 3) != 0)
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: Unaligned flash ram read ???", __FUNCTION__).c_str());
            }
            return;
        }
        memset(FlipBuffer, 0, sizeof(FlipBuffer));
        StartOffset = StartOffset << 1;
        SetFilePointer(m_hFile, StartOffset, NULL, FILE_BEGIN);
        DWORD dwRead;
        ReadFile(m_hFile, FlipBuffer, len, &dwRead, NULL);
        for (count = dwRead; (int32_t)count < len; count++)
        {
            FlipBuffer[count] = 0xFF;
        }

        for (count = 0; (int32_t)count < len; count += 4)
        {
            register uint32_t eax;

            eax = *(uint32_t *)&FlipBuffer[count];
            //	eax = swap32by8(eax); // ; bswap eax
            *(uint32_t *)(dest + count) = eax;
        }
        break;
    case FLASHRAM_MODE_STATUS:
        if (StartOffset != 0 && len != 8)
        {
            if (bHaveDebugger())
            {
                g_Notify->DisplayError(stdstr_f("%s: Reading m_FlashStatus not being handled correctly\nStart: %X len: %X", __FUNCTION__, StartOffset, len).c_str());
            }
        }
        *((uint32_t *)(dest)) = (uint32_t)((m_FlashStatus >> 32) & 0xFFFFFFFF);
        *((uint32_t *)(dest)+1) = (uint32_t)(m_FlashStatus & 0xFFFFFFFF);
        break;
    default:
        if (bHaveDebugger())
        {
            g_Notify->DisplayError(stdstr_f("%s: Start: %X, Offset: %X len: %X", __FUNCTION__, dest - g_MMU->Rdram(), StartOffset, len).c_str());
        }
    }
}
Example #3
0
void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
{
    uint8_t EmptyBlock[128];
    DWORD dwWritten;

    switch (FlashRAM_Command & 0xFF000000)
    {
    case 0xD2000000:
        switch (m_FlashFlag)
        {
        case FLASHRAM_MODE_NOPES: break;
        case FLASHRAM_MODE_READ: break;
        case FLASHRAM_MODE_STATUS: break;
        case FLASHRAM_MODE_ERASE:
            memset(EmptyBlock, 0xFF, sizeof(EmptyBlock));
            if (m_hFile == NULL) {
                if (!LoadFlashram())
                {
                    return;
                }
            }
            SetFilePointer(m_hFile, m_FlashRAM_Offset, NULL, FILE_BEGIN);
            WriteFile(m_hFile, EmptyBlock, 128, &dwWritten, NULL);
            break;
        case FLASHRAM_MODE_WRITE:
            if (m_hFile == NULL) {
                if (!LoadFlashram())
                {
                    return;
                }
            }
            {
                uint8_t FlipBuffer[128];
                register size_t edx;
                uint8_t * FlashRamPointer = m_FlashRamPointer;

                memset(FlipBuffer, 0, sizeof(FlipBuffer));
                for (edx = 0; edx < 128; edx += 4)
                {
                    register uint32_t eax;

                    eax = *(unsigned __int32 *)&FlashRamPointer[edx];
                    //	eax = swap32by8(eax); // ; bswap eax
                    *(unsigned __int32 *)(FlipBuffer + edx) = eax;
                }

                SetFilePointer(m_hFile, m_FlashRAM_Offset, NULL, FILE_BEGIN);
                WriteFile(m_hFile, FlipBuffer, 128, &dwWritten, NULL);
            }
            break;
        default:
            g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register\nm_FlashFlag: %d", FlashRAM_Command, m_FlashFlag).c_str());
        }
        m_FlashFlag = FLASHRAM_MODE_NOPES;
        break;
    case 0xE1000000:
        m_FlashFlag = FLASHRAM_MODE_STATUS;
        m_FlashStatus = 0x1111800100C2001E;
        break;
    case 0xF0000000:
    case 0x00000000:
        m_FlashFlag = FLASHRAM_MODE_READ;
        m_FlashStatus = 0x11118004F0000000;
        break;
    case 0x4B000000:
        m_FlashRAM_Offset = (FlashRAM_Command & 0xffff) * 128;
        break;
    case 0x78000000:
        m_FlashFlag = FLASHRAM_MODE_ERASE;
        m_FlashStatus = 0x1111800800C2001E;
        break;
    case 0xB4000000:
        m_FlashFlag = FLASHRAM_MODE_WRITE; //????
        break;
    case 0xA5000000:
        m_FlashRAM_Offset = (FlashRAM_Command & 0xffff) * 128;
        m_FlashStatus = 0x1111800400C2001E;
        break;
    default:
        if (bHaveDebugger())
        {
            g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register", FlashRAM_Command).c_str());
        }
    }
}
Example #4
0
void CFlashram::DmaFromFlashram ( BYTE * dest, int StartOffset, int len) 
{
	BYTE FlipBuffer[0x10000];
	DWORD dwRead, count;

	switch (m_FlashFlag)
	{
	case FLASHRAM_MODE_READ:
		if (m_hFile == NULL)
		{
			if (!LoadFlashram())
			{
				return;
			}
		}
		if (len > 0x10000) 
		{
			if (bHaveDebugger())
			{
				g_Notify->DisplayError(L"DmaFromFlashram FlipBuffer to small (len: %d)",len); 
			}
			len = 0x10000;
		}
		if ((len & 3) != 0) 
		{
			if (bHaveDebugger())
			{
				g_Notify->DisplayError(L"Unaligned flash ram read ???");
			}
			return;
		}
		memset(FlipBuffer,0,sizeof(FlipBuffer));
		StartOffset = StartOffset << 1;
		SetFilePointer(m_hFile,StartOffset,NULL,FILE_BEGIN);	
		ReadFile(m_hFile,FlipBuffer,len,&dwRead,NULL);
		for (count = dwRead; (int)count < len; count ++)
		{
			FlipBuffer[count] = 0xFF;
		}
		_asm
		{
			mov edi, dest
			lea ecx, [FlipBuffer]
			mov edx, 0
			mov ebx, len

		memcpyloop:
			mov eax, dword ptr [ecx + edx]
			;bswap eax
			mov  dword ptr [edi + edx],eax
			add edx, 4
			cmp edx, ebx
			jb memcpyloop
		}
		break;
	case FLASHRAM_MODE_STATUS:
		if (StartOffset != 0 && len != 8) 
		{
			if (bHaveDebugger())
			{
				g_Notify->DisplayError(L"Reading m_FlashStatus not being handled correctly\nStart: %X len: %X",StartOffset,len);
			}
		}
		*((DWORD *)(dest)) = (DWORD)((m_FlashStatus >> 32) & 0xFFFFFFFF);
		*((DWORD *)(dest) + 1) = (DWORD)(m_FlashStatus & 0xFFFFFFFF);
		break;
	default:
		if (bHaveDebugger())
		{
			g_Notify->DisplayError(L"DmaFromFlashram Start: %X, Offset: %X len: %X",dest - g_MMU->Rdram(),StartOffset,len);
		}
	}
}
Example #5
0
void CFlashram::WriteToFlashCommand(DWORD FlashRAM_Command)
{
	BYTE EmptyBlock[128];
	DWORD dwWritten;

	switch (FlashRAM_Command & 0xFF000000)
	{
	case 0xD2000000: 
		switch (m_FlashFlag)
		{
		case FLASHRAM_MODE_NOPES: break;
		case FLASHRAM_MODE_READ: break;
		case FLASHRAM_MODE_STATUS: break;
		case FLASHRAM_MODE_ERASE:
			memset(EmptyBlock,0xFF,sizeof(EmptyBlock));
			if (m_hFile == NULL) {
				if (!LoadFlashram())
				{
					return;
				}
			}
			SetFilePointer(m_hFile,m_FlashRAM_Offset,NULL,FILE_BEGIN);	
			WriteFile(m_hFile,EmptyBlock,128,&dwWritten,NULL);
			break;
		case FLASHRAM_MODE_WRITE:
			if (m_hFile == NULL) {
				if (!LoadFlashram())
				{
					return;
				}
			}
			{
				BYTE FlipBuffer[128];
				DWORD dwWritten;
				BYTE * FlashRamPointer = m_FlashRamPointer;

				memset(FlipBuffer,0,sizeof(FlipBuffer));
				_asm
				{
					lea edi, [FlipBuffer]
					mov ecx, FlashRamPointer
					mov edx, 0

				memcpyloop:
					mov eax, dword ptr [ecx + edx]
					;bswap eax
					mov  dword ptr [edi + edx],eax
					add edx, 4
					cmp edx, 128
					jb memcpyloop
				}

				SetFilePointer(m_hFile,m_FlashRAM_Offset,NULL,FILE_BEGIN);	
				WriteFile(m_hFile,FlipBuffer,128,&dwWritten,NULL);
			}
			break;
		default:
			g_Notify->DisplayError(L"Writing %X to flash ram command register\nm_FlashFlag: %d",FlashRAM_Command,m_FlashFlag);
		}
		m_FlashFlag = FLASHRAM_MODE_NOPES;
		break;
	case 0xE1000000: 
		m_FlashFlag = FLASHRAM_MODE_STATUS;
		m_FlashStatus = 0x1111800100C2001E;
		break;
	case 0xF0000000: 
		m_FlashFlag = FLASHRAM_MODE_READ;
		m_FlashStatus = 0x11118004F0000000;
		break;
	case 0x4B000000:
		m_FlashRAM_Offset = (FlashRAM_Command & 0xffff) * 128;
		break;
	case 0x78000000:
		m_FlashFlag = FLASHRAM_MODE_ERASE;
		m_FlashStatus = 0x1111800800C2001E;
		break;
	case 0xB4000000: 
		m_FlashFlag = FLASHRAM_MODE_WRITE; //????
		break;
	case 0xA5000000:
		m_FlashRAM_Offset = (FlashRAM_Command & 0xffff) * 128;
		m_FlashStatus = 0x1111800400C2001E;
		break;
	default:
		if (bHaveDebugger())
		{
			g_Notify->DisplayError(L"Writing %X to flash ram command register",FlashRAM_Command);
		}
	}
}
Example #6
0
void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
{
    uint8_t EmptyBlock[16 * sizeof(int64_t)];

    switch (FlashRAM_Command & 0xFF000000)
    {
    case 0xD2000000:
        switch (m_FlashFlag)
        {
        case FLASHRAM_MODE_NOPES: break;
        case FLASHRAM_MODE_READ: break;
        case FLASHRAM_MODE_STATUS: break;
        case FLASHRAM_MODE_ERASE:
            memset(EmptyBlock, 0xFF, sizeof(EmptyBlock));
            if (!m_File.IsOpen() && !LoadFlashram())
            {
                return;
            }
            m_File.Seek(m_FlashRAM_Offset, CFile::begin);
            m_File.Write(EmptyBlock, sizeof(EmptyBlock));
            m_File.Flush();
            break;
        case FLASHRAM_MODE_WRITE:
            if (!m_File.IsOpen() && !LoadFlashram())
            {
                return;
            }
            {
                uint8_t FlipBuffer[sizeof(EmptyBlock)];
                register size_t edx;
                uint8_t * FlashRamPointer = m_FlashRamPointer;

                memset(FlipBuffer, 0, sizeof(FlipBuffer));
                memcpy(&FlipBuffer[0], FlashRamPointer, sizeof(EmptyBlock));

                m_File.Seek(m_FlashRAM_Offset, CFile::begin);
                m_File.Write(FlipBuffer, sizeof(EmptyBlock));
                m_File.Flush();
            }
            break;
        default:
            g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register\nm_FlashFlag: %d", FlashRAM_Command, m_FlashFlag).c_str());
        }
        m_FlashFlag = FLASHRAM_MODE_NOPES;
        break;
    case 0xE1000000:
        m_FlashFlag = FLASHRAM_MODE_STATUS;
        m_FlashStatus = 0x1111800100C2001E;
        break;
    case 0xF0000000:
    case 0x00000000:
        m_FlashFlag = FLASHRAM_MODE_READ;
        m_FlashStatus = 0x11118004F0000000;
        break;
    case 0x4B000000:
        m_FlashRAM_Offset = (FlashRAM_Command & 0xFFFF) * sizeof(EmptyBlock);
        break;
    case 0x78000000:
        m_FlashFlag = FLASHRAM_MODE_ERASE;
        m_FlashStatus = 0x1111800800C2001E;
        break;
    case 0xB4000000:
        m_FlashFlag = FLASHRAM_MODE_WRITE; //????
        break;
    case 0xA5000000:
        m_FlashRAM_Offset = (FlashRAM_Command & 0xFFFF) * sizeof(EmptyBlock);
        m_FlashStatus = 0x1111800400C2001E;
        break;
    default:
        if (bHaveDebugger())
        {
            g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register", FlashRAM_Command).c_str());
        }
    }
}