Reviving my more-than-a-year-old Loader branch, by copying over various things (nothing functional yet)
This commit is contained in:
parent
2a23634c77
commit
ca6423b484
|
@ -27,14 +27,14 @@
|
|||
|
||||
#include "common\Error.h"
|
||||
|
||||
const std::string& Error::GetError()
|
||||
const std::string Error::GetError()
|
||||
{
|
||||
return m_strError;
|
||||
return std::string(m_szError);
|
||||
}
|
||||
|
||||
bool Error::HasError() const
|
||||
{
|
||||
return HasFatalError() || !m_strError.empty();
|
||||
return HasFatalError() || (m_szError[0] != '\0');
|
||||
}
|
||||
|
||||
bool Error::HasFatalError() const
|
||||
|
@ -46,7 +46,7 @@ bool Error::ClearError()
|
|||
{
|
||||
if (m_bFatal) { return false; }
|
||||
|
||||
m_strError.clear();
|
||||
m_szError[0] = '\0';
|
||||
m_bFatal = false;
|
||||
|
||||
return true;
|
||||
|
@ -54,11 +54,17 @@ bool Error::ClearError()
|
|||
|
||||
void Error::SetError(const std::string& strError)
|
||||
{
|
||||
m_strError = strError;
|
||||
// assert(strError.length()) < sizeof(m_szError));
|
||||
|
||||
memset(m_szError, '\0', sizeof(m_szError));
|
||||
memcpy(m_szError, strError.c_str(), strError.length());
|
||||
}
|
||||
|
||||
void Error::SetFatalError(const std::string& strError)
|
||||
{
|
||||
m_strError = strError;
|
||||
// assert(strError.length()) < sizeof(m_szError));
|
||||
|
||||
memset(m_szError, '\0', sizeof(m_szError));
|
||||
memcpy(m_szError, strError.c_str(), strError.length());
|
||||
m_bFatal = true;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
class Error
|
||||
{
|
||||
public:
|
||||
const std::string& GetError();
|
||||
const std::string GetError();
|
||||
|
||||
bool HasError() const;
|
||||
bool HasFatalError() const;
|
||||
|
@ -42,15 +42,15 @@ public:
|
|||
|
||||
protected:
|
||||
// protected constructor so this class must be inherited from
|
||||
Error() : m_bFatal(false) { }
|
||||
Error() : m_szError("\0"), m_bFatal(false) { }
|
||||
|
||||
// protected so only derived class may set an error
|
||||
void SetError(const std::string& strStrError);
|
||||
void SetFatalError(const std::string& strError);
|
||||
|
||||
private:
|
||||
std::string m_strError;
|
||||
bool m_bFatal;
|
||||
char m_szError[60]; // Cannot be std::string, which sizeof() differs between builds
|
||||
uint32_t m_bFatal; // Cannot be bool, to avoid bit packing altering memory layout
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -43,6 +43,8 @@ EmuShared *g_EmuShared = nullptr;
|
|||
// ******************************************************************
|
||||
HANDLE hMapObject = NULL;
|
||||
|
||||
HMODULE hActiveModule = NULL;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuShared::EmuSharedInit
|
||||
// ******************************************************************
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
#include <memory.h>
|
||||
|
||||
extern HMODULE hActiveModule; // Equals EXE Module handle in (GUI) Cxbx.exe, equals DLL Module handle in Cxbx-Reloaded.dll
|
||||
|
||||
typedef enum _XBOX_LED_COLOUR: unsigned char {
|
||||
XBOX_LED_COLOUR_OFF,
|
||||
XBOX_LED_COLOUR_GREEN,
|
||||
|
|
|
@ -1719,7 +1719,7 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid)
|
|||
sizeof(WNDCLASSEX),
|
||||
CS_CLASSDC,
|
||||
EmuMsgProc,
|
||||
0, 0, GetModuleHandle(nullptr),
|
||||
0, 0, hActiveModule, // Was GetModuleHandle(nullptr),
|
||||
0, // TODO : LoadIcon(hmodule, ?)
|
||||
LoadCursor(NULL, IDC_ARROW),
|
||||
(HBRUSH)(g_hBgBrush), NULL,
|
||||
|
@ -1766,7 +1766,8 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid)
|
|||
windowRect.top,
|
||||
windowRect.right - windowRect.left,
|
||||
windowRect.bottom - windowRect.top,
|
||||
hwndParent, NULL, GetModuleHandle(nullptr), nullptr
|
||||
hwndParent, nullptr, hActiveModule, // Was GetModuleHandle(nullptr),
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -345,13 +345,18 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CXBX_LOADER
|
||||
// TODO : Use ReserveMemoryRange / UnreserveMemoryRange(Mem??) where appropriate
|
||||
#endif
|
||||
|
||||
// Map memory.bin contents into memory :
|
||||
void *memory = (void *)MapViewOfFileEx(
|
||||
hFileMapping,
|
||||
FILE_MAP_READ | FILE_MAP_WRITE | FILE_MAP_EXECUTE,
|
||||
/* dwFileOffsetHigh */0,
|
||||
/* dwFileOffsetLow */0,
|
||||
CONTIGUOUS_MEMORY_CHIHIRO_SIZE,
|
||||
CHIHIRO_CONTIGUOUS_MEMORY_SIZE,
|
||||
(void *)CONTIGUOUS_MEMORY_BASE);
|
||||
if (memory != (void *)CONTIGUOUS_MEMORY_BASE)
|
||||
{
|
||||
|
@ -363,11 +368,11 @@ HANDLE CxbxRestoreContiguousMemory(char *szFilePath_memory_bin)
|
|||
}
|
||||
|
||||
EmuLogInit(LOG_LEVEL::INFO, "Mapped %d MiB of Xbox contiguous memory at 0x%.8X to 0x%.8X",
|
||||
CONTIGUOUS_MEMORY_CHIHIRO_SIZE / ONE_MB, CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_BASE + CONTIGUOUS_MEMORY_CHIHIRO_SIZE - 1);
|
||||
CHIHIRO_CONTIGUOUS_MEMORY_SIZE / ONE_MB, CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_BASE + CHIHIRO_CONTIGUOUS_MEMORY_SIZE - 1);
|
||||
|
||||
if (NeedsInitialization)
|
||||
{
|
||||
memset(memory, 0, CONTIGUOUS_MEMORY_CHIHIRO_SIZE);
|
||||
memset(memory, 0, CHIHIRO_CONTIGUOUS_MEMORY_SIZE);
|
||||
EmuLogInit(LOG_LEVEL::INFO, "Initialized contiguous memory");
|
||||
}
|
||||
else
|
||||
|
@ -1048,12 +1053,21 @@ void CxbxKrnlMain(int argc, char* argv[])
|
|||
return; // TODO : Halt(0);
|
||||
}
|
||||
|
||||
#ifndef CXBX_LOADER
|
||||
// verify virtual_memory_placeholder is located at 0x00011000
|
||||
if ((UINT_PTR)(&(virtual_memory_placeholder[0])) != (XBE_IMAGE_BASE + CXBX_BASE_OF_CODE))
|
||||
{
|
||||
CxbxPopupMessage(LOG_LEVEL::FATAL, CxbxMsgDlgIcon_Error, "virtual_memory_placeholder is not loaded to base address 0x00011000 (which is a requirement for Xbox emulation)");
|
||||
return; // TODO : Halt(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CXBX_LOADER
|
||||
if (!VerifyAddressRanges()) {
|
||||
CxbxPopupMessage("Cxbx-Reloaded hasn't got access to all required address ranges");
|
||||
return; // TODO : Halt(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create a safe copy of the complete EXE header:
|
||||
DWORD ExeHeaderSize = ExeOptionalHeader->SizeOfHeaders; // Should end up as 0x400
|
||||
|
@ -1074,7 +1088,27 @@ void CxbxKrnlMain(int argc, char* argv[])
|
|||
|
||||
// Mark the virtual memory range completely accessible
|
||||
DWORD OldProtection;
|
||||
VirtualProtect((void*)XBE_IMAGE_BASE, XBE_MAX_VA - XBE_IMAGE_BASE, PAGE_EXECUTE_READWRITE, &OldProtection);
|
||||
if (0 == VirtualProtect((void*)XBE_IMAGE_BASE, XBE_MAX_VA - XBE_IMAGE_BASE, PAGE_EXECUTE_READWRITE, &OldProtection)) {
|
||||
DWORD err = GetLastError();
|
||||
|
||||
// Translate ErrorCode to String.
|
||||
LPTSTR Error = 0;
|
||||
if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
err,
|
||||
0,
|
||||
(LPTSTR)&Error,
|
||||
0,
|
||||
NULL) == 0) {
|
||||
// Failed in translating.
|
||||
}
|
||||
|
||||
// Free the buffer.
|
||||
if (Error) {
|
||||
::LocalFree(Error);
|
||||
Error = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear out the virtual memory range
|
||||
memset((void*)XBE_IMAGE_BASE, 0, XBE_MAX_VA - XBE_IMAGE_BASE);
|
||||
|
|
|
@ -45,97 +45,103 @@ extern "C" {
|
|||
|
||||
// Sizes
|
||||
#define ONE_KB 1024
|
||||
#define ONE_MB (1024 * 1024)
|
||||
#define X64KB 64 * ONE_KB
|
||||
|
||||
// NT_TIB (Thread Information Block) offsets - see https://www.microsoft.com/msj/archive/S2CE.aspx
|
||||
#define TIB_ArbitraryDataSlot 0x14 // = 20 = offsetof(NT_TIB, ArbitraryUserPointer)
|
||||
#define TIB_LinearSelfAddress 0x18 // = 24 = offsetof(NT_TIB, Self)
|
||||
#define ONE_MB (1024 * ONE_KB)
|
||||
#define X64KB (64 * ONE_KB)
|
||||
|
||||
#define XBADDR_BITS 32
|
||||
#define XBADDR_MAX UINT32_MAX
|
||||
|
||||
// Base addresses of various components
|
||||
#define KSEG0_BASE 0x80000000
|
||||
|
||||
#define PHYSICAL_MAP_BASE 0x80000000
|
||||
#define PHYSICAL_MAP_SIZE (256 * ONE_MB) // = 0x10000000
|
||||
#define PHYSICAL_MAP_END (PHYSICAL_MAP_BASE + PHYSICAL_MAP_SIZE - 1) // 0x8FFFFFFF
|
||||
|
||||
#define CONTIGUOUS_MEMORY_BASE KSEG0_BASE // = 0x80000000
|
||||
#define XBOX_CONTIGUOUS_MEMORY_SIZE (64 * ONE_MB)
|
||||
#define CHIHIRO_CONTIGUOUS_MEMORY_SIZE (128 * ONE_MB)
|
||||
|
||||
#define DEVKIT_MEMORY_BASE 0xB0000000
|
||||
#define DEVKIT_MEMORY_SIZE (256 * ONE_MB) // = 0x10000000
|
||||
#define DEVKIT_MEMORY_END (DEVKIT_MEMORY_BASE + DEVKIT_MEMORY_SIZE - 1) // 0xBFFFFFFF
|
||||
|
||||
#define PAGE_TABLES_BASE 0xC0000000
|
||||
#define PAGE_TABLES_SIZE (4 * ONE_MB) // = 0x00400000
|
||||
#define PAGE_TABLES_END (PAGE_TABLES_BASE + PAGE_TABLES_SIZE - 1)
|
||||
|
||||
#define SYSTEM_MEMORY_BASE 0xD0000000
|
||||
#define SYSTEM_MEMORY_SIZE (512 * ONE_MB) // = 0x20000000
|
||||
#define SYSTEM_MEMORY_END (SYSTEM_MEMORY_BASE + SYSTEM_MEMORY_SIZE - 1) // 0xEFFFFFFF
|
||||
|
||||
#define XBOX_WRITE_COMBINED_BASE 0xF0000000 // WC (The WC memory is another name of the tiled memory)
|
||||
#define XBOX_WRITE_COMBINED_SIZE (128 * ONE_MB) // = 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 ((128 - 4) * ONE_MB) // = 0x07C00000
|
||||
#define XBOX_UNCACHED_END (XBOX_UNCACHED_BASE + XBOX_UNCACHED_SIZE - 1) // - 0xFFBFFFFF
|
||||
|
||||
#define XBOX_FLASH_ROM_BASE 0xFFF00000
|
||||
#define XBOX_FLASH_ROM_SIZE (1 * ONE_MB) // = 0x00100000
|
||||
#define XBOX_FLASH_ROM_END (XBOX_FLASH_ROM_BASE + XBOX_FLASH_ROM_SIZE - 1) // - 0xFFFFFFF
|
||||
|
||||
// Miscellaneous base addresses
|
||||
#define XBE_IMAGE_BASE 0x00010000
|
||||
#define PAGE_DIRECTORY_BASE 0xC0300000
|
||||
#define NV2A_INIT_VECTOR 0xFF000008
|
||||
|
||||
// Define virtual base and alternate virtual base of kernel
|
||||
#define XBOX_KERNEL_BASE (PHYSICAL_MAP_BASE + XBE_IMAGE_BASE)
|
||||
#define KERNEL_PHYSICAL_ADDRESS XBE_IMAGE_BASE // = 0x10000
|
||||
#define KERNEL_SIZE sizeof(DUMMY_KERNEL)
|
||||
#define KERNEL_STACK_SIZE 12288 // 0x03000, needed by PsCreateSystemThreadEx, however the current implementation doesn't use it
|
||||
|
||||
// Miscellaneous memory variables
|
||||
#define KERNEL_STACK_SIZE 12288 // 0x03000, needed by PsCreateSystemThreadEx, however the current implementation doesn't use it
|
||||
#define KERNEL_SIZE sizeof(DUMMY_KERNEL)
|
||||
#define PAGE_SHIFT 12 // 2^12 = 4K
|
||||
#define PAGE_SHIFT_LARGE 22 // 2^22 = 4M
|
||||
// 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_SIZE (1 << PAGE_SHIFT)
|
||||
#define PAGE_SIZE_LARGE 0x400000
|
||||
#define PAGE_MASK (PAGE_SIZE - 1)
|
||||
#define BYTES_IN_PHYSICAL_MAP 256 * ONE_MB // this refears to the system RAM physical window 0x80000000 - 0x8FFFFFFF
|
||||
#define MAXIMUM_ZERO_BITS 21 // for XbAllocateVirtualMemory
|
||||
#define PAGE_SHIFT 12 // 2^12 = 4 KiB
|
||||
#define PAGE_SIZE (1 << PAGE_SHIFT)
|
||||
#define PAGE_MASK (PAGE_SIZE - 1)
|
||||
|
||||
/*! memory size per system */
|
||||
#define XBOX_MEMORY_SIZE (64 * ONE_MB)
|
||||
#define CHIHIRO_MEMORY_SIZE (128 * ONE_MB)
|
||||
#define XBE_IMAGE_BASE 0x00010000
|
||||
#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 virtual base and alternate virtual base of kernel.
|
||||
#define KSEG0_BASE 0x80000000
|
||||
#define BYTES_IN_PHYSICAL_MAP (256 * ONE_MB) // this refers to the system RAM physical window 0x80000000 - 0x8FFFFFFF
|
||||
#define MAXIMUM_ZERO_BITS 21 // for XbAllocateVirtualMemory
|
||||
#define MAX_VIRTUAL_ADDRESS 0xFFFFFFFF
|
||||
|
||||
#define LOWEST_USER_ADDRESS XBE_IMAGE_BASE // = 0x00010000
|
||||
#define HIGHEST_USER_ADDRESS 0x7FFEFFFF
|
||||
#define HIGHEST_VMA_ADDRESS (HIGHEST_USER_ADDRESS - X64KB) // for NtAllocateVirtualMemory
|
||||
#define USER_MEMORY_SIZE (HIGHEST_USER_ADDRESS - LOWEST_USER_ADDRESS + 1) // 0x7FFE0000 = 2 GiB - 128 KiB
|
||||
|
||||
// Memory size per system
|
||||
#define XBOX_MEMORY_SIZE (64 * ONE_MB)
|
||||
#define CHIHIRO_MEMORY_SIZE (128 * ONE_MB)
|
||||
|
||||
// Define virtual base addresses used by the system.
|
||||
#define KERNEL_PHYSICAL_ADDRESS XBE_IMAGE_BASE // = 0x10000
|
||||
#define XBOX_HIGHEST_PHYSICAL_PAGE 0x03FFF
|
||||
#define CHIHIRO_HIGHEST_PHYSICAL_PAGE 0x07FFF
|
||||
#define X64M_PHYSICAL_PAGE 0x04000
|
||||
#define XBOX_INSTANCE_PHYSICAL_PAGE 0x03FE0
|
||||
#define CHIHIRO_INSTANCE_PHYSICAL_PAGE 0x07FF0
|
||||
#define XBOX_PFN_DATABASE_PHYSICAL_PAGE 0x03FF0
|
||||
#define CHIHIRO_PFN_DATABASE_PHYSICAL_PAGE 0x07FD0
|
||||
#define XBOX_CONTIGUOUS_MEMORY_LIMIT 0x03FDF
|
||||
#define CHIHIRO_CONTIGUOUS_MEMORY_LIMIT 0x07FCF
|
||||
#define PAGE_DIRECTORY_PHYSICAL_ADDRESS 0x0F000
|
||||
#define D3D_PHYSICAL_PAGE 0x00000
|
||||
#define DEBUGKIT_FIRST_UPPER_HALF_PAGE X64M_PHYSICAL_PAGE // = 0x4000
|
||||
#define NV2A_INSTANCE_PAGE_COUNT 16
|
||||
#define CONTIGUOUS_MEMORY_BASE KSEG0_BASE // = 0x80000000
|
||||
#define CONTIGUOUS_MEMORY_XBOX_SIZE (64 * ONE_MB)
|
||||
#define CONTIGUOUS_MEMORY_CHIHIRO_SIZE (128 * ONE_MB)
|
||||
#define XBOX_PFN_ADDRESS ((XBOX_PFN_DATABASE_PHYSICAL_PAGE << PAGE_SHIFT) + (PCHAR)KSEG0_BASE)
|
||||
#define CHIHIRO_PFN_ADDRESS ((CHIHIRO_PFN_DATABASE_PHYSICAL_PAGE << PAGE_SHIFT) + (PCHAR)KSEG0_BASE)
|
||||
#define MAX_VIRTUAL_ADDRESS 0xFFFFFFFF
|
||||
#define XBOX_CONTIGUOUS_MEMORY_LIMIT 0x03FDF
|
||||
#define XBOX_INSTANCE_PHYSICAL_PAGE 0x03FE0
|
||||
#define XBOX_PFN_DATABASE_PHYSICAL_PAGE 0x03FF0
|
||||
#define XBOX_HIGHEST_PHYSICAL_PAGE 0x03FFF
|
||||
|
||||
/*! base addresses of various components */
|
||||
// The WC memory is another name of the tiled memory
|
||||
#define XBOX_WRITE_COMBINED_BASE 0xF0000000 // WC
|
||||
#define XBOX_WRITE_COMBINED_SIZE 0x08000000 // - 0xF7FFFFFF
|
||||
#define XBOX_WRITE_COMBINE_END XBOX_WRITE_COMBINED_BASE + XBOX_WRITE_COMBINED_SIZE // 128 MiB
|
||||
#define X64M_PHYSICAL_PAGE 0x04000
|
||||
|
||||
#define XBOX_UNCACHED_BASE 0xF8000000 // UC
|
||||
#define XBOX_UNCACHED_SIZE 0x07C00000 // - 0xFFBFFFFF
|
||||
#define XBOX_UNCACHED_END XBOX_UNCACHED_BASE + XBOX_UNCACHED_SIZE - 1 // 128 MiB - 4 MiB
|
||||
#define CHIHIRO_CONTIGUOUS_MEMORY_LIMIT 0x07FCF
|
||||
#define CHIHIRO_PFN_DATABASE_PHYSICAL_PAGE 0x07FD0
|
||||
#define CHIHIRO_INSTANCE_PHYSICAL_PAGE 0x07FF0
|
||||
#define CHIHIRO_HIGHEST_PHYSICAL_PAGE 0x07FFF
|
||||
|
||||
#define SYSTEM_MEMORY_BASE 0xD0000000
|
||||
#define SYSTEM_MEMORY_SIZE 0x20000000 // 512 MiB
|
||||
#define SYSTEM_MEMORY_END SYSTEM_MEMORY_BASE + SYSTEM_MEMORY_SIZE - 1 // 0xEFFFFFFF
|
||||
#define PAGE_DIRECTORY_PHYSICAL_ADDRESS 0x0F000
|
||||
#define D3D_PHYSICAL_PAGE 0x00000
|
||||
#define DEBUGKIT_FIRST_UPPER_HALF_PAGE X64M_PHYSICAL_PAGE // = 0x4000
|
||||
|
||||
#define DEVKIT_MEMORY_BASE 0xB0000000
|
||||
#define DEVKIT_MEMORY_SIZE 0x10000000 // 256 MiB
|
||||
#define DEVKIT_MEMORY_END DEVKIT_MEMORY_BASE + DEVKIT_MEMORY_SIZE - 1 // 0xBFFFFFFF
|
||||
#define XBOX_PFN_ADDRESS ((XBOX_PFN_DATABASE_PHYSICAL_PAGE << PAGE_SHIFT) + (PCHAR)KSEG0_BASE)
|
||||
#define CHIHIRO_PFN_ADDRESS ((CHIHIRO_PFN_DATABASE_PHYSICAL_PAGE << PAGE_SHIFT) + (PCHAR)KSEG0_BASE)
|
||||
|
||||
#define PHYSICAL_MAP_BASE 0x80000000
|
||||
#define PHYSICAL_MAP_SIZE 0x10000000 // 256 MiB
|
||||
#define PHYSICAL_MAP_END PHYSICAL_MAP_BASE + PHYSICAL_MAP_SIZE - 1 // 0x8FFFFFFF
|
||||
|
||||
#define XBOX_NV2A_INIT_VECTOR 0xFF000008
|
||||
|
||||
#define XBOX_FLASH_ROM_BASE 0xFFF00000
|
||||
#define XBOX_FLASH_ROM_SIZE 0x00100000 // - 0xFFFFFFF
|
||||
|
||||
#define LOWEST_USER_ADDRESS XBE_IMAGE_BASE // = 0x10000
|
||||
#define HIGHEST_USER_ADDRESS 0x7FFEFFFF
|
||||
#define HIGHEST_VMA_ADDRESS HIGHEST_USER_ADDRESS - X64KB // for NtAllocateVirtualMemory
|
||||
#define USER_MEMORY_SIZE HIGHEST_USER_ADDRESS - LOWEST_USER_ADDRESS + 1 // 0x7FFE0000 = 2 GiB - 128 KiB
|
||||
|
||||
#define PAGE_DIRECTORY_BASE 0xC0300000
|
||||
#define PAGE_TABLES_BASE 0xC0000000
|
||||
#define PAGE_TABLES_SIZE 4 * ONE_MB
|
||||
#define PAGE_TABLES_END PAGE_TABLES_BASE + PAGE_TABLES_SIZE - 1
|
||||
|
||||
#define XBOX_KERNEL_BASE (PHYSICAL_MAP_BASE + XBE_IMAGE_BASE)
|
||||
#define NV2A_INSTANCE_PAGE_COUNT 16
|
||||
|
||||
// For now, virtual addresses are somewhat limited, as we use
|
||||
// these soley for loading XBE sections. The largest that we
|
||||
|
@ -144,11 +150,15 @@ extern "C" {
|
|||
// fit in 51 MB. If we ever encounter an even larger XBE, this
|
||||
// value will have to be increased likewise (maybe up to 64 MB
|
||||
// for XBOX_MEMORY_SIZE or even 128 MB for CHIHIRO_MEMORY_SIZE).
|
||||
#define XBE_MAX_VA (64 * ONE_MB)
|
||||
#define XBE_MAX_VA (64 * ONE_MB)
|
||||
|
||||
/*! base address of Cxbx host executable, see Cxbx project options, Linker, Advanced, Base Address */
|
||||
#define CXBX_BASE_ADDR XBE_IMAGE_BASE
|
||||
#define CXBX_BASE_OF_CODE 0x00001000
|
||||
#define CXBX_BASE_ADDR XBE_IMAGE_BASE
|
||||
#define CXBX_BASE_OF_CODE 0x00001000
|
||||
|
||||
// NT_TIB (Thread Information Block) offsets - see https://www.microsoft.com/msj/archive/S2CE.aspx
|
||||
#define TIB_ArbitraryDataSlot 0x14 // = 20 = offsetof(NT_TIB, ArbitraryUserPointer)
|
||||
#define TIB_LinearSelfAddress 0x18 // = 24 = offsetof(NT_TIB, Self)
|
||||
|
||||
#define MAX_BUS_INTERRUPT_LEVEL 27
|
||||
#define MAX_NUM_INTERRUPTS 256
|
||||
|
@ -194,7 +204,6 @@ typedef enum _CxbxMsgDlgIcon {
|
|||
CxbxMsgDlgIcon_Warn,
|
||||
CxbxMsgDlgIcon_Error,
|
||||
CxbxMsgDlgIcon_Unknown
|
||||
|
||||
} CxbxMsgDlgIcon;
|
||||
|
||||
void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...);
|
||||
|
|
|
@ -55,11 +55,11 @@ void PhysicalMemory::InitializePageDirectory()
|
|||
TempPte.Hardware.LargePage = 1;
|
||||
TempPte.Hardware.PFN = XBOX_WRITE_COMBINED_BASE >> PAGE_SHIFT;
|
||||
SET_WRITE_COMBINE(TempPte);
|
||||
pPde_end = GetPdeAddress(XBOX_WRITE_COMBINE_END - 1);
|
||||
pPde_end = GetPdeAddress(XBOX_WRITE_COMBINED_END);
|
||||
for (pPde = GetPdeAddress(XBOX_WRITE_COMBINED_BASE); pPde <= pPde_end; ++pPde)
|
||||
{
|
||||
WRITE_PTE(pPde, TempPte);
|
||||
TempPte.Default += PAGE_SIZE_LARGE; // increase PFN
|
||||
TempPte.Default += LARGE_PAGE_SIZE; // increase PFN
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ void PhysicalMemory::InitializePageDirectory()
|
|||
for (pPde = GetPdeAddress(XBOX_UNCACHED_BASE); pPde <= pPde_end; ++pPde)
|
||||
{
|
||||
WRITE_PTE(pPde, TempPte);
|
||||
TempPte.Default += PAGE_SIZE_LARGE; // increase PFN
|
||||
TempPte.Default += LARGE_PAGE_SIZE; // increase PFN
|
||||
}
|
||||
|
||||
|
||||
|
@ -667,7 +667,7 @@ bool PhysicalMemory::AllocatePT(size_t Size, VAddr addr)
|
|||
{
|
||||
PTtoCommit++;
|
||||
}
|
||||
StartingAddr += PAGE_SIZE_LARGE;
|
||||
StartingAddr += LARGE_PAGE_SIZE;
|
||||
}
|
||||
|
||||
if (!PTtoCommit)
|
||||
|
@ -703,7 +703,7 @@ bool PhysicalMemory::AllocatePT(size_t Size, VAddr addr)
|
|||
WRITE_PTE(pPde, TempPte);
|
||||
WritePfn(pfn, pfn, pPde, BusyType);
|
||||
}
|
||||
StartingAddr += PAGE_SIZE_LARGE;
|
||||
StartingAddr += LARGE_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -730,7 +730,7 @@ void PhysicalMemory::DeallocatePT(size_t Size, VAddr addr)
|
|||
WritePfn(pPde->Hardware.PFN, pPde->Hardware.PFN, pPde, (PageType)PTpfn->PTPageFrame.BusyType, true);
|
||||
WRITE_ZERO_PTE(pPde);
|
||||
}
|
||||
StartingAddr += PAGE_SIZE_LARGE;
|
||||
StartingAddr += LARGE_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -195,9 +195,9 @@ typedef enum _MmLayout
|
|||
#define ROUND_DOWN(size, alignment) ((size) & (~(alignment - 1)))
|
||||
#define CHECK_ALIGNMENT(size, alignment) (((size) % (alignment)) == 0)
|
||||
#define PAGES_SPANNED(Va, Size) ((ULONG)((((VAddr)(Va) & (PAGE_SIZE - 1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
|
||||
#define PAGES_SPANNED_LARGE(Va, Size) ((ULONG)((((VAddr)(Va) & (PAGE_SIZE_LARGE - 1)) + (Size) + (PAGE_SIZE_LARGE - 1)) >> PAGE_SHIFT_LARGE))
|
||||
#define PAGES_SPANNED_LARGE(Va, Size) ((ULONG)((((VAddr)(Va) & (LARGE_PAGE_SIZE - 1)) + (Size) + (LARGE_PAGE_SIZE - 1)) >> LARGE_PAGE_SHIFT))
|
||||
#define BYTE_OFFSET(Va) ((ULONG)((VAddr)(Va) & (PAGE_SIZE - 1)))
|
||||
#define BYTE_OFFSET_LARGE(Va) ((ULONG)((VAddr)(Va) & (PAGE_SIZE_LARGE - 1)))
|
||||
#define BYTE_OFFSET_LARGE(Va) ((ULONG)((VAddr)(Va) & (LARGE_PAGE_SIZE - 1)))
|
||||
#define PAGE_END(Va) (((ULONG_PTR)(Va) & (PAGE_SIZE - 1)) == 0)
|
||||
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
|
|||
|
||||
// Set up the structs tracking the memory regions
|
||||
ConstructMemoryRegion(LOWEST_USER_ADDRESS, USER_MEMORY_SIZE, UserRegion);
|
||||
ConstructMemoryRegion(CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_XBOX_SIZE, ContiguousRegion);
|
||||
ConstructMemoryRegion(CONTIGUOUS_MEMORY_BASE, XBOX_CONTIGUOUS_MEMORY_SIZE, ContiguousRegion);
|
||||
ConstructMemoryRegion(SYSTEM_MEMORY_BASE, SYSTEM_MEMORY_SIZE, SystemRegion);
|
||||
ConstructMemoryRegion(DEVKIT_MEMORY_BASE, DEVKIT_MEMORY_SIZE, DevkitRegion);
|
||||
|
||||
|
@ -104,14 +104,14 @@ void VMManager::Initialize(HANDLE memory_view, HANDLE pagetables_view, int BootF
|
|||
m_PhysicalPagesAvailable = g_SystemMaxMemory >> PAGE_SHIFT;
|
||||
m_HighestPage = CHIHIRO_HIGHEST_PHYSICAL_PAGE;
|
||||
m_NV2AInstancePage = CHIHIRO_INSTANCE_PHYSICAL_PAGE;
|
||||
m_MemoryRegionArray[ContiguousRegion].RegionMap[CONTIGUOUS_MEMORY_BASE].size = CONTIGUOUS_MEMORY_CHIHIRO_SIZE;
|
||||
m_MemoryRegionArray[ContiguousRegion].RegionMap[CONTIGUOUS_MEMORY_BASE].size = CHIHIRO_CONTIGUOUS_MEMORY_SIZE;
|
||||
}
|
||||
else if (m_MmLayoutDebug)
|
||||
{
|
||||
g_SystemMaxMemory = CHIHIRO_MEMORY_SIZE;
|
||||
m_DebuggerPagesAvailable = X64M_PHYSICAL_PAGE;
|
||||
m_HighestPage = CHIHIRO_HIGHEST_PHYSICAL_PAGE;
|
||||
m_MemoryRegionArray[ContiguousRegion].RegionMap[CONTIGUOUS_MEMORY_BASE].size = CONTIGUOUS_MEMORY_CHIHIRO_SIZE;
|
||||
m_MemoryRegionArray[ContiguousRegion].RegionMap[CONTIGUOUS_MEMORY_BASE].size = CHIHIRO_CONTIGUOUS_MEMORY_SIZE;
|
||||
|
||||
// Note that even if this is true, only the heap/Nt functions of the title are affected, the Mm functions
|
||||
// will still use only the lower 64 MiB and the same is true for the debugger pages, meaning they will only
|
||||
|
@ -653,10 +653,10 @@ void VMManager::RestorePersistentMemory()
|
|||
PMMPTE EndingPte;
|
||||
|
||||
if (m_MmLayoutRetail) {
|
||||
EndingPte = GetPteAddress(CONTIGUOUS_MEMORY_BASE + CONTIGUOUS_MEMORY_XBOX_SIZE - 1);
|
||||
EndingPte = GetPteAddress(CONTIGUOUS_MEMORY_BASE + XBOX_CONTIGUOUS_MEMORY_SIZE - 1);
|
||||
}
|
||||
else {
|
||||
EndingPte = GetPteAddress(CONTIGUOUS_MEMORY_BASE + CONTIGUOUS_MEMORY_CHIHIRO_SIZE - 1);
|
||||
EndingPte = GetPteAddress(CONTIGUOUS_MEMORY_BASE + CHIHIRO_CONTIGUOUS_MEMORY_SIZE - 1);
|
||||
}
|
||||
|
||||
while (PointerPte <= EndingPte)
|
||||
|
|
|
@ -867,7 +867,7 @@ void cxbx_gl_parse_overlay(NV2AState *d, int v)
|
|||
overlay.base = d->pvideo.regs[NV_PVIDEO_BASE(v)];
|
||||
overlay.limit = d->pvideo.regs[NV_PVIDEO_LIMIT(v)];
|
||||
assert(overlay.base == 0);
|
||||
assert(overlay.limit == (128 * ONE_MB) - 1); // = CONTIGUOUS_MEMORY_CHIHIRO_SIZE - 1
|
||||
assert(overlay.limit == (128 * ONE_MB) - 1); // = CHIHIRO_CONTIGUOUS_MEMORY_SIZE - 1
|
||||
assert(GET_MASK(overlay_format, NV_PVIDEO_FORMAT_COLOR) == NV_PVIDEO_FORMAT_COLOR_LE_CR8YB8CB8YA8);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,8 @@ processorArchitecture = '*' publicKeyToken = '6595b64144ccf1df' language = '*'\"
|
|||
/*! program entry point */
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
hActiveModule = hInstance; // == GetModuleHandle(NULL); // Points to GUI (Cxbx.exe) ImageBase
|
||||
|
||||
// First detect if we are running on WoW64, if not, prevent Cxbx-Reloaded from starting
|
||||
// Cxbx-Relaoded needs access to high memory, only exposed to WoW64.
|
||||
typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
|
||||
|
@ -56,6 +58,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifndef CXBX_LOADER
|
||||
/*! verify Cxbx.exe is loaded to base address 0x00010000 */
|
||||
if ((UINT_PTR)GetModuleHandle(nullptr) != CXBX_BASE_ADDR)
|
||||
{
|
||||
|
@ -66,6 +69,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool bRet, bKernel;
|
||||
HWND hWnd = nullptr;
|
||||
|
|
Loading…
Reference in New Issue