replace hardcode 384 to blocks_reserved_t plus add comments
This commit is contained in:
parent
897bc182f8
commit
1a1019b85c
|
@ -196,11 +196,6 @@ extern const struct _XboxAddressRanges {
|
|||
|
||||
extern const size_t XboxAddressRanges_size;
|
||||
|
||||
#define BLOCK_REGION_DEVKIT_INDEX_BEGIN 0
|
||||
#define BLOCK_REGION_DEVKIT_INDEX_END 4096
|
||||
#define BLOCK_REGION_SYSTEM_INDEX_BEGIN 4096
|
||||
#define BLOCK_REGION_SYSTEM_INDEX_END 12288
|
||||
|
||||
extern bool AddressRangeMatchesFlags(const int index, const unsigned int flags);
|
||||
extern bool IsOptionalAddressRange(const int index);
|
||||
extern int AddressRangeGetSystemFlags(const int index);
|
||||
|
|
|
@ -38,10 +38,11 @@
|
|||
#include <cstdint> // For uint32_t
|
||||
|
||||
#include "util/std_extend.hpp"
|
||||
#include "ReserveAddressRanges.h"
|
||||
#include "AddressRanges.h"
|
||||
|
||||
// Reserve an address range up to the extend of what the host allows.
|
||||
bool ReserveMemoryRange(int index, uint32_t blocks_reserved[384])
|
||||
bool ReserveMemoryRange(int index, blocks_reserved_t blocks_reserved)
|
||||
{
|
||||
uint32_t Start = XboxAddressRanges[index].Start;
|
||||
int Size = XboxAddressRanges[index].Size;
|
||||
|
@ -143,7 +144,7 @@ bool ReserveMemoryRange(int index, uint32_t blocks_reserved[384])
|
|||
}
|
||||
|
||||
// Free address range from the host.
|
||||
void FreeMemoryRange(int index, uint32_t blocks_reserved[384])
|
||||
void FreeMemoryRange(int index, blocks_reserved_t blocks_reserved)
|
||||
{
|
||||
uint32_t Start = XboxAddressRanges[index].Start, _Start;
|
||||
int Size = XboxAddressRanges[index].Size;
|
||||
|
@ -205,7 +206,7 @@ void FreeMemoryRange(int index, uint32_t blocks_reserved[384])
|
|||
#endif
|
||||
}
|
||||
|
||||
bool ReserveAddressRanges(const unsigned int system, uint32_t blocks_reserved[384]) {
|
||||
bool ReserveAddressRanges(const unsigned int system, blocks_reserved_t blocks_reserved) {
|
||||
// Loop over all Xbox address ranges
|
||||
for (size_t i = 0; i < XboxAddressRanges_size; i++) {
|
||||
// Skip address ranges that don't match the given flags
|
||||
|
@ -225,7 +226,7 @@ bool ReserveAddressRanges(const unsigned int system, uint32_t blocks_reserved[38
|
|||
return true;
|
||||
}
|
||||
|
||||
void FreeAddressRanges(const unsigned int system, unsigned int release_systems, uint32_t blocks_reserved[384]) {
|
||||
void FreeAddressRanges(const unsigned int system, unsigned int release_systems, blocks_reserved_t blocks_reserved) {
|
||||
// If reserved_systems is empty, then there's nothing to be freed up.
|
||||
if (release_systems == 0) {
|
||||
return;
|
||||
|
@ -245,7 +246,7 @@ void FreeAddressRanges(const unsigned int system, unsigned int release_systems,
|
|||
|
||||
}
|
||||
|
||||
bool AttemptReserveAddressRanges(unsigned int* p_reserved_systems, uint32_t blocks_reserved[384]) {
|
||||
bool AttemptReserveAddressRanges(unsigned int* p_reserved_systems, blocks_reserved_t blocks_reserved) {
|
||||
|
||||
size_t iLast = 0;
|
||||
unsigned int reserved_systems = *p_reserved_systems, clear_systems = 0;
|
||||
|
|
|
@ -26,10 +26,22 @@
|
|||
// ******************************************************************
|
||||
#pragma once
|
||||
|
||||
extern bool ReserveAddressRanges(const unsigned int system, uint32_t blocks_reserved[384]);
|
||||
#include <cstdint> // For uint32_t
|
||||
|
||||
extern void FreeAddressRanges(const unsigned int system, unsigned int release_systems, uint32_t blocks_reserved[384]);
|
||||
// First block section will be devkit region (256MiB) = 262144KiB / 64 KiB = 4096 bits needed -> 4096 / 32 (sizeof(uint32_t)) = 128 entries blocks_reserved array.
|
||||
// Next block section will be system region (512MiB) = 524288KiB / 64KiB = 8192 bits needed -> 8192 / 32 (sizeof(uint32_t)) = 256 entries of blocks_reserved array.
|
||||
// 1 bit per block_size (64KiB).
|
||||
typedef uint32_t blocks_reserved_t[384]; // 384 = 128 (devkit region) + 256 (system region)
|
||||
|
||||
extern bool AttemptReserveAddressRanges(unsigned int* p_reserved_systems, uint32_t blocks_reserved[384]);
|
||||
inline constexpr uint32_t BLOCK_REGION_DEVKIT_INDEX_BEGIN = 0;
|
||||
inline constexpr uint32_t BLOCK_REGION_DEVKIT_INDEX_END = 4096;
|
||||
inline constexpr uint32_t BLOCK_REGION_SYSTEM_INDEX_BEGIN = 4096;
|
||||
inline constexpr uint32_t BLOCK_REGION_SYSTEM_INDEX_END = 12288;
|
||||
|
||||
extern bool ReserveAddressRanges(const unsigned int system, blocks_reserved_t blocks_reserved);
|
||||
|
||||
extern void FreeAddressRanges(const unsigned int system, unsigned int release_systems, blocks_reserved_t blocks_reserved);
|
||||
|
||||
extern bool AttemptReserveAddressRanges(unsigned int* p_reserved_systems, blocks_reserved_t blocks_reserved);
|
||||
|
||||
extern bool isSystemFlagSupport(unsigned int reserved_systems, unsigned int assign_system);
|
||||
|
|
|
@ -708,7 +708,7 @@ bool HandleFirstLaunch()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CxbxKrnlEmulate(unsigned int reserved_systems, uint32_t blocks_reserved[384])
|
||||
void CxbxKrnlEmulate(unsigned int reserved_systems, blocks_reserved_t blocks_reserved)
|
||||
{
|
||||
std::string tempStr;
|
||||
|
||||
|
@ -1131,7 +1131,7 @@ void CxbxKrnlEmulate(unsigned int reserved_systems, uint32_t blocks_reserved[384
|
|||
|
||||
#ifndef CXBXR_EMU
|
||||
// Initialize the memory manager
|
||||
uint32_t SystemDevBlocksReserved[384] = { 0 };
|
||||
blocks_reserved_t SystemDevBlocksReserved = { 0 };
|
||||
g_VMManager.Initialize(0, BootFlags, SystemDevBlocksReserved);
|
||||
#else
|
||||
FreeAddressRanges(emulate_system, reserved_systems, blocks_reserved);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "Cxbx.h"
|
||||
#include "common\AddressRanges.h"
|
||||
#include "common/ReserveAddressRanges.h"
|
||||
#include "common\xbe\Xbe.h"
|
||||
#include "Logging.h"
|
||||
|
||||
|
@ -168,7 +169,7 @@ bool CreateSettings();
|
|||
bool HandleFirstLaunch();
|
||||
|
||||
/*! Cxbx Kernel Entry Point */
|
||||
void CxbxKrnlEmulate(unsigned int system, uint32_t blocks_reserved[384]);
|
||||
void CxbxKrnlEmulate(unsigned int system, blocks_reserved_t blocks_reserved);
|
||||
|
||||
/*! initialize emulation */
|
||||
__declspec(noreturn) void CxbxKrnlInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32_t XbeHeaderSize, void (*Entry)(), int BootFlags);
|
||||
|
|
|
@ -74,7 +74,7 @@ bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void VMManager::Initialize(unsigned int SystemType, int BootFlags, uint32_t blocks_reserved[384])
|
||||
void VMManager::Initialize(unsigned int SystemType, int BootFlags, blocks_reserved_t blocks_reserved)
|
||||
{
|
||||
if ((BootFlags & BOOT_QUICK_REBOOT) == 0) {
|
||||
#ifndef CXBXR_EMU
|
||||
|
@ -117,6 +117,7 @@ void VMManager::Initialize(unsigned int SystemType, int BootFlags, uint32_t bloc
|
|||
}
|
||||
|
||||
// Construct VMAs base on reserved bit indexes for devkit and system region blocks.
|
||||
// See "blocks_reserved_t" notes.
|
||||
if (SystemType == SYSTEM_DEVKIT) {
|
||||
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) {
|
||||
|
|
|
@ -99,7 +99,7 @@ class VMManager : public PhysicalMemory
|
|||
// shutdown routine
|
||||
void Shutdown();
|
||||
// initializes the memory manager to the default configuration
|
||||
void Initialize(unsigned int SystemType, int BootFlags, uint32_t blocks_reserved[384]);
|
||||
void Initialize(unsigned int SystemType, int BootFlags, blocks_reserved_t blocks_reserved);
|
||||
// retrieves memory statistics
|
||||
void MemoryStatistics(xboxkrnl::PMM_STATISTICS memory_statistics);
|
||||
// allocates memory in the user region
|
||||
|
|
|
@ -122,7 +122,7 @@ CommandLineToArgvA(
|
|||
return argv;
|
||||
}
|
||||
|
||||
DWORD WINAPI Emulate(unsigned int reserved_systems, uint32_t blocks_reserved[384])
|
||||
DWORD WINAPI Emulate(unsigned int reserved_systems, blocks_reserved_t blocks_reserved)
|
||||
{
|
||||
FUNC_EXPORTS
|
||||
|
||||
|
|
|
@ -172,9 +172,9 @@ DWORD CALLBACK rawMain()
|
|||
unsigned int system = SYSTEM_ALL; // Reserve all systems.
|
||||
|
||||
// Marking this as static to avoid an implicit call to memset, which is not available in the loader
|
||||
static uint32_t SystemDevBlocksReserved[384];
|
||||
static blocks_reserved_t blocks_reserved;
|
||||
|
||||
if (!AttemptReserveAddressRanges(&system, SystemDevBlocksReserved)) {
|
||||
if (!AttemptReserveAddressRanges(&system, blocks_reserved)) {
|
||||
// If we get here, emulation lacks important address ranges; Don't launch
|
||||
OutputMessage("None of system types' required address range(s) could be reserved!\n");
|
||||
return ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
@ -194,7 +194,7 @@ DWORD CALLBACK rawMain()
|
|||
}
|
||||
|
||||
// Find the main emulation function in our DLL
|
||||
typedef void (WINAPI *Emulate_t)(unsigned int, uint32_t[384]);
|
||||
typedef void (WINAPI *Emulate_t)(unsigned int, blocks_reserved_t);
|
||||
Emulate_t pfnEmulate = (Emulate_t)GetProcAddress(hEmulationDLL, "Emulate");
|
||||
if (!pfnEmulate) {
|
||||
OutputMessage("Entrypoint not found!\n");
|
||||
|
@ -203,7 +203,7 @@ DWORD CALLBACK rawMain()
|
|||
|
||||
// Call the main emulation function in our DLL, passing in the results
|
||||
// of the address range reservations
|
||||
pfnEmulate(system, SystemDevBlocksReserved);
|
||||
pfnEmulate(system, blocks_reserved);
|
||||
|
||||
// Once emulation actually started, execution may never return here
|
||||
// because all code and data that have been used up until now are
|
||||
|
|
Loading…
Reference in New Issue