Introduce panic_trace and small accuracy fix
This commit is contained in:
@@ -20,6 +20,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES Debug)
|
||||
add_compile_definitions(VULKAN_DEBUG)
|
||||
#add_compile_options(-fsanitize=address -fsanitize=undefined)
|
||||
#add_link_options(-fsanitize=address -fsanitize=undefined)
|
||||
add_link_options(-Wl,--export-dynamic)
|
||||
endif()
|
||||
|
||||
find_package(Qt6 COMPONENTS Core Gui Widgets)
|
||||
|
||||
@@ -208,7 +208,7 @@ template<> u8 Mem::Read(n64::Registers ®s, u32 paddr) {
|
||||
return si.pif.bootrom[BYTE_ADDRESS(paddr) - PIF_ROM_REGION_START];
|
||||
case PIF_RAM_REGION:
|
||||
return si.pif.ram[paddr - PIF_RAM_REGION_START];
|
||||
case 0x00800000 ... 0x03FFFFFF: // unused
|
||||
case 0x00800000 ... 0x03EFFFFF: // unused
|
||||
case 0x04200000 ... 0x042FFFFF: // unused
|
||||
case 0x04900000 ... 0x04FFFFFF: // unused
|
||||
case 0x1FC00800 ... 0xFFFFFFFF: // unused
|
||||
@@ -243,7 +243,7 @@ template<> u16 Mem::Read(n64::Registers ®s, u32 paddr) {
|
||||
return Util::ReadAccess<u16>(si.pif.bootrom, HALF_ADDRESS(paddr) - PIF_ROM_REGION_START);
|
||||
case PIF_RAM_REGION:
|
||||
return be16toh(Util::ReadAccess<u16>(si.pif.ram, paddr - PIF_RAM_REGION_START));
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case 0x1FC00800 ... 0xFFFFFFFF:
|
||||
@@ -278,7 +278,7 @@ template<> u32 Mem::Read(n64::Registers ®s, u32 paddr) {
|
||||
return Util::ReadAccess<u32>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
|
||||
case PIF_RAM_REGION:
|
||||
return be32toh(Util::ReadAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START));
|
||||
case 0x00800000 ... 0x03FFFFFF: case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF: case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF: case 0x1FC00800 ... 0xFFFFFFFF: return 0;
|
||||
default:
|
||||
Util::panic("Unimplemented 32-bit read at address {:08X} (PC = {:016X})", paddr, (u64) regs.pc);
|
||||
@@ -310,7 +310,7 @@ template<> u64 Mem::Read(n64::Registers ®s, u32 paddr) {
|
||||
return Util::ReadAccess<u64>(si.pif.bootrom, paddr - PIF_ROM_REGION_START);
|
||||
case PIF_RAM_REGION:
|
||||
return be64toh(Util::ReadAccess<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START));
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case 0x1FC00800 ... 0xFFFFFFFF:
|
||||
@@ -352,7 +352,7 @@ template<> void Mem::Write<u8>(Registers& regs, u32 paddr, u32 val) {
|
||||
Util::WriteAccess<u32>(si.pif.ram, paddr, htobe32(val));
|
||||
si.pif.ProcessCommands(*this);
|
||||
break;
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case PIF_ROM_REGION:
|
||||
@@ -397,7 +397,7 @@ template<> void Mem::Write<u16>(Registers& regs, u32 paddr, u32 val) {
|
||||
Util::WriteAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, htobe32(val));
|
||||
si.pif.ProcessCommands(*this);
|
||||
break;
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case PIF_ROM_REGION:
|
||||
@@ -439,7 +439,7 @@ template<> void Mem::Write<u32>(Registers& regs, u32 paddr, u32 val) {
|
||||
Util::WriteAccess<u32>(si.pif.ram, paddr - PIF_RAM_REGION_START, htobe32(val));
|
||||
si.pif.ProcessCommands(*this);
|
||||
break;
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case PIF_ROM_REGION:
|
||||
@@ -478,7 +478,7 @@ void Mem::Write(Registers& regs, u32 paddr, u64 val) {
|
||||
Util::WriteAccess<u64>(si.pif.ram, paddr - PIF_RAM_REGION_START, htobe64(val));
|
||||
si.pif.ProcessCommands(*this);
|
||||
break;
|
||||
case 0x00800000 ... 0x03FFFFFF:
|
||||
case 0x00800000 ... 0x03EFFFFF:
|
||||
case 0x04200000 ... 0x042FFFFF:
|
||||
case 0x04900000 ... 0x04FFFFFF:
|
||||
case 0x1FC00000 ... 0x1FC007BF:
|
||||
|
||||
@@ -146,7 +146,9 @@ void RSP::DMAtoRDRAM(std::vector<u8>& rdram) {
|
||||
|
||||
for (u32 i = 0; i < spDMALen.count + 1; i++) {
|
||||
for(u32 j = 0; j < length; j++) {
|
||||
dst[dram_address + j] = src[(mem_address + j) & 0xFFF];
|
||||
if((dram_address + j) < RDRAM_SIZE) {
|
||||
dst[dram_address + j] = src[(mem_address + j) & DMEM_DSIZE];
|
||||
}
|
||||
}
|
||||
|
||||
int skip = i == spDMALen.count ? 0 : spDMALen.skip;
|
||||
@@ -176,7 +178,11 @@ void RSP::DMAtoRSP(std::vector<u8>& rdram) {
|
||||
|
||||
for (u32 i = 0; i < spDMALen.count + 1; i++) {
|
||||
for(u32 j = 0; j < length; j++) {
|
||||
dst[(mem_address + j) & 0xFFF] = src[dram_address + j];
|
||||
if((dram_address + j) < RDRAM_SIZE) {
|
||||
dst[(mem_address + j) & DMEM_DSIZE] = src[dram_address + j];
|
||||
} else {
|
||||
dst[(mem_address + j) & DMEM_DSIZE] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int skip = i == spDMALen.count ? 0 : spDMALen.skip;
|
||||
|
||||
@@ -78,7 +78,7 @@ void MI::Write(u32 paddr, u32 val) {
|
||||
UpdateInterrupt();
|
||||
break;
|
||||
default:
|
||||
Util::panic("Unhandled MI[{:08X}] write ({:08X})", val, paddr);
|
||||
Util::panic_trace("Unhandled MI write @ 0x{:08X} with value 0x{:08X}", paddr, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
#include <common.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/color.h>
|
||||
#include <string>
|
||||
#ifndef NDEBUG
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
namespace Util {
|
||||
enum LogLevel : u8 {
|
||||
@@ -22,7 +26,7 @@ constexpr void print(const std::string& fmt, Args... args) {
|
||||
fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...);
|
||||
} else if constexpr(messageType == Warn) {
|
||||
fmt::print(fg(fmt::color::yellow), fmt, args...);
|
||||
} else if constexpr(messageType == Info) {
|
||||
} else if constexpr(messageType == Info || messageType == Trace) {
|
||||
fmt::print(fmt, args...);
|
||||
} else if constexpr(messageType == Debug) {
|
||||
#ifndef NDEBUG
|
||||
@@ -43,32 +47,60 @@ constexpr void print(const std::string& fmt, Args... args) {
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void panic(const std::string& fmt, Args... args) {
|
||||
print<Error>(fmt + "\n", args...);
|
||||
print<Error>("[FATAL] " + fmt + "\n", args...);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void error(const std::string& fmt, Args... args) {
|
||||
print<Error>(fmt + "\n", args...);
|
||||
print<Error>("[ERROR] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void warn(const std::string& fmt, Args... args) {
|
||||
print<Warn>(fmt + "\n", args...);
|
||||
print<Warn>("[WARN] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void info(const std::string& fmt, Args... args) {
|
||||
print(fmt + "\n", args...);
|
||||
print("[INFO] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void debug(const std::string& fmt, Args... args) {
|
||||
print<Debug>(fmt + "\n", args...);
|
||||
print<Debug>("[DEBUG] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void trace(const std::string& fmt, Args... args) {
|
||||
print<Trace>(fmt + "\n", args...);
|
||||
print<Trace>("[TRACE] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void panic_trace(const std::string& fmt, Args... args) {
|
||||
#ifndef NDEBUG
|
||||
Dl_info info;
|
||||
auto tmp = fmt::format(fmt + '\n', args...);
|
||||
tmp += "Called by:\n";
|
||||
if(dladdr(__builtin_return_address(0), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(1), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(2), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(3), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(4), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(5), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(6), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
|
||||
print<Error>("[FATAL TRACE] " + tmp);
|
||||
exit(-1);
|
||||
#else
|
||||
panic(fmt, args...);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user