2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* 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-12-21 07:35:22 +00:00
|
|
|
#include "MemoryVirtualMem.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "TranslateVaddr.h"
|
|
|
|
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
|
|
|
|
#include <Project64-core/N64System/Interpreter/InterpreterOps.h>
|
|
|
|
#include <Project64-core/N64System/Mips/PifRam.h>
|
|
|
|
#include <Project64-core/N64System/Mips/FlashRam.h>
|
|
|
|
#include <Project64-core/N64System/Mips/Sram.h>
|
|
|
|
#include <Project64-core/N64System/Mips/Dma.h>
|
2012-12-19 09:30:18 +00:00
|
|
|
|
2015-12-21 07:35:22 +00:00
|
|
|
__interface CMipsMemory_CallBack
|
|
|
|
{
|
|
|
|
//Protected memory has been written to, returns true if that memory has been unprotected
|
|
|
|
virtual bool WriteToProtectedMemory(uint32_t Address, int32_t length) = 0;
|
|
|
|
};
|
|
|
|
|
2015-09-30 17:45:30 +00:00
|
|
|
/*
|
2015-11-08 18:04:32 +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`.
|
|
|
|
*/
|
2015-09-30 17:45:30 +00:00
|
|
|
#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-10-01 17:58:19 +00:00
|
|
|
/*
|
2015-10-26 17:10:50 +00:00
|
|
|
* To do: Have address translation functions here?
|
|
|
|
* `return` either the translated address or the mask to XOR by?
|
|
|
|
*
|
|
|
|
* This will help us gradually be able to port Project64 for big-endian CPUs.
|
|
|
|
* Currently it is written to assume 32-bit little-endian, like so:
|
2015-10-01 17:58:19 +00:00
|
|
|
*
|
|
|
|
* 0xAABBCCDD EEFFGGHH --> 0xDDCCBBAA HHGGFFEE
|
|
|
|
* GPR bits[63..0] b1b2b3b4 b5b6b7b8
|
|
|
|
*/
|
2015-09-07 16:16:36 +00:00
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
class CMipsMemoryVM :
|
2015-11-08 18:04:32 +00:00
|
|
|
public CTransVaddr,
|
|
|
|
private CRecompilerOps,
|
|
|
|
private R4300iOp,
|
|
|
|
private CPifRam,
|
|
|
|
private CFlashram,
|
|
|
|
private CSram,
|
|
|
|
private CDMA
|
2010-05-31 00:21:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-11-08 18:04:32 +00:00
|
|
|
CMipsMemoryVM(CMipsMemory_CallBack * CallBack, bool SavesReadOnly);
|
|
|
|
~CMipsMemoryVM();
|
|
|
|
|
|
|
|
static void ReserveMemory();
|
|
|
|
static void FreeReservedMemory();
|
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
bool Initialize();
|
|
|
|
void Reset(bool EraseMemory);
|
|
|
|
|
|
|
|
uint8_t * Rdram();
|
|
|
|
uint32_t RdramSize();
|
|
|
|
uint8_t * Dmem();
|
|
|
|
uint8_t * Imem();
|
|
|
|
uint8_t * PifRam();
|
|
|
|
|
|
|
|
bool LB_VAddr(uint32_t VAddr, uint8_t & Value);
|
|
|
|
bool LH_VAddr(uint32_t VAddr, uint16_t & Value);
|
|
|
|
bool LW_VAddr(uint32_t VAddr, uint32_t & Value);
|
|
|
|
bool LD_VAddr(uint32_t VAddr, uint64_t & Value);
|
|
|
|
|
|
|
|
bool LB_PAddr(uint32_t PAddr, uint8_t & Value);
|
|
|
|
bool LH_PAddr(uint32_t PAddr, uint16_t & Value);
|
|
|
|
bool LW_PAddr(uint32_t PAddr, uint32_t & Value);
|
|
|
|
bool LD_PAddr(uint32_t PAddr, uint64_t & Value);
|
|
|
|
|
|
|
|
bool SB_VAddr(uint32_t VAddr, uint8_t Value);
|
|
|
|
bool SH_VAddr(uint32_t VAddr, uint16_t Value);
|
|
|
|
bool SW_VAddr(uint32_t VAddr, uint32_t Value);
|
|
|
|
bool SD_VAddr(uint32_t VAddr, uint64_t Value);
|
|
|
|
|
|
|
|
bool SB_PAddr(uint32_t PAddr, uint8_t Value);
|
|
|
|
bool SH_PAddr(uint32_t PAddr, uint16_t Value);
|
|
|
|
bool SW_PAddr(uint32_t PAddr, uint32_t Value);
|
|
|
|
bool SD_PAddr(uint32_t PAddr, uint64_t Value);
|
2015-11-08 18:04:32 +00:00
|
|
|
|
|
|
|
int32_t MemoryFilter(uint32_t dwExptCode, void * lpExceptionPointer);
|
|
|
|
void UpdateFieldSerration(uint32_t interlaced);
|
|
|
|
|
|
|
|
//Protect the Memory from being written to
|
|
|
|
void ProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr);
|
|
|
|
void UnProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr);
|
|
|
|
|
|
|
|
//Compilation Functions
|
|
|
|
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();
|
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
void ResetMemoryStack(CRegInfo& RegInfo);
|
|
|
|
void Compile_LB(CX86Ops::x86Reg Reg, uint32_t Addr, bool SignExtend);
|
|
|
|
void Compile_LH(CX86Ops::x86Reg Reg, uint32_t Addr, bool SignExtend);
|
|
|
|
void Compile_LW(CX86Ops::x86Reg Reg, uint32_t Addr);
|
|
|
|
void Compile_SB_Const(uint8_t Value, uint32_t Addr);
|
|
|
|
void Compile_SB_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
|
|
|
|
void Compile_SH_Const(uint16_t Value, uint32_t Addr);
|
|
|
|
void Compile_SH_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
|
|
|
|
void Compile_SW_Const(uint32_t Value, uint32_t Addr);
|
2015-11-08 18:04:32 +00:00
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
void Compile_SW_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
|
2015-11-08 18:04:32 +00:00
|
|
|
|
|
|
|
//Functions for TLB notification
|
|
|
|
void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly);
|
|
|
|
void TLB_Unmaped(uint32_t Vaddr, uint32_t Len);
|
|
|
|
|
|
|
|
// CTransVaddr interface
|
|
|
|
bool TranslateVaddr(uint32_t VAddr, uint32_t &PAddr) const;
|
|
|
|
bool ValidVaddr(uint32_t VAddr) const;
|
|
|
|
bool VAddrToRealAddr(uint32_t VAddr, void * &RealAddress) const;
|
|
|
|
|
|
|
|
// Labels
|
|
|
|
const char * LabelName(uint32_t Address) const;
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-08 18:04:32 +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
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
void Compile_LW(bool ResultSigned, bool bRecordLLbit);
|
|
|
|
void Compile_SW(bool bCheckLLbit);
|
2013-01-11 21:57:51 +00:00
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
static void RdramChanged(CMipsMemoryVM * _this);
|
|
|
|
static void ChangeSpStatus();
|
2015-11-08 18:04:32 +00:00
|
|
|
static void ChangeMiIntrMask();
|
2010-06-12 02:02:06 +00:00
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
bool LB_NonMemory(uint32_t PAddr, uint32_t * Value, bool SignExtend);
|
|
|
|
bool LH_NonMemory(uint32_t PAddr, uint32_t * Value, bool SignExtend);
|
|
|
|
bool LW_NonMemory(uint32_t PAddr, uint32_t * Value);
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
bool SB_NonMemory(uint32_t PAddr, uint8_t Value);
|
|
|
|
bool SH_NonMemory(uint32_t PAddr, uint16_t Value);
|
|
|
|
bool SW_NonMemory(uint32_t PAddr, uint32_t Value);
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-12-13 07:26:31 +00:00
|
|
|
void Compile_StoreInstructClean(x86Reg AddressReg, int32_t Length);
|
2010-06-16 07:31:47 +00:00
|
|
|
|
2015-12-21 09:45:08 +00:00
|
|
|
static void Load32RDRAMRegisters(void);
|
2015-12-21 09:49:13 +00:00
|
|
|
static void Load32SPRegisters(void);
|
2015-12-21 09:52:59 +00:00
|
|
|
static void Load32DPCommand(void);
|
2015-12-21 09:56:24 +00:00
|
|
|
static void Load32MIPSInterface(void);
|
2015-12-21 10:01:56 +00:00
|
|
|
static void Load32VideoInterface(void);
|
2015-12-21 10:06:51 +00:00
|
|
|
static void Load32AudioInterface(void);
|
2015-12-21 18:45:07 +00:00
|
|
|
static void Load32PeripheralInterface(void);
|
|
|
|
static void Load32RDRAMInterface(void);
|
2015-12-21 19:59:17 +00:00
|
|
|
static void Load32SerialInterface(void);
|
2015-12-21 21:03:14 +00:00
|
|
|
static void Load32CartridgeDomain2Address1(void);
|
|
|
|
static void Load32CartridgeDomain2Address2(void);
|
2015-12-21 21:15:26 +00:00
|
|
|
static void Load32PifRam(void);
|
2015-12-21 21:24:37 +00:00
|
|
|
static void Load32Rom(void);
|
2015-12-21 09:45:08 +00:00
|
|
|
|
2015-12-21 21:35:06 +00:00
|
|
|
static void Write32RDRAMRegisters(void);
|
2015-12-21 21:41:49 +00:00
|
|
|
static void Write32SPRegisters(void);
|
2015-12-21 21:49:58 +00:00
|
|
|
static void Write32DPCommandRegisters(void);
|
2015-12-22 05:31:13 +00:00
|
|
|
static void Write32MIPSInterface(void);
|
2015-12-22 05:40:19 +00:00
|
|
|
static void Write32VideoInterface(void);
|
2015-12-22 05:46:08 +00:00
|
|
|
static void Write32AudioInterface(void);
|
2015-12-22 05:51:50 +00:00
|
|
|
static void Write32PeripheralInterface(void);
|
2015-12-21 21:35:06 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
CMipsMemory_CallBack * const m_CBClass;
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
//Memory Locations
|
2015-12-13 07:26:31 +00:00
|
|
|
static uint8_t * m_Reserve1, *m_Reserve2;
|
|
|
|
uint8_t * m_RDRAM, *m_DMEM, *m_IMEM;
|
2015-11-08 18:04:32 +00:00
|
|
|
uint32_t m_AllocatedRdramSize;
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
//Rom Information
|
|
|
|
bool m_RomMapped;
|
|
|
|
uint8_t * m_Rom;
|
|
|
|
uint32_t m_RomSize;
|
|
|
|
bool m_RomWrittenTo;
|
|
|
|
uint32_t m_RomWroteValue;
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
//Current Half line
|
|
|
|
void UpdateHalfLine();
|
|
|
|
uint32_t m_HalfLine;
|
|
|
|
uint32_t m_HalfLineCheck;
|
|
|
|
uint32_t m_FieldSerration;
|
|
|
|
uint32_t m_TempValue;
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
//Initializing and resetting information about the memory system
|
|
|
|
void FreeMemory();
|
2012-12-18 10:43:29 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
mutable char m_strLabelName[100];
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-11-08 18:04:32 +00:00
|
|
|
//BIG look up table to quickly translate the tlb to real mem address
|
|
|
|
size_t * m_TLB_ReadMap;
|
|
|
|
size_t * m_TLB_WriteMap;
|
2015-12-21 09:45:08 +00:00
|
|
|
|
|
|
|
static uint32_t m_MemLookupAddress;
|
|
|
|
static MIPS_DWORD m_MemLookupValue;
|
|
|
|
static bool m_MemLookupValid;
|
2010-05-31 00:21:08 +00:00
|
|
|
};
|