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-06 09:59:58 +00:00
|
|
|
#include <Common/LogClass.h>
|
|
|
|
#include "RegisterClass.h"
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
class CDebugTlb;
|
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
__interface CTLB_CB
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2015-11-09 06:21:32 +00:00
|
|
|
virtual void TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly) = 0;
|
|
|
|
virtual void TLB_Unmaped(uint32_t VAddr, uint32_t Len) = 0;
|
|
|
|
virtual void TLB_Changed() = 0;
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201) // warning C4201: nonstandard extension used : nameless struct/union
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
class CTLB :
|
2015-11-09 06:21:32 +00:00
|
|
|
protected CSystemRegisters
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
public:
|
2015-11-09 06:21:32 +00:00
|
|
|
struct TLB_ENTRY
|
|
|
|
{
|
|
|
|
bool EntryDefined;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint32_t Value;
|
|
|
|
uint8_t A[4];
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned zero : 13;
|
|
|
|
unsigned Mask : 12;
|
|
|
|
unsigned zero2 : 7;
|
|
|
|
} ;
|
|
|
|
} PageMask;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint32_t Value;
|
|
|
|
uint8_t A[4];
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned ASID : 8;
|
|
|
|
unsigned Zero : 4;
|
|
|
|
unsigned G : 1;
|
|
|
|
unsigned VPN2 : 19;
|
|
|
|
};
|
|
|
|
} EntryHi;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint32_t Value;
|
|
|
|
uint8_t A[4];
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned GLOBAL: 1;
|
|
|
|
unsigned V : 1;
|
|
|
|
unsigned D : 1;
|
|
|
|
unsigned C : 3;
|
|
|
|
unsigned PFN : 20;
|
|
|
|
unsigned ZERO: 6;
|
|
|
|
} ;
|
|
|
|
} EntryLo0;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint32_t Value;
|
|
|
|
uint8_t A[4];
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned GLOBAL: 1;
|
|
|
|
unsigned V : 1;
|
|
|
|
unsigned D : 1;
|
|
|
|
unsigned C : 3;
|
|
|
|
unsigned PFN : 20;
|
|
|
|
unsigned ZERO: 6;
|
|
|
|
} ;
|
|
|
|
} EntryLo1;
|
|
|
|
};
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
public:
|
2015-11-09 06:21:32 +00:00
|
|
|
CTLB(CTLB_CB * CallBack);
|
|
|
|
~CTLB();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
void Reset(bool InvalidateTLB);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
//Used by opcodes of the same name to manipulate the tlb (reads the registers)
|
|
|
|
void Probe();
|
|
|
|
void ReadEntry();
|
|
|
|
void WriteEntry(int32_t index, bool Random);
|
2010-06-22 20:36:28 +00:00
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
//See if a VAddr has an entry to translate to a PAddr
|
|
|
|
bool AddressDefined(uint32_t VAddr);
|
2010-06-22 20:36:28 +00:00
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
const TLB_ENTRY & TlbEntry(int32_t Entry) const
|
|
|
|
{
|
|
|
|
return m_tlb[Entry];
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 06:21:32 +00:00
|
|
|
bool PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index);
|
|
|
|
|
|
|
|
void RecordDifference(CLog &LogFile, const CTLB& rTLB);
|
|
|
|
|
|
|
|
bool operator == (const CTLB& rTLB) const;
|
|
|
|
bool operator != (const CTLB& rTLB) const;
|
2012-09-28 20:17:44 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-09 06:21:32 +00:00
|
|
|
struct FASTTLB
|
|
|
|
{
|
|
|
|
uint32_t VSTART;
|
|
|
|
uint32_t VEND;
|
|
|
|
uint32_t PHYSSTART;
|
|
|
|
uint32_t PHYSEND;
|
|
|
|
uint32_t Length;
|
|
|
|
bool VALID;
|
|
|
|
bool DIRTY;
|
|
|
|
bool GLOBAL;
|
|
|
|
bool ValidEntry;
|
|
|
|
bool Random;
|
|
|
|
bool Probed;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend CDebugTlb; // enable debug window to read class
|
|
|
|
|
|
|
|
CTLB_CB * const m_CB;
|
|
|
|
|
|
|
|
TLB_ENTRY m_tlb[32];
|
|
|
|
FASTTLB m_FastTlb[64];
|
|
|
|
|
|
|
|
void SetupTLB_Entry(int32_t index, bool Random);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CTLB(); // Disable default constructor
|
|
|
|
CTLB(const CTLB&); // Disable copy constructor
|
|
|
|
CTLB& operator=(const CTLB&); // Disable assignment
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|
2015-11-09 06:21:32 +00:00
|
|
|
|
|
|
|
#pragma warning(pop)
|