MMU: Small fixes.

This commit is contained in:
degasus 2016-08-23 22:39:09 +02:00
parent d557310371
commit ef0dcfe558
2 changed files with 16 additions and 25 deletions

View File

@ -209,8 +209,6 @@ void Init()
PanicAlert("MemoryMap_Setup: Failed finding a memory base."); PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
exit(0); exit(0);
} }
mem_size += region.size;
} }
#ifndef _ARCH_32 #ifndef _ARCH_32
@ -252,15 +250,8 @@ void UpdateLogicalMemory(u32* dbat_table)
if (intersection_start < intersection_end) if (intersection_start < intersection_end)
{ {
// Found an overlapping region; map it. // Found an overlapping region; map it.
// We only worry about one overlapping region; in theory, a logical u32 position = physical_region.shm_position + intersection_start - mapping_address;
// region could translate to more than one physical region, but in u8* base = logical_base + logical_address + intersection_start - translated_address;
// practice, that doesn't happen.
u32 position = physical_region.shm_position;
if (intersection_start > mapping_address)
position += intersection_start - mapping_address;
u8* base = logical_base + logical_address;
if (intersection_start > translated_address)
base += intersection_start - translated_address;
u32 mapped_size = intersection_end - intersection_start; u32 mapped_size = intersection_end - intersection_start;
void* mapped_pointer = g_arena.CreateView(position, mapped_size, base); void* mapped_pointer = g_arena.CreateView(position, mapped_size, base);
@ -270,7 +261,6 @@ void UpdateLogicalMemory(u32* dbat_table)
exit(0); exit(0);
} }
logical_mapped_entries.push_back({mapped_pointer, mapped_size}); logical_mapped_entries.push_back({mapped_pointer, mapped_size});
break;
} }
} }
} }

View File

@ -179,20 +179,20 @@ __forceinline static T ReadFromHardware(u32 em_address)
// TODO: floats on non-word-aligned boundaries should technically cause alignment exceptions. // TODO: floats on non-word-aligned boundaries should technically cause alignment exceptions.
// Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned! // Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned!
u32 em_address_next_page = (em_address + sizeof(T) - 1) & ~(HW_PAGE_SIZE - 1); u32 em_address_next_page = (em_address + sizeof(T) - 1) & ~(HW_PAGE_SIZE - 1);
auto tlb_addr_next_page = TranslateAddress<flag>(em_address_next_page); auto addr_next_page = TranslateAddress<flag>(em_address_next_page);
if (!tlb_addr_next_page.Success()) if (!addr_next_page.Success())
{ {
if (flag == FLAG_READ) if (flag == FLAG_READ)
GenerateDSIException(em_address_next_page, false); GenerateDSIException(em_address_next_page, false);
return 0; return 0;
} }
T var = 0; T var = 0;
u32 tlb_addr = translated_addr.address; u32 addr_translated = translated_addr.address;
for (u32 addr = em_address; addr < em_address + sizeof(T); addr++, tlb_addr++) for (u32 addr = em_address; addr < em_address + sizeof(T); addr++, addr_translated++)
{ {
if (addr == em_address_next_page) if (addr == em_address_next_page)
tlb_addr = tlb_addr_next_page.address; addr_translated = addr_next_page.address;
var = (var << 8) | ReadFromHardware<flag, u8, true>(tlb_addr); var = (var << 8) | ReadFromHardware<flag, u8, true>(addr_translated);
} }
return var; return var;
} }
@ -260,20 +260,21 @@ __forceinline static void WriteToHardware(u32 em_address, const T data)
// TODO: floats on non-word-aligned boundaries should technically cause alignment exceptions. // TODO: floats on non-word-aligned boundaries should technically cause alignment exceptions.
// Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned! // Note that "word" means 32-bit, so paired singles or doubles might still be 32-bit aligned!
u32 em_address_next_page = (em_address + sizeof(T) - 1) & ~(HW_PAGE_SIZE - 1); u32 em_address_next_page = (em_address + sizeof(T) - 1) & ~(HW_PAGE_SIZE - 1);
auto tlb_addr_next_page = TranslateAddress<flag>(em_address_next_page); auto addr_next_page = TranslateAddress<flag>(em_address_next_page);
if (!tlb_addr_next_page.Success()) if (!addr_next_page.Success())
{ {
if (flag == FLAG_WRITE) if (flag == FLAG_WRITE)
GenerateDSIException(em_address_next_page, true); GenerateDSIException(em_address_next_page, true);
return; return;
} }
T val = bswap(data); T val = bswap(data);
u32 tlb_addr = translated_addr.address; u32 addr_translated = translated_addr.address;
for (u32 addr = em_address; addr < em_address + sizeof(T); addr++, tlb_addr++, val >>= 8) for (u32 addr = em_address; addr < em_address + sizeof(T);
addr++, addr_translated++, val >>= 8)
{ {
if (addr == em_address_next_page) if (addr == em_address_next_page)
tlb_addr = tlb_addr_next_page.address; addr_translated = addr_next_page.address;
WriteToHardware<flag, u8, true>(tlb_addr, (u8)val); WriteToHardware<flag, u8, true>(addr_translated, (u8)val);
} }
return; return;
} }
@ -1151,7 +1152,7 @@ static void UpdateBATs(u32* bat_table, u32 base_spr)
// invalid BATs as well. // invalid BATs as well.
WARN_LOG(POWERPC, "Bad BAT setup: invalid mask in BL"); WARN_LOG(POWERPC, "Bad BAT setup: invalid mask in BL");
} }
for (u32 j = 0; j < (1 << 11); ++j) for (u32 j = 0; j <= batu.BL; ++j)
{ {
// Enumerate all bit-patterns which fit within the given mask. // Enumerate all bit-patterns which fit within the given mask.
if ((j & batu.BL) == j) if ((j & batu.BL) == j)