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

110 lines
2.3 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
*/
2020-03-28 16:58:01 +00:00
#pragma once
2013-12-19 17:10:14 +00:00
#include "types.h"
#include "decoder.h"
#include "stdclass.h"
#include <memory>
2013-12-19 17:10:14 +00:00
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);
const char* hash();
2013-12-19 17:10:14 +00:00
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; // set by host code generator, optional
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;
BlockEndType BlockType;
bool has_jcond;
2020-03-29 17:29:14 +00:00
std::vector<shil_opcode> oplist;
2013-12-19 17:10:14 +00:00
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
2020-03-29 17:29:14 +00:00
std::vector<RuntimeBlockInfoPtr> pre_refs;
2013-12-19 17:10:14 +00:00
void AddRef(const RuntimeBlockInfoPtr& other);
void RemRef(const RuntimeBlockInfoPtr& other);
2013-12-19 17:10:14 +00:00
void Discard();
void SetProtectedFlags();
2013-12-19 17:10:14 +00:00
bool read_only;
2013-12-19 17:10:14 +00:00
};
2020-03-29 17:29:14 +00:00
void bm_WriteBlockMap(const std::string& file);
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];
}