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-19 23:57:27 +00:00
|
|
|
#include <Common/md5.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "RecompilerOps.h"
|
|
|
|
#include "ExitInfo.h"
|
|
|
|
#include "CodeSection.h"
|
2012-12-19 09:30:18 +00:00
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
class CCodeBlock :
|
2015-11-08 21:00:16 +00:00
|
|
|
private CRecompilerOps
|
2010-05-30 01:54:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-11-08 21:00:16 +00:00
|
|
|
CCodeBlock(uint32_t VAddrEnter, uint8_t * RecompPos );
|
|
|
|
~CCodeBlock();
|
2012-10-14 06:33:51 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
bool Compile();
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t VAddrEnter() const { return m_VAddrEnter; }
|
|
|
|
uint32_t VAddrFirst() const { return m_VAddrFirst; }
|
|
|
|
uint32_t VAddrLast() const { return m_VAddrLast; }
|
|
|
|
uint8_t * CompiledLocation() const { return m_CompiledLocation; }
|
|
|
|
int32_t NoOfSections() const { return m_Sections.size(); }
|
|
|
|
const CCodeSection & EnterSection() const { return *m_EnterSection; }
|
|
|
|
const MD5Digest & Hash() const { return m_Hash; }
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
void SetVAddrFirst(uint32_t VAddr) { m_VAddrFirst = VAddr; }
|
|
|
|
void SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; }
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
CCodeSection * ExistingSection(uint32_t Addr) { return m_EnterSection->ExistingSection(Addr, NextTest()); }
|
|
|
|
bool SectionAccessible(uint32_t m_SectionID) { return m_EnterSection->SectionAccessible(m_SectionID, NextTest()); }
|
2010-07-23 10:45:35 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint64_t MemContents(int32_t i) const { return m_MemContents[i]; }
|
|
|
|
uint64_t * MemLocation(int32_t i) const { return m_MemLocation[i]; }
|
2015-04-28 22:19:02 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t NextTest();
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
EXIT_LIST m_ExitInfo;
|
2010-05-30 01:54:42 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-08 21:00:16 +00:00
|
|
|
CCodeBlock(); // Disable default constructor
|
|
|
|
CCodeBlock(const CCodeBlock&); // Disable copy constructor
|
|
|
|
CCodeBlock& operator=(const CCodeBlock&); // Disable assignment
|
2012-10-14 06:33:51 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
bool AnalyseBlock();
|
|
|
|
void CompileExitCode();
|
2010-05-30 01:54:42 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
bool CreateBlockLinkage ( CCodeSection * EnterSection );
|
|
|
|
void DetermineLoops ();
|
|
|
|
void LogSectionInfo ();
|
|
|
|
bool SetSection ( CCodeSection * & Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC );
|
|
|
|
bool AnalyzeInstruction ( uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot,
|
|
|
|
bool & EndBlock, bool & PermLoop );
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
uint32_t m_VAddrEnter;
|
|
|
|
uint32_t m_VAddrFirst; // the address of the first opcode in the block
|
|
|
|
uint32_t m_VAddrLast; // the address of the first opcode in the block
|
|
|
|
uint8_t* m_CompiledLocation; // What address is this compiled at
|
2012-10-14 01:05:52 +00:00
|
|
|
|
2015-11-08 21:00:16 +00:00
|
|
|
typedef std::map<uint32_t,CCodeSection *> SectionMap;
|
|
|
|
typedef std::list<CCodeSection *> SectionList;
|
|
|
|
|
|
|
|
SectionMap m_SectionMap;
|
|
|
|
SectionList m_Sections;
|
|
|
|
CCodeSection * m_EnterSection;
|
|
|
|
int32_t m_Test;
|
|
|
|
MD5Digest m_Hash;
|
|
|
|
uint64_t m_MemContents[2];
|
|
|
|
uint64_t * m_MemLocation[2];
|
2010-05-30 01:54:42 +00:00
|
|
|
};
|