Skip to content

Commit

Permalink
Check if the CPU is in an exception vector and use EPC instead if so
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Wiseguy committed Feb 9, 2023
1 parent 05b7ff4 commit f42bd33
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ uint32_t get_cpu_reg(duk_context* ctx, const std::string& name) {
}
}

uint32_t get_cop0_reg(duk_context* ctx, const std::string& name) {
duk_push_string(ctx, ("cpu.cop0." + name).c_str());
if (!duk_peval(ctx)) {
return duk_get_number(ctx, -1);
} else {
duk_push_error_object(ctx, -1, "Invalid cop0 register name", name.c_str());
return 0;
}
}

uint32_t get_cpu_pc(duk_context* ctx) {
duk_push_string(ctx, "cpu.pc");
if (!duk_peval(ctx)) {
Expand Down Expand Up @@ -253,8 +263,14 @@ static duk_ret_t unwind(duk_context* ctx) {
return 1;
}

std::string ret = "Running Thread:\n";
ret += read_thread(ctx, rdram, elf_data, read_mem<uint32_t>(rdram, elf_data.__osRunningThread), get_cpu_pc(ctx), get_cpu_reg(ctx, "ra"), get_cpu_reg(ctx, "sp"));
std::string ret = "Running Thread:";
uint32_t cur_pc = get_cpu_pc(ctx);
if (cur_pc >= 0x80000000 && cur_pc < 0x80000190) {
cur_pc = get_cop0_reg(ctx, "epc");
ret += " (in exception handler)";
}
ret += "\n";
ret += read_thread(ctx, rdram, elf_data, read_mem<uint32_t>(rdram, elf_data.__osRunningThread), cur_pc, get_cpu_reg(ctx, "ra"), get_cpu_reg(ctx, "sp"));
ret += "Queued Running Threads:\n";

uint32_t cur_thread = read_mem<uint32_t>(rdram, elf_data.__osRunQueue);
Expand Down

0 comments on commit f42bd33

Please sign in to comment.