2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-10-21 08:57:05 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-28 20:26:43 +00:00
|
|
|
#pragma once
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2021-05-13 12:09:28 +00:00
|
|
|
#include "Config.h"
|
2022-12-28 06:53:37 +00:00
|
|
|
#include "vtlb.h"
|
2021-05-13 12:09:28 +00:00
|
|
|
|
2010-10-22 16:23:52 +00:00
|
|
|
// This is a table of default virtual map addresses for ps2vm components. These locations
|
|
|
|
// are provided and used to assist in debugging and possibly hacking; as it makes it possible
|
|
|
|
// for a programmer to know exactly where to look (consistently!) for the base address of
|
|
|
|
// the various virtual machine components. These addresses can be keyed directly into the
|
2010-11-15 14:05:02 +00:00
|
|
|
// debugger's disasm window to get disassembly of recompiled code, and they can be used to help
|
2010-10-22 16:23:52 +00:00
|
|
|
// identify recompiled code addresses in the callstack.
|
|
|
|
|
|
|
|
// All of these areas should be reserved as soon as possible during program startup, and its
|
|
|
|
// important that none of the areas overlap. In all but superVU's case, failure due to overlap
|
|
|
|
// or other conflict will result in the operating system picking a preferred address for the mapping.
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2010-10-22 16:23:52 +00:00
|
|
|
namespace HostMemoryMap
|
|
|
|
{
|
2022-10-12 13:57:53 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Main
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
// PS2 main memory, SPR, and ROMs (approximately 138.5MB, but we round up to 139MB for simplicity).
|
|
|
|
static constexpr u32 EEmemOffset = 0x00000000;
|
|
|
|
static constexpr u32 EEmemSize = 0x8B00000;
|
2010-10-22 16:23:52 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
// IOP main memory (2MB + 64K + 256b, rounded up to 3MB for simplicity).
|
|
|
|
static constexpr u32 IOPmemOffset = EEmemOffset + EEmemSize;
|
|
|
|
static constexpr u32 IOPmemSize = 0x300000;
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
// VU0 and VU1 memory (40KB, rounded up to 1MB for simplicity).
|
|
|
|
static constexpr u32 VUmemOffset = IOPmemOffset + IOPmemSize;
|
|
|
|
static constexpr u32 VUmemSize = 0x100000;
|
2010-10-22 16:23:52 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
// VTLB virtual map ((4GB / 4096) * sizeof(ptr))
|
|
|
|
static constexpr u32 VTLBVirtualMapOffset = VUmemOffset + VUmemSize;
|
|
|
|
static constexpr u32 VTLBVirtualMapSize = (0x100000000ULL / 4096) * sizeof(void*);
|
|
|
|
|
|
|
|
// VTLB address map ((4GB / 4096) * sizeof(u32))
|
|
|
|
static constexpr u32 VTLBAddressMapOffset = VTLBVirtualMapOffset + VTLBVirtualMapSize;
|
|
|
|
static constexpr u32 VTLBAddressMapSize = (0x100000000ULL / 4096) * sizeof(u32);
|
|
|
|
|
|
|
|
// Overall size.
|
|
|
|
static constexpr u32 MainSize = VTLBAddressMapOffset + VTLBAddressMapSize;
|
2022-10-12 13:57:53 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Code
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-10-22 16:23:52 +00:00
|
|
|
// EE recompiler code cache area (64mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 EErecOffset = 0x00000000;
|
|
|
|
static constexpr u32 EErecSize = 0x4000000;
|
2010-10-22 16:23:52 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
// IOP recompiler code cache area (32mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 IOPrecOffset = EErecOffset + EErecSize;
|
|
|
|
static constexpr u32 IOPrecSize = 0x2000000;
|
2010-10-22 16:23:52 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
// newVif0 recompiler code cache area (8mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 VIF0recOffset = IOPrecOffset + IOPrecSize;
|
|
|
|
static constexpr u32 VIF0recSize = 0x800000;
|
2010-11-16 15:58:42 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
// newVif1 recompiler code cache area (8mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 VIF1recOffset = VIF0recOffset + VIF0recSize;
|
|
|
|
static constexpr u32 VIF1recSize = 0x800000;
|
2010-11-16 15:58:42 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
// microVU1 recompiler code cache area (64mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 mVU0recOffset = VIF1recOffset + VIF1recSize;
|
|
|
|
static constexpr u32 mVU0recSize = 0x4000000;
|
2010-10-22 16:23:52 +00:00
|
|
|
|
|
|
|
// microVU0 recompiler code cache area (64mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 mVU1recOffset = mVU0recOffset + mVU0recSize;
|
|
|
|
static constexpr u32 mVU1recSize = 0x4000000;
|
game settings/patches: don't apply acidentally to the bios
While c782b62 added much more reliable game game startup detection, the
settings system did not yet gain that knowledge, but typically that's OK.
Typically the settings (and patches) are loaded according to the current
CRC, which happens once on bios boot (with general settings) and then again
when the game starts, which includes game-specific fixes, patches, etc.
However, if the setting are changed (and therefore also applied) after
the game CRC is known but before the game starts, such as if the user
presses Tab to change framelimiter while at the bios, then until now it
was accidentally applying the game's settings while still at the bios.
This commit makes the settings routine know whether or not the game actually
started, and apply the generic/game settings accordingly.
2016-07-29 17:55:58 +00:00
|
|
|
|
2022-10-12 13:57:53 +00:00
|
|
|
// SSE-optimized VIF unpack functions (1mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 VIFUnpackRecOffset = mVU1recOffset + mVU1recSize;
|
|
|
|
static constexpr u32 VIFUnpackRecSize = 0x100000;
|
2023-01-25 10:51:23 +00:00
|
|
|
|
|
|
|
// Software Renderer JIT buffer (64mb)
|
2023-10-09 14:16:15 +00:00
|
|
|
static constexpr u32 SWrecOffset = VIFUnpackRecOffset + VIFUnpackRecSize;
|
|
|
|
static constexpr u32 SWrecSize = 0x04000000;
|
|
|
|
|
|
|
|
// Overall size.
|
|
|
|
static constexpr u32 CodeSize = SWrecOffset + SWrecSize; // 305 mb
|
|
|
|
} // namespace HostMemoryMap
|
2010-10-22 16:23:52 +00:00
|
|
|
|
2010-10-22 19:47:02 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2023-10-09 14:16:15 +00:00
|
|
|
// HostMemory
|
2010-10-22 19:47:02 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
game settings/patches: don't apply acidentally to the bios
While c782b62 added much more reliable game game startup detection, the
settings system did not yet gain that knowledge, but typically that's OK.
Typically the settings (and patches) are loaded according to the current
CRC, which happens once on bios boot (with general settings) and then again
when the game starts, which includes game-specific fixes, patches, etc.
However, if the setting are changed (and therefore also applied) after
the game CRC is known but before the game starts, such as if the user
presses Tab to change framelimiter while at the bios, then until now it
was accidentally applying the game's settings while still at the bios.
This commit makes the settings routine know whether or not the game actually
started, and apply the generic/game settings accordingly.
2016-07-29 17:55:58 +00:00
|
|
|
// This class provides the main memory for the virtual machines.
|
2023-10-09 14:16:15 +00:00
|
|
|
|
|
|
|
namespace SysMemory
|
2010-10-22 19:47:02 +00:00
|
|
|
{
|
2023-10-09 14:16:15 +00:00
|
|
|
bool Allocate();
|
|
|
|
void Reset();
|
|
|
|
void Release();
|
2022-10-12 13:57:53 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
/// Returns data memory (Main in Memory Map).
|
|
|
|
u8* GetDataPtr(size_t offset);
|
2022-10-12 13:57:53 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
/// Returns memory used for the recompilers.
|
|
|
|
u8* GetCodePtr(size_t offset);
|
game settings/patches: don't apply acidentally to the bios
While c782b62 added much more reliable game game startup detection, the
settings system did not yet gain that knowledge, but typically that's OK.
Typically the settings (and patches) are loaded according to the current
CRC, which happens once on bios boot (with general settings) and then again
when the game starts, which includes game-specific fixes, patches, etc.
However, if the setting are changed (and therefore also applied) after
the game CRC is known but before the game starts, such as if the user
presses Tab to change framelimiter while at the bios, then until now it
was accidentally applying the game's settings while still at the bios.
This commit makes the settings routine know whether or not the game actually
started, and apply the generic/game settings accordingly.
2016-07-29 17:55:58 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
/// Returns the file mapping which backs the data memory.
|
|
|
|
void* GetDataFileHandle();
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
// clang-format off
|
2020-08-19 08:20:48 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Data Memory Accessors
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
__fi static u8* GetEEMem() { return GetDataPtr(HostMemoryMap::EEmemOffset); }
|
|
|
|
__fi static u8* GetEEMemEnd() { return GetDataPtr(HostMemoryMap::EEmemOffset + HostMemoryMap::EEmemSize); }
|
|
|
|
__fi static u8* GetIOPMem() { return GetDataPtr(HostMemoryMap::IOPmemOffset); }
|
|
|
|
__fi static u8* GetIOPMemEnd() { return GetDataPtr(HostMemoryMap::IOPmemOffset + HostMemoryMap::IOPmemSize); }
|
|
|
|
__fi static u8* GetVUMem() { return GetDataPtr(HostMemoryMap::VUmemOffset); }
|
|
|
|
__fi static u8* GetVUMemEnd() { return GetDataPtr(HostMemoryMap::VUmemOffset + HostMemoryMap::VUmemSize); }
|
|
|
|
__fi static u8* GetVTLBVirtualMap() { return GetDataPtr(HostMemoryMap::VTLBVirtualMapOffset); }
|
|
|
|
__fi static u8* GetVTLBVirtualMapEnd() { return GetDataPtr(HostMemoryMap::VTLBVirtualMapOffset + HostMemoryMap::VTLBVirtualMapSize); }
|
|
|
|
__fi static u8* GetVTLBAddressMap() { return GetDataPtr(HostMemoryMap::VTLBAddressMapOffset); }
|
|
|
|
__fi static u8* GetVTLBAddressMapEnd() { return GetDataPtr(HostMemoryMap::VTLBAddressMapOffset + HostMemoryMap::VTLBAddressMapSize); }
|
2022-10-12 13:57:53 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Code Memory Accessors
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
__fi static u8* GetEERec() { return GetCodePtr(HostMemoryMap::EErecOffset); }
|
|
|
|
__fi static u8* GetEERecEnd() { return GetCodePtr(HostMemoryMap::EErecOffset + HostMemoryMap::EErecSize); }
|
|
|
|
__fi static u8* GetIOPRec() { return GetCodePtr(HostMemoryMap::IOPrecOffset); }
|
|
|
|
__fi static u8* GetIOPRecEnd() { return GetCodePtr(HostMemoryMap::IOPrecOffset + HostMemoryMap::IOPrecSize); }
|
|
|
|
__fi static u8* GetVU0Rec() { return GetCodePtr(HostMemoryMap::mVU0recOffset); }
|
|
|
|
__fi static u8* GetVU0RecEnd() { return GetCodePtr(HostMemoryMap::mVU0recOffset + HostMemoryMap::mVU0recSize); }
|
|
|
|
__fi static u8* GetVU1Rec() { return GetCodePtr(HostMemoryMap::mVU1recOffset); }
|
|
|
|
__fi static u8* GetVU1RecEnd() { return GetCodePtr(HostMemoryMap::mVU1recOffset + HostMemoryMap::mVU1recSize); }
|
|
|
|
__fi static u8* GetVIFUnpackRec() { return GetCodePtr(HostMemoryMap::VIFUnpackRecOffset); }
|
|
|
|
__fi static u8* GetVIFUnpackRecEnd() { return GetCodePtr(HostMemoryMap::VIFUnpackRecOffset + HostMemoryMap::VIFUnpackRecSize); }
|
|
|
|
__fi static u8* GetSWRec() { return GetCodePtr(HostMemoryMap::SWrecOffset); }
|
|
|
|
__fi static u8* GetSWRecEnd() { return GetCodePtr(HostMemoryMap::SWrecOffset + HostMemoryMap::SWrecSize); }
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
} // namespace SysMemory
|
2022-10-29 03:39:19 +00:00
|
|
|
|
2010-10-22 19:47:02 +00:00
|
|
|
|
2010-08-16 15:57:01 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// SysCpuProviderPack
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
class SysCpuProviderPack
|
2009-09-16 17:23:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-08-16 15:57:01 +00:00
|
|
|
SysCpuProviderPack();
|
2022-10-12 15:42:36 +00:00
|
|
|
~SysCpuProviderPack();
|
2009-08-31 03:47:05 +00:00
|
|
|
|
2010-08-16 15:57:01 +00:00
|
|
|
void ApplyConfig() const;
|
2009-09-16 17:23:02 +00:00
|
|
|
};
|
|
|
|
|
2010-08-16 15:57:01 +00:00
|
|
|
// GetCpuProviders - this function is not implemented by PCSX2 core -- it must be
|
2009-12-03 15:51:39 +00:00
|
|
|
// implemented by the provisioning interface.
|
2010-08-16 15:57:01 +00:00
|
|
|
extern SysCpuProviderPack& GetCpuProviders();
|
2009-09-16 17:23:02 +00:00
|
|
|
|
2023-10-09 14:16:15 +00:00
|
|
|
extern void SysLogMachineCaps(); // Detects cpu type and fills cpuInfo structs.
|
|
|
|
extern void SysClearExecutionCache(); // clears recompiled execution caches!
|
2010-11-15 14:05:02 +00:00
|
|
|
|
2022-12-28 04:44:34 +00:00
|
|
|
extern void SetCPUState(SSE_MXCSR sseMXCSR, SSE_MXCSR sseVU0MXCSR, SSE_MXCSR sseVU1MXCSR);
|
|
|
|
extern SSE_MXCSR g_sseVU0MXCSR, g_sseVU1MXCSR, g_sseMXCSR;
|