need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)

This commit is contained in:
2026-06-03 16:03:24 +02:00
parent 204f0e13b0
commit 12e81e73e8
37 changed files with 305 additions and 3355 deletions
+50
View File
@@ -0,0 +1,50 @@
#pragma once
#include <Instruction.hpp>
#include <vector>
#include <array>
namespace n64 {
static constexpr u32 MAX_INSTR_PER_BLOCK = 128;
#define CACHE_GET_BLOCK(addr) (addr / (cachedState.MAX_LINES))
#define CACHE_GET_LINE(addr) ((addr & ((cachedState.MAX_LINES) - 1)) >> 2)
template <typename T>
struct CachedLine {
bool idleSkip = false;
std::array<T, MAX_INSTR_PER_BLOCK> code = {};
u32 len = 0;
u32 cycles = 0;
};
template <typename T>
struct CachedBlock {
CachedBlock(u32 lineAmount) { lines.resize(lineAmount); }
std::vector<CachedLine<T> *> lines = {};
};
template <u32 blockBits, u64 addressSpace, typename T = Instruction>
struct CachedState {
static constexpr u32 MAX_LINES = 1 << blockBits;
std::vector<CachedBlock<T> *> blocks = {};
bool exception = false;
void EvictCachedBlock(u32 addr) { blocks[addr / MAX_LINES] = {}; }
void EvictCachedBlocksRange(u32 start, u32 end) {
for (u32 i = start; i < end; i += 4)
blocks[i / MAX_LINES] = {};
}
void Reset() {
for (auto block : blocks) {
if (block)
for (auto line : block->lines)
delete line;
delete block;
}
blocks = {};
blocks.resize((addressSpace + 1) / MAX_LINES);
}
};
} // namespace n64