callbacks: Factorize memory callbacks into inner structure

This commit is contained in:
MerryMage 2017-01-30 21:42:17 +00:00
parent 642ccb0f66
commit 2447f2f360
9 changed files with 74 additions and 72 deletions

View file

@ -18,29 +18,31 @@ class Jit;
/// These function pointers may be inserted into compiled code.
struct UserCallbacks {
// All reads through this callback are 4-byte aligned.
// Memory must be interpreted as little endian.
std::uint32_t (*MemoryReadCode)(std::uint32_t vaddr);
struct Memory {
// All reads through this callback are 4-byte aligned.
// Memory must be interpreted as little endian.
std::uint32_t (*ReadCode)(std::uint32_t vaddr);
// Reads through these callbacks may not be aligned.
// Memory must be interpreted as if ENDIANSTATE == 0, endianness will be corrected by the JIT.
std::uint8_t (*MemoryRead8)(std::uint32_t vaddr);
std::uint16_t (*MemoryRead16)(std::uint32_t vaddr);
std::uint32_t (*MemoryRead32)(std::uint32_t vaddr);
std::uint64_t (*MemoryRead64)(std::uint32_t vaddr);
// Reads through these callbacks may not be aligned.
// Memory must be interpreted as if ENDIANSTATE == 0, endianness will be corrected by the JIT.
std::uint8_t (*Read8)(std::uint32_t vaddr);
std::uint16_t (*Read16)(std::uint32_t vaddr);
std::uint32_t (*Read32)(std::uint32_t vaddr);
std::uint64_t (*Read64)(std::uint32_t vaddr);
// Writes through these callbacks may not be aligned.
// Memory must be interpreted as if ENDIANSTATE == 0, endianness will be corrected by the JIT.
void (*MemoryWrite8)(std::uint32_t vaddr, std::uint8_t value);
void (*MemoryWrite16)(std::uint32_t vaddr, std::uint16_t value);
void (*MemoryWrite32)(std::uint32_t vaddr, std::uint32_t value);
void (*MemoryWrite64)(std::uint32_t vaddr, std::uint64_t value);
// Writes through these callbacks may not be aligned.
// Memory must be interpreted as if ENDIANSTATE == 0, endianness will be corrected by the JIT.
void (*Write8)(std::uint32_t vaddr, std::uint8_t value);
void (*Write16)(std::uint32_t vaddr, std::uint16_t value);
void (*Write32)(std::uint32_t vaddr, std::uint32_t value);
void (*Write64)(std::uint32_t vaddr, std::uint64_t value);
// If this callback returns true, the JIT will assume MemoryRead* callbacks will always
// return the same value at any point in time for this vaddr. The JIT may use this information
// in optimizations.
// An conservative implementation that always returns false is safe.
bool (*IsReadOnlyMemory)(std::uint32_t vaddr);
// If this callback returns true, the JIT will assume MemoryRead* callbacks will always
// return the same value at any point in time for this vaddr. The JIT may use this information
// in optimizations.
// An conservative implementation that always returns false is safe.
bool (*IsReadOnlyMemory)(std::uint32_t vaddr);
} memory = {};
/// The intrepreter must execute only one instruction at PC.
void (*InterpreterFallback)(std::uint32_t pc, Jit* jit, void* user_arg);