change KB/MB to KiB/MiB

This commit is contained in:
RadWolfie 2020-04-03 04:33:25 -05:00
parent 1a1019b85c
commit d2f104f251
5 changed files with 44 additions and 44 deletions

View File

@ -48,10 +48,10 @@ const _XboxAddressRanges XboxAddressRanges[] = {
// See http://xboxdevwiki.net/Memory
// and http://xboxdevwiki.net/Boot_Process#Paging
// Entry : Start , End , Size , Protect , RangeFlags , Comment
RANGE_ENTRY(USER_ADDRESS1_BASE, USER_ADDRESS1_END, USER_ADDRESS1_SIZE, PROT_XRW, SYSTEM_ALL | MAY_FAIL, "MemLowVirtual (General Xbox type) lower 64 MB Optional (already reserved via virtual_memory_placeholder)"),
RANGE_ENTRY(USER_ADDRESS2_BASE, USER_ADDRESS2_END, USER_ADDRESS2_SIZE, PROT_XRW, SYSTEM_128MB | MAY_FAIL, "MemLowVirtual (Chihiro / DevKit) ^ + upper 64 MB"),
RANGE_ENTRY(PHYSICAL_MAP1_BASE, PHYSICAL_MAP1_END, PHYSICAL_MAP1_SIZE, PROT_UNH, SYSTEM_ALL , "MemPhysical (General Xbox type) lower 64 MB"),
RANGE_ENTRY(PHYSICAL_MAP2_BASE, PHYSICAL_MAP2_END, PHYSICAL_MAP2_SIZE, PROT_UNH, SYSTEM_128MB , "MemPhysical (Chihiro / DevKit) ^ + upper 64 MB"),
RANGE_ENTRY(USER_ADDRESS1_BASE, USER_ADDRESS1_END, USER_ADDRESS1_SIZE, PROT_XRW, SYSTEM_ALL | MAY_FAIL, "MemLowVirtual (General Xbox type) lower 64 MiB Optional (already reserved via virtual_memory_placeholder)"),
RANGE_ENTRY(USER_ADDRESS2_BASE, USER_ADDRESS2_END, USER_ADDRESS2_SIZE, PROT_XRW, SYSTEM_128MB | MAY_FAIL, "MemLowVirtual (Chihiro / DevKit) ^ + upper 64 MiB"),
RANGE_ENTRY(PHYSICAL_MAP1_BASE, PHYSICAL_MAP1_END, PHYSICAL_MAP1_SIZE, PROT_UNH, SYSTEM_ALL , "MemPhysical (General Xbox type) lower 64 MiB"),
RANGE_ENTRY(PHYSICAL_MAP2_BASE, PHYSICAL_MAP2_END, PHYSICAL_MAP2_SIZE, PROT_UNH, SYSTEM_128MB , "MemPhysical (Chihiro / DevKit) ^ + upper 64 MiB"),
RANGE_ENTRY(DEVKIT_MEMORY_BASE, DEVKIT_MEMORY_END, DEVKIT_MEMORY_SIZE, PROT_NAC, SYSTEM_DEVKIT , "DevKitMemory"), // TODO : Check reserved range (might behave like MemTiled)
RANGE_ENTRY(PAGE_TABLES_BASE , PAGE_TABLES_END , PAGE_TABLES_SIZE , PROT_RW , SYSTEM_ALL , "MemPageTable"), // See PAGE_TABLES_SIZE, which contains one 4 byte entry per PAGE_SIZE
RANGE_ENTRY(SYSTEM_MEMORY_BASE, SYSTEM_MEMORY_END, SYSTEM_MEMORY_SIZE, PROT_RW , SYSTEM_ALL | MAY_FAIL, "SystemMemory Optional"), // TODO : Check reserved range (might behave like MemTiled)

View File

@ -29,93 +29,93 @@
#include <cstdint> // For uint32_t
#define KB(x) ((x) * 1024 ) // = 0x00000400
#define MB(x) ((x) * KB(1024)) // = 0x00100000
#define KiB(x) ((x) * 1024 ) // = 0x00000400
#define MiB(x) ((x) * KiB(1024)) // = 0x00100000
#define USER_ADDRESS1_BASE 0x00010000
#define USER_ADDRESS1_SIZE (MB(64) - KB(64)) // = 0x03FF0000
#define USER_ADDRESS1_SIZE (MiB(64) - KiB(64)) // = 0x03FF0000
#define USER_ADDRESS1_END (USER_ADDRESS1_BASE + USER_ADDRESS1_SIZE - 1) // 0x03FFFFFF
#define USER_ADDRESS2_BASE 0x04000000
#define USER_ADDRESS2_SIZE (MB(64)) // = 0x04000000
#define USER_ADDRESS2_SIZE (MiB(64)) // = 0x04000000
#define USER_ADDRESS2_END (USER_ADDRESS2_BASE + USER_ADDRESS2_SIZE - 1) // 0x07FFFFFF
// Base addresses of various components
#define KSEG0_BASE 0x80000000
#define PHYSICAL_MAP_BASE 0x80000000
#define PHYSICAL_MAP_SIZE (MB(256)) // = 0x10000000
#define PHYSICAL_MAP_SIZE (MiB(256)) // = 0x10000000
#define PHYSICAL_MAP_END (PHYSICAL_MAP_BASE + PHYSICAL_MAP_SIZE - 1) // 0x8FFFFFFF
inline constexpr uint32_t PHYSICAL_MAP1_BASE = 0x80000000;
inline constexpr uint32_t PHYSICAL_MAP1_SIZE = (MB(64)); // = 0x04000000
inline constexpr uint32_t PHYSICAL_MAP1_SIZE = (MiB(64)); // = 0x04000000
inline constexpr uint32_t PHYSICAL_MAP1_END = (PHYSICAL_MAP1_BASE + PHYSICAL_MAP1_SIZE - 1); // 0x83FFFFFF
inline constexpr uint32_t PHYSICAL_MAP2_BASE = 0x84000000;
inline constexpr uint32_t PHYSICAL_MAP2_SIZE = (MB(64)); // = 0x04000000
inline constexpr uint32_t PHYSICAL_MAP2_SIZE = (MiB(64)); // = 0x04000000
inline constexpr uint32_t PHYSICAL_MAP2_END = (PHYSICAL_MAP2_BASE + PHYSICAL_MAP2_SIZE - 1); // 0x8FFFFFFF
#define CONTIGUOUS_MEMORY_BASE KSEG0_BASE // = 0x80000000
#define XBOX_CONTIGUOUS_MEMORY_SIZE (MB(64))
#define CHIHIRO_CONTIGUOUS_MEMORY_SIZE (MB(128))
#define XBOX_CONTIGUOUS_MEMORY_SIZE (MiB(64))
#define CHIHIRO_CONTIGUOUS_MEMORY_SIZE (MiB(128))
inline constexpr uint32_t DEVKIT_MEMORY_BASE = 0xB0000000;
inline constexpr uint32_t DEVKIT_MEMORY_SIZE = (MB(256)); // = 0x10000000
inline constexpr uint32_t DEVKIT_MEMORY_SIZE = (MiB(256)); // = 0x10000000
inline constexpr uint32_t DEVKIT_MEMORY_END = (DEVKIT_MEMORY_BASE + DEVKIT_MEMORY_SIZE - 1); // 0xBFFFFFFF
inline constexpr uint32_t PAGE_TABLES_BASE = 0xC0000000;
inline constexpr uint32_t PAGE_TABLES_SIZE = (MB(4)); // = 0x00400000
inline constexpr uint32_t PAGE_TABLES_SIZE = (MiB(4)); // = 0x00400000
inline constexpr uint32_t PAGE_TABLES_END = (PAGE_TABLES_BASE + PAGE_TABLES_SIZE - 1); // 0xC03FFFFF
inline constexpr uint32_t SYSTEM_MEMORY_BASE = 0xD0000000;
inline constexpr uint32_t SYSTEM_MEMORY_SIZE = (MB(512)); // = 0x20000000
inline constexpr uint32_t SYSTEM_MEMORY_SIZE = (MiB(512)); // = 0x20000000
inline constexpr uint32_t SYSTEM_MEMORY_END = (SYSTEM_MEMORY_BASE + SYSTEM_MEMORY_SIZE - 1); // 0xEFFFFFFF
inline constexpr uint32_t TILED_MEMORY_BASE = 0xF0000000;
inline constexpr uint32_t TILED_MEMORY_SIZE = (MB(64)); // = 0x04000000
inline constexpr uint32_t TILED_MEMORY_SIZE = (MiB(64)); // = 0x04000000
inline constexpr uint32_t TILED_MEMORY_END = (TILED_MEMORY_BASE + TILED_MEMORY_SIZE - 1); // 0xF3FFFFFF
#define XBOX_WRITE_COMBINED_BASE 0xF0000000 // WC (The WC memory is another name of the tiled memory)
#define XBOX_WRITE_COMBINED_SIZE (MB(128)) // = 0x08000000
#define XBOX_WRITE_COMBINED_SIZE (MiB(128)) // = 0x08000000
#define XBOX_WRITE_COMBINED_END (XBOX_WRITE_COMBINED_BASE + XBOX_WRITE_COMBINED_SIZE - 1) // 0xF7FFFFFF
#define XBOX_UNCACHED_BASE 0xF8000000 // UC
#define XBOX_UNCACHED_SIZE (MB(128 - 4)) // = 0x07C00000
#define XBOX_UNCACHED_SIZE (MiB(128 - 4)) // = 0x07C00000
#define XBOX_UNCACHED_END (XBOX_UNCACHED_BASE + XBOX_UNCACHED_SIZE - 1) // - 0xFFBFFFFF
inline constexpr uint32_t NV2A_DEVICE1_BASE = 0xFD000000;
inline constexpr uint32_t NV2A_DEVICE1_SIZE = (MB(7)); // = 0x00700000
inline constexpr uint32_t NV2A_DEVICE1_SIZE = (MiB(7)); // = 0x00700000
inline constexpr uint32_t NV2A_DEVICE1_END = (NV2A_DEVICE1_BASE + NV2A_DEVICE1_SIZE - 1); // 0xFD6FFFFF
inline constexpr uint32_t NV2A_PRAMIN_BASE = 0xFD700000;
inline constexpr uint32_t NV2A_PRAMIN_SIZE1 = (MB(1)); // = 0x00100000 // TODO: Might be best to merge PCIDevice.h's address ranges into this header file.
inline constexpr uint32_t NV2A_PRAMIN_SIZE1 = (MiB(1)); // = 0x00100000 // TODO: Might be best to merge PCIDevice.h's address ranges into this header file.
inline constexpr uint32_t NV2A_PRAMIN_END = (NV2A_PRAMIN_BASE + NV2A_PRAMIN_SIZE1 - 1); // 0xFD7FFFFF
inline constexpr uint32_t NV2A_DEVICE2_BASE = 0xFD800000;
inline constexpr uint32_t NV2A_DEVICE2_SIZE = (MB(8)); // = 0x00800000
inline constexpr uint32_t NV2A_DEVICE2_SIZE = (MiB(8)); // = 0x00800000
inline constexpr uint32_t NV2A_DEVICE2_END = (NV2A_DEVICE2_BASE + NV2A_DEVICE2_SIZE - 1); // 0xFDFFFFFF
inline constexpr uint32_t APU_DEVICE_BASE = 0xFE800000;
inline constexpr uint32_t APU_DEVICE_SIZE = (KB(512)); // = 0x00080000
inline constexpr uint32_t APU_DEVICE_SIZE = (KiB(512)); // = 0x00080000
inline constexpr uint32_t APU_DEVICE_END = (APU_DEVICE_BASE + APU_DEVICE_SIZE - 1); // 0xFE87FFFF
inline constexpr uint32_t AC97_DEVICE_BASE = 0xFEC00000;
inline constexpr uint32_t AC97_DEVICE_SIZE = (KB(4)); // = 0x0001000
inline constexpr uint32_t AC97_DEVICE_SIZE = (KiB(4)); // = 0x0001000
inline constexpr uint32_t AC97_DEVICE_END = (AC97_DEVICE_BASE + AC97_DEVICE_SIZE - 1); // 0xFEC00FFF
inline constexpr uint32_t USB_DEVICE_BASE = 0xFED00000;
inline constexpr uint32_t USB_DEVICE_SIZE = (KB(4)); // = 0x0001000
inline constexpr uint32_t USB_DEVICE_SIZE = (KiB(4)); // = 0x0001000
inline constexpr uint32_t USB_DEVICE_END = (USB_DEVICE_BASE + USB_DEVICE_SIZE - 1); // 0xFED00FFF
inline constexpr uint32_t NVNET_DEVICE_BASE = 0xFEF00000;
inline constexpr uint32_t NVNET_DEVICE_SIZE = (KB(1)); // = 0x00000400
inline constexpr uint32_t NVNET_DEVICE_SIZE = (KiB(1)); // = 0x00000400
inline constexpr uint32_t NVNET_DEVICE_END = (NVNET_DEVICE_BASE + NVNET_DEVICE_SIZE - 1); // 0xFEF003FF
#define XBOX_FLASH_ROM_BASE 0xFFF00000
#define XBOX_FLASH_ROM_SIZE (MB(1)) // = 0x00100000
#define XBOX_FLASH_ROM_SIZE (MiB(1)) // = 0x00100000
#define XBOX_FLASH_ROM_END (XBOX_FLASH_ROM_BASE + XBOX_FLASH_ROM_SIZE - 1) // - 0xFFFFFFF
inline constexpr uint32_t FLASH_DEVICEN_SIZE = (MB(4)); // = 0x00400000
inline constexpr uint32_t FLASH_DEVICEN_SIZE = (MiB(4)); // = 0x00400000
inline constexpr uint32_t FLASH_DEVICE1_BASE = 0xFF000000;
inline constexpr uint32_t FLASH_DEVICE1_END = (FLASH_DEVICE1_BASE + FLASH_DEVICEN_SIZE - 1); // 0xFF3FFFFF
@ -143,14 +143,14 @@ inline constexpr uint32_t FLASH_DEVICE4_END = (FLASH_DEVICE4_BASE - 1 + FLA
// Xbox pages are (1 << 12) = 0x00001000 = 4096 bytes in size. Large pages are 4 MiB instead
// NOTE: PAGE_SIZE is also defined in xfile.h (oxdk) and linux_wrapper.h (oxdk)
#define PAGE_SHIFT 12 // 2^12 = 4 KiB
#define PAGE_SIZE (1 << PAGE_SHIFT)
#define PAGE_SIZE (1 << PAGE_SHIFT) // = 0x00001000 = KiB(4)
#define PAGE_MASK (PAGE_SIZE - 1)
#define LARGE_PAGE_SHIFT 22 // 2^22 = 4 MiB
#define LARGE_PAGE_SIZE (1 << LARGE_PAGE_SHIFT) // = 0x00400000 = 4 MiB
#define LARGE_PAGE_MASK (LARGE_PAGE_SIZE - 1)
#define BYTES_IN_PHYSICAL_MAP (MB(256)) // this refers to the system RAM physical window 0x80000000 - 0x8FFFFFFF
#define BYTES_IN_PHYSICAL_MAP (MiB(256)) // this refers to the system RAM physical window 0x80000000 - 0x8FFFFFFF
#define MAXIMUM_ZERO_BITS 21 // for XbAllocateVirtualMemory
#define MAX_VIRTUAL_ADDRESS 0xFFFFFFFF
@ -160,12 +160,12 @@ inline constexpr uint32_t FLASH_DEVICE4_END = (FLASH_DEVICE4_BASE - 1 + FLA
#define USER_MEMORY_SIZE (HIGHEST_USER_ADDRESS - LOWEST_USER_ADDRESS + 1) // 0x7FFE0000 = 2 GiB - 128 KiB
// Memory size per system
#define XBOX_MEMORY_SIZE (MB(64))
#define CHIHIRO_MEMORY_SIZE (MB(128))
#define XBOX_MEMORY_SIZE (MiB(64))
#define CHIHIRO_MEMORY_SIZE (MiB(128))
// Windows' address space allocation granularity;
// See https://blogs.msdn.microsoft.com/oldnewthing/20031008-00/?p=42223
const int BLOCK_SIZE = KB(64);
const int BLOCK_SIZE = KiB(64);
extern const struct _XboxAddressRanges {
uint32_t Start;

View File

@ -48,7 +48,7 @@ bool ReserveMemoryRange(int index, blocks_reserved_t blocks_reserved)
int Size = XboxAddressRanges[index].Size;
bool HadAnyFailure = false;
// Reserve this range in 64 Kb block increments, so that during emulation
// Reserve this range in 64 KiB block increments, so that during emulation
// our memory-management code can VirtualFree() each block individually :
const DWORD Protect = XboxAddressRanges[index].InitialMemoryProtection;

View File

@ -98,7 +98,7 @@ void VMManager::Initialize(unsigned int SystemType, int BootFlags, blocks_reserv
// Set up the critical section to synchronize accesses
InitializeCriticalSectionAndSpinCount(&m_CriticalSection, 0x400);
m_AllocationGranularity = 64 * ONE_KB;
m_AllocationGranularity = KiB(64);
g_SystemMaxMemory = XBOX_MEMORY_SIZE;
// Set up the structs tracking the memory regions
@ -111,7 +111,7 @@ void VMManager::Initialize(unsigned int SystemType, int BootFlags, blocks_reserv
// We are looping here because memory-reservation happens in 64 KiB increments
for (int i = 0; i < 64; i++) {
LPVOID ret = VirtualAlloc((LPVOID)(PAGE_TABLES_BASE + i * m_AllocationGranularity), m_AllocationGranularity, MEM_COMMIT, PAGE_READWRITE);
if (ret != (LPVOID)(PAGE_TABLES_BASE + i * (64 * ONE_KB))) {
if (ret != (LPVOID)(PAGE_TABLES_BASE + i * KiB(64))) {
CxbxKrnlCleanup("VirtualAlloc failed to commit the memory for the page tables. The error was 0x%08X", GetLastError());
}
}
@ -122,14 +122,14 @@ void VMManager::Initialize(unsigned int SystemType, int BootFlags, blocks_reserv
for (unsigned int i = BLOCK_REGION_DEVKIT_INDEX_BEGIN; i < BLOCK_REGION_DEVKIT_INDEX_END; i++) {
if ((blocks_reserved[i / 32] & (1 << (i % 32))) == 0) {
// The loader was unable to reserve this block, so discard it from the memory region
ConstructVMA(DEVKIT_MEMORY_BASE + i * (64 * ONE_KB), (64 * ONE_KB), DevkitRegion, ReservedVma, false);
ConstructVMA(DEVKIT_MEMORY_BASE + i * KiB(64), KiB(64), DevkitRegion, ReservedVma, false);
}
}
}
for (unsigned int i = BLOCK_REGION_SYSTEM_INDEX_BEGIN; i < BLOCK_REGION_SYSTEM_INDEX_END; i++) {
if ((blocks_reserved[i / 32] & (1 << (i % 32))) == 0) {
// The loader was unable to reserve this block, so discard it from the memory region
ConstructVMA(SYSTEM_MEMORY_BASE + i * (64 * ONE_KB), (64 * ONE_KB), SystemRegion, ReservedVma, false);
ConstructVMA(SYSTEM_MEMORY_BASE + i * KiB(64), KiB(64), SystemRegion, ReservedVma, false);
}
}
@ -345,18 +345,18 @@ void VMManager::RestorePersistentMemory()
RemoveFree(1, &pfn, 0, pte.Hardware.PFN, pte.Hardware.PFN);
if (m_MmLayoutChihiro) {
memcpy(CHIHIRO_PFN_ELEMENT(pte.Hardware.PFN),
&((PXBOX_PFN)&persisted_mem->Data[(persisted_mem->NumOfPtes * 2) + (persisted_mem->NumOfPtes - 32) * ONE_KB])[pte.Hardware.PFN],
&((PXBOX_PFN)&persisted_mem->Data[(persisted_mem->NumOfPtes * 2) + (persisted_mem->NumOfPtes - 32) * KiB(1)])[pte.Hardware.PFN],
sizeof(XBOX_PFN));
if ((uint32_t*)persisted_mem->Data[i] < (uint32_t*)CHIHIRO_PFN_ADDRESS) {
memcpy((void*)(persisted_mem->Data[i]), &persisted_mem->Data[persisted_mem->NumOfPtes * 2 + i * ONE_KB], PAGE_SIZE);
memcpy((void*)(persisted_mem->Data[i]), &persisted_mem->Data[persisted_mem->NumOfPtes * 2 + i * KiB(1)], PAGE_SIZE);
}
}
else {
memcpy(XBOX_PFN_ELEMENT(pte.Hardware.PFN),
&((PXBOX_PFN)&persisted_mem->Data[(persisted_mem->NumOfPtes * 2) + (persisted_mem->NumOfPtes - 16) * ONE_KB])[pte.Hardware.PFN],
&((PXBOX_PFN)&persisted_mem->Data[(persisted_mem->NumOfPtes * 2) + (persisted_mem->NumOfPtes - 16) * KiB(1)])[pte.Hardware.PFN],
sizeof(XBOX_PFN));
if ((uint32_t*)persisted_mem->Data[i] < (uint32_t*)XBOX_PFN_ADDRESS) {
memcpy((void*)(persisted_mem->Data[i]), &persisted_mem->Data[persisted_mem->NumOfPtes * 2 + i * ONE_KB], PAGE_SIZE);
memcpy((void*)(persisted_mem->Data[i]), &persisted_mem->Data[persisted_mem->NumOfPtes * 2 + i * KiB(1)], PAGE_SIZE);
}
}
}
@ -480,7 +480,7 @@ void VMManager::SavePersistentMemory()
for (const auto &pte : cached_persisted_ptes) {
persisted_mem->Data[i] = GetVAddrMappedByPte(pte);
persisted_mem->Data[num_persisted_ptes + i] = pte->Default;
memcpy(&persisted_mem->Data[num_persisted_ptes * 2 + i * ONE_KB], (void *)(persisted_mem->Data[i]), PAGE_SIZE);
memcpy(&persisted_mem->Data[num_persisted_ptes * 2 + i * KiB(1)], (void *)(persisted_mem->Data[i]), PAGE_SIZE);
i++;
}

View File

@ -38,7 +38,7 @@
// This variable *MUST* be this large, for it to take up address space
// so that all other code and data in this module are placed outside of the
// maximum virtual memory range.
#define VM_PLACEHOLDER_SIZE MB(128) // Enough to cover MemLowVirtual (Cihiro/Devkit)
#define VM_PLACEHOLDER_SIZE MiB(128) // Enough to cover MemLowVirtual (Cihiro/Devkit)
// Note : In the old setup, we used #pragma section(".text"); __declspec(allocate(".text"))
// to put this variable at the exact image base address 0x00010000, but that resulted in