From b62cac2ca93006c3deae1b4406588ec218d1d0ba Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 20 Nov 2011 15:50:33 -0800 Subject: [PATCH 1/2] Allow modifying main ram size at compile time by changing Memory::REALRAM_SIZE. --- Source/Core/Common/Src/CommonFuncs.h | 7 +++ Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp | 7 ++- Source/Core/Core/Src/HW/Memmap.cpp | 61 ++++++++++------------- Source/Core/Core/Src/HW/Memmap.h | 20 ++++---- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index c79137780d..74d317d95f 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -27,6 +27,13 @@ template struct CompileTimeAssert; template<> struct CompileTimeAssert {}; +#define b2(x) ( (x) | ( (x) >> 1) ) +#define b4(x) ( b2(x) | ( b2(x) >> 2) ) +#define b8(x) ( b4(x) | ( b4(x) >> 4) ) +#define b16(x) ( b8(x) | ( b8(x) >> 8) ) +#define b32(x) (b16(x) | (b16(x) >>16) ) +#define ROUND_UP_POW2(x) (b32(x - 1) + 1) + #if defined __GNUC__ && !defined __SSSE3__ #include static __inline __m128i __attribute__((__always_inline__)) diff --git a/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp index c04938ca65..2555416a04 100644 --- a/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp @@ -66,7 +66,7 @@ bool CBoot::EmulatedBS2_GC() DVDInterface::DVDRead(0x00000000, 0x80000000, 0x20); // write disc info Memory::Write_U32(0x0D15EA5E, 0x80000020); // booted from bootrom. 0xE5207C22 = booted from jtag - Memory::Write_U32(0x01800000, 0x80000028); // Physical Memory Size (24MB on retail) + Memory::Write_U32(Memory::REALRAM_SIZE, 0x80000028); // Physical Memory Size (24MB on retail) // TODO determine why some games fail when using a retail id. (Seem to take different EXI paths, see ikaruga for example) Memory::Write_U32(0x10000006, 0x8000002C); // Console type - DevKit (retail ID == 0x00000003) see yagcd 4.2.1.1.2 @@ -172,7 +172,6 @@ bool CBoot::EmulatedBS2_GC() return true; } - bool CBoot::SetupWiiMemory(unsigned int _CountryCode) { INFO_LOG(BOOT, "Setup Wii Memory..."); @@ -238,14 +237,14 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode) DVDInterface::DVDRead(0x00000000, 0x00000000, 0x20); // Game Code Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word Memory::Write_U32(0x00000001, 0x00000024); // Unknown - Memory::Write_U32(0x01800000, 0x00000028); // MEM1 size 24MB + Memory::Write_U32(Memory::REALRAM_SIZE, 0x00000028); // MEM1 size 24MB Memory::Write_U32(0x00000023, 0x0000002c); // Production Board Model Memory::Write_U32(0x00000000, 0x00000030); // Init Memory::Write_U32(0x817FEC60, 0x00000034); // Init // 38, 3C should get start, size of FST through apploader Memory::Write_U32(0x38a00040, 0x00000060); // Exception init Memory::Write_U32(0x8008f7b8, 0x000000e4); // Thread Init - Memory::Write_U32(0x01800000, 0x000000f0); // "Simulated memory size" (debug mode?) + Memory::Write_U32(Memory::REALRAM_SIZE, 0x000000f0); // "Simulated memory size" (debug mode?) Memory::Write_U32(0x8179b500, 0x000000f4); // __start Memory::Write_U32(0x0e7be2c0, 0x000000f8); // Bus speed Memory::Write_U32(0x2B73A840, 0x000000fc); // CPU speed diff --git a/Source/Core/Core/Src/HW/Memmap.cpp b/Source/Core/Core/Src/HW/Memmap.cpp index 8b99243528..a0631a0fa3 100644 --- a/Source/Core/Core/Src/HW/Memmap.cpp +++ b/Source/Core/Core/Src/HW/Memmap.cpp @@ -625,53 +625,45 @@ void GetString(std::string& _string, const u32 em_address) // GetPointer must always return an address in the bottom 32 bits of address space, so that 64-bit // programs don't have problems directly addressing any part of memory. +// TODO re-think with respect to other BAT setups... u8 *GetPointer(const u32 _Address) { - switch (_Address >> 24) + switch (_Address >> 28) { - case 0x00: - case 0x01: - case 0x80: - case 0x81: - case 0xC0: - case 0xC1: - return (u8*)(((char*)m_pPhysicalRAM) + (_Address & RAM_MASK)); + case 0x0: + case 0x8: + return m_pPhysicalRAM + (_Address & RAM_MASK); + case 0xc: + switch (_Address >> 24) + { + case 0xcc: + case 0xcd: + _dbg_assert_msg_(MEMMAP, 0, "GetPointer from IO Bridge doesnt work"); + case 0xc8: + // EFB. We don't want to return a pointer here since we have no memory mapped for it. + return 0; - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0xD0: - case 0xD1: - case 0xD2: - case 0xD3: + default: + return m_pPhysicalRAM + (_Address & RAM_MASK); + } + + case 0x1: + case 0x9: + case 0xd: if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) - return (u8*)(((char*)m_pPhysicalEXRAM) + (_Address & EXRAM_MASK)); + return m_pPhysicalEXRAM + (_Address & EXRAM_MASK); else return 0; - case 0xE0: + case 0xe: if (_Address < (0xE0000000 + L1_CACHE_SIZE)) return GetCachePtr() + (_Address & L1_CACHE_MASK); else return 0; - case 0xC8: - return 0; // EFB. We don't want to return a pointer here since we have no memory mapped for it. - - case 0xCC: - case 0xCD: - _dbg_assert_msg_(MEMMAP, 0, "GetPointer from IO Bridge doesnt work"); - return NULL; default: if (bFakeVMEM) - { - return (u8*)(((char*)m_pVirtualFakeVMEM) + (_Address & RAM_MASK)); - } + return m_pVirtualFakeVMEM + (_Address & FAKEVMEM_MASK); else { if (!Core::g_CoreStartupParameter.bMMU && @@ -679,15 +671,14 @@ u8 *GetPointer(const u32 _Address) Crash(); return 0; } - break; } - return NULL; } bool IsRAMAddress(const u32 addr, bool allow_locked_cache) { - switch ((addr >> 24) & 0xFC) { + switch ((addr >> 24) & 0xFC) + { case 0x00: case 0x80: case 0xC0: diff --git a/Source/Core/Core/Src/HW/Memmap.h b/Source/Core/Core/Src/HW/Memmap.h index 26a918fee8..6c808cbc00 100644 --- a/Source/Core/Core/Src/HW/Memmap.h +++ b/Source/Core/Core/Src/HW/Memmap.h @@ -58,20 +58,22 @@ extern u8 *m_pL1Cache; enum { - // The size should be just 24MB instead of 32, but the RAM_MASK wouldn't - // work. - RAM_SIZE = 0x2000000, - RAM_MASK = 0x1FFFFFF, + // RAM_SIZE is the amount allocated by the emulator, whereas REALRAM_SIZE is + // what will be reported in lowmem, and thus used by emulated software. + // Note: Writing to lowmem is done by IPL. If using retail IPL, it will + // always be set to 24MB. + REALRAM_SIZE = 0x1800000, + RAM_SIZE = ROUND_UP_POW2(REALRAM_SIZE), + RAM_MASK = RAM_SIZE - 1, FAKEVMEM_SIZE = 0x2000000, - FAKEVMEM_MASK = 0x1FFFFFF, - REALRAM_SIZE = 0x1800000, + FAKEVMEM_MASK = FAKEVMEM_SIZE - 1, L1_CACHE_SIZE = 0x40000, - L1_CACHE_MASK = 0x3FFFF, + L1_CACHE_MASK = L1_CACHE_SIZE - 1, EFB_SIZE = 0x200000, - EFB_MASK = 0x1FFFFF, + EFB_MASK = EFB_SIZE - 1, IO_SIZE = 0x10000, EXRAM_SIZE = 0x4000000, - EXRAM_MASK = 0x3FFFFFF, + EXRAM_MASK = EXRAM_SIZE - 1, ADDR_MASK_HW_ACCESS = 0x0c000000, ADDR_MASK_MEM1 = 0x20000000, From 62858c8c140a281cc5145ca1b81b1aeffbb5015a Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sat, 10 Dec 2011 18:42:49 -0800 Subject: [PATCH 2/2] Small logging changes. Pause core if Jit64 tries to compile at 0. --- Source/Core/Core/Src/HLE/HLE_OS.cpp | 7 ++++--- Source/Core/Core/Src/HW/Memmap.cpp | 17 +++++++---------- Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp | 5 ++++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/Src/HLE/HLE_OS.cpp b/Source/Core/Core/Src/HLE/HLE_OS.cpp index eebff67ece..3ced001268 100644 --- a/Source/Core/Core/Src/HLE/HLE_OS.cpp +++ b/Source/Core/Core/Src/HLE/HLE_OS.cpp @@ -69,9 +69,10 @@ void GetStringVA(std::string& _rOutBuffer, u32 strReg) char ArgumentBuffer[256]; u32 ParameterCounter = 4; u32 FloatingParameterCounter = 1; - char* pString = (char*)Memory::GetPointer(GPR(strReg)); - if (!pString) { - //PanicAlert("Invalid GetStringVA call"); + char *pString = (char*)Memory::GetPointer(GPR(strReg)); + if (!pString) + { + ERROR_LOG(OSREPORT, "r%i invalid", strReg); return; } diff --git a/Source/Core/Core/Src/HW/Memmap.cpp b/Source/Core/Core/Src/HW/Memmap.cpp index a0631a0fa3..980b080761 100644 --- a/Source/Core/Core/Src/HW/Memmap.cpp +++ b/Source/Core/Core/Src/HW/Memmap.cpp @@ -641,7 +641,7 @@ u8 *GetPointer(const u32 _Address) _dbg_assert_msg_(MEMMAP, 0, "GetPointer from IO Bridge doesnt work"); case 0xc8: // EFB. We don't want to return a pointer here since we have no memory mapped for it. - return 0; + break; default: return m_pPhysicalRAM + (_Address & RAM_MASK); @@ -653,25 +653,22 @@ u8 *GetPointer(const u32 _Address) if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) return m_pPhysicalEXRAM + (_Address & EXRAM_MASK); else - return 0; + break; case 0xe: if (_Address < (0xE0000000 + L1_CACHE_SIZE)) return GetCachePtr() + (_Address & L1_CACHE_MASK); else - return 0; + break; default: if (bFakeVMEM) return m_pVirtualFakeVMEM + (_Address & FAKEVMEM_MASK); - else - { - if (!Core::g_CoreStartupParameter.bMMU && - !PanicYesNoT("Unknown pointer %#08x\nContinue?", _Address)) - Crash(); - return 0; - } } + + ERROR_LOG(MEMMAP, "Unknown Pointer %#8x PC %#8x LR %#8x", _Address, PC, LR); + + return NULL; } diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp index f9fd3c4635..0d31893b53 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp @@ -418,7 +418,10 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc } if (em_address == 0) - PanicAlert("ERROR : Trying to compile at 0. LR=%08x", LR); + { + Core::SetState(Core::CORE_PAUSE); + PanicAlert("ERROR: Compiling at 0. LR=%08x CTR=%08x", LR, CTR); + } if (Core::g_CoreStartupParameter.bMMU && (em_address & JIT_ICACHE_VMEM_BIT)) {