2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
|
2015-09-30 17:45:30 +00:00
|
|
|
/*
|
|
|
|
* 64-bit Windows exception recovery facilities will expect to interact with
|
|
|
|
* the 64-bit registers of the Intel architecture (e.g., rax instead of eax).
|
|
|
|
*
|
|
|
|
* Attempting to read the 32-bit subsets seems to be erroneous and forbidden.
|
|
|
|
* Refer to "MemoryFilter" in `Memory Virtual Mem.cpp`.
|
|
|
|
*/
|
|
|
|
#ifdef _WIN64
|
|
|
|
#define Eax Rax
|
|
|
|
#define Ebx Rbx
|
|
|
|
#define Ecx Rcx
|
|
|
|
#define Edx Rdx
|
|
|
|
#define Esp Rsp
|
|
|
|
#define Ebp Rbp
|
|
|
|
#define Esi Rsi
|
|
|
|
#define Edi Rdi
|
|
|
|
|
|
|
|
#define Eip Rip
|
|
|
|
#endif
|
|
|
|
|
2015-09-07 16:16:36 +00:00
|
|
|
extern unsigned long swap32by8(unsigned long word);
|
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
class CMipsMemoryVM :
|
|
|
|
public CMipsMemory,
|
|
|
|
public CTransVaddr,
|
2010-06-07 02:23:58 +00:00
|
|
|
private CRecompilerOps,
|
2010-06-14 21:14:58 +00:00
|
|
|
private R4300iOp,
|
2010-06-22 20:36:28 +00:00
|
|
|
private CPifRam,
|
|
|
|
private CFlashram,
|
|
|
|
private CSram,
|
|
|
|
private CDMA
|
2010-05-31 00:21:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-04-28 22:19:02 +00:00
|
|
|
CMipsMemoryVM(CMipsMemory_CallBack * CallBack, bool SavesReadOnly);
|
|
|
|
~CMipsMemoryVM();
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
static void ReserveMemory();
|
|
|
|
static void FreeReservedMemory();
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool Initialize ();
|
2010-06-14 21:14:58 +00:00
|
|
|
void Reset ( bool EraseMemory );
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
BYTE * Rdram ();
|
|
|
|
DWORD RdramSize ();
|
|
|
|
BYTE * Dmem ();
|
|
|
|
BYTE * Imem ();
|
|
|
|
BYTE * PifRam ();
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool LB_VAddr ( DWORD VAddr, BYTE & Value );
|
|
|
|
bool LH_VAddr ( DWORD VAddr, WORD & Value );
|
|
|
|
bool LW_VAddr ( DWORD VAddr, DWORD & Value );
|
|
|
|
bool LD_VAddr ( DWORD VAddr, QWORD & Value );
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool LB_PAddr ( DWORD PAddr, BYTE & Value );
|
|
|
|
bool LH_PAddr ( DWORD PAddr, WORD & Value );
|
|
|
|
bool LW_PAddr ( DWORD PAddr, DWORD & Value );
|
|
|
|
bool LD_PAddr ( DWORD PAddr, QWORD & Value );
|
2015-01-22 05:50:20 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool SB_VAddr ( DWORD VAddr, BYTE Value );
|
|
|
|
bool SH_VAddr ( DWORD VAddr, WORD Value );
|
|
|
|
bool SW_VAddr ( DWORD VAddr, DWORD Value );
|
|
|
|
bool SD_VAddr ( DWORD VAddr, QWORD Value );
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool SB_PAddr ( DWORD PAddr, BYTE Value );
|
|
|
|
bool SH_PAddr ( DWORD PAddr, WORD Value );
|
|
|
|
bool SW_PAddr ( DWORD PAddr, DWORD Value );
|
|
|
|
bool SD_PAddr ( DWORD PAddr, QWORD Value );
|
2015-01-22 05:50:20 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
int MemoryFilter(DWORD dwExptCode, void * lpExceptionPointer);
|
|
|
|
void UpdateFieldSerration(unsigned int interlaced);
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
//Protect the Memory from being written to
|
2015-04-28 22:19:02 +00:00
|
|
|
void ProtectMemory(DWORD StartVaddr, DWORD EndVaddr);
|
|
|
|
void UnProtectMemory(DWORD StartVaddr, DWORD EndVaddr);
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
//Compilation Functions
|
2015-04-28 22:19:02 +00:00
|
|
|
void ResetMemoryStack();
|
|
|
|
|
|
|
|
void Compile_LB();
|
|
|
|
void Compile_LBU();
|
|
|
|
void Compile_LH();
|
|
|
|
void Compile_LHU();
|
|
|
|
void Compile_LW();
|
|
|
|
void Compile_LL();
|
|
|
|
void Compile_LWC1();
|
|
|
|
void Compile_LWU();
|
|
|
|
void Compile_LWL();
|
|
|
|
void Compile_LWR();
|
|
|
|
void Compile_LD();
|
|
|
|
void Compile_LDC1();
|
|
|
|
void Compile_LDL();
|
|
|
|
void Compile_LDR();
|
|
|
|
void Compile_SB();
|
|
|
|
void Compile_SH();
|
|
|
|
void Compile_SW();
|
|
|
|
void Compile_SWL();
|
|
|
|
void Compile_SWR();
|
|
|
|
void Compile_SD();
|
|
|
|
void Compile_SDL();
|
|
|
|
void Compile_SDR();
|
|
|
|
void Compile_SC();
|
|
|
|
void Compile_SWC1();
|
|
|
|
void Compile_SDC1();
|
|
|
|
|
|
|
|
void ResetMemoryStack ( CRegInfo& RegInfo );
|
2015-05-02 22:14:19 +00:00
|
|
|
void Compile_LB ( CX86Ops::x86Reg Reg, DWORD Addr, bool SignExtend );
|
|
|
|
void Compile_LH ( CX86Ops::x86Reg Reg, DWORD Addr, bool SignExtend );
|
2010-06-04 06:25:07 +00:00
|
|
|
void Compile_LW ( CX86Ops::x86Reg Reg, DWORD Addr );
|
2010-05-31 00:21:08 +00:00
|
|
|
void Compile_SB_Const ( BYTE Value, DWORD Addr );
|
|
|
|
void Compile_SB_Register ( CX86Ops::x86Reg Reg, DWORD Addr );
|
|
|
|
void Compile_SH_Const ( WORD Value, DWORD Addr );
|
|
|
|
void Compile_SH_Register ( CX86Ops::x86Reg Reg, DWORD Addr );
|
|
|
|
void Compile_SW_Const ( DWORD Value, DWORD Addr );
|
|
|
|
|
|
|
|
void Compile_SW_Register ( CX86Ops::x86Reg Reg, DWORD Addr );
|
|
|
|
|
|
|
|
//Functions for TLB notification
|
2015-04-28 22:19:02 +00:00
|
|
|
void TLB_Mapped(DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly);
|
|
|
|
void TLB_Unmaped(DWORD Vaddr, DWORD Len);
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
// CTransVaddr interface
|
2015-04-28 22:19:02 +00:00
|
|
|
bool TranslateVaddr(DWORD VAddr, DWORD &PAddr) const;
|
|
|
|
bool ValidVaddr(DWORD VAddr) const;
|
|
|
|
bool VAddrToRealAddr(DWORD VAddr, void * &RealAddress) const;
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
// Labels
|
2015-04-28 22:19:02 +00:00
|
|
|
LPCTSTR LabelName(DWORD Address) const;
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
private:
|
2015-04-28 22:19:02 +00:00
|
|
|
CMipsMemoryVM(); // Disable default constructor
|
|
|
|
CMipsMemoryVM(const CMipsMemoryVM&); // Disable copy constructor
|
|
|
|
CMipsMemoryVM& operator=(const CMipsMemoryVM&); // Disable assignment
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2013-02-19 18:31:10 +00:00
|
|
|
void Compile_LW ( bool ResultSigned, bool bRecordLLbit );
|
|
|
|
void Compile_SW ( bool bCheckLLbit );
|
2013-01-11 21:57:51 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
static void RdramChanged ( CMipsMemoryVM * _this );
|
|
|
|
static void ChangeSpStatus ();
|
|
|
|
static void ChangeMiIntrMask();
|
2010-06-12 02:02:06 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool LB_NonMemory ( DWORD PAddr, DWORD * Value, bool SignExtend );
|
|
|
|
bool LH_NonMemory ( DWORD PAddr, DWORD * Value, bool SignExtend );
|
|
|
|
bool LW_NonMemory ( DWORD PAddr, DWORD * Value );
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-05-02 22:14:19 +00:00
|
|
|
bool SB_NonMemory ( DWORD PAddr, BYTE Value );
|
|
|
|
bool SH_NonMemory ( DWORD PAddr, WORD Value );
|
|
|
|
bool SW_NonMemory ( DWORD PAddr, DWORD Value );
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2010-06-16 07:31:47 +00:00
|
|
|
void Compile_StoreInstructClean (x86Reg AddressReg, int Length );
|
|
|
|
|
2012-12-18 10:43:29 +00:00
|
|
|
CMipsMemory_CallBack * const m_CBClass;
|
|
|
|
|
|
|
|
//Memory Locations
|
|
|
|
static BYTE * m_Reserve1, * m_Reserve2;
|
|
|
|
BYTE * m_RDRAM, * m_DMEM, * m_IMEM;
|
|
|
|
DWORD m_AllocatedRdramSize;
|
|
|
|
|
|
|
|
//Rom Information
|
|
|
|
bool m_RomMapped;
|
|
|
|
BYTE * m_Rom;
|
|
|
|
DWORD m_RomSize;
|
|
|
|
bool m_RomWrittenTo;
|
|
|
|
DWORD m_RomWroteValue;
|
|
|
|
|
|
|
|
//Current Half line
|
2015-04-28 22:19:02 +00:00
|
|
|
void UpdateHalfLine();
|
2012-12-18 10:43:29 +00:00
|
|
|
DWORD m_HalfLine;
|
2012-12-30 20:56:49 +00:00
|
|
|
DWORD m_HalfLineCheck;
|
2015-02-06 23:19:49 +00:00
|
|
|
DWORD m_FieldSerration;
|
2012-12-18 10:43:29 +00:00
|
|
|
DWORD m_TempValue;
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
//Initializing and resetting information about the memory system
|
2015-04-28 22:19:02 +00:00
|
|
|
void FreeMemory();
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
mutable char m_strLabelName[100];
|
|
|
|
|
|
|
|
//BIG look up table to quickly translate the tlb to real mem address
|
2015-08-27 02:30:45 +00:00
|
|
|
size_t * m_TLB_ReadMap;
|
|
|
|
size_t * m_TLB_WriteMap;
|
2010-05-31 00:21:08 +00:00
|
|
|
};
|