flycast/core/hw/sh4/dyna/blockmanager.h

114 lines
2.5 KiB
C
Raw Normal View History

2013-12-19 17:10:14 +00:00
/*
In case you wonder, the extern "C" stuff are for the assembly code on beagleboard/pandora
*/
#include <memory>
2013-12-19 17:10:14 +00:00
#include "types.h"
#include "decoder.h"
#pragma once
2015-05-08 16:59:20 +00:00
typedef void (*DynarecCodeEntryPtr)();
typedef std::shared_ptr<RuntimeBlockInfo> RuntimeBlockInfoPtr;
2013-12-19 17:10:14 +00:00
struct RuntimeBlockInfo_Core
{
u32 addr;
2015-05-08 16:59:20 +00:00
DynarecCodeEntryPtr code;
2013-12-19 17:10:14 +00:00
u32 lookups;
};
struct RuntimeBlockInfo: RuntimeBlockInfo_Core
{
bool Setup(u32 pc,fpscr_t fpu_cfg);
2013-12-19 17:10:14 +00:00
const char* hash(bool full=true, bool reloc=false);
u32 vaddr;
2013-12-19 17:10:14 +00:00
u32 host_code_size; //in bytes
u32 sh4_code_size; //in bytes
u32 runs;
s32 staging_runs;
fpscr_t fpu_cfg;
u32 guest_cycles;
u32 guest_opcodes;
u32 host_opcodes;
bool has_fpu_op;
u32 blockcheck_failures;
bool temp_block;
2013-12-19 17:10:14 +00:00
u32 BranchBlock; //if not 0xFFFFFFFF then jump target
u32 NextBlock; //if not 0xFFFFFFFF then next block (by position)
2013-12-19 17:10:14 +00:00
//0 if not available
2013-12-19 17:10:14 +00:00
RuntimeBlockInfo* pBranchBlock;
RuntimeBlockInfo* pNextBlock;
u32 relink_offset;
u32 relink_data;
u32 csc_RetCache; //only for stats for now
BlockEndType BlockType;
bool has_jcond;
vector<shil_opcode> oplist;
bool contains_code(u8* ptr)
{
return ((unat)(ptr-(u8*)code))<host_code_size;
}
virtual ~RuntimeBlockInfo();
virtual u32 Relink()=0;
virtual void Relocate(void* dst)=0;
//predecessors references
vector<RuntimeBlockInfoPtr> pre_refs;
2013-12-19 17:10:14 +00:00
void AddRef(RuntimeBlockInfoPtr other);
void RemRef(RuntimeBlockInfoPtr other);
2013-12-19 17:10:14 +00:00
void Discard();
void UpdateRefs();
void SetProtectedFlags();
2013-12-19 17:10:14 +00:00
u32 memops;
u32 linkedmemops;
std::map<void*, u32> memory_accesses; // key is host pc when access is made, value is opcode id
bool read_only;
2013-12-19 17:10:14 +00:00
};
void bm_WriteBlockMap(const string& file);
2015-05-08 16:59:20 +00:00
DynarecCodeEntryPtr DYNACALL bm_GetCode(u32 addr);
2013-12-19 17:10:14 +00:00
extern "C" {
ATTR_USED DynarecCodeEntryPtr DYNACALL bm_GetCodeByVAddr(u32 addr);
2013-12-19 17:10:14 +00:00
}
RuntimeBlockInfoPtr bm_GetBlock(void* dynarec_code);
RuntimeBlockInfoPtr bm_GetStaleBlock(void* dynarec_code);
RuntimeBlockInfoPtr DYNACALL bm_GetBlock(u32 addr);
2013-12-19 17:10:14 +00:00
void bm_AddBlock(RuntimeBlockInfo* blk);
void bm_DiscardBlock(RuntimeBlockInfo* block);
2013-12-19 17:10:14 +00:00
void bm_Reset();
void bm_ResetCache();
void bm_ResetTempCache(bool full);
2013-12-19 17:10:14 +00:00
void bm_Periodical_1s();
void bm_Init();
void bm_Term();
void bm_vmem_pagefill(void** ptr,u32 PAGE_SZ);
2019-06-19 20:55:47 +00:00
bool bm_RamWriteAccess(void *p);
void bm_RamWriteAccess(u32 addr);
static inline bool bm_IsRamPageProtected(u32 addr)
{
extern bool unprotected_pages[RAM_SIZE_MAX/PAGE_SIZE];
addr &= RAM_MASK;
return !unprotected_pages[addr / PAGE_SIZE];
}