summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2011-11-20 15:50:33 -0800
committerShawn Hoffman <godisgovernment@gmail.com>2011-11-27 19:52:05 -0800
commitb62cac2ca93006c3deae1b4406588ec218d1d0ba (patch)
treebfb90ea3dc0a4041e8a6c0fe064a8eb0963971ed /Source/Core
parent04026ae19ac902f946b8f238f96c4f8b2e740ff1 (diff)
Allow modifying main ram size at compile time by changing Memory::REALRAM_SIZE.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/Src/CommonFuncs.h7
-rw-r--r--Source/Core/Core/Src/Boot/Boot_BS2Emu.cpp7
-rw-r--r--Source/Core/Core/Src/HW/Memmap.cpp61
-rw-r--r--Source/Core/Core/Src/HW/Memmap.h20
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 <bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert<true> {};
+#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 <emmintrin.h>
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,