From 423cdb63989ffeba9bca27fe4155391ea578dbf9 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 3 Apr 2012 03:06:40 -0700 Subject: [PATCH] fixes issue 5335 --- Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp | 3 +- Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp | 219 ++++++++++++---------- Source/Core/Core/Src/HW/EXI_DeviceIPL.h | 15 ++ 3 files changed, 133 insertions(+), 104 deletions(-) diff --git a/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp index 2555416a04..788b8c317c 100644 --- a/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp @@ -253,6 +253,7 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode) Memory::Write_U32(0x00000000, 0x000030c4); // EXI Memory::Write_U32(0x00000000, 0x000030dc); // Time Memory::Write_U32(0x00000000, 0x000030d8); // Time + Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable Memory::Write_U32(0x00000000, 0x000030f0); // Apploader Memory::Write_U32(0x01800000, 0x00003100); // BAT Memory::Write_U32(0x01800000, 0x00003104); // BAT @@ -265,7 +266,7 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode) Memory::Write_U32(0x93ae0000, 0x00003128); // Init - MEM2 high Memory::Write_U32(0x93ae0000, 0x00003130); // IOS MEM2 low Memory::Write_U32(0x93b00000, 0x00003134); // IOS MEM2 high - Memory::Write_U32(0x00000011, 0x00003138); // Console type + Memory::Write_U32(0x00000012, 0x00003138); // Console type // 40 is copied from 88 after running apploader Memory::Write_U32(0x00090204, 0x00003140); // IOS revision (IOS9, v2.4) Memory::Write_U32(0x00062507, 0x00003144); // IOS date in USA format (June 25, 2007) diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp index 4aefb6dbdb..7bf15cf9a4 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp @@ -197,7 +197,7 @@ void CEXIIPL::TransferByte(u8& _uByte) // The first 4 bytes must be the address // If we haven't read it, do it now - if (m_uPosition < 4) + if (m_uPosition <= 3) { m_uAddress <<= 8; m_uAddress |= _uByte; @@ -207,137 +207,150 @@ void CEXIIPL::TransferByte(u8& _uByte) // Check if the command is complete if (m_uPosition == 3) { - // Get the time ... + // Get the time ... + u32 &rtc = *((u32 *)&m_RTC); if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) - *((u32 *)&m_RTC) = Common::swap32(CEXIIPL::GetGCTime() - cWiiBias); // Subtract Wii bias + { + // Subtract Wii bias + rtc = Common::swap32(CEXIIPL::GetGCTime() - cWiiBias); + } else - *((u32 *)&m_RTC) = Common::swap32(CEXIIPL::GetGCTime()); + { + rtc = Common::swap32(CEXIIPL::GetGCTime()); + } -#if MAX_LOGLEVEL >= INFO_LEVEL - - if ((m_uAddress & 0xF0000000) == 0xb0000000) + // Log the command + std::string device_name; + + switch (CommandRegion()) { - INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: WII something"); + case REGION_RTC: + device_name = "RTC"; + break; + case REGION_SRAM: + device_name = "SRAM"; + break; + case REGION_UART: + device_name = "UART"; + break; + case REGION_EUART: + device_name = "EUART"; + break; + case REGION_UART_UNK: + device_name = "UART Other?"; + break; + case REGION_BARNACLE: + device_name = "UART Barnacle"; + break; + case REGION_WRTC0: + case REGION_WRTC1: + case REGION_WRTC2: + device_name = "Wii RTC flags - not implemented"; + break; + default: + if ((m_uAddress >> 6) < ROM_SIZE) + { + device_name = "ROM"; + } + else + { + device_name = "illegal address"; + _dbg_assert_msg_(EXPANSIONINTERFACE, 0, + "EXI IPL-DEV: %s %08x", device_name.c_str(), m_uAddress); + } + break; } - else if ((m_uAddress & 0xF0000000) == 0x30000000) - { - // wii stuff perhaps wii SRAM? - INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: WII something (perhaps SRAM?)"); - } - else if ((m_uAddress & 0x60000000) == 0) - { - INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: IPL access"); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20000000) - { - INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: RTC access"); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20000100) - { - INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: SRAM access"); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20010000) - { - DEBUG_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: UART"); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20011300) - { - DEBUG_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: UART Barnacle"); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20010300) - { - DEBUG_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: UART Other?"); - } - else if (((m_uAddress & 0x7FFFFF00) == 0x21000000) || - ((m_uAddress & 0x7FFFFF00) == 0x21000100) || - ((m_uAddress & 0x7FFFFF00) == 0x21000800)) - { - ERROR_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: RTC flags (WII only) - not implemented"); - } - else - { - //_dbg_assert_(EXPANSIONINTERFACE, 0); - _dbg_assert_msg_(EXPANSIONINTERFACE, 0, "EXI IPL-DEV: illegal access address %08x", m_uAddress); - ERROR_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: illegal address %08x", m_uAddress); - } -#endif + + DEBUG_LOG(EXPANSIONINTERFACE, "%s %s %08x", device_name.c_str(), + IsWriteCommand() ? "write" : "read", m_uAddress); } } else { - // --- Encrypted ROM --- - // atm we pre-decrypt the whole thing, see CEXIIPL ctor - if ((m_uAddress & 0x60000000) == 0) + // Actually read or write a byte + switch (CommandRegion()) { - if ((m_uAddress & 0x80000000) == 0) - { - u32 position = ((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset; - - // Technically we should apply descrambling here, if it's currently enabled. - _uByte = m_pIPL[position]; - - if ((position >= 0x001AFF00) && (position <= 0x001FF474) && !m_FontsLoaded) - { - PanicAlertT("Error: Trying to access %s fonts but they are not loaded. Games may not show fonts correctly, or crash.", - (position >= 0x001FCF00)?"ANSI":"SJIS"); - m_FontsLoaded = true; // Don't be a nag :p - } - } - } - // --- Real Time Clock (RTC) --- - else if ((m_uAddress & 0x7FFFFF00) == 0x20000000) - { - if (m_uAddress & 0x80000000) + case REGION_RTC: + if (IsWriteCommand()) m_RTC[(m_uAddress & 0x03) + m_uRWOffset] = _uByte; else _uByte = m_RTC[(m_uAddress & 0x03) + m_uRWOffset]; - } - // --- SRAM --- - else if ((m_uAddress & 0x7FFFFF00) == 0x20000100) - { - if (m_uAddress & 0x80000000) + break; + + case REGION_SRAM: + if (IsWriteCommand()) g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte; else _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; - } - // --- UART --- - else if ((m_uAddress & 0x7FFFFF00) == 0x20010000) - { - if (m_uAddress & 0x80000000) + break; + + case REGION_UART: + case REGION_EUART: + if (IsWriteCommand()) { - m_szBuffer[m_count++] = _uByte; + if (_uByte != '\0') + m_szBuffer[m_count++] = _uByte; if ((m_count >= 256) || (_uByte == 0xD)) { m_szBuffer[m_count] = 0x00; - INFO_LOG(OSREPORT, "%s", m_szBuffer); + NOTICE_LOG(OSREPORT, "%s", m_szBuffer); memset(m_szBuffer, 0, sizeof(m_szBuffer)); m_count = 0; } } else - _uByte = 0x01; // dunno - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20011300) - { - INFO_LOG(OSREPORT, "UART Barnacle %x", _uByte); - } - else if ((m_uAddress & 0x7FFFFF00) == 0x20010300) - { - INFO_LOG(OSREPORT, "UART? %x", _uByte); + { + // "Queue Length"... return 0 cause we're instant + _uByte = 0; + } + break; + + case REGION_UART_UNK: + DEBUG_LOG(OSREPORT, "UART? %x", _uByte); _uByte = 0xff; + break; + + case REGION_BARNACLE: + DEBUG_LOG(OSREPORT, "UART Barnacle %x", _uByte); + break; + + case REGION_WRTC0: + case REGION_WRTC1: + case REGION_WRTC2: + // WII only RTC flags... afaik just the wii menu initialize it + default: + if ((m_uAddress >> 6) < ROM_SIZE) + { + if (!IsWriteCommand()) + { + u32 position = ((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset; + + // Technically we should descramble here iff descrambling logic is enabled. + // At the moment, we pre-decrypt the whole thing and + // ignore the "enabled" bit - see CEXIIPL::CEXIIPL + _uByte = m_pIPL[position]; + + if ((position >= 0x001AFF00) && (position <= 0x001FF474) && !m_FontsLoaded) + { + PanicAlertT( + "Error: Trying to access %s fonts but they are not loaded. " + "Games may not show fonts correctly, or crash.", + (position >= 0x001FCF00) ? "ANSI" : "SJIS"); + m_FontsLoaded = true; // Don't be a nag :p + } + } + } + else + { + NOTICE_LOG(OSREPORT, "EXI IPL-DEV: %s %x at %08x", + IsWriteCommand() ? "write" : "read", _uByte, m_uAddress); + } + break; } - else if (((m_uAddress & 0x7FFFFF00) == 0x21000000) || - ((m_uAddress & 0x7FFFFF00) == 0x21000100) || - ((m_uAddress & 0x7FFFFF00) == 0x21000800)) - { - // WII only RTC flags... afaik just the wii menu initialize it -// if (m_uAddress & 0x80000000) -// g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte; -// else -// _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; - } + m_uRWOffset++; } + m_uPosition++; } diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.h b/Source/Core/Core/Src/HW/EXI_DeviceIPL.h index bcc04c2e8f..7e0710bb02 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.h +++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.h @@ -43,6 +43,19 @@ private: ROM_MASK = (ROM_SIZE - 1) }; + enum + { + REGION_RTC = 0x200000, + REGION_SRAM = 0x200001, + REGION_UART = 0x200100, + REGION_UART_UNK = 0x200103, + REGION_BARNACLE = 0x200113, + REGION_WRTC0 = 0x210000, + REGION_WRTC1 = 0x210001, + REGION_WRTC2 = 0x210008, + REGION_EUART = 0x300001 + }; + // Region bool m_bNTSC; @@ -63,6 +76,8 @@ private: bool m_FontsLoaded; virtual void TransferByte(u8 &_uByte); + bool IsWriteCommand() const { return !!(m_uAddress & (1 << 31)); } + u32 const CommandRegion() const { return (m_uAddress & ~(1 << 31)) >> 8; } void LoadFileToIPL(std::string filename, u32 offset); };