set svn:eol-style=native for **.cpp

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1442 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bushing
2008-12-08 05:30:24 +00:00
parent 901fe7c00f
commit 49cfded60b
177 changed files with 53968 additions and 53968 deletions
File diff suppressed because it is too large Load Diff
+200 -200
View File
@@ -1,200 +1,200 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <memory.h> #include <memory.h>
#ifdef _WIN32 #ifdef _WIN32
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set #define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset #define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64 #define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
#define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64 #define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64
#include <intrin.h> #include <intrin.h>
#undef _interlockedbittestandset #undef _interlockedbittestandset
#undef _interlockedbittestandreset #undef _interlockedbittestandreset
#undef _interlockedbittestandset64 #undef _interlockedbittestandset64
#undef _interlockedbittestandreset64 #undef _interlockedbittestandreset64
#else #else
//#include <config/i386/cpuid.h> //#include <config/i386/cpuid.h>
#include <xmmintrin.h> #include <xmmintrin.h>
static inline void do_cpuid(unsigned int *eax, unsigned int *ebx, static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx) unsigned int *ecx, unsigned int *edx)
{ {
#ifdef _LP64 #ifdef _LP64
__asm__("cpuid" __asm__("cpuid"
: "=a" (*eax), : "=a" (*eax),
"=b" (*ebx), "=b" (*ebx),
"=c" (*ecx), "=c" (*ecx),
"=d" (*edx) "=d" (*edx)
: "a" (*eax) : "a" (*eax)
); );
#else #else
// Note: EBX is reserved on Mac OS X and in PIC on Linux, so it has to be // Note: EBX is reserved on Mac OS X and in PIC on Linux, so it has to be
// restored at the end of the asm block. // restored at the end of the asm block.
__asm__( __asm__(
"pushl %%ebx;" "pushl %%ebx;"
"cpuid;" "cpuid;"
"movl %%ebx,%1;" "movl %%ebx,%1;"
"popl %%ebx;" "popl %%ebx;"
: "=a" (*eax), : "=a" (*eax),
"=r" (*ebx), "=r" (*ebx),
"=c" (*ecx), "=c" (*ecx),
"=d" (*edx) "=d" (*edx)
: "a" (*eax) : "a" (*eax)
); );
#endif #endif
} }
void __cpuid(int info[4], int x) void __cpuid(int info[4], int x)
{ {
unsigned int eax = x, ebx = 0, ecx = 0, edx = 0; unsigned int eax = x, ebx = 0, ecx = 0, edx = 0;
do_cpuid(&eax, &ebx, &ecx, &edx); do_cpuid(&eax, &ebx, &ecx, &edx);
info[0] = eax; info[0] = eax;
info[1] = ebx; info[1] = ebx;
info[2] = ecx; info[2] = ecx;
info[3] = edx; info[3] = edx;
} }
#endif #endif
#include "Common.h" #include "Common.h"
#include "CPUDetect.h" #include "CPUDetect.h"
#include "StringUtil.h" #include "StringUtil.h"
CPUInfo cpu_info; CPUInfo cpu_info;
void CPUInfo::Detect() void CPUInfo::Detect()
{ {
memset(this, 0, sizeof(*this)); memset(this, 0, sizeof(*this));
#ifdef _M_IX86 #ifdef _M_IX86
Mode64bit = false; Mode64bit = false;
#elif defined (_M_X64) #elif defined (_M_X64)
Mode64bit = true; Mode64bit = true;
OS64bit = true; OS64bit = true;
#endif #endif
num_cores = 1; num_cores = 1;
#ifdef _WIN32 #ifdef _WIN32
#ifdef _M_IX86 #ifdef _M_IX86
BOOL f64 = FALSE; BOOL f64 = FALSE;
OS64bit = IsWow64Process(GetCurrentProcess(), &f64) && f64; OS64bit = IsWow64Process(GetCurrentProcess(), &f64) && f64;
#endif #endif
#endif #endif
// Set obvious defaults, for extra safety // Set obvious defaults, for extra safety
if (Mode64bit) if (Mode64bit)
{ {
bSSE = true; bSSE = true;
bSSE2 = true; bSSE2 = true;
bLongMode = true; bLongMode = true;
} }
// Assume CPU supports the CPUID instruction. Those that don't can barely boot modern OS:es anyway. // Assume CPU supports the CPUID instruction. Those that don't can barely boot modern OS:es anyway.
int cpu_id[4]; int cpu_id[4];
memset(cpu_string, 0, sizeof(cpu_string)); memset(cpu_string, 0, sizeof(cpu_string));
// Detect CPU's CPUID capabilities, and grab cpu string // Detect CPU's CPUID capabilities, and grab cpu string
__cpuid(cpu_id, 0x00000000); __cpuid(cpu_id, 0x00000000);
u32 max_std_fn = cpu_id[0]; // EAX u32 max_std_fn = cpu_id[0]; // EAX
*((int *)cpu_string) = cpu_id[1]; *((int *)cpu_string) = cpu_id[1];
*((int *)(cpu_string + 4)) = cpu_id[3]; *((int *)(cpu_string + 4)) = cpu_id[3];
*((int *)(cpu_string + 8)) = cpu_id[2]; *((int *)(cpu_string + 8)) = cpu_id[2];
__cpuid(cpu_id, 0x80000000); __cpuid(cpu_id, 0x80000000);
u32 max_ex_fn = cpu_id[0]; u32 max_ex_fn = cpu_id[0];
if (!strcmp(cpu_string, "GenuineIntel")) if (!strcmp(cpu_string, "GenuineIntel"))
vendor = VENDOR_INTEL; vendor = VENDOR_INTEL;
else if (!strcmp(cpu_string, "AuthenticAMD")) else if (!strcmp(cpu_string, "AuthenticAMD"))
vendor = VENDOR_AMD; vendor = VENDOR_AMD;
else else
vendor = VENDOR_OTHER; vendor = VENDOR_OTHER;
// Set reasonable default brand string even if brand string not available. // Set reasonable default brand string even if brand string not available.
strcpy(brand_string, cpu_string); strcpy(brand_string, cpu_string);
// Detect family and other misc stuff. // Detect family and other misc stuff.
bool HTT = false; bool HTT = false;
int logical_cpu_count = 1; int logical_cpu_count = 1;
if (max_std_fn >= 1) { if (max_std_fn >= 1) {
__cpuid(cpu_id, 0x00000001); __cpuid(cpu_id, 0x00000001);
logical_cpu_count = (cpu_id[1] >> 16) & 0xFF; logical_cpu_count = (cpu_id[1] >> 16) & 0xFF;
if ((cpu_id[3] >> 28) & 1) { if ((cpu_id[3] >> 28) & 1) {
// wtf, we get here on my core 2 // wtf, we get here on my core 2
HTT = true; HTT = true;
} }
if ((cpu_id[3] >> 25) & 1) bSSE = true; if ((cpu_id[3] >> 25) & 1) bSSE = true;
if ((cpu_id[3] >> 26) & 1) bSSE2 = true; if ((cpu_id[3] >> 26) & 1) bSSE2 = true;
if (cpu_id[2] & 1) bSSE3 = true; if (cpu_id[2] & 1) bSSE3 = true;
if ((cpu_id[2] >> 9) & 1) bSSSE3 = true; if ((cpu_id[2] >> 9) & 1) bSSSE3 = true;
if ((cpu_id[2] >> 19) & 1) bSSE4_1 = true; if ((cpu_id[2] >> 19) & 1) bSSE4_1 = true;
if ((cpu_id[2] >> 20) & 1) bSSE4_2 = true; if ((cpu_id[2] >> 20) & 1) bSSE4_2 = true;
} }
if (max_ex_fn >= 0x80000004) { if (max_ex_fn >= 0x80000004) {
// Extract brand string // Extract brand string
__cpuid(cpu_id, 0x80000002); __cpuid(cpu_id, 0x80000002);
memcpy(brand_string, cpu_id, sizeof(cpu_id)); memcpy(brand_string, cpu_id, sizeof(cpu_id));
__cpuid(cpu_id, 0x80000003); __cpuid(cpu_id, 0x80000003);
memcpy(brand_string + 16, cpu_id, sizeof(cpu_id)); memcpy(brand_string + 16, cpu_id, sizeof(cpu_id));
__cpuid(cpu_id, 0x80000004); __cpuid(cpu_id, 0x80000004);
memcpy(brand_string + 32, cpu_id, sizeof(cpu_id)); memcpy(brand_string + 32, cpu_id, sizeof(cpu_id));
} }
if (max_ex_fn >= 0x80000001) { if (max_ex_fn >= 0x80000001) {
// Check for more features. // Check for more features.
__cpuid(cpu_id, 0x80000001); __cpuid(cpu_id, 0x80000001);
bool cmp_legacy = false; bool cmp_legacy = false;
if (cpu_id[2] & 1) bLAHFSAHF64 = true; if (cpu_id[2] & 1) bLAHFSAHF64 = true;
if (cpu_id[2] & 2) cmp_legacy = true; //wtf is this? if (cpu_id[2] & 2) cmp_legacy = true; //wtf is this?
if ((cpu_id[3] >> 29) & 1) bLongMode = true; if ((cpu_id[3] >> 29) & 1) bLongMode = true;
} }
if (max_ex_fn >= 0x80000008) { if (max_ex_fn >= 0x80000008) {
// Get number of cores. This is a bit complicated. Following AMD manual here. // Get number of cores. This is a bit complicated. Following AMD manual here.
__cpuid(cpu_id, 0x80000008); __cpuid(cpu_id, 0x80000008);
int apic_id_core_id_size = (cpu_id[2] >> 12) & 0xF; int apic_id_core_id_size = (cpu_id[2] >> 12) & 0xF;
if (apic_id_core_id_size == 0) { if (apic_id_core_id_size == 0) {
// Use what AMD calls the "legacy method" to determine # of cores. // Use what AMD calls the "legacy method" to determine # of cores.
if (HTT) { if (HTT) {
num_cores = logical_cpu_count; num_cores = logical_cpu_count;
} else { } else {
num_cores = 1; num_cores = 1;
} }
} else { } else {
// Use AMD's new method. // Use AMD's new method.
num_cores = (cpu_id[2] & 0xFF) + 1; num_cores = (cpu_id[2] & 0xFF) + 1;
} }
} else { } else {
// Wild guess // Wild guess
if (logical_cpu_count) if (logical_cpu_count)
num_cores = logical_cpu_count; num_cores = logical_cpu_count;
} }
} }
std::string CPUInfo::Summarize() std::string CPUInfo::Summarize()
{ {
std::string sum; std::string sum;
if (num_cores == 1) if (num_cores == 1)
sum = StringFromFormat("%s, %i core, ", cpu_string, num_cores); sum = StringFromFormat("%s, %i core, ", cpu_string, num_cores);
else else
sum = StringFromFormat("%s, %i cores, ", cpu_string, num_cores); sum = StringFromFormat("%s, %i cores, ", cpu_string, num_cores);
if (bSSE) sum += "SSE"; if (bSSE) sum += "SSE";
if (bSSE2) sum += ", SSE2"; if (bSSE2) sum += ", SSE2";
if (bSSE3) sum += ", SSE3"; if (bSSE3) sum += ", SSE3";
if (bSSSE3) sum += ", SSSE3"; if (bSSSE3) sum += ", SSSE3";
if (bSSE4_1) sum += ", SSE4.1"; if (bSSE4_1) sum += ", SSE4.1";
if (bSSE4_2) sum += ", SSE4.2"; if (bSSE4_2) sum += ", SSE4.2";
if (bLongMode) sum += ", 64-bit support"; if (bLongMode) sum += ", 64-bit support";
return sum; return sum;
} }
+22 -22
View File
@@ -1,22 +1,22 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#include "ChunkFile.h" #include "ChunkFile.h"
#include <stdio.h> #include <stdio.h>
+113 -113
View File
@@ -1,113 +1,113 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <stdio.h> #include <stdio.h>
#include "Common.h" #include "Common.h"
#include "StringUtil.h" #include "StringUtil.h"
namespace namespace
{ {
static PanicAlertHandler panic_handler = 0; static PanicAlertHandler panic_handler = 0;
} }
void RegisterPanicAlertHandler(PanicAlertHandler handler) void RegisterPanicAlertHandler(PanicAlertHandler handler)
{ {
panic_handler = handler; panic_handler = handler;
} }
void PanicAlert(const char* format, ...) void PanicAlert(const char* format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
if (panic_handler) if (panic_handler)
{ {
std::string msg; std::string msg;
StringFromFormatV(&msg, format, args); StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "PANIC: %s", msg.c_str()); LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
panic_handler(msg.c_str(), false); panic_handler(msg.c_str(), false);
} }
else else
{ {
#ifdef _WIN32 #ifdef _WIN32
std::string msg; std::string msg;
StringFromFormatV(&msg, format, args); StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "PANIC: %s", msg.c_str()); LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
MessageBox(0, msg.c_str(), "PANIC!", MB_ICONWARNING); MessageBox(0, msg.c_str(), "PANIC!", MB_ICONWARNING);
#elif __GNUC__ #elif __GNUC__
//#error Do a messagebox! //#error Do a messagebox!
vprintf(format, args); vprintf(format, args);
printf("\n"); printf("\n");
// asm ("int $3") ; // asm ("int $3") ;
#endif #endif
} }
va_end(args); va_end(args);
} }
bool PanicYesNo(const char* format, ...) bool PanicYesNo(const char* format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
bool retval; bool retval;
#ifdef _WIN32 #ifdef _WIN32
std::string msg; std::string msg;
StringFromFormatV(&msg, format, args); StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "PANIC: %s", msg.c_str()); LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
retval = IDYES == MessageBox(0, msg.c_str(), "PANIC! Continue?", MB_ICONQUESTION | MB_YESNO); retval = IDYES == MessageBox(0, msg.c_str(), "PANIC! Continue?", MB_ICONQUESTION | MB_YESNO);
#elif __GNUC__ #elif __GNUC__
//vprintf(format, args); //vprintf(format, args);
return(true); //#error Do a messagebox! return(true); //#error Do a messagebox!
#endif #endif
va_end(args); va_end(args);
return(retval); return(retval);
} }
bool AskYesNo(const char* format, ...) bool AskYesNo(const char* format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
bool retval; bool retval;
#ifdef _WIN32 #ifdef _WIN32
std::string msg; std::string msg;
StringFromFormatV(&msg, format, args); StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "ASK: %s", msg.c_str()); LOG(MASTER_LOG, "ASK: %s", msg.c_str());
retval = IDYES == MessageBox(0, msg.c_str(), "Dolphin", MB_ICONQUESTION | MB_YESNO); retval = IDYES == MessageBox(0, msg.c_str(), "Dolphin", MB_ICONQUESTION | MB_YESNO);
#elif __GNUC__ #elif __GNUC__
//vprintf(format, args); //vprintf(format, args);
return(true); //#error Do a messagebox! return(true); //#error Do a messagebox!
#endif #endif
va_end(args); va_end(args);
return(retval); return(retval);
} }
// Standard implementation of logging - simply print to standard output. // Standard implementation of logging - simply print to standard output.
// Programs are welcome to override this. // Programs are welcome to override this.
/* /*
void __Log(int logNumber, const char *text, ...) void __Log(int logNumber, const char *text, ...)
{ {
va_list args; va_list args;
va_start(args, text); va_start(args, text);
vprintf(text, args); vprintf(text, args);
va_end(args); va_end(args);
}*/ }*/
+57 -57
View File
@@ -1,57 +1,57 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <winioctl.h> #include <winioctl.h>
#endif #endif
void GetAllRemovableDrives(std::vector<std::string> *drives) { void GetAllRemovableDrives(std::vector<std::string> *drives) {
drives->clear(); drives->clear();
#ifdef _WIN32 #ifdef _WIN32
HANDLE hDisk; HANDLE hDisk;
DISK_GEOMETRY diskGeometry; DISK_GEOMETRY diskGeometry;
for (int i = 'A'; i < 'Z'; i++) for (int i = 'A'; i < 'Z'; i++)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
sprintf(path, "\\\\.\\%c:", i); sprintf(path, "\\\\.\\%c:", i);
hDisk = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); hDisk = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hDisk != INVALID_HANDLE_VALUE) if (hDisk != INVALID_HANDLE_VALUE)
{ {
DWORD dwBytes; DWORD dwBytes;
DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &diskGeometry, sizeof(DISK_GEOMETRY), &dwBytes, NULL); DeviceIoControl(hDisk, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &diskGeometry, sizeof(DISK_GEOMETRY), &dwBytes, NULL);
// Only proceed if disk is a removable media // Only proceed if disk is a removable media
if (diskGeometry.MediaType == RemovableMedia) if (diskGeometry.MediaType == RemovableMedia)
{ {
if (diskGeometry.BytesPerSector == 2048) { if (diskGeometry.BytesPerSector == 2048) {
// Probably CD/DVD drive. // Probably CD/DVD drive.
// "Remove" the "\\.\" part of the path and return it. // "Remove" the "\\.\" part of the path and return it.
drives->push_back(path + 4); drives->push_back(path + 4);
} }
} }
} }
CloseHandle(hDisk); CloseHandle(hDisk);
} }
#else #else
// TODO // TODO
// stat("/media/cdrom") or whatever etc etc // stat("/media/cdrom") or whatever etc etc
#endif #endif
} }
+151 -151
View File
@@ -1,151 +1,151 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <dlfcn.h> #include <dlfcn.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
#include "Common.h" #include "Common.h"
#include "StringUtil.h" #include "StringUtil.h"
#include "DynamicLibrary.h" #include "DynamicLibrary.h"
#include "../../Core/Src/PowerPC/PowerPC.h" #include "../../Core/Src/PowerPC/PowerPC.h"
DynamicLibrary::DynamicLibrary() DynamicLibrary::DynamicLibrary()
{ {
library = 0; library = 0;
} }
#ifdef _WIN32 #ifdef _WIN32
std::string GetLastErrorAsString() std::string GetLastErrorAsString()
{ {
LPVOID lpMsgBuf = 0; LPVOID lpMsgBuf = 0;
DWORD error = GetLastError(); DWORD error = GetLastError();
FormatMessage( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, NULL,
error, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, NULL); 0, NULL);
std::string s; std::string s;
if (lpMsgBuf) if (lpMsgBuf)
{ {
s = ((char *)lpMsgBuf); s = ((char *)lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
} else { } else {
s = StringFromFormat("(unknown error %08x)", error); s = StringFromFormat("(unknown error %08x)", error);
} }
return s; return s;
} }
#endif #endif
// ------------------------------------------------------------------ // ------------------------------------------------------------------
/* Loading means loading the dll with LoadLibrary() to get an instance to the dll. /* Loading means loading the dll with LoadLibrary() to get an instance to the dll.
This is done when Dolphin is started to determine which dlls are good, and This is done when Dolphin is started to determine which dlls are good, and
before opening the Config and Debugging windowses from Plugin.cpp and before opening the Config and Debugging windowses from Plugin.cpp and
before opening the dll for running the emulation in Video_...cpp in Core. */ before opening the dll for running the emulation in Video_...cpp in Core. */
// ----------------------- // -----------------------
int DynamicLibrary::Load(const char* filename) int DynamicLibrary::Load(const char* filename)
{ {
if (!filename || strlen(filename) == 0) if (!filename || strlen(filename) == 0)
{ {
LOG(MASTER_LOG, "Missing filename of dynamic library to load"); LOG(MASTER_LOG, "Missing filename of dynamic library to load");
return 0; return 0;
} }
LOG(MASTER_LOG, "Trying to load library %s", filename); LOG(MASTER_LOG, "Trying to load library %s", filename);
if (IsLoaded()) if (IsLoaded())
{ {
LOG(MASTER_LOG, "Trying to load already loaded library %s", filename); LOG(MASTER_LOG, "Trying to load already loaded library %s", filename);
return 2; return 2;
} }
#ifdef _WIN32 #ifdef _WIN32
library = LoadLibrary(filename); library = LoadLibrary(filename);
if (!library) { if (!library) {
LOG(MASTER_LOG, "Error loading DLL %s: %s", filename, GetLastErrorAsString().c_str()); LOG(MASTER_LOG, "Error loading DLL %s: %s", filename, GetLastErrorAsString().c_str());
return 0; return 0;
} }
#else #else
library = dlopen(filename, RTLD_NOW | RTLD_LOCAL); library = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
if (!library) if (!library)
{ {
#ifdef LOGGING #ifdef LOGGING
LOG(MASTER_LOG, "Error loading DLL %s: %s", filename, dlerror()); LOG(MASTER_LOG, "Error loading DLL %s: %s", filename, dlerror());
#else #else
printf("Error loading DLL %s: %s", filename, dlerror()); printf("Error loading DLL %s: %s", filename, dlerror());
#endif #endif
return false; return false;
} }
#endif #endif
library_file = filename; library_file = filename;
return 1; return 1;
} }
void DynamicLibrary::Unload() void DynamicLibrary::Unload()
{ {
if (!IsLoaded()) if (!IsLoaded())
{ {
PanicAlert("Trying to unload non-loaded library"); PanicAlert("Trying to unload non-loaded library");
return; return;
} }
#ifdef _WIN32 #ifdef _WIN32
/* TEMPORARY SOLUTION: To prevent that Dolphin hangs when a game is stopped /* TEMPORARY SOLUTION: To prevent that Dolphin hangs when a game is stopped
or when we try to close Dolphin. It's possible that it only occur when we render or when we try to close Dolphin. It's possible that it only occur when we render
to the main window. And sometimes FreeLibrary works without any problem, so to the main window. And sometimes FreeLibrary works without any problem, so
don't remove this just because it doesn't hang once. I could not find the don't remove this just because it doesn't hang once. I could not find the
actual cause of it. */ actual cause of it. */
if( ! (library_file.find("OGL.") != std::string::npos) && !PowerPC::CPU_POWERDOWN) if( ! (library_file.find("OGL.") != std::string::npos) && !PowerPC::CPU_POWERDOWN)
FreeLibrary(library); FreeLibrary(library);
#else #else
dlclose(library); dlclose(library);
#endif #endif
library = 0; library = 0;
} }
void* DynamicLibrary::Get(const char* funcname) const void* DynamicLibrary::Get(const char* funcname) const
{ {
void* retval; void* retval;
#ifdef _WIN32 #ifdef _WIN32
if (!library) if (!library)
{ {
PanicAlert("Can't find function %s - Library not loaded."); PanicAlert("Can't find function %s - Library not loaded.");
} }
retval = GetProcAddress(library, funcname); retval = GetProcAddress(library, funcname);
//if (!retval) //if (!retval)
//{ //{
// PanicAlert("Did not find function %s in library %s.", funcname, library_file.c_str()); // PanicAlert("Did not find function %s in library %s.", funcname, library_file.c_str());
//} //}
#else #else
retval = dlsym(library, funcname); retval = dlsym(library, funcname);
if (!retval) if (!retval)
{ {
printf("Symbol %s missing in %s (error: %s)\n", funcname, library_file.c_str(), dlerror()); printf("Symbol %s missing in %s (error: %s)\n", funcname, library_file.c_str(), dlerror());
} }
#endif #endif
return retval; return retval;
} }
File diff suppressed because it is too large Load Diff
+119 -119
View File
@@ -1,119 +1,119 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#ifndef _WIN32 #ifndef _WIN32
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#else #else
#include <windows.h> #include <windows.h>
#endif #endif
#include <string> #include <string>
#include "FileSearch.h" #include "FileSearch.h"
#include "StringUtil.h" #include "StringUtil.h"
CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories) CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
{ {
// Reverse the loop order for speed? // Reverse the loop order for speed?
for (size_t j = 0; j < _rSearchStrings.size(); j++) for (size_t j = 0; j < _rSearchStrings.size(); j++)
{ {
for (size_t i = 0; i < _rDirectories.size(); i++) for (size_t i = 0; i < _rDirectories.size(); i++)
{ {
FindFiles(_rSearchStrings[j], _rDirectories[i]); FindFiles(_rSearchStrings[j], _rDirectories[i]);
} }
} }
} }
void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath) void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
{ {
std::string GCMSearchPath; std::string GCMSearchPath;
BuildCompleteFilename(GCMSearchPath, _strPath, _searchString); BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
#ifdef _WIN32 #ifdef _WIN32
WIN32_FIND_DATA findData; WIN32_FIND_DATA findData;
HANDLE FindFirst = FindFirstFile(GCMSearchPath.c_str(), &findData); HANDLE FindFirst = FindFirstFile(GCMSearchPath.c_str(), &findData);
if (FindFirst != INVALID_HANDLE_VALUE) if (FindFirst != INVALID_HANDLE_VALUE)
{ {
bool bkeepLooping = true; bool bkeepLooping = true;
while (bkeepLooping) while (bkeepLooping)
{ {
if (findData.cFileName[0] != '.') if (findData.cFileName[0] != '.')
{ {
std::string strFilename; std::string strFilename;
BuildCompleteFilename(strFilename, _strPath, findData.cFileName); BuildCompleteFilename(strFilename, _strPath, findData.cFileName);
m_FileNames.push_back(strFilename); m_FileNames.push_back(strFilename);
} }
bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false; bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
} }
} }
FindClose(FindFirst); FindClose(FindFirst);
#else #else
size_t dot_pos = _searchString.rfind("."); size_t dot_pos = _searchString.rfind(".");
if (dot_pos == std::string::npos) if (dot_pos == std::string::npos)
{ {
return; return;
} }
std::string ext = _searchString.substr(dot_pos); std::string ext = _searchString.substr(dot_pos);
DIR* dir = opendir(_strPath.c_str()); DIR* dir = opendir(_strPath.c_str());
if (!dir) if (!dir)
{ {
return; return;
} }
dirent* dp; dirent* dp;
while (true) while (true)
{ {
dp = readdir(dir); dp = readdir(dir);
if (!dp) if (!dp)
{ {
break; break;
} }
std::string s(dp->d_name); std::string s(dp->d_name);
if ( (s.size() > ext.size()) && (!strcasecmp(s.substr(s.size() - ext.size()).c_str(), ext.c_str())) ) if ( (s.size() > ext.size()) && (!strcasecmp(s.substr(s.size() - ext.size()).c_str(), ext.c_str())) )
{ {
std::string full_name = _strPath + "/" + s; std::string full_name = _strPath + "/" + s;
m_FileNames.push_back(full_name); m_FileNames.push_back(full_name);
} }
} }
closedir(dir); closedir(dir);
#endif #endif
} }
const CFileSearch::XStringVector& CFileSearch::GetFileNames() const const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
{ {
return(m_FileNames); return(m_FileNames);
} }
File diff suppressed because it is too large Load Diff
+136 -136
View File
@@ -1,136 +1,136 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Hash.h" #include "Hash.h"
// uint32_t // uint32_t
// WARNING - may read one more byte! // WARNING - may read one more byte!
// Implementation from Wikipedia. // Implementation from Wikipedia.
u32 HashFletcher(const u8* data_u8, size_t length) u32 HashFletcher(const u8* data_u8, size_t length)
{ {
const u16* data = (const u16*)data_u8; /* Pointer to the data to be summed */ const u16* data = (const u16*)data_u8; /* Pointer to the data to be summed */
size_t len = (length + 1) / 2; /* Length in 16-bit words */ size_t len = (length + 1) / 2; /* Length in 16-bit words */
u32 sum1 = 0xffff, sum2 = 0xffff; u32 sum1 = 0xffff, sum2 = 0xffff;
while (len) while (len)
{ {
size_t tlen = len > 360 ? 360 : len; size_t tlen = len > 360 ? 360 : len;
len -= tlen; len -= tlen;
do { do {
sum1 += *data++; sum1 += *data++;
sum2 += sum1; sum2 += sum1;
} }
while (--tlen); while (--tlen);
sum1 = (sum1 & 0xffff) + (sum1 >> 16); sum1 = (sum1 & 0xffff) + (sum1 >> 16);
sum2 = (sum2 & 0xffff) + (sum2 >> 16); sum2 = (sum2 & 0xffff) + (sum2 >> 16);
} }
/* Second reduction step to reduce sums to 16 bits */ /* Second reduction step to reduce sums to 16 bits */
sum1 = (sum1 & 0xffff) + (sum1 >> 16); sum1 = (sum1 & 0xffff) + (sum1 >> 16);
sum2 = (sum2 & 0xffff) + (sum2 >> 16); sum2 = (sum2 & 0xffff) + (sum2 >> 16);
return(sum2 << 16 | sum1); return(sum2 << 16 | sum1);
} }
// Implementation from Wikipedia // Implementation from Wikipedia
// Slightly slower than Fletcher above, but slighly more reliable. // Slightly slower than Fletcher above, but slighly more reliable.
#define MOD_ADLER 65521 #define MOD_ADLER 65521
// data: Pointer to the data to be summed; len is in bytes // data: Pointer to the data to be summed; len is in bytes
u32 HashAdler32(const u8* data, size_t len) u32 HashAdler32(const u8* data, size_t len)
{ {
u32 a = 1, b = 0; u32 a = 1, b = 0;
while (len) while (len)
{ {
size_t tlen = len > 5550 ? 5550 : len; size_t tlen = len > 5550 ? 5550 : len;
len -= tlen; len -= tlen;
do do
{ {
a += *data++; a += *data++;
b += a; b += a;
} }
while (--tlen); while (--tlen);
a = (a & 0xffff) + (a >> 16) * (65536 - MOD_ADLER); a = (a & 0xffff) + (a >> 16) * (65536 - MOD_ADLER);
b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER); b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER);
} }
// It can be shown that a <= 0x1013a here, so a single subtract will do. // It can be shown that a <= 0x1013a here, so a single subtract will do.
if (a >= MOD_ADLER) if (a >= MOD_ADLER)
{ {
a -= MOD_ADLER; a -= MOD_ADLER;
} }
// It can be shown that b can reach 0xfff87 here. // It can be shown that b can reach 0xfff87 here.
b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER); b = (b & 0xffff) + (b >> 16) * (65536 - MOD_ADLER);
if (b >= MOD_ADLER) if (b >= MOD_ADLER)
{ {
b -= MOD_ADLER; b -= MOD_ADLER;
} }
return((b << 16) | a); return((b << 16) | a);
} }
// Another fast and decent hash // Another fast and decent hash
u32 HashFNV(const u8* ptr, int length) u32 HashFNV(const u8* ptr, int length)
{ {
u32 hash = 0x811c9dc5; u32 hash = 0x811c9dc5;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
hash *= 1677761; hash *= 1677761;
hash ^= ptr[i]; hash ^= ptr[i];
} }
return(hash); return(hash);
} }
// Another fast and decent hash // Another fast and decent hash
u32 HashFNV1(const u8* ptr, int length) u32 HashFNV1(const u8* ptr, int length)
{ {
u32 hash = 0x811c9dc5; u32 hash = 0x811c9dc5;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
hash *= 1677761; hash *= 1677761;
hash ^= ptr[i]; hash ^= ptr[i];
} }
return(hash); return(hash);
} }
// Stupid hash - but can't go back now :) // Stupid hash - but can't go back now :)
// Don't use for new things. At least it's reasonably fast. // Don't use for new things. At least it's reasonably fast.
u32 HashEctor(const u8* ptr, int length) u32 HashEctor(const u8* ptr, int length)
{ {
u32 crc = 0; u32 crc = 0;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
crc ^= ptr[i]; crc ^= ptr[i];
crc = (crc << 3) | (crc >> 29); crc = (crc << 3) | (crc >> 29);
} }
return(crc); return(crc);
} }
File diff suppressed because it is too large Load Diff
+233 -233
View File
@@ -1,233 +1,233 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include "Common.h" #include "Common.h"
#include "MappedFile.h" #include "MappedFile.h"
namespace Common namespace Common
{ {
class CMappedFile class CMappedFile
: public IMappedFile : public IMappedFile
{ {
public: public:
CMappedFile(void); CMappedFile(void);
~CMappedFile(void); ~CMappedFile(void);
bool Open(const char* _szFilename); bool Open(const char* _szFilename);
bool IsOpen(void); bool IsOpen(void);
void Close(void); void Close(void);
u64 GetSize(void); u64 GetSize(void);
u8* Lock(u64 _offset, u64 _size); u8* Lock(u64 _offset, u64 _size);
void Unlock(u8* ptr); void Unlock(u8* ptr);
private: private:
u64 size; u64 size;
typedef std::map<u8*, u8*>Lockmap; typedef std::map<u8*, u8*>Lockmap;
Lockmap lockMap; Lockmap lockMap;
#ifdef _WIN32 #ifdef _WIN32
HANDLE hFile; HANDLE hFile;
HANDLE hFileMapping; HANDLE hFileMapping;
#elif POSIX #elif POSIX
int fd; int fd;
typedef std::map<u8*, size_t>Sizemap; typedef std::map<u8*, size_t>Sizemap;
Sizemap sizeMap; Sizemap sizeMap;
#endif #endif
int granularity; int granularity;
}; };
CMappedFile::CMappedFile() CMappedFile::CMappedFile()
{ {
#ifdef _WIN32 #ifdef _WIN32
hFile = INVALID_HANDLE_VALUE; hFile = INVALID_HANDLE_VALUE;
SYSTEM_INFO info; SYSTEM_INFO info;
GetSystemInfo(&info); GetSystemInfo(&info);
granularity = (int)info.dwAllocationGranularity; granularity = (int)info.dwAllocationGranularity;
#elif POSIX #elif POSIX
fd = -1; fd = -1;
granularity = getpagesize(); //sysconf(_SC_PAGE_SIZE); granularity = getpagesize(); //sysconf(_SC_PAGE_SIZE);
#endif #endif
} }
CMappedFile::~CMappedFile() CMappedFile::~CMappedFile()
{ {
Close(); Close();
} }
bool CMappedFile::Open(const char* filename) bool CMappedFile::Open(const char* filename)
{ {
Close(); Close();
#ifdef _WIN32 #ifdef _WIN32
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
return(false); return(false);
} }
hFileMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, NULL); hFileMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, 0, 0, NULL);
if (hFileMapping == NULL) if (hFileMapping == NULL)
{ {
CloseHandle(hFile); CloseHandle(hFile);
hFile = 0; hFile = 0;
return(false); return(false);
} }
u32 high = 0; u32 high = 0;
u32 low = GetFileSize(hFile, (LPDWORD)&high); u32 low = GetFileSize(hFile, (LPDWORD)&high);
size = (u64)low | ((u64)high << 32); size = (u64)low | ((u64)high << 32);
#elif POSIX #elif POSIX
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
size = lseek(fd, 0, SEEK_END); size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
#endif #endif
return(true); return(true);
} }
bool CMappedFile::IsOpen() bool CMappedFile::IsOpen()
{ {
#ifdef _WIN32 #ifdef _WIN32
return(hFile != INVALID_HANDLE_VALUE); return(hFile != INVALID_HANDLE_VALUE);
#elif POSIX #elif POSIX
return(fd != -1); return(fd != -1);
#endif #endif
} }
u64 CMappedFile::GetSize() u64 CMappedFile::GetSize()
{ {
return(size); return(size);
} }
void CMappedFile::Close() void CMappedFile::Close()
{ {
#ifdef _WIN32 #ifdef _WIN32
if (hFile != INVALID_HANDLE_VALUE) if (hFile != INVALID_HANDLE_VALUE)
{ {
CloseHandle(hFileMapping); CloseHandle(hFileMapping);
CloseHandle(hFile); CloseHandle(hFile);
lockMap.clear(); lockMap.clear();
hFile = INVALID_HANDLE_VALUE; hFile = INVALID_HANDLE_VALUE;
} }
#elif POSIX #elif POSIX
if (fd != -1) if (fd != -1)
{ {
lockMap.clear(); lockMap.clear();
sizeMap.clear(); sizeMap.clear();
close(fd); close(fd);
} }
fd = -1; fd = -1;
#endif #endif
} }
u8* CMappedFile::Lock(u64 offset, u64 _size) u8* CMappedFile::Lock(u64 offset, u64 _size)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (hFile != INVALID_HANDLE_VALUE) if (hFile != INVALID_HANDLE_VALUE)
#elif POSIX #elif POSIX
if (fd != -1) if (fd != -1)
#endif #endif
{ {
u64 realOffset = offset & ~(granularity - 1); u64 realOffset = offset & ~(granularity - 1);
s64 difference = offset - realOffset; s64 difference = offset - realOffset;
u64 fake_size = (difference + _size + granularity - 1) & ~(granularity - 1); u64 fake_size = (difference + _size + granularity - 1) & ~(granularity - 1);
#ifdef _WIN32 #ifdef _WIN32
u8* realPtr = (u8*)MapViewOfFile(hFileMapping, FILE_MAP_READ, (DWORD)(realOffset >> 32), (DWORD)realOffset, (SIZE_T)(_size)); u8* realPtr = (u8*)MapViewOfFile(hFileMapping, FILE_MAP_READ, (DWORD)(realOffset >> 32), (DWORD)realOffset, (SIZE_T)(_size));
if (realPtr == NULL) if (realPtr == NULL)
{ {
return(NULL); return(NULL);
} }
#elif POSIX #elif POSIX
// TODO // TODO
u8* realPtr = (u8*)mmap(0, fake_size, PROT_READ, MAP_PRIVATE, fd, (off_t)realOffset); u8* realPtr = (u8*)mmap(0, fake_size, PROT_READ, MAP_PRIVATE, fd, (off_t)realOffset);
if (!realPtr) if (!realPtr)
{ {
PanicAlert("Map Failed"); PanicAlert("Map Failed");
exit(0); exit(0);
} }
#endif #endif
u8* fakePtr = realPtr + difference; u8* fakePtr = realPtr + difference;
//add to map //add to map
lockMap[fakePtr] = realPtr; lockMap[fakePtr] = realPtr;
#ifndef _WIN32 #ifndef _WIN32
sizeMap[fakePtr] = _size + difference; sizeMap[fakePtr] = _size + difference;
#endif #endif
return(fakePtr); return(fakePtr);
} }
else else
{ {
return(0); return(0);
} }
} }
void CMappedFile::Unlock(u8* ptr) void CMappedFile::Unlock(u8* ptr)
{ {
if (ptr != 0) if (ptr != 0)
{ {
Lockmap::iterator iter = lockMap.find(ptr); Lockmap::iterator iter = lockMap.find(ptr);
if (iter != lockMap.end()) if (iter != lockMap.end())
{ {
#ifdef _WIN32 #ifdef _WIN32
UnmapViewOfFile((*iter).second); UnmapViewOfFile((*iter).second);
#else #else
munmap((*iter).second, sizeMap[ptr]); munmap((*iter).second, sizeMap[ptr]);
#endif #endif
lockMap.erase(iter); lockMap.erase(iter);
} }
else else
{ {
PanicAlert("CMappedFile : Unlock failed"); PanicAlert("CMappedFile : Unlock failed");
} }
} }
} }
IMappedFile* IMappedFile::CreateMappedFileDEPRECATED(void) IMappedFile* IMappedFile::CreateMappedFileDEPRECATED(void)
{ {
return(new CMappedFile); return(new CMappedFile);
} }
} // end of namespace Common } // end of namespace Common
+44 -44
View File
@@ -1,44 +1,44 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <xmmintrin.h> #include <xmmintrin.h>
#include "Common.h" #include "Common.h"
#include "MathUtil.h" #include "MathUtil.h"
static u32 saved_sse_state = _mm_getcsr(); static u32 saved_sse_state = _mm_getcsr();
static const u32 default_sse_state = _mm_getcsr(); static const u32 default_sse_state = _mm_getcsr();
void LoadDefaultSSEState() void LoadDefaultSSEState()
{ {
_mm_setcsr(default_sse_state); _mm_setcsr(default_sse_state);
} }
void LoadSSEState() void LoadSSEState()
{ {
_mm_setcsr(saved_sse_state); _mm_setcsr(saved_sse_state);
} }
void SaveSSEState() void SaveSSEState()
{ {
saved_sse_state = _mm_getcsr(); saved_sse_state = _mm_getcsr();
} }
+144 -144
View File
@@ -1,144 +1,144 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#include "MemArena.h" #include "MemArena.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
#endif #endif
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
#endif #endif
const char* ram_temp_file = "/tmp/gc_mem.tmp"; const char* ram_temp_file = "/tmp/gc_mem.tmp";
void MemArena::GrabLowMemSpace(size_t size) void MemArena::GrabLowMemSpace(size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
hMemoryMapping = CreateFileMapping(NULL, NULL, PAGE_READWRITE, 0, (DWORD)(size), _T("All GC Memory")); hMemoryMapping = CreateFileMapping(NULL, NULL, PAGE_READWRITE, 0, (DWORD)(size), _T("All GC Memory"));
#else #else
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
fd = open(ram_temp_file, O_RDWR | O_CREAT, mode); fd = open(ram_temp_file, O_RDWR | O_CREAT, mode);
ftruncate(fd, size); ftruncate(fd, size);
return; return;
#endif #endif
} }
void MemArena::ReleaseSpace() void MemArena::ReleaseSpace()
{ {
#ifdef _WIN32 #ifdef _WIN32
CloseHandle(hMemoryMapping); CloseHandle(hMemoryMapping);
hMemoryMapping = 0; hMemoryMapping = 0;
#else #else
close(fd); close(fd);
unlink(ram_temp_file); unlink(ram_temp_file);
#endif #endif
} }
void* MemArena::CreateView(s64 offset, size_t size, bool ensure_low_mem) void* MemArena::CreateView(s64 offset, size_t size, bool ensure_low_mem)
{ {
#ifdef _WIN32 #ifdef _WIN32
return(MapViewOfFile(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size)); return(MapViewOfFile(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size));
#else #else
void* ptr = mmap(0, size, void* ptr = mmap(0, size,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED MAP_SHARED
#ifdef __x86_64__ #ifdef __x86_64__
| (ensure_low_mem ? MAP_32BIT : 0) | (ensure_low_mem ? MAP_32BIT : 0)
#endif #endif
, fd, offset); , fd, offset);
if (!ptr) if (!ptr)
{ {
PanicAlert("Failed to create view"); PanicAlert("Failed to create view");
} }
return(ptr); return(ptr);
#endif #endif
} }
void* MemArena::CreateViewAt(s64 offset, size_t size, void* base) void* MemArena::CreateViewAt(s64 offset, size_t size, void* base)
{ {
#ifdef _WIN32 #ifdef _WIN32
return(MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base)); return(MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base));
#else #else
return(mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset)); return(mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, offset));
#endif #endif
} }
void MemArena::ReleaseView(void* view, size_t size) void MemArena::ReleaseView(void* view, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
UnmapViewOfFile(view); UnmapViewOfFile(view);
#else #else
munmap(view, size); munmap(view, size);
#endif #endif
} }
u8* MemArena::Find4GBBase() u8* MemArena::Find4GBBase()
{ {
#ifdef _M_X64 #ifdef _M_X64
#ifdef _WIN32 #ifdef _WIN32
// 64 bit // 64 bit
u8* base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE); u8* base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);
VirtualFree(base, 0, MEM_RELEASE); VirtualFree(base, 0, MEM_RELEASE);
return base; return base;
#else #else
// Very precarious - mmap cannot return an error when trying to map already used pages. // Very precarious - mmap cannot return an error when trying to map already used pages.
// This makes the Windows approach above unusable on Linux, so we will simply pray... // This makes the Windows approach above unusable on Linux, so we will simply pray...
return reinterpret_cast<u8*>(0x2300000000ULL); return reinterpret_cast<u8*>(0x2300000000ULL);
#endif #endif
#else #else
// 32 bit // 32 bit
#ifdef _WIN32 #ifdef _WIN32
// The highest thing in any 1GB section of memory space is the locked cache. We only need to fit it. // The highest thing in any 1GB section of memory space is the locked cache. We only need to fit it.
u8* base = (u8*)VirtualAlloc(0, 0x31000000, MEM_RESERVE, PAGE_READWRITE); u8* base = (u8*)VirtualAlloc(0, 0x31000000, MEM_RESERVE, PAGE_READWRITE);
if (base) { if (base) {
VirtualFree(base, 0, MEM_RELEASE); VirtualFree(base, 0, MEM_RELEASE);
} }
return base; return base;
#else #else
void* base = mmap(0, 0x31000000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0); void* base = mmap(0, 0x31000000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
if (base == MAP_FAILED) { if (base == MAP_FAILED) {
PanicAlert("Failed to map 1 GB of memory space: %s", strerror(errno)); PanicAlert("Failed to map 1 GB of memory space: %s", strerror(errno));
return 0; return 0;
} }
munmap(base, 0x31000000); munmap(base, 0x31000000);
return static_cast<u8*>(base); return static_cast<u8*>(base);
#endif #endif
#endif #endif
} }
+135 -135
View File
@@ -1,135 +1,135 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#include "MemoryUtil.h" #include "MemoryUtil.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#elif __GNUC__ #elif __GNUC__
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
#endif #endif
// MacOSX does not support MAP_VARIABLE // MacOSX does not support MAP_VARIABLE
#ifndef MAP_VARIABLE #ifndef MAP_VARIABLE
#define MAP_VARIABLE 0 #define MAP_VARIABLE 0
#endif #endif
// This is purposedely not a full wrapper for virtualalloc/mmap, but it // This is purposedely not a full wrapper for virtualalloc/mmap, but it
// provides exactly the primitive operations that Dolphin needs. // provides exactly the primitive operations that Dolphin needs.
void* AllocateExecutableMemory(int size, bool low) void* AllocateExecutableMemory(int size, bool low)
{ {
#ifdef _WIN32 #ifdef _WIN32
void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if ((u64)ptr >= 0x80000000) if ((u64)ptr >= 0x80000000)
{ {
PanicAlert("Executable memory ended up above 2GB!"); PanicAlert("Executable memory ended up above 2GB!");
// If this happens, we have to implement a free ram search scheme. ector knows how. // If this happens, we have to implement a free ram search scheme. ector knows how.
} }
return(ptr); return(ptr);
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, void* retval = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE MAP_ANONYMOUS | MAP_PRIVATE
#ifdef __x86_64__ #ifdef __x86_64__
| (low ? MAP_32BIT : 0) | (low ? MAP_32BIT : 0)
#endif #endif
, -1, 0); // | MAP_FIXED , -1, 0); // | MAP_FIXED
// printf("Mapped executable memory at %p (size %i)\n", retval, size); // printf("Mapped executable memory at %p (size %i)\n", retval, size);
if (!retval) if (!retval)
{ {
PanicAlert("Failed to allocate executable memory, errno=%i", errno); PanicAlert("Failed to allocate executable memory, errno=%i", errno);
} }
return(retval); return(retval);
#endif #endif
} }
void* AllocateMemoryPages(int size) void* AllocateMemoryPages(int size)
{ {
#ifdef _WIN32 #ifdef _WIN32
void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
if (!ptr) if (!ptr)
{ {
PanicAlert("Failed to allocate raw memory"); PanicAlert("Failed to allocate raw memory");
} }
return(ptr); return(ptr);
#else #else
void* retval = mmap(0, size, PROT_READ | PROT_WRITE, void* retval = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // | MAP_FIXED MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // | MAP_FIXED
// printf("Mapped memory at %p (size %i)\n", retval, size); // printf("Mapped memory at %p (size %i)\n", retval, size);
if (!retval) if (!retval)
{ {
PanicAlert("Failed to allocate raw memory, errno=%i", errno); PanicAlert("Failed to allocate raw memory, errno=%i", errno);
} }
return(retval); return(retval);
#endif #endif
} }
void FreeMemoryPages(void* ptr, int size) void FreeMemoryPages(void* ptr, int size)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (ptr) if (ptr)
{ {
VirtualFree(ptr, 0, MEM_RELEASE); VirtualFree(ptr, 0, MEM_RELEASE);
ptr = NULL; ptr = NULL;
} }
#else #else
munmap(ptr, size); munmap(ptr, size);
#endif #endif
} }
void WriteProtectMemory(void* ptr, int size, bool allowExecute) void WriteProtectMemory(void* ptr, int size, bool allowExecute)
{ {
#ifdef _WIN32 #ifdef _WIN32
VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, 0); VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, 0);
#else #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ); mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
#endif #endif
} }
void UnWriteProtectMemory(void* ptr, int size, bool allowExecute) void UnWriteProtectMemory(void* ptr, int size, bool allowExecute)
{ {
#ifdef _WIN32 #ifdef _WIN32
VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READONLY, 0); VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READONLY, 0);
#else #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ); mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
#endif #endif
} }
+100 -100
View File
@@ -1,100 +1,100 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
// ======================================================= // =======================================================
// File description // File description
// ------------- // -------------
/* This file is a simpler version of Plugin_...cpp found in Core. This file only loads /* This file is a simpler version of Plugin_...cpp found in Core. This file only loads
the config and debugging windowses and works with all plugins. */ the config and debugging windowses and works with all plugins. */
// ============= // =============
#include "Plugin.h" #include "Plugin.h"
namespace Common namespace Common
{ {
DynamicLibrary CPlugin::m_hInstLib; DynamicLibrary CPlugin::m_hInstLib;
void(__cdecl * CPlugin::m_GetDllInfo) (PLUGIN_INFO * _PluginInfo) = 0; void(__cdecl * CPlugin::m_GetDllInfo) (PLUGIN_INFO * _PluginInfo) = 0;
//void(__cdecl * CPlugin::m_DllAbout) (HWND _hParent) = 0; //void(__cdecl * CPlugin::m_DllAbout) (HWND _hParent) = 0;
void(__cdecl * CPlugin::m_DllConfig) (HWND _hParent) = 0; void(__cdecl * CPlugin::m_DllConfig) (HWND _hParent) = 0;
void(__cdecl * CPlugin::m_DllDebugger) (HWND _hParent, bool Show) = 0; void(__cdecl * CPlugin::m_DllDebugger) (HWND _hParent, bool Show) = 0;
void void
CPlugin::Release(void) CPlugin::Release(void)
{ {
m_GetDllInfo = 0; m_GetDllInfo = 0;
//m_DllAbout = 0; //m_DllAbout = 0;
m_DllConfig = 0; m_DllConfig = 0;
m_DllDebugger = 0; m_DllDebugger = 0;
m_hInstLib.Unload(); m_hInstLib.Unload();
} }
bool bool
CPlugin::Load(const char* _szName) CPlugin::Load(const char* _szName)
{ {
if (m_hInstLib.Load(_szName)) if (m_hInstLib.Load(_szName))
{ {
m_GetDllInfo = (void (__cdecl*)(PLUGIN_INFO*)) m_hInstLib.Get("GetDllInfo"); m_GetDllInfo = (void (__cdecl*)(PLUGIN_INFO*)) m_hInstLib.Get("GetDllInfo");
m_DllConfig = (void (__cdecl*)(HWND)) m_hInstLib.Get("DllConfig"); m_DllConfig = (void (__cdecl*)(HWND)) m_hInstLib.Get("DllConfig");
m_DllDebugger = (void (__cdecl*)(HWND, bool)) m_hInstLib.Get("DllDebugger"); m_DllDebugger = (void (__cdecl*)(HWND, bool)) m_hInstLib.Get("DllDebugger");
return(true); return(true);
} }
return(false); return(false);
} }
bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo) bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo)
{ {
if (m_GetDllInfo != 0) if (m_GetDllInfo != 0)
{ {
m_GetDllInfo(&_pluginInfo); m_GetDllInfo(&_pluginInfo);
return(true); return(true);
} }
return(false); return(false);
} }
void CPlugin::Config(HWND _hwnd) void CPlugin::Config(HWND _hwnd)
{ {
if (m_DllConfig != 0) if (m_DllConfig != 0)
{ {
m_DllConfig(_hwnd); m_DllConfig(_hwnd);
} }
} }
//void CPlugin::About(HWND _hwnd) //void CPlugin::About(HWND _hwnd)
//{ //{
// if (m_DllAbout != 0) // if (m_DllAbout != 0)
// { // {
// m_DllAbout(_hwnd); // m_DllAbout(_hwnd);
// } // }
//} //}
void CPlugin::Debug(HWND _hwnd, bool Show) void CPlugin::Debug(HWND _hwnd, bool Show)
{ {
if (m_DllDebugger != 0) if (m_DllDebugger != 0)
{ {
m_DllDebugger(_hwnd, Show); m_DllDebugger(_hwnd, Show);
} }
} }
} // end of namespace Common } // end of namespace Common
File diff suppressed because it is too large Load Diff
+38 -38
View File
@@ -1,38 +1,38 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "TestFramework.h" #include "TestFramework.h"
namespace __test namespace __test
{ {
int numTests; int numTests;
int numTestsFailed; int numTestsFailed;
} }
int GetNumTests() int GetNumTests()
{ {
return(__test::numTests); return(__test::numTests);
} }
int GetNumTestsFailed() int GetNumTestsFailed()
{ {
return(__test::numTestsFailed); return(__test::numTestsFailed);
} }
File diff suppressed because it is too large Load Diff
+153 -153
View File
@@ -1,153 +1,153 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <map> #include <map>
#include "Common.h" #include "Common.h"
#include "Thunk.h" #include "Thunk.h"
#include "x64Emitter.h" #include "x64Emitter.h"
#include "MemoryUtil.h" #include "MemoryUtil.h"
#include "ABI.h" #include "ABI.h"
using namespace Gen; using namespace Gen;
#define THUNK_ARENA_SIZE 1024*1024*1 #define THUNK_ARENA_SIZE 1024*1024*1
namespace { namespace {
static std::map<void *, const u8 *> thunks; static std::map<void *, const u8 *> thunks;
u8 GC_ALIGNED32(saved_fp_state[16 * 4 * 4]); u8 GC_ALIGNED32(saved_fp_state[16 * 4 * 4]);
u8 GC_ALIGNED32(saved_gpr_state[16 * 8]); u8 GC_ALIGNED32(saved_gpr_state[16 * 8]);
static u8 *thunk_memory; static u8 *thunk_memory;
static u8 *thunk_code; static u8 *thunk_code;
static const u8 *save_regs; static const u8 *save_regs;
static const u8 *load_regs; static const u8 *load_regs;
static u16 saved_mxcsr; static u16 saved_mxcsr;
} }
void Thunk_Init() void Thunk_Init()
{ {
thunk_memory = (u8 *)AllocateExecutableMemory(THUNK_ARENA_SIZE); thunk_memory = (u8 *)AllocateExecutableMemory(THUNK_ARENA_SIZE);
thunk_code = thunk_memory; thunk_code = thunk_memory;
GenContext ctx(&thunk_code); GenContext ctx(&thunk_code);
save_regs = GetCodePtr(); save_regs = GetCodePtr();
for (int i = 2; i < ABI_GetNumXMMRegs(); i++) for (int i = 2; i < ABI_GetNumXMMRegs(); i++)
MOVAPS(M(saved_fp_state + i * 16), (X64Reg)(XMM0 + i)); MOVAPS(M(saved_fp_state + i * 16), (X64Reg)(XMM0 + i));
STMXCSR(M(&saved_mxcsr)); STMXCSR(M(&saved_mxcsr));
#ifdef _M_X64 #ifdef _M_X64
MOV(64, M(saved_gpr_state + 0 ), R(RCX)); MOV(64, M(saved_gpr_state + 0 ), R(RCX));
MOV(64, M(saved_gpr_state + 8 ), R(RDX)); MOV(64, M(saved_gpr_state + 8 ), R(RDX));
MOV(64, M(saved_gpr_state + 16), R(R8) ); MOV(64, M(saved_gpr_state + 16), R(R8) );
MOV(64, M(saved_gpr_state + 24), R(R9) ); MOV(64, M(saved_gpr_state + 24), R(R9) );
MOV(64, M(saved_gpr_state + 32), R(R10)); MOV(64, M(saved_gpr_state + 32), R(R10));
MOV(64, M(saved_gpr_state + 40), R(R11)); MOV(64, M(saved_gpr_state + 40), R(R11));
#ifndef _WIN32 #ifndef _WIN32
MOV(64, M(saved_gpr_state + 48), R(RSI)); MOV(64, M(saved_gpr_state + 48), R(RSI));
MOV(64, M(saved_gpr_state + 56), R(RDI)); MOV(64, M(saved_gpr_state + 56), R(RDI));
#endif #endif
MOV(64, M(saved_gpr_state + 64), R(RBX)); MOV(64, M(saved_gpr_state + 64), R(RBX));
#else #else
MOV(32, M(saved_gpr_state + 0 ), R(RCX)); MOV(32, M(saved_gpr_state + 0 ), R(RCX));
MOV(32, M(saved_gpr_state + 4 ), R(RDX)); MOV(32, M(saved_gpr_state + 4 ), R(RDX));
#endif #endif
RET(); RET();
load_regs = GetCodePtr(); load_regs = GetCodePtr();
LDMXCSR(M(&saved_mxcsr)); LDMXCSR(M(&saved_mxcsr));
for (int i = 2; i < ABI_GetNumXMMRegs(); i++) for (int i = 2; i < ABI_GetNumXMMRegs(); i++)
MOVAPS((X64Reg)(XMM0 + i), M(saved_fp_state + i * 16)); MOVAPS((X64Reg)(XMM0 + i), M(saved_fp_state + i * 16));
#ifdef _M_X64 #ifdef _M_X64
MOV(64, R(RCX), M(saved_gpr_state + 0 )); MOV(64, R(RCX), M(saved_gpr_state + 0 ));
MOV(64, R(RDX), M(saved_gpr_state + 8 )); MOV(64, R(RDX), M(saved_gpr_state + 8 ));
MOV(64, R(R8) , M(saved_gpr_state + 16)); MOV(64, R(R8) , M(saved_gpr_state + 16));
MOV(64, R(R9) , M(saved_gpr_state + 24)); MOV(64, R(R9) , M(saved_gpr_state + 24));
MOV(64, R(R10), M(saved_gpr_state + 32)); MOV(64, R(R10), M(saved_gpr_state + 32));
MOV(64, R(R11), M(saved_gpr_state + 40)); MOV(64, R(R11), M(saved_gpr_state + 40));
#ifndef _WIN32 #ifndef _WIN32
MOV(64, R(RSI), M(saved_gpr_state + 48)); MOV(64, R(RSI), M(saved_gpr_state + 48));
MOV(64, R(RDI), M(saved_gpr_state + 56)); MOV(64, R(RDI), M(saved_gpr_state + 56));
#endif #endif
MOV(64, R(RBX), M(saved_gpr_state + 64)); MOV(64, R(RBX), M(saved_gpr_state + 64));
#else #else
MOV(32, R(RCX), M(saved_gpr_state + 0 )); MOV(32, R(RCX), M(saved_gpr_state + 0 ));
MOV(32, R(RDX), M(saved_gpr_state + 4 )); MOV(32, R(RDX), M(saved_gpr_state + 4 ));
#endif #endif
RET(); RET();
} }
void Thunk_Reset() void Thunk_Reset()
{ {
thunks.clear(); thunks.clear();
thunk_code = thunk_memory; thunk_code = thunk_memory;
} }
void Thunk_Shutdown() void Thunk_Shutdown()
{ {
Thunk_Reset(); Thunk_Reset();
FreeMemoryPages(thunk_memory, THUNK_ARENA_SIZE); FreeMemoryPages(thunk_memory, THUNK_ARENA_SIZE);
thunk_memory = 0; thunk_memory = 0;
thunk_code = 0; thunk_code = 0;
} }
void *ProtectFunction(void *function, int num_params) void *ProtectFunction(void *function, int num_params)
{ {
std::map<void *, const u8 *>::iterator iter; std::map<void *, const u8 *>::iterator iter;
iter = thunks.find(function); iter = thunks.find(function);
if (iter != thunks.end()) if (iter != thunks.end())
return (void *)iter->second; return (void *)iter->second;
if (!thunk_memory) if (!thunk_memory)
PanicAlert("Trying to protect functions before the emu is started. Bad bad bad."); PanicAlert("Trying to protect functions before the emu is started. Bad bad bad.");
GenContext gen(&thunk_code); GenContext gen(&thunk_code);
const u8 *call_point = GetCodePtr(); const u8 *call_point = GetCodePtr();
// Make sure to align stack. // Make sure to align stack.
#ifdef _M_X64 #ifdef _M_X64
#ifdef _WIN32 #ifdef _WIN32
SUB(64, R(ESP), Imm8(0x28)); SUB(64, R(ESP), Imm8(0x28));
#else #else
SUB(64, R(ESP), Imm8(0x8)); SUB(64, R(ESP), Imm8(0x8));
#endif #endif
CALL((void*)save_regs); CALL((void*)save_regs);
CALL((void*)function); CALL((void*)function);
CALL((void*)load_regs); CALL((void*)load_regs);
#ifdef _WIN32 #ifdef _WIN32
ADD(64, R(ESP), Imm8(0x28)); ADD(64, R(ESP), Imm8(0x28));
#else #else
ADD(64, R(ESP), Imm8(0x8)); ADD(64, R(ESP), Imm8(0x8));
#endif #endif
RET(); RET();
#else #else
CALL((void*)save_regs); CALL((void*)save_regs);
// Since parameters are in the previous stack frame, not in registers, this takes some // Since parameters are in the previous stack frame, not in registers, this takes some
// trickery : we simply re-push the parameters. might not be optimal, but that doesn't really // trickery : we simply re-push the parameters. might not be optimal, but that doesn't really
// matter. // matter.
ABI_AlignStack(num_params * 4); ABI_AlignStack(num_params * 4);
unsigned int alignedSize = ABI_GetAlignedFrameSize(num_params * 4); unsigned int alignedSize = ABI_GetAlignedFrameSize(num_params * 4);
for (int i = 0; i < num_params; i++) { for (int i = 0; i < num_params; i++) {
// ESP is changing, so we do not need i // ESP is changing, so we do not need i
PUSH(32, MDisp(ESP, alignedSize - 4)); PUSH(32, MDisp(ESP, alignedSize - 4));
} }
CALL(function); CALL(function);
ABI_RestoreStack(num_params * 4); ABI_RestoreStack(num_params * 4);
CALL((void*)load_regs); CALL((void*)load_regs);
RET(); RET();
#endif #endif
thunks[function] = call_point; thunks[function] = call_point;
return (void *)call_point; return (void *)call_point;
} }

Some files were not shown because too many files have changed in this diff Show More