2007-12-09 22:01:01 +00:00
|
|
|
#include "BasicBlock.h"
|
|
|
|
#include "MemStream.h"
|
|
|
|
#include "offsetof_def.h"
|
2010-08-11 03:47:19 +00:00
|
|
|
#include "MipsJitter.h"
|
|
|
|
#include "Jitter_CodeGenFactory.h"
|
2007-12-09 22:01:01 +00:00
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#if defined(AOT_BUILD_CACHE) || defined(AOT_USE_CACHE)
|
|
|
|
#define AOT_ENABLED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AOT_ENABLED
|
|
|
|
|
|
|
|
#include <zlib.h>
|
|
|
|
#include "StdStream.h"
|
|
|
|
#include "StdStreamUtils.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-08-10 09:06:39 +00:00
|
|
|
#ifdef VTUNE_ENABLED
|
|
|
|
#include <jitprofiling.h>
|
|
|
|
#include "string_format.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_USE_CACHE
|
|
|
|
|
2015-10-19 17:10:16 +00:00
|
|
|
#pragma pack(push, 1)
|
2013-04-14 06:35:40 +00:00
|
|
|
struct AOT_BLOCK
|
|
|
|
{
|
2018-04-30 20:01:23 +00:00
|
|
|
AOT_BLOCK_KEY key;
|
|
|
|
void* fct;
|
2013-04-14 06:35:40 +00:00
|
|
|
};
|
2015-10-19 17:10:16 +00:00
|
|
|
#pragma pack(pop)
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2018-04-30 20:01:23 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2015-11-03 05:10:44 +00:00
|
|
|
extern AOT_BLOCK _aot_firstBlock;
|
|
|
|
extern uint32 _aot_blockCount;
|
2015-08-25 01:38:09 +00:00
|
|
|
}
|
2013-04-14 06:35:40 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-06-27 12:20:55 +00:00
|
|
|
#define INVALID_LINK_SLOT (~0U)
|
|
|
|
|
2012-04-15 22:00:47 +00:00
|
|
|
CBasicBlock::CBasicBlock(CMIPS& context, uint32 begin, uint32 end)
|
2018-04-30 20:01:23 +00:00
|
|
|
: m_begin(begin)
|
|
|
|
, m_end(end)
|
|
|
|
, m_context(context)
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_USE_CACHE
|
2018-04-30 20:01:23 +00:00
|
|
|
, m_function(nullptr)
|
2013-04-14 06:35:40 +00:00
|
|
|
#endif
|
2007-12-09 22:01:01 +00:00
|
|
|
{
|
2012-04-15 22:00:47 +00:00
|
|
|
assert(m_end >= m_begin);
|
2018-06-27 12:20:55 +00:00
|
|
|
for(uint32 i = 0; i < LINK_SLOT_MAX; i++)
|
|
|
|
{
|
2018-06-30 00:34:04 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
m_linkBlock[i] = nullptr;
|
|
|
|
#endif
|
|
|
|
m_linkTargetAddress[i] = MIPS_INVALID_PC;
|
2018-06-27 12:20:55 +00:00
|
|
|
m_linkBlockTrampolineOffset[i] = INVALID_LINK_SLOT;
|
|
|
|
}
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifdef AOT_BUILD_CACHE
|
|
|
|
|
2018-04-30 20:01:23 +00:00
|
|
|
Framework::CStdStream* CBasicBlock::m_aotBlockOutputStream(nullptr);
|
|
|
|
std::mutex CBasicBlock::m_aotBlockOutputStreamMutex;
|
2013-04-14 06:35:40 +00:00
|
|
|
|
|
|
|
void CBasicBlock::SetAotBlockOutputStream(Framework::CStdStream* outputStream)
|
|
|
|
{
|
|
|
|
assert(m_aotBlockOutputStream == nullptr || outputStream == nullptr);
|
|
|
|
m_aotBlockOutputStream = outputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-12-09 22:01:01 +00:00
|
|
|
void CBasicBlock::Compile()
|
|
|
|
{
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifndef AOT_USE_CACHE
|
|
|
|
|
2012-04-15 22:00:47 +00:00
|
|
|
Framework::CMemStream stream;
|
|
|
|
{
|
2016-03-27 23:01:01 +00:00
|
|
|
static
|
|
|
|
#ifdef AOT_BUILD_CACHE
|
2018-04-30 20:01:23 +00:00
|
|
|
__declspec(thread)
|
2016-03-27 23:01:01 +00:00
|
|
|
#endif
|
2018-04-30 20:01:23 +00:00
|
|
|
CMipsJitter* jitter = nullptr;
|
2016-03-27 23:01:01 +00:00
|
|
|
if(jitter == nullptr)
|
2010-08-11 03:47:19 +00:00
|
|
|
{
|
|
|
|
Jitter::CCodeGen* codeGen = Jitter::CreateCodeGen();
|
|
|
|
jitter = new CMipsJitter(codeGen);
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
jitter->SetVariableAsConstant(
|
2018-04-30 20:01:23 +00:00
|
|
|
offsetof(CMIPS, m_State.nGPR[CMIPS::R0].nV[i]),
|
|
|
|
0);
|
2010-08-11 03:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 01:36:00 +00:00
|
|
|
jitter->GetCodeGen()->SetExternalSymbolReferencedHandler([&](auto symbol, auto offset) { this->HandleExternalFunctionReference(symbol, offset); });
|
2010-08-11 03:47:19 +00:00
|
|
|
jitter->SetStream(&stream);
|
|
|
|
jitter->Begin();
|
|
|
|
CompileRange(jitter);
|
|
|
|
jitter->End();
|
2012-04-15 22:00:47 +00:00
|
|
|
}
|
2007-12-09 22:01:01 +00:00
|
|
|
|
2013-04-12 02:35:55 +00:00
|
|
|
m_function = CMemoryFunction(stream.GetBuffer(), stream.GetSize());
|
2018-04-30 20:01:23 +00:00
|
|
|
|
2014-08-10 09:06:39 +00:00
|
|
|
#ifdef VTUNE_ENABLED
|
|
|
|
if(iJIT_IsProfilingActive() == iJIT_SAMPLING_ON)
|
|
|
|
{
|
|
|
|
iJIT_Method_Load jmethod = {};
|
|
|
|
jmethod.method_id = iJIT_GetNewMethodID();
|
|
|
|
jmethod.class_file_name = "";
|
|
|
|
jmethod.source_file_name = __FILE__;
|
|
|
|
|
|
|
|
jmethod.method_load_address = m_function.GetCode();
|
|
|
|
jmethod.method_size = m_function.GetSize();
|
|
|
|
jmethod.line_number_size = 0;
|
|
|
|
|
2017-05-29 05:01:32 +00:00
|
|
|
auto functionName = string_format("BasicBlock_0x%08X_0x%08X", m_begin, m_end);
|
2014-08-10 09:06:39 +00:00
|
|
|
|
|
|
|
jmethod.method_name = const_cast<char*>(functionName.c_str());
|
|
|
|
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, reinterpret_cast<void*>(&jmethod));
|
|
|
|
}
|
|
|
|
#endif
|
2013-04-14 06:35:40 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AOT_ENABLED
|
|
|
|
|
|
|
|
size_t blockSize = ((m_end - m_begin) / 4) + 1;
|
|
|
|
auto blockData = new uint32[blockSize];
|
|
|
|
|
|
|
|
for(uint32 i = 0; i < blockSize; i++)
|
|
|
|
{
|
|
|
|
blockData[i] = m_context.m_pMemoryMap->GetWord(m_begin + (i * 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 blockChecksum = crc32(0, reinterpret_cast<Bytef*>(blockData), blockSize * 4);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AOT_USE_CACHE
|
|
|
|
|
|
|
|
AOT_BLOCK* blocksBegin = &_aot_firstBlock;
|
|
|
|
AOT_BLOCK* blocksEnd = blocksBegin + _aot_blockCount;
|
|
|
|
|
2018-04-30 20:01:23 +00:00
|
|
|
AOT_BLOCK blockRef = {blockChecksum, m_begin, m_end, nullptr};
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2018-04-30 20:01:23 +00:00
|
|
|
static const auto blockComparer =
|
|
|
|
[](const AOT_BLOCK& item1, const AOT_BLOCK& item2) {
|
|
|
|
return item1.key < item2.key;
|
|
|
|
};
|
2013-04-14 06:35:40 +00:00
|
|
|
|
2018-04-30 20:01:23 +00:00
|
|
|
// assert(std::is_sorted(blocksBegin, blocksEnd, blockComparer));
|
2013-04-14 06:35:40 +00:00
|
|
|
|
|
|
|
bool blockExists = std::binary_search(blocksBegin, blocksEnd, blockRef, blockComparer);
|
|
|
|
auto blockIterator = std::lower_bound(blocksBegin, blocksEnd, blockRef, blockComparer);
|
2018-04-30 20:01:23 +00:00
|
|
|
|
2013-04-14 06:35:40 +00:00
|
|
|
assert(blockExists);
|
|
|
|
assert(blockIterator != blocksEnd);
|
2013-04-21 06:56:03 +00:00
|
|
|
assert(blockIterator->key.crc == blockChecksum);
|
|
|
|
assert(blockIterator->key.begin == m_begin);
|
|
|
|
assert(blockIterator->key.end == m_end);
|
2013-04-14 06:35:40 +00:00
|
|
|
|
|
|
|
m_function = reinterpret_cast<void (*)(void*)>(blockIterator->fct);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AOT_BUILD_CACHE
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(m_aotBlockOutputStreamMutex);
|
|
|
|
|
|
|
|
m_aotBlockOutputStream->Write32(blockChecksum);
|
|
|
|
m_aotBlockOutputStream->Write32(m_begin);
|
|
|
|
m_aotBlockOutputStream->Write32(m_end);
|
|
|
|
m_aotBlockOutputStream->Write(blockData, blockSize * 4);
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
|
|
|
|
2010-08-11 03:47:19 +00:00
|
|
|
void CBasicBlock::CompileRange(CMipsJitter* jitter)
|
2009-06-06 15:38:03 +00:00
|
|
|
{
|
2018-06-05 17:26:17 +00:00
|
|
|
if(IsEmpty())
|
|
|
|
{
|
|
|
|
jitter->JumpTo(reinterpret_cast<void*>(&EmptyBlockHandler));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-22 00:49:58 +00:00
|
|
|
CompileProlog(jitter);
|
|
|
|
|
2018-06-11 16:59:00 +00:00
|
|
|
for(uint32 address = m_begin; address <= m_end; address += 4)
|
2009-06-06 15:38:03 +00:00
|
|
|
{
|
|
|
|
m_context.m_pArch->CompileInstruction(
|
2018-04-30 20:01:23 +00:00
|
|
|
address,
|
|
|
|
jitter,
|
|
|
|
&m_context);
|
2009-06-06 15:38:03 +00:00
|
|
|
//Sanity check
|
2010-08-11 03:47:19 +00:00
|
|
|
assert(jitter->IsStackEmpty());
|
2009-06-06 15:38:03 +00:00
|
|
|
}
|
2017-04-14 23:16:55 +00:00
|
|
|
|
2018-07-03 23:06:25 +00:00
|
|
|
jitter->MarkFinalBlockLabel();
|
2018-07-17 22:51:31 +00:00
|
|
|
CompileEpilog(jitter);
|
2009-06-06 15:38:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 00:49:58 +00:00
|
|
|
void CBasicBlock::CompileProlog(CMipsJitter* jitter)
|
|
|
|
{
|
|
|
|
#ifdef DEBUGGER_INCLUDED
|
|
|
|
if(HasBreakpoint())
|
|
|
|
{
|
|
|
|
jitter->PushCtx();
|
|
|
|
jitter->Call(reinterpret_cast<void*>(&BreakpointFilter), 1, Jitter::CJitter::RETURN_VALUE_32);
|
|
|
|
|
|
|
|
jitter->PushCst(0);
|
|
|
|
jitter->BeginIf(Jitter::CONDITION_EQ);
|
|
|
|
{
|
|
|
|
jitter->JumpTo(reinterpret_cast<void*>(&BreakpointHandler));
|
|
|
|
}
|
|
|
|
jitter->EndIf();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-17 22:51:31 +00:00
|
|
|
void CBasicBlock::CompileEpilog(CMipsJitter* jitter)
|
2007-12-09 22:01:01 +00:00
|
|
|
{
|
2018-06-14 10:35:56 +00:00
|
|
|
//Update cycle quota
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.cycleQuota));
|
|
|
|
jitter->PushCst(((m_end - m_begin) / 4) + 1);
|
|
|
|
jitter->Sub();
|
|
|
|
jitter->PullRel(offsetof(CMIPS, m_State.cycleQuota));
|
|
|
|
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.cycleQuota));
|
|
|
|
jitter->PushCst(0);
|
|
|
|
jitter->BeginIf(Jitter::CONDITION_LE);
|
|
|
|
{
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.nHasException));
|
|
|
|
jitter->PushCst(MIPS_EXECUTION_STATUS_QUOTADONE);
|
|
|
|
jitter->Or();
|
|
|
|
jitter->PullRel(offsetof(CMIPS, m_State.nHasException));
|
|
|
|
}
|
|
|
|
jitter->EndIf();
|
|
|
|
|
2018-06-05 17:00:28 +00:00
|
|
|
//We probably don't need to pay for this since we know in advance if there's a branch
|
|
|
|
jitter->PushCst(MIPS_INVALID_PC);
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
|
|
|
|
jitter->BeginIf(Jitter::CONDITION_NE);
|
2012-04-15 22:00:47 +00:00
|
|
|
{
|
2018-06-05 17:00:28 +00:00
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
|
|
|
|
jitter->PullRel(offsetof(CMIPS, m_State.nPC));
|
|
|
|
|
|
|
|
jitter->PushCst(MIPS_INVALID_PC);
|
|
|
|
jitter->PullRel(offsetof(CMIPS, m_State.nDelayedJumpAddr));
|
2018-06-14 10:35:56 +00:00
|
|
|
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.nHasException));
|
|
|
|
jitter->PushCst(0);
|
|
|
|
jitter->BeginIf(Jitter::CONDITION_EQ);
|
|
|
|
{
|
2018-06-23 15:33:27 +00:00
|
|
|
jitter->JumpTo(reinterpret_cast<void*>(&NextBlockTrampoline));
|
2018-06-14 10:35:56 +00:00
|
|
|
}
|
|
|
|
jitter->EndIf();
|
2012-04-15 22:00:47 +00:00
|
|
|
}
|
2018-06-05 17:00:28 +00:00
|
|
|
jitter->Else();
|
2012-04-15 22:00:47 +00:00
|
|
|
{
|
2018-06-05 17:00:28 +00:00
|
|
|
jitter->PushCst(m_end + 4);
|
|
|
|
jitter->PullRel(offsetof(CMIPS, m_State.nPC));
|
2018-06-14 10:35:56 +00:00
|
|
|
|
|
|
|
jitter->PushRel(offsetof(CMIPS, m_State.nHasException));
|
|
|
|
jitter->PushCst(0);
|
|
|
|
jitter->BeginIf(Jitter::CONDITION_EQ);
|
|
|
|
{
|
2018-06-23 15:33:27 +00:00
|
|
|
jitter->JumpTo(reinterpret_cast<void*>(&NextBlockTrampoline));
|
2018-06-14 10:35:56 +00:00
|
|
|
}
|
|
|
|
jitter->EndIf();
|
2012-04-15 22:00:47 +00:00
|
|
|
}
|
2018-06-05 17:00:28 +00:00
|
|
|
jitter->EndIf();
|
|
|
|
}
|
|
|
|
|
2018-06-05 17:19:18 +00:00
|
|
|
void CBasicBlock::Execute()
|
2018-06-05 17:00:28 +00:00
|
|
|
{
|
|
|
|
m_function(&m_context);
|
2007-12-09 22:01:01 +00:00
|
|
|
|
2015-04-08 04:20:28 +00:00
|
|
|
assert(m_context.m_State.nGPR[0].nV0 == 0);
|
|
|
|
assert(m_context.m_State.nGPR[0].nV1 == 0);
|
|
|
|
assert(m_context.m_State.nGPR[0].nV2 == 0);
|
|
|
|
assert(m_context.m_State.nGPR[0].nV3 == 0);
|
2015-05-03 05:35:15 +00:00
|
|
|
assert((m_context.m_State.nPC & 3) == 0);
|
2011-12-26 05:52:20 +00:00
|
|
|
assert((m_context.m_State.nGPR[CMIPS::RA].nV0 & 3) == 0);
|
2011-12-06 03:13:21 +00:00
|
|
|
assert(m_context.m_State.nCOP2[0].nV0 == 0x00000000);
|
|
|
|
assert(m_context.m_State.nCOP2[0].nV1 == 0x00000000);
|
|
|
|
assert(m_context.m_State.nCOP2[0].nV2 == 0x00000000);
|
|
|
|
assert(m_context.m_State.nCOP2[0].nV3 == 0x3F800000);
|
2015-04-09 03:30:15 +00:00
|
|
|
assert(m_context.m_State.nCOP2VI[0] == 0);
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CBasicBlock::GetBeginAddress() const
|
|
|
|
{
|
2012-04-15 22:00:47 +00:00
|
|
|
return m_begin;
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CBasicBlock::GetEndAddress() const
|
|
|
|
{
|
2012-04-15 22:00:47 +00:00
|
|
|
return m_end;
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBasicBlock::IsCompiled() const
|
|
|
|
{
|
2013-04-14 06:35:40 +00:00
|
|
|
#ifndef AOT_USE_CACHE
|
2013-04-12 02:35:55 +00:00
|
|
|
return !m_function.IsEmpty();
|
2013-04-14 06:35:40 +00:00
|
|
|
#else
|
|
|
|
return (m_function != nullptr);
|
|
|
|
#endif
|
2007-12-09 22:01:01 +00:00
|
|
|
}
|
2018-06-05 17:26:17 +00:00
|
|
|
|
|
|
|
bool CBasicBlock::IsEmpty() const
|
|
|
|
{
|
2018-06-11 17:06:21 +00:00
|
|
|
return (m_begin == MIPS_INVALID_PC) &&
|
|
|
|
(m_end == MIPS_INVALID_PC);
|
2018-06-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 00:34:04 +00:00
|
|
|
uint32 CBasicBlock::GetLinkTargetAddress(LINK_SLOT linkSlot)
|
|
|
|
{
|
|
|
|
assert(linkSlot < LINK_SLOT_MAX);
|
|
|
|
return m_linkTargetAddress[linkSlot];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBasicBlock::SetLinkTargetAddress(LINK_SLOT linkSlot, uint32 address)
|
|
|
|
{
|
|
|
|
assert(linkSlot < LINK_SLOT_MAX);
|
|
|
|
m_linkTargetAddress[linkSlot] = address;
|
|
|
|
}
|
|
|
|
|
2018-06-27 12:20:55 +00:00
|
|
|
void CBasicBlock::LinkBlock(LINK_SLOT linkSlot, CBasicBlock* otherBlock)
|
2018-06-14 10:35:56 +00:00
|
|
|
{
|
|
|
|
assert(!IsEmpty());
|
|
|
|
assert(!otherBlock->IsEmpty());
|
2018-06-27 12:20:55 +00:00
|
|
|
assert(linkSlot < LINK_SLOT_MAX);
|
|
|
|
assert(m_linkBlockTrampolineOffset[linkSlot] != INVALID_LINK_SLOT);
|
2018-06-30 00:34:04 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
assert(m_linkBlock[linkSlot] == nullptr);
|
|
|
|
m_linkBlock[linkSlot] = otherBlock;
|
|
|
|
#endif
|
2018-06-14 10:35:56 +00:00
|
|
|
auto patchValue = reinterpret_cast<uintptr_t>(otherBlock->m_function.GetCode());
|
|
|
|
auto code = reinterpret_cast<uint8*>(m_function.GetCode());
|
2018-07-16 17:17:41 +00:00
|
|
|
m_function.BeginModify();
|
2018-06-27 12:20:55 +00:00
|
|
|
*reinterpret_cast<uintptr_t*>(code + m_linkBlockTrampolineOffset[linkSlot]) = patchValue;
|
2018-07-16 17:17:41 +00:00
|
|
|
m_function.EndModify();
|
2018-06-14 10:35:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 00:34:04 +00:00
|
|
|
void CBasicBlock::UnlinkBlock(LINK_SLOT linkSlot)
|
|
|
|
{
|
|
|
|
assert(!IsEmpty());
|
|
|
|
assert(linkSlot < LINK_SLOT_MAX);
|
|
|
|
assert(m_linkBlockTrampolineOffset[linkSlot] != INVALID_LINK_SLOT);
|
|
|
|
#ifdef _DEBUG
|
|
|
|
assert(m_linkBlock[linkSlot] != nullptr);
|
|
|
|
m_linkBlock[linkSlot] = nullptr;
|
|
|
|
#endif
|
|
|
|
auto patchValue = reinterpret_cast<uintptr_t>(&NextBlockTrampoline);
|
|
|
|
auto code = reinterpret_cast<uint8*>(m_function.GetCode());
|
2018-07-16 17:17:41 +00:00
|
|
|
m_function.BeginModify();
|
2018-06-30 00:34:04 +00:00
|
|
|
*reinterpret_cast<uintptr_t*>(code + m_linkBlockTrampolineOffset[linkSlot]) = patchValue;
|
2018-07-16 17:17:41 +00:00
|
|
|
m_function.EndModify();
|
2018-06-30 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 10:35:56 +00:00
|
|
|
void CBasicBlock::HandleExternalFunctionReference(uintptr_t symbol, uint32 offset)
|
|
|
|
{
|
|
|
|
if(symbol == reinterpret_cast<uintptr_t>(&NextBlockTrampoline))
|
|
|
|
{
|
2018-06-27 12:20:55 +00:00
|
|
|
if(m_linkBlockTrampolineOffset[LINK_SLOT_BRANCH] == INVALID_LINK_SLOT)
|
2018-06-14 10:35:56 +00:00
|
|
|
{
|
2018-06-27 12:20:55 +00:00
|
|
|
m_linkBlockTrampolineOffset[LINK_SLOT_BRANCH] = offset;
|
2018-06-14 10:35:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-27 12:20:55 +00:00
|
|
|
m_linkBlockTrampolineOffset[LINK_SLOT_NEXT] = offset;
|
2018-06-14 10:35:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 16:40:17 +00:00
|
|
|
#ifdef DEBUGGER_INCLUDED
|
|
|
|
|
2018-07-22 00:49:58 +00:00
|
|
|
bool CBasicBlock::HasBreakpoint() const
|
|
|
|
{
|
|
|
|
for(auto breakpointAddress : m_context.m_breakpoints)
|
|
|
|
{
|
|
|
|
if(breakpointAddress >= GetBeginAddress() && breakpointAddress <= GetEndAddress()) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CBasicBlock::BreakpointFilter(CMIPS* context)
|
|
|
|
{
|
|
|
|
return context->m_executor->FilterBreakpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBasicBlock::BreakpointHandler(CMIPS* context)
|
|
|
|
{
|
|
|
|
assert(context->m_State.nHasException == MIPS_EXCEPTION_NONE);
|
|
|
|
context->m_State.nHasException = MIPS_EXCEPTION_BREAKPOINT;
|
|
|
|
}
|
|
|
|
|
2018-07-23 16:40:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void CBasicBlock::EmptyBlockHandler(CMIPS* context)
|
|
|
|
{
|
|
|
|
context->m_emptyBlockHandler(context);
|
|
|
|
}
|
|
|
|
|
2018-06-14 10:35:56 +00:00
|
|
|
void CBasicBlock::NextBlockTrampoline(CMIPS* context)
|
|
|
|
{
|
|
|
|
}
|