2013-04-12 02:35:55 +00:00
|
|
|
#pragma once
|
2007-12-01 04:08:34 +00:00
|
|
|
|
|
|
|
#include "MIPS.h"
|
2010-08-11 03:47:19 +00:00
|
|
|
#include "MemoryFunction.h"
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
|
|
|
#include "StdStream.h"
|
|
|
|
#include <mutex>
|
|
|
|
#endif
|
|
|
|
|
2022-08-15 10:45:12 -04:00
|
|
|
enum BLOCK_CATEGORY : uint32
|
|
|
|
{
|
|
|
|
BLOCK_CATEGORY_UNKNOWN = 0,
|
|
|
|
BLOCK_CATEGORY_PS2_EE = 0x65650000,
|
|
|
|
BLOCK_CATEGORY_PS2_IOP = 0x696F7000,
|
|
|
|
BLOCK_CATEGORY_PS2_VU = 0x76750000,
|
2022-10-17 16:15:05 -04:00
|
|
|
BLOCK_CATEGORY_PSP = 0x50535000,
|
2022-08-15 10:45:12 -04:00
|
|
|
};
|
|
|
|
|
2022-10-21 14:37:11 +01:00
|
|
|
#pragma pack(push, 1)
|
2013-04-14 06:35:40 +00:00
|
|
|
struct AOT_BLOCK_KEY
|
|
|
|
{
|
2022-08-15 10:45:12 -04:00
|
|
|
BLOCK_CATEGORY category;
|
2022-10-21 09:42:16 +01:00
|
|
|
uint128 hash;
|
2022-10-21 13:37:21 +01:00
|
|
|
uint32 size;
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
bool operator<(const AOT_BLOCK_KEY& k2) const
|
2013-04-14 06:35:40 +00:00
|
|
|
{
|
2014-12-18 07:33:18 +00:00
|
|
|
const auto& k1 = (*this);
|
2022-10-21 13:37:21 +01:00
|
|
|
return std::tie(k1.category, k1.hash, k1.size) <
|
|
|
|
std::tie(k2.category, k2.hash, k2.size);
|
2013-04-14 06:35:40 +00:00
|
|
|
}
|
|
|
|
};
|
2022-10-21 14:37:11 +01:00
|
|
|
#pragma pack(pop)
|
|
|
|
static_assert(sizeof(AOT_BLOCK_KEY) == 0x18, "AOT_BLOCK_KEY must be 24 bytes long.");
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2010-08-11 03:47:19 +00:00
|
|
|
namespace Jitter
|
|
|
|
{
|
|
|
|
class CJitter;
|
|
|
|
};
|
2009-06-06 15:38:03 +00:00
|
|
|
|
2019-05-01 20:23:35 -04:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
void EmptyBlockHandler(CMIPS*);
|
|
|
|
void NextBlockTrampoline(CMIPS*);
|
2022-12-01 11:14:30 -05:00
|
|
|
void BranchBlockTrampoline(CMIPS*);
|
2019-05-01 20:23:35 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 12:39:24 -04:00
|
|
|
enum LINK_SLOT
|
|
|
|
{
|
|
|
|
LINK_SLOT_NEXT,
|
|
|
|
LINK_SLOT_BRANCH,
|
|
|
|
LINK_SLOT_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
//Block outgoing link
|
|
|
|
struct BLOCK_OUT_LINK
|
|
|
|
{
|
|
|
|
LINK_SLOT slot; //slot used in the source block
|
|
|
|
uint32 srcAddress; //address of source block
|
|
|
|
bool live; //live if linked to another block, otherwise, link is pending
|
|
|
|
};
|
|
|
|
|
|
|
|
//Block outgoing links map (key: target link address, value: struct describing link status)
|
|
|
|
typedef std::multimap<uint32, BLOCK_OUT_LINK> BlockOutLinkMap;
|
|
|
|
|
|
|
|
//When block linking is used, each basic block will maintain pointers
|
|
|
|
//to their outgoing link definitions inside the map
|
|
|
|
typedef BlockOutLinkMap::iterator BlockOutLinkPointer;
|
|
|
|
|
2007-12-01 04:08:34 +00:00
|
|
|
class CBasicBlock
|
|
|
|
{
|
|
|
|
public:
|
2022-08-15 10:45:12 -04:00
|
|
|
CBasicBlock(CMIPS&, uint32 = MIPS_INVALID_PC, uint32 = MIPS_INVALID_PC, BLOCK_CATEGORY = BLOCK_CATEGORY_UNKNOWN);
|
2018-04-30 21:01:23 +01:00
|
|
|
virtual ~CBasicBlock() = default;
|
2018-06-05 13:19:18 -04:00
|
|
|
void Execute();
|
2018-04-30 21:01:23 +01:00
|
|
|
void Compile();
|
2019-05-02 12:45:14 -04:00
|
|
|
virtual void CompileRange(CMipsJitter*);
|
2010-08-11 03:47:19 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
uint32 GetBeginAddress() const;
|
|
|
|
uint32 GetEndAddress() const;
|
|
|
|
bool IsCompiled() const;
|
2018-06-05 13:26:17 -04:00
|
|
|
bool IsEmpty() const;
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2019-12-20 21:25:33 -05:00
|
|
|
uint32 GetRecycleCount() const;
|
|
|
|
void SetRecycleCount(uint32);
|
|
|
|
|
2022-12-01 11:14:30 -05:00
|
|
|
bool HasLinkSlot(LINK_SLOT) const;
|
2020-08-03 12:39:24 -04:00
|
|
|
BlockOutLinkPointer GetOutLink(LINK_SLOT) const;
|
|
|
|
void SetOutLink(LINK_SLOT, BlockOutLinkPointer);
|
|
|
|
|
2018-06-27 08:20:55 -04:00
|
|
|
void LinkBlock(LINK_SLOT, CBasicBlock*);
|
2018-06-29 20:34:04 -04:00
|
|
|
void UnlinkBlock(LINK_SLOT);
|
2018-06-14 06:35:56 -04:00
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
static void SetAotBlockOutputStream(Framework::CStdStream*);
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
2007-12-01 04:08:34 +00:00
|
|
|
|
2022-10-18 16:22:51 -04:00
|
|
|
void CopyFunctionFrom(const std::shared_ptr<CBasicBlock>& basicBlock);
|
2022-10-18 20:01:53 +01:00
|
|
|
|
2009-06-06 15:38:03 +00:00
|
|
|
protected:
|
2018-04-30 21:01:23 +01:00
|
|
|
uint32 m_begin;
|
|
|
|
uint32 m_end;
|
2022-08-15 10:45:12 -04:00
|
|
|
BLOCK_CATEGORY m_category;
|
2018-04-30 21:01:23 +01:00
|
|
|
CMIPS& m_context;
|
2009-06-06 15:38:03 +00:00
|
|
|
|
2022-01-18 10:23:23 -05:00
|
|
|
virtual void CompileProlog(CMipsJitter*);
|
2022-11-30 17:25:50 -05:00
|
|
|
virtual void CompileEpilog(CMipsJitter*, bool);
|
2009-06-06 15:38:03 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-28 13:31:24 -04:00
|
|
|
void HandleExternalFunctionReference(uintptr_t, uint32, Jitter::CCodeGen::SYMBOL_REF_TYPE);
|
2018-06-14 06:35:56 -04:00
|
|
|
|
2018-07-23 12:40:17 -04:00
|
|
|
#ifdef DEBUGGER_INCLUDED
|
2018-07-21 20:49:58 -04:00
|
|
|
bool HasBreakpoint() const;
|
|
|
|
static uint32 BreakpointFilter(CMIPS*);
|
|
|
|
static void BreakpointHandler(CMIPS*);
|
2018-07-23 12:40:17 -04:00
|
|
|
#endif
|
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
static Framework::CStdStream* m_aotBlockOutputStream;
|
|
|
|
static std::mutex m_aotBlockOutputStreamMutex;
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AOT_USE_CACHE
|
2018-04-30 21:01:23 +01:00
|
|
|
CMemoryFunction m_function;
|
2013-04-14 06:35:40 +00:00
|
|
|
#else
|
2018-04-30 21:01:23 +01:00
|
|
|
void (*m_function)(void*);
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
2019-12-20 21:25:33 -05:00
|
|
|
uint32 m_recycleCount = 0;
|
2020-08-03 12:39:24 -04:00
|
|
|
BlockOutLinkPointer m_outLinks[LINK_SLOT_MAX];
|
2018-06-27 08:20:55 -04:00
|
|
|
uint32 m_linkBlockTrampolineOffset[LINK_SLOT_MAX];
|
2018-06-29 20:34:04 -04:00
|
|
|
#ifdef _DEBUG
|
|
|
|
CBasicBlock* m_linkBlock[LINK_SLOT_MAX];
|
|
|
|
#endif
|
2007-12-01 04:08:34 +00:00
|
|
|
};
|