diff --git a/src/Common/Logging.cpp b/src/Common/Logging.cpp index 7662695f7..b434d519b 100644 --- a/src/Common/Logging.cpp +++ b/src/Common/Logging.cpp @@ -67,7 +67,7 @@ inline void output_char(std::ostream& os, char c) case '\t': os << "\\t"; break; case '\v': os << "\\v"; break; // All other to-escape-characters are rendered as hexadecimal : - default: os << "\\x" << std::hex << std::uppercase << (int)c; + default: os << "\\x" << std::setfill('0') << std::setw(2) << std::right << std::hex << std::uppercase << (int)c; } } else @@ -92,7 +92,7 @@ inline void output_wchar(std::ostream& os, wchar_t c) case '\t': os << "\\t"; break; case '\v': os << "\\v"; break; // All other to-escape-characters are rendered as hexadecimal : - default: os << "\\x" << std::hex << std::uppercase << (wint_t)c; + default: os << "\\x" << std::setfill('0') << std::setw(4) << std::right << std::hex << std::uppercase << (wint_t)c; } } else @@ -101,17 +101,17 @@ inline void output_wchar(std::ostream& os, wchar_t c) LOG_SANITIZE_HEADER(hex1, uint8_t) { - return os << "0x" << std::hex << std::uppercase << (int)container.value; + return os << hexstring8 << (int)container.value; } LOG_SANITIZE_HEADER(hex2, uint16_t) { - return os << "0x" << std::hex << std::uppercase << (int)container.value; + return os << hexstring16 << (int)container.value; } LOG_SANITIZE_HEADER(hex4, uint32_t) { - return os << "0x" << std::hex << std::uppercase << (int)container.value; + return os << hexstring32 << (int)container.value; } LOG_SANITIZE_HEADER(sanitized_char, char) @@ -144,7 +144,7 @@ LOG_SANITIZE_HEADER(sanitized_char_pointer, char *) } v = container.value; - os << "0x" << std::hex << std::uppercase << (void *)v << " = \""; + os << hexstring32 << (uint32_t)v << " = \""; if (needsEscaping) { while (*v) @@ -174,14 +174,14 @@ LOG_SANITIZE_HEADER(sanitized_wchar_pointer, wchar_t *) } v = container.value; - os << "0x" << std::hex << std::uppercase << (void *)v << " = \""; + os << hexstring32 << (uint32_t)v << " = \""; if (needsEscaping) { while (*v) output_wchar(os, *v++); } else - os << v; + os << v; // TODO : FIXME - VS2015 doesn''t render this string (instead, it shows a hexadecimal memory address) return os << "\""; } diff --git a/src/Common/Logging.h b/src/Common/Logging.h index 037d6bd07..ecdb814ea 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -139,8 +139,33 @@ LOG_SANITIZE(sanitized_wchar_pointer, wchar_t *); // Function (and argument) logging defines // -#define LOG_ARG_START "\n " << std::setw(20) << std::left -#define LOG_ARG_OUT_START "\n OUT " << std::setw(18) << std::left +constexpr const int str_length(const char* str) { + return str_end(str) - str; +} + +constexpr const char* str_skip_prefix(const char* str, const char *prefix) { + return (*str == *prefix) ? str_skip_prefix(str + 1, prefix + 1) : str; +} + +constexpr const char* remove_prefix(const char* str, const char *prefix) { + return (str_skip_prefix(str, prefix) == str + str_length(prefix)) ? str_skip_prefix(str, prefix) : str; +} + +constexpr char* xtl_prefix = "XTL::"; +constexpr char* emupatch_prefix = "EmuPatch_"; // See #define EMUPATCH + +constexpr const char* remove_emupatch_prefix(const char* str) { + // return an empty string when str isn't given + // skip XTL:: and/or EmuPatch_ prefix if present + return remove_prefix(remove_prefix(str, xtl_prefix), emupatch_prefix); +} + +#define LOG_ARG_START "\n " << std::setfill(' ') << std::setw(20) << std::left +#define LOG_ARG_OUT_START "\n OUT " << std::setfill(' ') << std::setw(18) << std::left + +#ifndef LOG_PREFIX +#define LOG_PREFIX __FILENAME__ +#endif // LOG_PREFIX #ifdef _DEBUG_TRACE @@ -151,7 +176,7 @@ extern thread_local std::string _logPrefix; #define LOG_THREAD_INIT \ if (_logPrefix.length() == 0) { \ std::stringstream tmp; \ - tmp << "[" << hex2((uint16_t)GetCurrentThreadId()) << "] "; \ + tmp << "[" << hexstring16 << GetCurrentThreadId() << "] "; \ _logPrefix = tmp.str(); \ } @@ -160,7 +185,7 @@ extern thread_local std::string _logPrefix; static thread_local std::string _logFuncPrefix; \ if (_logFuncPrefix.length() == 0) { \ std::stringstream tmp; \ - tmp << _logPrefix << __FILENAME__ << " : " << (func != nullptr ? func : ""); \ + tmp << _logPrefix << LOG_PREFIX << ": " << (func != nullptr ? remove_emupatch_prefix(func) : ""); \ _logFuncPrefix = tmp.str(); \ } @@ -278,6 +303,10 @@ extern thread_local std::string _logPrefix; // RETURN logs the given result and then returns it (so this should appear last in functions) #define RETURN(r) do { LOG_FUNC_RESULT(r) return r; } while (0) +#define LOG_ONCE(msg, ...) { static bool bFirstTime = true; if(bFirstTime) { bFirstTime = false; DbgPrintf("TRAC: " ## msg, __VA_ARGS__); } } + +#define LOG_XBOX_CALL(func) DbgPrintf("TRAC: Xbox " ## func ## "() call\n"); +#define LOG_FIRST_XBOX_CALL(func) LOG_ONCE("First Xbox " ## func ## "() call\n"); // // Headers for rendering enums, flags and (pointer-to-)types : @@ -321,11 +350,34 @@ extern thread_local std::string _logPrefix; // Macro to ease declaration of two render functions, for type and pointer-to-type : #define LOGRENDER_HEADER(Type) LOGRENDER_HEADER_BY_PTR(Type); LOGRENDER_HEADER_BY_REF(Type); +// Traits to switch ostreams to our preferred rendering of hexadecimal values +template +std::basic_ostream<_CharT, _Traits>& +hexstring8(std::basic_ostream<_CharT, _Traits>&os) +{ + // std::noshowbase is not neccessary to set (it's the default, and we never use std::showbase) + return os << "0x" << std::setfill('0') << std::setw(2) << std::right << std::hex << std::uppercase; +} + +template +std::basic_ostream<_CharT, _Traits>& +hexstring16(std::basic_ostream<_CharT, _Traits>&os) +{ + return os << "0x" << std::setfill('0') << std::setw(4) << std::right << std::hex << std::uppercase; +} + +template +std::basic_ostream<_CharT, _Traits>& +hexstring32(std::basic_ostream<_CharT, _Traits>&os) +{ + return os << "0x" << std::setfill('0') << std::setw(8) << std::right << std::hex << std::uppercase; +} + // Macro combining pointer-to-type implementation and type rendering header : #define LOGRENDER(Type) \ LOGRENDER_HEADER_BY_PTR(Type) \ { \ - os << "0x" << std::hex << std::uppercase << (void*)(value); \ + os << hexstring32 << (void*)(value); \ if (value) \ os << " -> "#Type"* {" << *value << "}"; \ \ diff --git a/src/Cxbx.h b/src/Cxbx.h index 70d2d62ec..60d2b2c3d 100644 --- a/src/Cxbx.h +++ b/src/Cxbx.h @@ -48,11 +48,30 @@ typedef unsigned char uint8; typedef unsigned char uint08; typedef unsigned short uint16; typedef unsigned long uint32; -typedef signed char sint08; -typedef signed short sint16; -typedef signed long sint32; /*! \} */ +typedef signed char s8; +typedef __int16 s16; +typedef __int32 s32; +typedef __int64 s64; +typedef unsigned char u8; +typedef unsigned __int16 u16; +typedef unsigned __int32 u32; +typedef unsigned __int64 u64; +typedef s8 i8; +typedef s16 i16; +typedef s32 i32; +typedef s64 i64; + +/*! xbaddr is the type of a physical address */ +typedef u32 xbaddr; + +/*! xbnullptr is the type of null pointer address*/ +#define xbnullptr nullptr + +/*! xbnull is the type of null address or value*/ +#define xbnull 0 + /*! define this to track vertex buffers */ #define _DEBUG_TRACK_VB /*! define this to track vertex shaders */ @@ -81,6 +100,13 @@ typedef signed long sint32; /*! define this to dump textures that are registered */ //#define _DEBUG_DUMP_TEXTURE_REGISTER "D:\\cxbx\\_textures\\" +extern bool g_bIntegrityChecking; +#ifdef _DEBUG +extern void CxbxCheckIntegrity(); +#define CXBX_CHECK_INTEGRITY() CxbxCheckIntegrity() +#else +#define CXBX_CHECK_INTEGRITY() +#endif /*! debug mode choices */ enum DebugMode { DM_NONE, DM_CONSOLE, DM_FILE }; @@ -105,7 +131,7 @@ extern volatile bool g_bPrintfOn; /*! DbgPrintf enabled if _DEBUG_TRACE is set */ #ifdef _DEBUG_TRACE - #define DbgPrintf(fmt, ...) do { if(g_bPrintfOn) printf("[0x%X] "##fmt, GetCurrentThreadId(), ##__VA_ARGS__); } while (0) + #define DbgPrintf(fmt, ...) do { CXBX_CHECK_INTEGRITY(); if(g_bPrintfOn) printf("[0x%.4X] "##fmt, GetCurrentThreadId(), ##__VA_ARGS__); } while (0) #else inline void null_func(...) { } #define DbgPrintf null_func diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index 7106ef2d0..c9d8bf806 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -62,6 +62,8 @@ namespace xboxkrnl #include #include #include // For time() +#include // For std::ostringstream + /* prevent name collisions */ namespace NtDll @@ -99,7 +101,7 @@ bool g_bIsChihiro = false; DWORD_PTR g_CPUXbox = 0; DWORD_PTR g_CPUOthers = 0; -HANDLE g_CurrentProcessHandle = 0; // Set in CxbxKrnlInit +HANDLE g_CurrentProcessHandle = 0; // Set in CxbxKrnlMain // Define function located in EmuXApi so we can call it from here void SetupXboxDeviceTypes(); @@ -180,7 +182,7 @@ void CxbxLaunchXbe(void(*Entry)()) } __except (EmuException(GetExceptionInformation())) { - printf("Emu: WARNING!! Problem with ExceptionFilter\n"); + EmuWarning("Problem with ExceptionFilter"); } } @@ -235,11 +237,48 @@ void RestoreExeImageHeader() ExeOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] = NewOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS]; } +// Returns the Win32 error in string format. Returns an empty string if there is no error. +std::string CxbxGetErrorCodeAsString(DWORD errorCode) +{ + std::string result; + LPSTR lpMessageBuffer = nullptr; + DWORD dwLength = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, // lpSource + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&lpMessageBuffer, + 0, // nSize + NULL); // Arguments + if (dwLength > 0) { + result = std::string(lpMessageBuffer, dwLength); + } + + LocalFree(lpMessageBuffer); + return result; +} + +// Returns the last Win32 error, in string format. Returns an empty string if there is no error. +std::string CxbxGetLastErrorString(char * lpszFunction) +{ + DWORD errorCode = ::GetLastError(); // Do this first, before any following code changes it + std::string result = "No error"; + if (errorCode > 0) { + std::ostringstream stringStream; + stringStream << lpszFunction << " failed with error " << errorCode << ": " << CxbxGetErrorCodeAsString(errorCode); + result = stringStream.str(); + } + + return result; +} + void *CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) { // First, try to open an existing memory.bin file : HANDLE hFile = CreateFile(szFilePath_memory_bin, - GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE, + GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE, FILE_SHARE_READ | FILE_SHARE_WRITE, /* lpSecurityAttributes */nullptr, OPEN_EXISTING, @@ -286,20 +325,26 @@ void *CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) /* dwFileOffsetHigh */0, /* dwFileOffsetLow */0, CONTIGUOUS_MEMORY_SIZE, - (void *)MM_SYSTEM_PHYSICAL_MAP); - if (memory == NULL) + (void *)CONTIGUOUS_MEMORY_BASE); + if (memory != (void *)CONTIGUOUS_MEMORY_BASE) { - CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin into memory!"); + if (memory) + UnmapViewOfFile(memory); + + CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin to 0x80000000!"); return nullptr; } + printf("[0x%.4X] INIT: Mapped %d MiB of Xbox contiguous memory at 0x%.8X to 0x%.8X\n", + GetCurrentThreadId(), CONTIGUOUS_MEMORY_SIZE / ONE_MB, CONTIGUOUS_MEMORY_BASE, CONTIGUOUS_MEMORY_BASE + CONTIGUOUS_MEMORY_SIZE - 1); + if (NeedsInitialization) { memset(memory, 0, CONTIGUOUS_MEMORY_SIZE); - DbgPrintf("EmuMain: Initialized contiguous memory\n"); + printf("[0x%.4X] INIT: Initialized contiguous memory\n", GetCurrentThreadId()); } else - DbgPrintf("EmuMain: Loaded contiguous memory.bin\n"); + printf("[0x%.4X] INIT: Loaded contiguous memory.bin\n", GetCurrentThreadId()); // Map memory.bin contents into tiled memory too : void *tiled_memory = (void *)MapViewOfFileEx( @@ -307,40 +352,52 @@ void *CxbxRestoreContiguousMemory(char *szFilePath_memory_bin) FILE_MAP_READ | FILE_MAP_WRITE | FILE_MAP_EXECUTE, /* dwFileOffsetHigh */0, /* dwFileOffsetLow */0, - CONTIGUOUS_MEMORY_SIZE, - (void *)0xF0000000); - if (tiled_memory == NULL) + TILED_MEMORY_SIZE, + (void *)TILED_MEMORY_BASE); + if (tiled_memory != (void *)TILED_MEMORY_BASE) { - CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin into tiled memory!"); + if (tiled_memory) + UnmapViewOfFile(tiled_memory); + + CxbxKrnlCleanup("CxbxRestoreContiguousMemory: Couldn't map contiguous memory.bin into tiled memory at 0xF0000000!"); return nullptr; } - DbgPrintf("EmuMain: Mapped contiguous to tiled memory\n"); + printf("[0x%.4X] INIT: Mapped contiguous memory to Xbox tiled memory at 0x%.8X to 0x%.8X\n", + GetCurrentThreadId(), TILED_MEMORY_BASE, TILED_MEMORY_BASE + TILED_MEMORY_SIZE - 1); return memory; } #pragma optimize("", off) -void CxbxPopupMessage(char *message) +void CxbxPopupMessage(const char *message, ...) { - DbgPrintf("Popup : %s\n", message); - MessageBox(NULL, message, "Cxbx-Reloaded", MB_OK | MB_ICONEXCLAMATION); + char Buffer[1024]; + va_list argp; + + va_start(argp, message); + vsprintf(Buffer, message, argp); + va_end(argp); + + DbgPrintf("Popup : %s\n", Buffer); + MessageBox(NULL, Buffer, TEXT("Cxbx-Reloaded"), MB_OK | MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND); } -void PrintCurrentConfigurationLog() { +void PrintCurrentConfigurationLog() +{ // Print current LLE configuration { printf("---------------------------- LLE CONFIG ----------------------------\n"); - printf("EmuMain: LLE for APU is %s\n", bLLE_APU ? "enabled" : "disabled"); - printf("EmuMain: LLE for GPU is %s\n", bLLE_GPU ? "enabled" : "disabled"); - printf("EmuMain: LLE for JIT is %s\n", bLLE_JIT ? "enabled" : "disabled"); + printf("LLE for APU is %s\n", bLLE_APU ? "enabled" : "disabled"); + printf("LLE for GPU is %s\n", bLLE_GPU ? "enabled" : "disabled"); + printf("LLE for JIT is %s\n", bLLE_JIT ? "enabled" : "disabled"); } // Print current INPUT configuration { printf("--------------------------- INPUT CONFIG ---------------------------\n"); - printf("EmuMain: Using %s\n", g_XInputEnabled ? "XInput" : "DirectInput"); + printf("Using %s\n", g_XInputEnabled ? "XInput" : "DirectInput"); } // Print current video configuration @@ -349,11 +406,11 @@ void PrintCurrentConfigurationLog() { g_EmuShared->GetXBVideo(&XBVideoConf); printf("--------------------------- VIDEO CONFIG ---------------------------\n"); - printf("EmuMain: Direct3D Device: %s\n", XBVideoConf.GetDirect3DDevice() == 0 ? "Direct3D HAL (Hardware Accelerated)" : "Direct3D REF (Software)"); - printf("EmuMain: Video Resolution: %s\n", XBVideoConf.GetVideoResolution()); - printf("EmuMain: Force VSync is %s\n", XBVideoConf.GetVSync() ? "enabled" : "disabled"); - printf("EmuMain: Fullscreen is %s\n", XBVideoConf.GetFullscreen() ? "enabled" : "disabled"); - printf("EmuMain: Hardware YUV is %s\n", XBVideoConf.GetHardwareYUV() ? "enabled" : "disabled"); + printf("Direct3D Device: %s\n", XBVideoConf.GetDirect3DDevice() == 0 ? "Direct3D HAL (Hardware Accelerated)" : "Direct3D REF (Software)"); + printf("Video Resolution: %s\n", XBVideoConf.GetVideoResolution()); + printf("Force VSync is %s\n", XBVideoConf.GetVSync() ? "enabled" : "disabled"); + printf("Fullscreen is %s\n", XBVideoConf.GetFullscreen() ? "enabled" : "disabled"); + printf("Hardware YUV is %s\n", XBVideoConf.GetHardwareYUV() ? "enabled" : "disabled"); } // Print current audio configuration @@ -362,11 +419,11 @@ void PrintCurrentConfigurationLog() { g_EmuShared->GetXBAudio(&XBAudioConf); printf("--------------------------- AUDIO CONFIG ---------------------------\n"); - printf("EmuMain: Audio Adapter: %s\n", XBAudioConf.GetAudioAdapter().Data1 == 0 ? "Primary Audio Device" : "Secondary Audio Device"); - printf("EmuMain: Legacy Audio Hack is %s\n", XBAudioConf.GetLegacyAudioHack() ? "enabled" : "disabled"); - printf("EmuMain: PCM is %s\n", XBAudioConf.GetPCM() ? "enabled" : "disabled"); - printf("EmuMain: XADPCM is %s\n", XBAudioConf.GetXADPCM() ? "enabled" : "disabled"); - printf("EmuMain: Unknown Codec is %s\n", XBAudioConf.GetUnknownCodec() ? "enabled" : "disabled"); + printf("Audio Adapter: %s\n", XBAudioConf.GetAudioAdapter().Data1 == 0 ? "Primary Audio Device" : "Secondary Audio Device"); + printf("Legacy Audio Hack is %s\n", XBAudioConf.GetLegacyAudioHack() ? "enabled" : "disabled"); + printf("PCM is %s\n", XBAudioConf.GetPCM() ? "enabled" : "disabled"); + printf("XADPCM is %s\n", XBAudioConf.GetXADPCM() ? "enabled" : "disabled"); + printf("Unknown Codec is %s\n", XBAudioConf.GetUnknownCodec() ? "enabled" : "disabled"); } printf("------------------------- END OF CONFIG LOG ------------------------\n"); @@ -415,6 +472,55 @@ void CxbxKrnlMain(int argc, char* argv[]) DebugFileName = argv[5]; } + // debug console allocation (if configured) + if (DbgMode == DM_CONSOLE) + { + if (AllocConsole()) + { + HANDLE StdHandle = GetStdHandle(STD_OUTPUT_HANDLE); + // Maximise the console scroll buffer height : + CONSOLE_SCREEN_BUFFER_INFO coninfo; + GetConsoleScreenBufferInfo(StdHandle, &coninfo); + coninfo.dwSize.Y = SHRT_MAX - 1; // = 32767-1 = 32766 = maximum value that works + SetConsoleScreenBufferSize(StdHandle, coninfo.dwSize); + freopen("CONOUT$", "wt", stdout); + freopen("CONIN$", "rt", stdin); + SetConsoleTitle("Cxbx-Reloaded : Kernel Debug Console"); + SetConsoleTextAttribute(StdHandle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); + } + } + else + { + FreeConsole(); + if (DbgMode == DM_FILE) + freopen(DebugFileName.c_str(), "wt", stdout); + else + { + char buffer[16]; + if (GetConsoleTitle(buffer, 16) != NULL) + freopen("nul", "w", stdout); + } + } + + g_CurrentProcessHandle = GetCurrentProcess(); // OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); + + // Write a header to the log + { + printf("[0x%.4X] INIT: Cxbx-Reloaded Version %s\n", GetCurrentThreadId(), _CXBX_VERSION); + + time_t startTime = time(nullptr); + struct tm* tm_info = localtime(&startTime); + char timeString[26]; + strftime(timeString, 26, "%F %T", tm_info); + printf("[0x%.4X] INIT: Log started at %s\n", GetCurrentThreadId(), timeString); + +#ifdef _DEBUG_TRACE + printf("[0x%.4X] INIT: Debug Trace Enabled.\n", GetCurrentThreadId()); +#else + printf("[0x%.4X] INIT: Debug Trace Disabled.\n", GetCurrentThreadId()); +#endif + } + // Now we got the arguments, start by initializing the Xbox memory map : // PrepareXBoxMemoryMap() { @@ -616,13 +722,13 @@ const char *GameRegionToString(DWORD aGameRegion) }; if ((aGameRegion & ~XBEIMAGE_GAME_REGION_KNOWN) > 0) - return "REGION ERROR"; + DbgPrintf("REGION ERROR! (0x%X)\n", aGameRegion); DWORD index = (aGameRegion & 7) | (aGameRegion & XBEIMAGE_GAME_REGION_MANUFACTURING ? 8 : 0); return Regions[index]; } -void CxbxKrnlInit +__declspec(noreturn) void CxbxKrnlInit ( HWND hwndParent, void *pTLSData, @@ -649,59 +755,17 @@ void CxbxKrnlInit // for unicode conversions setlocale(LC_ALL, "English"); - g_CurrentProcessHandle = GetCurrentProcess(); CxbxInitPerformanceCounters(); #ifdef _DEBUG // CxbxPopupMessage("Attach a Debugger"); // Debug child processes using https://marketplace.visualstudio.com/items?itemName=GreggMiskelly.MicrosoftChildProcessDebuggingPowerTool #endif - // debug console allocation (if configured) - if (DbgMode == DM_CONSOLE) - { - if (AllocConsole()) - { - HANDLE StdHandle = GetStdHandle(STD_OUTPUT_HANDLE); - // Maximise the console scroll buffer height : - CONSOLE_SCREEN_BUFFER_INFO coninfo; - GetConsoleScreenBufferInfo(StdHandle, &coninfo); - coninfo.dwSize.Y = SHRT_MAX - 1; // = 32767-1 = 32766 = maximum value that works - SetConsoleScreenBufferSize(StdHandle, coninfo.dwSize); - freopen("CONOUT$", "wt", stdout); - freopen("CONIN$", "rt", stdin); - SetConsoleTitle("Cxbx-Reloaded : Kernel Debug Console"); - SetConsoleTextAttribute(StdHandle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); - } - } - else - { - FreeConsole(); - if (DbgMode == DM_FILE) - freopen(szDebugFilename, "wt", stdout); - else - { - char buffer[16]; - if (GetConsoleTitle(buffer, 16) != NULL) - freopen("nul", "w", stdout); - } - } - - // Write a header to the log - { - printf("[0x%X] EmuMain: Cxbx-Reloaded Version %s\n", GetCurrentThreadId(), _CXBX_VERSION); - - time_t startTime = time(nullptr); - struct tm* tm_info = localtime(&startTime); - char timeString[26]; - strftime(timeString, 26, "%F %T", tm_info); - printf("[0x%X] EmuMain: Log started at %s\n", GetCurrentThreadId(), timeString); - } - // debug trace { #ifdef _DEBUG_TRACE - printf("[0x%X] EmuMain: Debug Trace Enabled.\n", GetCurrentThreadId()); - printf("[0x%X] EmuMain: CxbxKrnlInit\n" + printf("[0x%X] INIT: Debug Trace Enabled.\n", GetCurrentThreadId()); + printf("[0x%X] INIT: CxbxKrnlInit\n" "(\n" " hwndParent : 0x%.08X\n" " pTLSData : 0x%.08X\n" @@ -715,7 +779,7 @@ void CxbxKrnlInit ");\n", GetCurrentThreadId(), hwndParent, pTLSData, pTLS, pLibraryVersion, DbgMode, szDebugFilename, pXbeHeader, dwXbeHeaderSize, Entry); #else - printf("[0x%X] EmuMain: Debug Trace Disabled.\n", GetCurrentThreadId()); + printf("[0x%X] INIT: Debug Trace Disabled.\n", GetCurrentThreadId()); #endif } @@ -736,6 +800,7 @@ void CxbxKrnlInit DummyKernel->FileHeader.NumberOfSections = 1; // as long as this doesn't start with "INIT" strncpy_s((PSTR)DummyKernel->SectionHeader.Name, 8, "DONGS", 8); + printf("[0x%.4X] INIT: Initialized dummy kernel image header.\n", GetCurrentThreadId()); } // Read which components need to be LLE'ed : @@ -793,7 +858,7 @@ void CxbxKrnlInit CxbxRegisterDeviceHostPath(DeviceHarddisk0Partition7, CxbxBasePath + "Partition7"); // Create default symbolic links : - DbgPrintf("EmuMain : Creating default symbolic links.\n"); + DbgPrintf("INIT: Creating default symbolic links.\n"); { // TODO: DriveD should always point to the Xbe Path // This is the only symbolic link the Xbox Kernel sets, the rest are set by the application, usually via XAPI. @@ -822,23 +887,27 @@ void CxbxKrnlInit xboxkrnl::XeImageFileName.Buffer = (PCHAR)g_MemoryManager.Allocate(MAX_PATH); sprintf(xboxkrnl::XeImageFileName.Buffer, "%c:\\%s", CxbxDefaultXbeDriveLetter, fileName.c_str()); xboxkrnl::XeImageFileName.Length = (USHORT)strlen(xboxkrnl::XeImageFileName.Buffer); - printf("EmuMain : XeImageFileName = %s\n", xboxkrnl::XeImageFileName.Buffer); + printf("[0x%.4X] INIT: XeImageFileName = %s\n", GetCurrentThreadId(), xboxkrnl::XeImageFileName.Buffer); } // Dump Xbe information { + if (CxbxKrnl_Xbe != nullptr) { + printf("[0x%.4X] INIT: Title : %s\n", GetCurrentThreadId(), CxbxKrnl_Xbe->m_szAsciiTitle); + } + // Dump Xbe certificate if (g_pCertificate != NULL) { - printf("EmuMain : XBE TitleID : %.8X\n", g_pCertificate->dwTitleId); - printf("EmuMain : XBE TitleName : %ls\n", g_pCertificate->wszTitleName); - printf("EmuMain : XBE Region : %s\n", GameRegionToString(g_pCertificate->dwGameRegion)); + printf("[0x%.4X] INIT: XBE TitleID : %.8X\n", GetCurrentThreadId(), g_pCertificate->dwTitleId); + printf("[0x%.4X] INIT: XBE TitleName : %ls\n", GetCurrentThreadId(), g_pCertificate->wszTitleName); + printf("[0x%.4X] INIT: XBE Region : %s\n", GetCurrentThreadId(), GameRegionToString(g_pCertificate->dwGameRegion)); } // Dump Xbe library build numbers Xbe::LibraryVersion* libVersionInfo = pLibraryVersion;// (LibraryVersion *)(CxbxKrnl_XbeHeader->dwLibraryVersionsAddr); if (libVersionInfo != NULL) { for (uint32 v = 0; v < CxbxKrnl_XbeHeader->dwLibraryVersions; v++) { - printf("EmuMain : XBE Library %u : %.8s (version %d)\n", v, libVersionInfo->szName, libVersionInfo->wBuildVersion); + printf("[0x%.4X] INIT: XBE Library %u : %.8s (version %d)\n", GetCurrentThreadId(), v, libVersionInfo->szName, libVersionInfo->wBuildVersion); libVersionInfo++; } } @@ -858,10 +927,10 @@ void CxbxKrnlInit // Make sure the Xbox1 code runs on one core (as the box itself has only 1 CPU, // this will better aproximate the environment with regard to multi-threading) : - DbgPrintf("EmuMain : Determining CPU affinity.\n"); + DbgPrintf("INIT: Determining CPU affinity.\n"); { if (!GetProcessAffinityMask(g_CurrentProcessHandle, &g_CPUXbox, &g_CPUOthers)) - CxbxKrnlCleanup("EmuMain: GetProcessAffinityMask failed."); + CxbxKrnlCleanup("INIT: GetProcessAffinityMask failed."); // For the other threads, remove one bit from the processor mask: g_CPUOthers = ((g_CPUXbox - 1) & g_CPUXbox); @@ -877,7 +946,7 @@ void CxbxKrnlInit } // initialize grapchics - DbgPrintf("EmuMain: Initializing render window.\n"); + DbgPrintf("INIT: Initializing render window.\n"); XTL::CxbxInitWindow(pXbeHeader, dwXbeHeaderSize); XTL::CxbxInitAudio(); @@ -890,12 +959,12 @@ void CxbxKrnlInit if (bLLE_GPU) { - DbgPrintf("EmuMain: Initializing OpenGL.\n"); + DbgPrintf("INIT: Initializing OpenGL.\n"); InitOpenGLContext(); } else { - DbgPrintf("EmuMain: Initializing Direct3D.\n"); + DbgPrintf("INIT: Initializing Direct3D.\n"); XTL::EmuD3DInit(); } @@ -915,13 +984,12 @@ void CxbxKrnlInit // Create the interrupt processing thread DWORD dwThreadId; HANDLE hThread = (HANDLE)_beginthreadex(NULL, NULL, CxbxKrnlInterruptThread, NULL, NULL, (uint*)&dwThreadId); - DbgPrintf("EmuMain: Initial thread starting.\n"); + DbgPrintf("INIT: Calling XBE entry point...\n"); CxbxLaunchXbe(Entry); - DbgPrintf("EmuMain: Initial thread ended.\n"); + DbgPrintf("INIT: XBE entry point returned\n"); fflush(stdout); // EmuShared::Cleanup(); FIXME: commenting this line is a bad workaround for issue #617 (https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/617) CxbxKrnlTerminateThread(); - return; } void CxbxInitFilePaths() @@ -973,7 +1041,7 @@ void CxbxRestoreLaunchDataPage() // Delete the file once we're done. remove(szFilePath_LaunchDataPage_bin); - DbgPrintf("EmuMain: Restored LaunchDataPage\n"); + DbgPrintf("INIT: Restored LaunchDataPage\n"); } } @@ -983,7 +1051,7 @@ void CxbxRestorePersistentMemoryRegions() // TODO : Restore all other persistent memory regions here too. } -void CxbxKrnlCleanup(const char *szErrorMessage, ...) +__declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...) { g_bEmuException = true; @@ -992,24 +1060,17 @@ void CxbxKrnlCleanup(const char *szErrorMessage, ...) // print out error message (if exists) if(szErrorMessage != NULL) { - char szBuffer1[255]; - char szBuffer2[255]; - + char szBuffer2[1024]; va_list argp; - sprintf(szBuffer1, "[0x%X] EmuMain: Received Fatal Message:\n\n* ", GetCurrentThreadId()); - va_start(argp, szErrorMessage); vsprintf(szBuffer2, szErrorMessage, argp); va_end(argp); - strcat(szBuffer1, szBuffer2); - strcat(szBuffer1, "\n"); - - CxbxPopupMessage(szBuffer1); // Will also DbgPrintf + CxbxPopupMessage("Received Fatal Message:\n\n* %s\n", szBuffer2); // Will also DbgPrintf } - printf("CxbxKrnl: Terminating Process\n"); + printf("[0x%.4X] MAIN: Terminating Process\n", GetCurrentThreadId()); fflush(stdout); // cleanup debug output @@ -1027,8 +1088,6 @@ void CxbxKrnlCleanup(const char *szErrorMessage, ...) EmuShared::Cleanup(); TerminateProcess(g_CurrentProcessHandle, 0); - - return; } void CxbxKrnlRegisterThread(HANDLE hThread) @@ -1129,14 +1188,12 @@ void CxbxKrnlResume() g_bEmuSuspended = false; } -void CxbxKrnlTerminateThread() +__declspec(noreturn) void CxbxKrnlTerminateThread() { TerminateThread(GetCurrentThread(), 0); } void CxbxKrnlPanic() { - DbgPrintf("EmuMain: CxbxKrnlPanic()\n"); - CxbxKrnlCleanup("Kernel Panic!"); } diff --git a/src/CxbxKrnl/CxbxKrnl.h b/src/CxbxKrnl/CxbxKrnl.h index 69725c515..4a2661b70 100644 --- a/src/CxbxKrnl/CxbxKrnl.h +++ b/src/CxbxKrnl/CxbxKrnl.h @@ -59,12 +59,6 @@ extern "C" { #define TIB_ArbitraryDataSlot 0x14 #define TIB_LinearSelfAddress 0x18 -/*! xbaddr is the type of a physical address */ -typedef uint32 xbaddr; - -/*! xbnullptr is the type of null pointer address*/ -#define xbnullptr nullptr - #define XBADDR_BITS 32 #define XBADDR_MAX UINT32_MAX @@ -72,12 +66,17 @@ typedef uint32 xbaddr; #define KSEG0_BASE 0x80000000 // Define virtual base addresses for physical memory windows. -#define MM_SYSTEM_PHYSICAL_MAP KSEG0_BASE +#define MM_SYSTEM_PHYSICAL_MAP KSEG0_BASE // = 0x80000000 #define MM_HIGHEST_PHYSICAL_PAGE 0x07FFF #define MM_64M_PHYSICAL_PAGE 0x04000 #define MM_INSTANCE_PHYSICAL_PAGE 0x03FE0 // Chihiro arcade should use 0x07FF0 #define MM_INSTANCE_PAGE_COUNT 16 +#define CONTIGUOUS_MEMORY_BASE MM_SYSTEM_PHYSICAL_MAP // = 0x80000000 #define CONTIGUOUS_MEMORY_SIZE (64 * ONE_MB) +#define TILED_MEMORY_BASE 0xF0000000 // Tiled memory is a mirror of contiguous memory, residing at 0xF0000000 +#define TILED_MEMORY_SIZE CONTIGUOUS_MEMORY_SIZE +#define NV2A_MEMORY_BASE 0xFD000000 // See NV2A_ADDR +#define NV2A_MEMORY_SIZE 0x01000000 // See NV2A_SIZE /*! memory size per system */ #define XBOX_MEMORY_SIZE (64 * ONE_MB) @@ -123,7 +122,13 @@ typedef uint32 xbaddr; #define VECTOR2IRQ(vector) ((vector)-IRQ_BASE) #define VECTOR2IRQL(vector) (PROFILE_LEVEL - VECTOR2IRQ(vector)) -void CxbxPopupMessage(char *message); +void CxbxPopupMessage(const char *message, ...); + +#define LOG_TEST_CASE(message) do { static bool bPopupShown = false; \ + if (!bPopupShown) { bPopupShown = true; \ + CxbxPopupMessage("Please report that %s shows this test-case: %s\nIn %s (%s line %d)", \ + CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); } } while(0) +// was g_pCertificate->wszTitleName extern Xbe::Certificate *g_pCertificate; @@ -134,10 +139,10 @@ bool CxbxKrnlVerifyVersion(const char *szVersion); void CxbxKrnlMain(int argc, char* argv[]); /*! initialize emulation */ -void CxbxKrnlInit(HWND hwndParent, void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)()); +__declspec(noreturn) void CxbxKrnlInit(HWND hwndParent, void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)()); /*! cleanup emulation */ -void CxbxKrnlCleanup(const char *szErrorMessage, ...); +__declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...); /*! register a thread handle */ void CxbxKrnlRegisterThread(HANDLE hThread); @@ -149,7 +154,7 @@ void CxbxKrnlSuspend(); void CxbxKrnlResume(); /*! terminate the calling thread */ -void CxbxKrnlTerminateThread(); +__declspec(noreturn) void CxbxKrnlTerminateThread(); /*! kernel panic (trap for unimplemented kernel functions) */ void CxbxKrnlPanic(); diff --git a/src/CxbxKrnl/DbgConsole.cpp b/src/CxbxKrnl/DbgConsole.cpp index a5df2d337..572403989 100644 --- a/src/CxbxKrnl/DbgConsole.cpp +++ b/src/CxbxKrnl/DbgConsole.cpp @@ -145,11 +145,11 @@ static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &tracker, break; if(action == ETA_ENABLE) - printf("CxbxDbg: #%.02d (0x%.08X) enabled\n", a, cur->pResource); + printf("CxbxDbg: #%.02d (0x%p) enabled\n", a, cur->pResource); else if(action == ETA_DISABLE) - printf("CxbxDbg: #%.02d (0x%.08X) disabled\n", a, cur->pResource); + printf("CxbxDbg: #%.02d (0x%p) disabled\n", a, cur->pResource); else if(action == ETA_SHOW) - printf("CxbxDbg: #%.02d (0x%.08X) queued for show info..\n", a, cur->pResource); + printf("CxbxDbg: #%.02d (0x%p) queued for show info..\n", a, cur->pResource); if(action == ETA_ENABLE) { @@ -240,9 +240,9 @@ void DbgConsole::ParseCommand() while(cur != NULL && cur->pNext != NULL) { - bool enabled = !g_VBTrackDisable.exists(cur->pResource); + bool enabled = g_VBTrackDisable.exists(cur->pResource); - printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); + printf("CxbxDbg: %.2d : 0x%p (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); cur = cur->pNext; } @@ -287,10 +287,6 @@ void DbgConsole::ParseCommand() printf("CxbxDbg: Syntax Incorrect (dvb #)\n"); } } - else if(_stricmp(szCmd, "dsc") == 0 || _stricmp(szCmd, "DumpStreamCache") == 0) - { - XTL::VertexPatcher::DumpCache(); - } #endif #ifdef _DEBUG_TRACK_PB else if(_stricmp(szCmd, "lpb") == 0 || _stricmp(szCmd, "ListPB") == 0) @@ -303,9 +299,9 @@ void DbgConsole::ParseCommand() while(cur != NULL && cur->pNext != NULL) { - bool enabled = !g_PBTrackDisable.exists(cur->pResource); + bool enabled = g_PBTrackDisable.exists(cur->pResource); - printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); + printf("CxbxDbg: %.2d : 0x%p (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); cur = cur->pNext; } diff --git a/src/CxbxKrnl/Emu.cpp b/src/CxbxKrnl/Emu.cpp index 401d93210..78861c439 100644 --- a/src/CxbxKrnl/Emu.cpp +++ b/src/CxbxKrnl/Emu.cpp @@ -91,7 +91,7 @@ void NTAPI EmuWarning(const char *szWarningMessage, ...) va_list argp; - sprintf(szBuffer1, "[0x%X] EmuWarn: ", GetCurrentThreadId()); + sprintf(szBuffer1, "[0x%.4X] WARN: ", GetCurrentThreadId()); va_start(argp, szWarningMessage); @@ -134,9 +134,9 @@ void EmuExceptionPrintDebugInformation(LPEXCEPTION_POINTERS e, bool IsBreakpoint // print debug information { if (IsBreakpointException) - printf("[0x%X] EmuMain: Received Breakpoint Exception (int 3)\n", GetCurrentThreadId()); + printf("[0x%.4X] MAIN: Received Breakpoint Exception (int 3)\n", GetCurrentThreadId()); else - printf("[0x%X] EmuMain: Received Exception (Code := 0x%.08X)\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode); + printf("[0x%.4X] MAIN: Received Exception (Code := 0x%.8X)\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode); printf("\n" " EIP := %s\n" @@ -162,7 +162,7 @@ void EmuExceptionPrintDebugInformation(LPEXCEPTION_POINTERS e, bool IsBreakpoint void EmuExceptionExitProcess() { - printf("[0x%X] EmuMain: Aborting Emulation\n", GetCurrentThreadId()); + printf("[0x%.4X] MAIN: Aborting Emulation\n", GetCurrentThreadId()); fflush(stdout); if (CxbxKrnl_hEmuParent != NULL) @@ -192,7 +192,7 @@ bool EmuExceptionBreakpointAsk(LPEXCEPTION_POINTERS e) } else if (ret == IDIGNORE) { - printf("[0x%X] EmuMain: Ignored Breakpoint Exception\n", GetCurrentThreadId()); + printf("[0x%.4X] MAIN: Ignored Breakpoint Exception\n", GetCurrentThreadId()); fflush(stdout); e->ContextRecord->Eip += EmuX86_OpcodeSize((uint8_t*)e->ContextRecord->Eip); // Skip instruction size bytes @@ -207,6 +207,9 @@ void EmuExceptionNonBreakpointUnhandledShow(LPEXCEPTION_POINTERS e) { EmuExceptionPrintDebugInformation(e, /*IsBreakpointException=*/false); + int symbolOffset = 0; + std::string symbolName = GetDetectedSymbolName(e->ContextRecord->Eip, &symbolOffset); + char buffer[256]; sprintf(buffer, "Received Exception Code 0x%.08X @ EIP := %s\n" @@ -260,9 +263,9 @@ int ExitException(LPEXCEPTION_POINTERS e) static int count = 0; // debug information - printf("[0x%X] EmuMain: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId()); - printf("[0x%X] EmuMain: Received Exception [0x%.08X]@%s\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str()); - printf("[0x%X] EmuMain: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId()); + printf("[0x%.4X] MAIN: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId()); + printf("[0x%.4X] MAIN: Received Exception [0x%.8X]@%s\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str()); + printf("[0x%.4X] MAIN: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId()); fflush(stdout); @@ -330,29 +333,28 @@ void EmuPrintStackTrace(PCONTEXT ContextRecord) std::string symbolName = ""; DWORD64 dwDisplacement = 0; - if(fSymInitialized) - { + if (fSymInitialized) + { PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)&symbol; - pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO) + SYMBOL_MAXLEN - 1; - pSymbol->MaxNameLen = SYMBOL_MAXLEN; + pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO) + SYMBOL_MAXLEN - 1; + pSymbol->MaxNameLen = SYMBOL_MAXLEN; if (SymFromAddr(g_CurrentProcessHandle, frame.AddrPC.Offset, &dwDisplacement, pSymbol)) symbolName = pSymbol->Name; + } + + if (symbolName.empty()) { + // Try getting a symbol name from the HLE cache : + int symbolOffset = 0; + + symbolName = GetDetectedSymbolName((xbaddr)frame.AddrPC.Offset, &symbolOffset); + if (symbolOffset < 1000) + dwDisplacement = (DWORD64)symbolOffset; else - { - // Try getting a symbol name from the HLE cache : - int symbolOffset = 0; - - symbolName = GetDetectedSymbolName((xbaddr)frame.AddrPC.Offset, &symbolOffset); - - if (symbolOffset < 1000) - dwDisplacement = (DWORD64)symbolOffset; - else - symbolName = ""; - } + symbolName = ""; } - if(symbolName.length() > 0) - printf(" %s+0x%.04X\n", symbolName.c_str(), dwDisplacement); + if (!symbolName.empty()) + printf(" %s+0x%.04X\n", symbolName.c_str(), dwDisplacement); else printf("\n"); } diff --git a/src/CxbxKrnl/Emu.h b/src/CxbxKrnl/Emu.h index 915a500a9..77794500f 100644 --- a/src/CxbxKrnl/Emu.h +++ b/src/CxbxKrnl/Emu.h @@ -74,7 +74,7 @@ extern int g_iThreadNotificationCount; extern DWORD_PTR g_CPUXbox; extern DWORD_PTR g_CPUOthers; -extern HANDLE g_CurrentProcessHandle; // Set in CxbxKrnlInit +extern HANDLE g_CurrentProcessHandle; // Set in CxbxKrnlMain // Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime extern LARGE_INTEGER HostSystemTimeDelta; diff --git a/src/CxbxKrnl/EmuD3D8Logging.cpp b/src/CxbxKrnl/EmuD3D8Logging.cpp index bd046f9f0..cc612c33e 100644 --- a/src/CxbxKrnl/EmuD3D8Logging.cpp +++ b/src/CxbxKrnl/EmuD3D8Logging.cpp @@ -147,7 +147,7 @@ LOGRENDER(X_D3DRESOURCE_COMMON) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" RefCount", int, value & X_D3DCOMMON_REFCOUNT_MASK) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" Type", X_D3DCOMMON_TYPE, value & X_D3DCOMMON_TYPE_MASK) // Don't >> X_D3DCOMMON_TYPE_SHIFT, see ENUM2STR_START(X_D3DCOMMON_TYPE) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" IntRefCount", int, (value & X_D3DCOMMON_INTREFCOUNT_MASK) >> X_D3DCOMMON_INTREFCOUNT_SHIFT) - LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?D3DCreated", bool, value & X_D3DCOMMON_D3DCREATED) + LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?D3DCreated", bool, (value & X_D3DCOMMON_D3DCREATED) > 0) //LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?IsLocked", bool, value & X_D3DCOMMON_ISLOCKED) //LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?VideoMemory", bool, value & X_D3DCOMMON_VIDEOMEMORY) ; @@ -156,8 +156,8 @@ LOGRENDER(X_D3DRESOURCE_COMMON) LOGRENDER(X_D3DRESOURCE_FORMAT) { return os << (DWORD)value << " :" - LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?Cubemap", bool, value & X_D3DFORMAT_CUBEMAP) - LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?BorderColor", bool, value & X_D3DFORMAT_BORDERSOURCE_COLOR) + LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?Cubemap", bool, (value & X_D3DFORMAT_CUBEMAP) > 0) + LOGRENDER_MEMBER_NAME_TYPE_VALUE(" ?BorderColor", bool, (value & X_D3DFORMAT_BORDERSOURCE_COLOR) > 0) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" #Dimensions", int, (value & X_D3DFORMAT_DIMENSION_MASK) >> X_D3DFORMAT_DIMENSION_SHIFT) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" D3DFormat", X_D3DFORMAT, (value & X_D3DFORMAT_FORMAT_MASK) >> X_D3DFORMAT_FORMAT_SHIFT) LOGRENDER_MEMBER_NAME_TYPE_VALUE(" #MipMaps", int, (value & X_D3DFORMAT_MIPMAP_MASK) >> X_D3DFORMAT_MIPMAP_SHIFT) diff --git a/src/CxbxKrnl/EmuDInput.cpp b/src/CxbxKrnl/EmuDInput.cpp index f681719ad..aa473ff99 100644 --- a/src/CxbxKrnl/EmuDInput.cpp +++ b/src/CxbxKrnl/EmuDInput.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "DINP" + #include "Emu.h" #include "EmuXTL.h" #include "EmuShared.h" diff --git a/src/CxbxKrnl/EmuFS.cpp b/src/CxbxKrnl/EmuFS.cpp index 44d7d618b..f00a23458 100644 --- a/src/CxbxKrnl/EmuFS.cpp +++ b/src/CxbxKrnl/EmuFS.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { @@ -213,6 +215,7 @@ __declspec(naked) void EmuFS_MovEsiFs00() __declspec(naked) void EmuFS_MovzxEaxBytePtrFs24() { + // Note : Inlined KeGetCurrentIrql() __asm { mov eax, fs : [TIB_ArbitraryDataSlot] @@ -334,7 +337,7 @@ void EmuInitFS() fsInstructions.push_back({ { 0x64, 0xA1, 0x58, 0x00, 0x00, 0x00 }, &EmuFS_MovEaxFs58 }); // mov eax, large fs:58 fsInstructions.push_back({ { 0x64, 0xA3, 0x00, 0x00, 0x00, 0x00 }, &EmuFS_MovFs00Eax }); // mov large fs:0, eax - DbgPrintf("Patching FS Register Accesses\n"); + DbgPrintf("INIT: Patching FS Register Accesses\n"); DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage; long numberOfInstructions = fsInstructions.size(); @@ -344,7 +347,7 @@ void EmuInitFS() continue; } - DbgPrintf("Searching for FS Instruction in section %s\n", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); + DbgPrintf("INIT: Searching for FS Instruction in section %s\n", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]); xbaddr startAddr = CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwVirtualAddr; xbaddr endAddr = startAddr + CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwSizeofRaw; for (xbaddr addr = startAddr; addr < endAddr; addr++) @@ -361,7 +364,7 @@ void EmuInitFS() if (memcmp((void*)addr, &fsInstructions[i].data[0], sizeOfData) == 0) { - DbgPrintf("Patching FS Instruction at 0x%08X\n", addr); + DbgPrintf("INIT: Patching FS Instruction at 0x%.8X\n", addr); // Write Call opcode *(uint08*)addr = OPCODE_CALL_E8; @@ -377,7 +380,7 @@ void EmuInitFS() } } - DbgPrintf("Done\n"); + DbgPrintf("INIT: Done patching FS Register Accesses\n"); } // generate fs segment selector @@ -411,10 +414,10 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) #ifdef _DEBUG_TRACE // dump raw TLS data if (pNewTLS == nullptr) - DbgPrintf("EmuFS: TLS Non-Existant (OK)\n"); + DbgPrintf("KRNL: TLS Non-Existant (OK)\n"); else { - DbgPrintf("EmuFS: TLS Data Dump...\n"); + DbgPrintf("KRNL: TLS Data Dump...\n"); if (g_bPrintfOn) { for (uint32 v = 0; v < dwCopySize; v++) // Note : Don't dump dwZeroSize @@ -422,10 +425,10 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) uint08 *bByte = (uint08*)pNewTLS + v; if (v % 0x10 == 0) - DbgPrintf("EmuFS: 0x%.08X: ", (xbaddr)bByte); + DbgPrintf("KRNL: 0x%.8X:", (xbaddr)bByte); // Note : Use printf instead of DbgPrintf here, which prefixes with GetCurrentThreadId() : - printf("%.01X", (uint32)(*bByte)); + printf(" %.2X", *bByte); } printf("\n"); @@ -436,7 +439,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) // prepare TLS { - *(xbaddr*)pTLS->dwTLSIndexAddr = (xbaddr)nullptr; + *(xbaddr*)pTLS->dwTLSIndexAddr = xbnull; // dword @ pTLSData := pTLSData if (pNewTLS != nullptr) @@ -498,5 +501,5 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) // Make the KPCR struct available to KeGetPcr() EmuKeSetPcr(NewPcr); - DbgPrintf("EmuFS: Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.08X)\n", pTLS); + DbgPrintf("KRNL: Installed KPCR in TIB_ArbitraryDataSlot (with pTLS = 0x%.8X)\n", pTLS); } diff --git a/src/CxbxKrnl/EmuFile.cpp b/src/CxbxKrnl/EmuFile.cpp index ab1b28a8a..38a34f929 100644 --- a/src/CxbxKrnl/EmuFile.cpp +++ b/src/CxbxKrnl/EmuFile.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "FILE" + #include "EmuFile.h" #include #include @@ -300,15 +302,15 @@ NTSTATUS CxbxConvertFilePath( } */ - DbgPrintf("EmuKrnl : %s Corrected path...\n", aFileAPIName.c_str()); - DbgPrintf(" Org:\"%s\"\n", OriginalPath.c_str()); - if (_strnicmp(HostPath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0) - { - DbgPrintf(" New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str()); + if (g_bPrintfOn) { + DbgPrintf("FILE: %s Corrected path...\n", aFileAPIName.c_str()); + printf(" Org:\"%s\"\n", OriginalPath.c_str()); + if (_strnicmp(HostPath.c_str(), CxbxBasePath.c_str(), CxbxBasePath.length()) == 0) { + printf(" New:\"$CxbxPath\\%s%s\"\n", (HostPath.substr(CxbxBasePath.length(), std::string::npos)).c_str(), RelativePath.c_str()); + } + else + printf(" New:\"$XbePath\\%s\"\n", RelativePath.c_str()); } - else - DbgPrintf(" New:\"$XbePath\\%s\"\n", RelativePath.c_str()); - } else { @@ -525,7 +527,7 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin else { NtSymbolicLinkObjects[DriveLetter - 'A'] = this; - DbgPrintf("EmuMain : Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str()); + DbgPrintf("FILE: Linked \"%s\" to \"%s\" (residing at \"%s\")\n", aSymbolicLinkName.c_str(), aFullPath.c_str(), HostSymbolicLinkPath.c_str()); } } } diff --git a/src/CxbxKrnl/EmuKrnl.cpp b/src/CxbxKrnl/EmuKrnl.cpp index 849f3706d..28eccd26c 100644 --- a/src/CxbxKrnl/EmuKrnl.cpp +++ b/src/CxbxKrnl/EmuKrnl.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlAv.cpp b/src/CxbxKrnl/EmuKrnlAv.cpp index d84078301..f6e4ebf83 100644 --- a/src/CxbxKrnl/EmuKrnlAv.cpp +++ b/src/CxbxKrnl/EmuKrnlAv.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlDbg.cpp b/src/CxbxKrnl/EmuKrnlDbg.cpp index 6c7868c45..b6ab636f5 100644 --- a/src/CxbxKrnl/EmuKrnlDbg.cpp +++ b/src/CxbxKrnl/EmuKrnlDbg.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlEx.cpp b/src/CxbxKrnl/EmuKrnlEx.cpp index 6c7364807..5329296ef 100644 --- a/src/CxbxKrnl/EmuKrnlEx.cpp +++ b/src/CxbxKrnl/EmuKrnlEx.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlFs.cpp b/src/CxbxKrnl/EmuKrnlFs.cpp index c835003dc..eeef3592a 100644 --- a/src/CxbxKrnl/EmuKrnlFs.cpp +++ b/src/CxbxKrnl/EmuKrnlFs.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp index 5ee2578d5..c8e52b1ad 100644 --- a/src/CxbxKrnl/EmuKrnlHal.cpp +++ b/src/CxbxKrnl/EmuKrnlHal.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlIo.cpp b/src/CxbxKrnl/EmuKrnlIo.cpp index 785d58b6d..f6161afc6 100644 --- a/src/CxbxKrnl/EmuKrnlIo.cpp +++ b/src/CxbxKrnl/EmuKrnlIo.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlKd.cpp b/src/CxbxKrnl/EmuKrnlKd.cpp index db35d71d1..14ef2cf45 100644 --- a/src/CxbxKrnl/EmuKrnlKd.cpp +++ b/src/CxbxKrnl/EmuKrnlKd.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp index a31ff4156..c7f8533a5 100644 --- a/src/CxbxKrnl/EmuKrnlKe.cpp +++ b/src/CxbxKrnl/EmuKrnlKe.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlLogging.cpp b/src/CxbxKrnl/EmuKrnlLogging.cpp index 534fe8a17..f681b48cc 100644 --- a/src/CxbxKrnl/EmuKrnlLogging.cpp +++ b/src/CxbxKrnl/EmuKrnlLogging.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlMm.cpp b/src/CxbxKrnl/EmuKrnlMm.cpp index a0eb576fc..df67e9d84 100644 --- a/src/CxbxKrnl/EmuKrnlMm.cpp +++ b/src/CxbxKrnl/EmuKrnlMm.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlNt.cpp b/src/CxbxKrnl/EmuKrnlNt.cpp index 117e9ee59..635b2a77c 100644 --- a/src/CxbxKrnl/EmuKrnlNt.cpp +++ b/src/CxbxKrnl/EmuKrnlNt.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlOb.cpp b/src/CxbxKrnl/EmuKrnlOb.cpp index 5afbbd871..7d147d731 100644 --- a/src/CxbxKrnl/EmuKrnlOb.cpp +++ b/src/CxbxKrnl/EmuKrnlOb.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlPs.cpp b/src/CxbxKrnl/EmuKrnlPs.cpp index 815d6bff5..0d0cc3e51 100644 --- a/src/CxbxKrnl/EmuKrnlPs.cpp +++ b/src/CxbxKrnl/EmuKrnlPs.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlRtl.cpp b/src/CxbxKrnl/EmuKrnlRtl.cpp index f97783f74..06e2c20c1 100644 --- a/src/CxbxKrnl/EmuKrnlRtl.cpp +++ b/src/CxbxKrnl/EmuKrnlRtl.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlXbox.cpp b/src/CxbxKrnl/EmuKrnlXbox.cpp index cf473d2d2..f70a99ed0 100644 --- a/src/CxbxKrnl/EmuKrnlXbox.cpp +++ b/src/CxbxKrnl/EmuKrnlXbox.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlXc.cpp b/src/CxbxKrnl/EmuKrnlXc.cpp index cb6a88d39..ad7e668a0 100644 --- a/src/CxbxKrnl/EmuKrnlXc.cpp +++ b/src/CxbxKrnl/EmuKrnlXc.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuKrnlXe.cpp b/src/CxbxKrnl/EmuKrnlXe.cpp index 6c5bdda52..e2ed137c3 100644 --- a/src/CxbxKrnl/EmuKrnlXe.cpp +++ b/src/CxbxKrnl/EmuKrnlXe.cpp @@ -37,6 +37,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "KRNL" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuNV2A.cpp b/src/CxbxKrnl/EmuNV2A.cpp index 85cb44077..ff1ed0647 100644 --- a/src/CxbxKrnl/EmuNV2A.cpp +++ b/src/CxbxKrnl/EmuNV2A.cpp @@ -42,6 +42,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "NV2A" + #include // For __beginthreadex(), etc. #include "vga.h" diff --git a/src/CxbxKrnl/EmuNVNet.cpp b/src/CxbxKrnl/EmuNVNet.cpp index 62f774b11..ecebc2865 100644 --- a/src/CxbxKrnl/EmuNVNet.cpp +++ b/src/CxbxKrnl/EmuNVNet.cpp @@ -40,6 +40,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "NET " // Intentional extra space to align on 4 characters + // prevent name collisions namespace xboxkrnl diff --git a/src/CxbxKrnl/EmuX86.cpp b/src/CxbxKrnl/EmuX86.cpp index 6ffbba4ea..1edbb061e 100644 --- a/src/CxbxKrnl/EmuX86.cpp +++ b/src/CxbxKrnl/EmuX86.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "X86 " // Intentional extra space to align on 4 characters + // Link the library into our project. #pragma comment(lib, "distorm.lib") @@ -157,11 +159,11 @@ uint32_t EmuFlash_Read32(xbaddr addr) // TODO : Move to EmuFlash.cpp r = 0x90; // Luke's hardware revision 1.6 Xbox returns this (also since XboxKrnlVersion is set to 5838) break; default: - EmuWarning("EmuX86 Read32 FLASH_ROM (0x%.8X) [Unknown address]", addr); + EmuWarning("Read32 FLASH_ROM (0x%.8X) [Unknown address]", addr); return -1; } - DbgPrintf("EmuX86 Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r); + DbgPrintf("X86 : Read32 FLASH_ROM (0x%.8X) = 0x%.8X [HANDLED]\n", addr, r); return r; } @@ -176,7 +178,7 @@ uint32_t EmuX86_Read32Aligned(xbaddr addr) uint32_t value; if (addr >= NV2A_ADDR && addr < NV2A_ADDR + NV2A_SIZE) { - // Access NV2A regardless weither HLE is disabled or not + // Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU) value = EmuNV2A_Read(addr - NV2A_ADDR, 32); // Note : EmuNV2A_Read32 does it's own logging } else if (addr >= NVNET_ADDR && addr < NVNET_ADDR + NVNET_SIZE) { @@ -191,6 +193,7 @@ uint32_t EmuX86_Read32Aligned(xbaddr addr) // Outside EmuException, pass the memory-access through to normal memory : value = EmuX86_Mem_Read32(addr); } + DbgPrintf("EmuX86_Read32Aligned(0x%08X) = 0x%08X\n", addr, value); } @@ -231,7 +234,8 @@ uint16_t EmuX86_Read16(xbaddr addr) // Outside EmuException, pass the memory-access through to normal memory : value = EmuX86_Mem_Read16(addr); } - DbgPrintf("EmuX86_Read16(0x%08X) = 0x%04X\n", addr, value); + + DbgPrintf("X86 : Read16(0x%.8X) = 0x%.4X\n", addr, value); } return value; @@ -258,7 +262,8 @@ uint8_t EmuX86_Read8(xbaddr addr) // Outside EmuException, pass the memory-access through to normal memory : value = EmuX86_Mem_Read8(addr); } - DbgPrintf("EmuX86_Read8(0x%08X) = 0x%02X\n", addr, value); + + DbgPrintf("X86 : Read8(0x%.8X) = 0x%.2X\n", addr, value); } return value; @@ -269,7 +274,7 @@ void EmuX86_Write32Aligned(xbaddr addr, uint32_t value) assert((addr & 3) == 0); if (addr >= NV2A_ADDR && addr < NV2A_ADDR + NV2A_SIZE) { - // Access NV2A regardless weither HLE is disabled or not + // Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU) EmuNV2A_Write(addr - NV2A_ADDR, value, 32); // Note : EmuNV2A_Write32 does it's own logging return; @@ -291,7 +296,7 @@ void EmuX86_Write32Aligned(xbaddr addr, uint32_t value) } // Outside EmuException, pass the memory-access through to normal memory : - DbgPrintf("EmuX86_Write32Aligned(0x%08X, 0x%08X)\n", addr, value); + DbgPrintf("X86 : Write32Aligned(0x%.8X, 0x%.8X)\n", addr, value); EmuX86_Mem_Write32(addr, value); } @@ -300,14 +305,15 @@ void EmuX86_Write32(xbaddr addr, uint32_t value) if ((addr & 3) == 0) { EmuX86_Write32Aligned(addr, value); } - else + else { EmuWarning("EmuX86_Write32(0x%08X, 0x%08X) [Unaligned unimplemented]", addr, value); + // LOG_UNIMPLEMENTD(); + } } void EmuX86_Write16(xbaddr addr, uint16_t value) { if (addr >= NV2A_ADDR && addr < NV2A_ADDR + NV2A_SIZE) { - // Access NV2A regardless weither HLE is disabled or not EmuNV2A_Write(addr - NV2A_ADDR, value, 16); // Note : EmuNV2A_Write32 does it's own logging @@ -330,7 +336,7 @@ void EmuX86_Write16(xbaddr addr, uint16_t value) } // Outside EmuException, pass the memory-access through to normal memory : - DbgPrintf("EmuX86_Write16(0x%08X, 0x%04X)\n", addr, value); + DbgPrintf("X86 : Write16(0x%.8X, 0x%.4X)\n", addr, value); EmuX86_Mem_Write16(addr, value); } @@ -360,7 +366,7 @@ void EmuX86_Write8(xbaddr addr, uint8_t value) } // Outside EmuException, pass the memory-access through to normal memory : - DbgPrintf("EmuX86_Write8(0x%08X, 0x%02X)\n", addr, value); + DbgPrintf("X86 : Write8(0x%.8X, 0x%.2X)\n", addr, value); EmuX86_Mem_Write8(addr, value); } @@ -538,7 +544,7 @@ xbaddr EmuX86_Operand_Addr(LPEXCEPTION_POINTERS e, _DInst& info, int operand, bo case O_NONE: { // ignore operand - return (xbaddr)nullptr; + return xbnull; } case O_REG: is_internal_addr = true; @@ -586,10 +592,10 @@ xbaddr EmuX86_Operand_Addr(LPEXCEPTION_POINTERS e, _DInst& info, int operand, bo return (xbaddr)info.imm.ptr.off; // TODO : What about info.imm.ptr.seg ? } default: - return (xbaddr)nullptr; + return xbnull; } - return (xbaddr)nullptr; + return xbnull; } bool EmuX86_Addr_Read(xbaddr srcAddr, bool is_internal_addr, uint16_t size, OUT uint32_t *value) @@ -668,7 +674,7 @@ bool EmuX86_Operand_Read(LPEXCEPTION_POINTERS e, _DInst& info, int operand, OUT { bool is_internal_addr; xbaddr srcAddr = EmuX86_Operand_Addr(e, info, operand, OUT is_internal_addr); - if (srcAddr != (xbaddr)nullptr) + if (srcAddr != xbnull) return EmuX86_Addr_Read(srcAddr, is_internal_addr, info.ops[operand].size, value); return false; @@ -678,7 +684,7 @@ bool EmuX86_Operand_Write(LPEXCEPTION_POINTERS e, _DInst& info, int operand, uin { bool is_internal_addr; xbaddr destAddr = EmuX86_Operand_Addr(e, info, operand, OUT is_internal_addr); - if (destAddr != (xbaddr)nullptr) + if (destAddr != xbnull) return EmuX86_Addr_Write(destAddr, is_internal_addr, info.ops[operand].size, value); return false; @@ -694,7 +700,7 @@ bool EmuX86_Opcode_ADD(LPEXCEPTION_POINTERS e, _DInst& info) // ADD reads and writes destination : bool is_internal_addr; xbaddr addr = EmuX86_Operand_Addr(e, info, 0, OUT is_internal_addr); - if (addr == (xbaddr)nullptr) + if (addr == xbnull) return false; if (is_internal_addr) @@ -1165,7 +1171,7 @@ int EmuX86_OpcodeSize(uint8_t *Eip) if (EmuX86_DecodeOpcode((uint8_t*)Eip, info)) return info.size; - EmuWarning("EmuX86: Error decoding opcode size at 0x%.8X", Eip); + EmuWarning("Error decoding opcode size at 0x%.8X", Eip); return 1; } @@ -1180,7 +1186,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) _DInst info; if (!EmuX86_DecodeOpcode((uint8_t*)e->ContextRecord->Eip, info)) { - EmuWarning("EmuX86: Error decoding opcode at 0x%08X", e->ContextRecord->Eip); + EmuWarning("Error decoding opcode at 0x%08X", e->ContextRecord->Eip); } else { @@ -1259,7 +1265,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) // Some titles attempt to manually set the TSC via this instruction // This needs fixing eventually, but should be acceptible to ignore for now! // Chase: Hollywood Stunt Driver hits this - EmuWarning("EmuX86: WRMSR instruction ignored"); + EmuWarning("WRMSR instruction ignored"); break; default: goto unimplemented_opcode; @@ -1271,7 +1277,7 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) return true; unimplemented_opcode: - EmuWarning("EmuX86: 0x%08X: Not Implemented\n", e->ContextRecord->Eip); // TODO : format decodedInstructions[0] + EmuWarning("0x%08X: Not Implemented\n", e->ContextRecord->Eip); // TODO : format decodedInstructions[0] e->ContextRecord->Eip += info.size; } @@ -1280,7 +1286,7 @@ unimplemented_opcode: void EmuX86_Init() { - DbgPrintf("EmuX86: Initializing distorm version %d\n", distorm_version()); + DbgPrintf("X86 : Initializing distorm version %d\n", distorm_version()); EmuX86_InitContextRecordOffsetByRegisterType(); } diff --git a/src/CxbxKrnl/EmuXG.cpp b/src/CxbxKrnl/EmuXG.cpp index c6020c993..9a07c17fa 100644 --- a/src/CxbxKrnl/EmuXG.cpp +++ b/src/CxbxKrnl/EmuXG.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "XGRP" + #undef FIELD_OFFSET // prevent macro redefinition warnings #include diff --git a/src/CxbxKrnl/EmuXInput.cpp b/src/CxbxKrnl/EmuXInput.cpp index 0b190e000..411cd6668 100644 --- a/src/CxbxKrnl/EmuXInput.cpp +++ b/src/CxbxKrnl/EmuXInput.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "XINP" + #include "Emu.h" #include "EmuXTL.h" #include "EmuShared.h" diff --git a/src/CxbxKrnl/EmuXOnline.cpp b/src/CxbxKrnl/EmuXOnline.cpp index 4824ca015..7b91d60da 100644 --- a/src/CxbxKrnl/EmuXOnline.cpp +++ b/src/CxbxKrnl/EmuXOnline.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "XONL" + #include "Emu.h" #include "Logging.h" #include "EmuFS.h" diff --git a/src/CxbxKrnl/EmuXactEng.cpp b/src/CxbxKrnl/EmuXactEng.cpp index d5cf3139e..7226678ed 100644 --- a/src/CxbxKrnl/EmuXactEng.cpp +++ b/src/CxbxKrnl/EmuXactEng.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "XACT" + // prevent name collisions namespace xboxkrnl { diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index cea9c27fb..7b7bf2517 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -36,6 +36,8 @@ #define _CXBXKRNL_INTERNAL #define _XBOXKRNL_DEFEXTRN_ +#define LOG_PREFIX "XAPI" + #undef FIELD_OFFSET // prevent macro redefinition warnings /* prevent name collisions */ namespace xboxkrnl @@ -97,7 +99,7 @@ void SetupXboxDeviceTypes() if (gDeviceType_Gamepad == nullptr) { // First, attempt to find GetTypeInformation auto typeInformation = g_SymbolAddresses.find("GetTypeInformation"); - if (typeInformation != g_SymbolAddresses.end() && typeInformation->second != (xbaddr)nullptr) { + if (typeInformation != g_SymbolAddresses.end() && typeInformation->second != xbnull) { printf("Deriving XDEVICE_TYPE_GAMEPAD from DeviceTable (via GetTypeInformation)\n"); // Read the offset values of the device table structure from GetTypeInformation xbaddr deviceTableStartOffset = *(uint32_t*)((uint32_t)typeInformation->second + 0x01); @@ -236,7 +238,7 @@ VOID WINAPI XTL::EMUPATCH(XInitDevices) // * Note: This could be unpatched however, // * XInitDevices is required to be unpatched first. // * This in turn requires USB LLE to be implemented, or USBD_Init -// * patched with a stub, so this patch is still ennabled for now +// * patched with a stub, so this patch is still enabled for now // ****************************************************************** DWORD WINAPI XTL::EMUPATCH(XGetDevices) ( @@ -249,7 +251,7 @@ DWORD WINAPI XTL::EMUPATCH(XGetDevices) UCHAR oldIrql = xboxkrnl::KeRaiseIrqlToDpcLevel(); - DWORD ret = DeviceType->CurrentConnected; + DWORD ret = DeviceType->CurrentConnected; DeviceType->ChangeConnected = 0; DeviceType->PreviousConnected = DeviceType->CurrentConnected; @@ -263,7 +265,7 @@ DWORD WINAPI XTL::EMUPATCH(XGetDevices) // * Note: This could be unpatched however, // * XInitDevices is required to be unpatched first. // * This in turn requires USB LLE to be implemented, or USBD_Init -// * patched with a stub, so this patch is still ennabled for now +// * patched with a stub, so this patch is still enabled for now // ****************************************************************** BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges) ( @@ -281,7 +283,7 @@ BOOL WINAPI XTL::EMUPATCH(XGetDeviceChanges) LOG_FUNC_END; BOOL ret = FALSE; - + if(!DeviceType->ChangeConnected) { *pdwInsertions = 0; @@ -444,9 +446,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputPoll) for(v=0;v= 0) && (dwPort <= 3)) { - DbgPrintf( "EmuXInputGetState(): dwPort = %d\n", dwPort ); + DbgPrintf("XAPI: EmuXInputGetState(): dwPort = %d\n", dwPort ); if(dwPort == 0) { @@ -563,7 +563,7 @@ DWORD WINAPI XTL::EMUPATCH(XInputGetState) } } else - EmuWarning( "EmuXInputGetState(): pph == NULL!" ); + EmuWarning("EmuXInputGetState(): pph == NULL!"); RETURN(ret); } @@ -848,7 +848,7 @@ LPVOID WINAPI XTL::EMUPATCH(CreateFiber) if( !pFiber ) EmuWarning( "CreateFiber failed!" ); else - DbgPrintf("CreateFiber returned 0x%X\n", pFiber); + DbgPrintf("XAPI: CreateFiber returned 0x%X\n", pFiber); // Add to list of queued fiber routines g_Fibers[g_FiberCount].pfnRoutine = lpStartRoutine; @@ -871,7 +871,7 @@ VOID WINAPI XTL::EMUPATCH(DeleteFiber) { FUNC_EXPORTS - DbgPrintf("EmuXapi: EmuDeleteFiber\n" + DbgPrintf("XAPI: EmuDeleteFiber\n" "(\n" " lpFiber : 0x%.08X\n" ");\n", @@ -893,7 +893,7 @@ VOID WINAPI XTL::EMUPATCH(SwitchToFiber) { FUNC_EXPORTS - DbgPrintf("EmuXapi: EmuSwitchToFiber\n" + DbgPrintf("XAPI: EmuSwitchToFiber\n" "(\n" " lpFiber : 0x%.08X\n" ");\n", @@ -911,7 +911,7 @@ VOID WINAPI XTL::EMUPATCH(SwitchToFiber) g_FiberCount = 0; - DbgPrintf( "Finished executing fibers!\n" ); + DbgPrintf("XAPI: Finished executing fibers!\n" ); } #endif @@ -927,7 +927,7 @@ LPVOID WINAPI XTL::EMUPATCH(ConvertThreadToFiber) { FUNC_EXPORTS - DbgPrintf("EmuXapi: EmuConvertThreadToFiber\n" + DbgPrintf("XAPI: EmuConvertThreadToFiber\n" "(\n" " lpParameter : 0x%.08X\n" ");\n", @@ -935,7 +935,7 @@ LPVOID WINAPI XTL::EMUPATCH(ConvertThreadToFiber) LPVOID pRet = ConvertThreadToFiber( lpParameter ); - DbgPrintf( "EmuConvertThreadToFiber returned 0x%X\n", pRet ); + DbgPrintf("XAPI: EmuConvertThreadToFiber returned 0x%X\n", pRet ); return pRet; @@ -950,7 +950,7 @@ VOID WINAPI XTL::EMUPATCH(XapiFiberStartup)(DWORD dwDummy) { FUNC_EXPORTS - DbgPrintf("EmuXapi: EmuXapiFiberStarup()\n" + DbgPrintf("XAPI: EmuXapiFiberStarup()\n" "(\n" " dwDummy : 0x%.08X\n" ");\n", @@ -1130,11 +1130,13 @@ DWORD WINAPI XTL::EMUPATCH(XGetLaunchInfo) ) { FUNC_EXPORTS + // TODO : This patch can be removed once we're sure all XAPI library // functions indirectly reference our xboxkrnl::LaunchDataPage variable. // For this, we need a test-case that hits this function, and run that // with and without this patch enabled. Behavior should be identical. // When this is verified, this patch can be removed. + LOG_TEST_CASE("Unpatching test needed"); LOG_FUNC_BEGIN LOG_FUNC_ARG(pdwLaunchDataType) diff --git a/src/CxbxKrnl/HLEIntercept.cpp b/src/CxbxKrnl/HLEIntercept.cpp index 48232c495..0cde80fb1 100644 --- a/src/CxbxKrnl/HLEIntercept.cpp +++ b/src/CxbxKrnl/HLEIntercept.cpp @@ -35,6 +35,8 @@ // ****************************************************************** #define _CXBXKRNL_INTERNAL +#define LOG_PREFIX "HLE " // Intentional extra space to align on 4 characters + #include #include // For std::setfill and std::setw #include "CxbxKrnl.h" @@ -61,6 +63,7 @@ std::map g_SymbolAddresses; std::unordered_map g_FunctionHooks; bool g_HLECacheUsed = false; +// D3D build version uint32 g_BuildVersion = 0; bool bLLE_APU = false; // Set this to true for experimental APU (sound) LLE diff --git a/src/CxbxKrnl/MemoryManager.cpp b/src/CxbxKrnl/MemoryManager.cpp index 1cc9a3ff1..717465bc6 100644 --- a/src/CxbxKrnl/MemoryManager.cpp +++ b/src/CxbxKrnl/MemoryManager.cpp @@ -34,6 +34,8 @@ // * // ****************************************************************** +#define LOG_PREFIX "XMEM" + #include // For assert() #include // For _aligned_malloc()