move MapVAddr to Cop0.hpp and no template necessary

This commit is contained in:
CocoSimone
2023-02-19 12:14:39 +01:00
parent 6e3b81655e
commit abc14302cc
3 changed files with 18 additions and 24 deletions

View File

@@ -65,26 +65,6 @@ CartInfo Mem::LoadROM(const std::string& filename) {
return result;
}
template <bool tlb>
bool MapVAddr(Registers& regs, TLBAccessType accessType, u64 vaddr, u32& paddr) {
paddr = vaddr & 0x1FFFFFFF;
if constexpr(!tlb) return true;
switch(u32(vaddr) >> 29) {
case 0 ... 3: case 7:
return ProbeTLB(regs, accessType, vaddr, paddr, nullptr);
case 4 ... 5: return true;
case 6: Util::panic("Unimplemented virtual mapping in KSSEG! ({:08X})\n", vaddr);
default:
Util::panic("Should never end up in default case in map_vaddr! ({:08X})\n", vaddr);
}
return false;
}
template bool MapVAddr<true>(Registers& regs, TLBAccessType accessType, u64 vaddr, u32& paddr);
template bool MapVAddr<false>(Registers& regs, TLBAccessType accessType, u64 vaddr, u32& paddr);
u8 Mem::Read8(n64::Registers &regs, u32 paddr) {
const auto page = paddr >> 12;
const auto offset = paddr & 0xFFF;

View File

@@ -127,7 +127,4 @@ private:
// return false;
}
};
template <bool tlb = true>
bool MapVAddr(Registers& regs, TLBAccessType accessType, u64 vaddr, u32& paddr);
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <common.hpp>
#include "log.hpp"
namespace n64 {
#define STATUS_MASK 0xFF57FFFF
@@ -272,8 +273,24 @@ enum TLBAccessType {
LOAD, STORE
};
TLBEntry* TLBTryMatch(Registers& regs, u64 vaddr, int* match);
bool ProbeTLB(Registers& regs, TLBAccessType access_type, u64 vaddr, u32& paddr, int* match);
static inline bool MapVAddr(Registers& regs, TLBAccessType accessType, u64 vaddr, u32& paddr) {
switch(u32(vaddr) >> 29) {
case 0 ... 3: case 7:
return ProbeTLB(regs, accessType, vaddr, paddr, nullptr);
case 4 ... 5:
paddr = vaddr & 0x1FFFFFFF;
return true;
case 6: Util::panic("Unimplemented virtual mapping in KSSEG! ({:08X})\n", vaddr);
default:
Util::panic("Should never end up in default case in map_vaddr! ({:08X})\n", vaddr);
}
return false;
}
TLBEntry* TLBTryMatch(Registers& regs, u64 vaddr, int* match);
void HandleTLBException(Registers& regs, u64 vaddr);
ExceptionCode GetTLBExceptionCode(TLBError error, TLBAccessType access_type);
}