From c5ac0a2420cd2da84f095521a804bb6f45b729a7 Mon Sep 17 00:00:00 2001 From: dingusdev Date: Sat, 11 Jan 2020 18:43:47 -0700 Subject: [PATCH] FPU Fixing + Preparing for more debugging --- cpu/ppc/ppcemu.h | 10 +++++++++- cpu/ppc/ppcexec.cpp | 7 ++++--- cpu/ppc/ppcfpopcodes.cpp | 34 +++++++++++++++++++++++++++------- debugger/debugger.cpp | 16 +++++++++++++++- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/cpu/ppc/ppcemu.h b/cpu/ppc/ppcemu.h index 31bd3f8..d32354a 100644 --- a/cpu/ppc/ppcemu.h +++ b/cpu/ppc/ppcemu.h @@ -189,6 +189,11 @@ extern uint32_t ppc_effective_address; extern uint32_t ppc_real_address; extern uint32_t ppc_next_instruction_address; +//Profiling Stats +extern uint32_t mmu_operations_num; +extern uint32_t exceptions_performed; +extern uint32_t supervisor_inst_num; + //Function prototypes void reg_init(); uint32_t reg_print(); @@ -233,6 +238,7 @@ extern void ppc_store_dfpresult(); void ppc_carry(uint32_t a, uint32_t b); void ppc_setsoov(uint32_t a, uint32_t b); void ppc_changecrf0(uint32_t set_result); +void ppc_fp_changecrf1(); void ppc_tbr_update(); void ppc_exception_handler(uint32_t exception_type, uint32_t handle_args); @@ -409,7 +415,9 @@ extern void ppc_fmr(); extern void ppc_mffs(); extern void ppc_mffsdot(); extern void ppc_mtfsf(); -extern void ppc_mtfsfdot(); +extern void ppc_mtfsfdot(); +extern void ppc_mtfsfi(); +extern void ppc_mtfsfidot(); extern void ppc_addi(); extern void ppc_addic(); diff --git a/cpu/ppc/ppcexec.cpp b/cpu/ppc/ppcexec.cpp index 64a7d8d..4cb4a9b 100644 --- a/cpu/ppc/ppcexec.cpp +++ b/cpu/ppc/ppcexec.cpp @@ -269,8 +269,9 @@ static std::unordered_map SubOpcode63Grabber = { { 239, &ppc_fseldot}, { 242, &ppc_fmult}, { 243, &ppc_fmultdot}, { 248, &ppc_fmsub}, { 249, &ppc_fmsubdot}, { 250, &ppc_fmadd}, { 251, &ppc_fmadddot}, { 252, &ppc_fnmsub}, { 253, &ppc_fnmsubdot}, - { 254, &ppc_fnmadd}, { 255, &ppc_fnmadddot}, { 272, &ppc_fnabs}, - { 273, &ppc_fnabsdot}, { 302, &ppc_fsel}, { 303, &ppc_fseldot}, + { 254, &ppc_fnmadd}, { 255, &ppc_fnmadddot}, { 268, &ppc_mtfsfi}, + { 272, &ppc_fnabs}, { 273, &ppc_fnabsdot}, + { 302, &ppc_fsel}, { 303, &ppc_fseldot}, { 306, &ppc_fmult}, { 307, &ppc_fmultdot}, { 312, &ppc_fmsub}, { 313, &ppc_fmsubdot}, { 314, &ppc_fmadd}, { 315, &ppc_fmadddot}, { 316, &ppc_fnmsub}, { 317, &ppc_fnmsubdot}, { 318, &ppc_fnmadd}, @@ -287,7 +288,7 @@ static std::unordered_map SubOpcode63Grabber = { { 505, &ppc_fmsubdot}, { 506, &ppc_fmadd}, { 507, &ppc_fmadddot}, { 508, &ppc_fnmsub}, { 509, &ppc_fnmsubdot}, { 510, &ppc_fnmadd}, { 511, &ppc_fnmadddot}, { 528, &ppc_fabs}, { 529, &ppc_fabsdot}, - { 558, &ppc_fsel}, { 559, &ppc_fseldot}, { 562, &ppc_fmult}, + { 536, &ppc_mtfsfidot}, { 558, &ppc_fsel}, { 559, &ppc_fseldot}, { 562, &ppc_fmult}, { 563, &ppc_fmultdot}, { 568, &ppc_fmsub}, { 569, &ppc_fmsubdot}, { 570, &ppc_fmadd}, { 571, &ppc_fmadddot}, { 572, &ppc_fnmsub}, { 573, &ppc_fnmsubdot}, { 574, &ppc_fnmadd}, { 575, &ppc_fnmadddot}, diff --git a/cpu/ppc/ppcfpopcodes.cpp b/cpu/ppc/ppcfpopcodes.cpp index c17c83f..01619f7 100644 --- a/cpu/ppc/ppcfpopcodes.cpp +++ b/cpu/ppc/ppcfpopcodes.cpp @@ -110,6 +110,10 @@ void ppc_grab_regsfpdabc(){ ppc_result64_c = ppc_state.ppc_fpr[reg_c]; } +void ppc_fp_changecrf1() { + ppc_state.ppc_fpscr |= 0xf0000000; +} + void ppc_divbyzero(uint64_t input_a, uint64_t input_b, bool is_single){ if (input_b == 0){ ppc_state.ppc_fpscr |= 0x84000000; @@ -1047,12 +1051,13 @@ void ppc_mffsdot(){ fpstore1 |= fpstore2; ppc_state.ppc_fpr[reg_d] = fpstore1; ppc_store_sfpresult(); + ppc_fp_changecrf1(); } void ppc_mtfsf(){ reg_b = (ppc_cur_instruction >> 11) & 31; uint32_t fm_mask = (ppc_cur_instruction >> 17) & 255; - crm += ((fm_mask & 1) == 1)? 0xF0000000 : 0x00000000; + crm = ((fm_mask & 1) == 1)? 0xF0000000 : 0x00000000; crm += (((fm_mask >> 1) & 1) == 1)? 0x0F000000 : 0x00000000; crm += (((fm_mask >> 2) & 1) == 1)? 0x00F00000 : 0x00000000; crm += (((fm_mask >> 3) & 1) == 1)? 0x000F0000 : 0x00000000; @@ -1065,9 +1070,9 @@ void ppc_mtfsf(){ } void ppc_mtfsfdot(){ - reg_b = (ppc_cur_instruction >> 11) & 31; - uint32_t fm_mask = (ppc_cur_instruction >> 17) & 255; - crm += ((fm_mask & 1) == 1)? 0xF0000000 : 0x00000000; + uint32_t quickfprval = (ppc_cur_instruction >> 12) & 15; + ppc_result_d = (ppc_cur_instruction >> 23) & 7; + crm = ((fm_mask & 1) == 1)? 0xF0000000 : 0x00000000; crm += (((fm_mask >> 1) & 1) == 1)? 0x0F000000 : 0x00000000; crm += (((fm_mask >> 2) & 1) == 1)? 0x00F00000 : 0x00000000; crm += (((fm_mask >> 3) & 1) == 1)? 0x000F0000 : 0x00000000; @@ -1077,6 +1082,22 @@ void ppc_mtfsfdot(){ crm += (((fm_mask >> 7) & 1) == 1)? 0x0000000F : 0x00000000; uint32_t quickfprval = (uint32_t)ppc_state.ppc_fpr[reg_b]; ppc_state.ppc_fpscr = (quickfprval & crm) | (quickfprval & ~(crm)); + ppc_fp_changecrf1(); +} + +void ppc_mtfsfi() { + ppc_result_b = (ppc_cur_instruction >> 11) & 15; + crf_d = (ppc_cur_instruction >> 23) & 7; + crf_d = crf_d << 2; + ppc_state.ppc_fpscr = (ppc_state.ppc_cr & ~(0xF0000000UL >> crf_d)) | ((ppc_state.ppc_spr[1] & 0xF0000000UL) >> crf_d); +} + +void ppc_mtfsfidot() { + ppc_result_b = (ppc_cur_instruction >> 11) & 15; + crf_d = (ppc_cur_instruction >> 23) & 7; + crf_d = crf_d << 2; + ppc_state.ppc_fpscr = (ppc_state.ppc_cr & ~(0xF0000000UL >> crf_d)) | ((ppc_state.ppc_spr[1] & 0xF0000000UL) >> crf_d); + ppc_fp_changecrf1(); } void ppc_mtfsb0(){ @@ -1087,11 +1108,11 @@ void ppc_mtfsb0(){ } void ppc_mtfsb0dot(){ - //PLACEHOLDER crf_d = (ppc_cur_instruction >> 21) & 0x31; if ((crf_d == 0) || (crf_d > 2)){ ppc_state.ppc_fpscr &= ~(1 << crf_d); } + ppc_fp_changecrf1(); } void ppc_mtfsb1(){ @@ -1102,12 +1123,11 @@ void ppc_mtfsb1(){ } void ppc_mtfsb1dot(){ - //PLACEHOLDER crf_d = ~(ppc_cur_instruction >> 21) & 0x31; if ((crf_d == 0) || (crf_d > 2)){ ppc_state.ppc_fpscr |= (1 << crf_d); } - + ppc_fp_changecrf1(); } void ppc_mcrfs(){ diff --git a/debugger/debugger.cpp b/debugger/debugger.cpp index 89aa05a..cbe2e67 100644 --- a/debugger/debugger.cpp +++ b/debugger/debugger.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "ppcemu.h" #include "../cpu/ppc/ppcmmu.h" @@ -22,6 +23,7 @@ void show_help() cout << " step -- execute single instruction" << endl; cout << " until X -- execute until address X is reached" << endl; cout << " regs -- dump content of the GRPs" << endl; + cout << " memdump -- dump content of the system memory to memdump.bin" << endl; cout << " disas X,n -- disassemble N instructions starting at address X" << endl; cout << " quit -- quit the debugger" << endl << endl; cout << "Pressing ENTER will repeat last command." << endl; @@ -40,6 +42,14 @@ void dump_regs() cout << "MSR: " << hex << ppc_state.ppc_msr << endl; } +void dump_mem_file() +{ + std::ofstream memdumpfile; + memdumpfile.open("memdump.bin", std::ofstream::out | std::ofstream::binary); + memdumpfile.write((char *)&machine_sysram_mem, sizeof(char) * 67108864); + memdumpfile.close(); +} + void enter_debugger() { string inp, cmd, addr_str, last_cmd; @@ -69,7 +79,11 @@ void enter_debugger() show_help(); } else if (cmd == "quit") { break; - } else if (cmd == "regs") { + } + else if (cmd == "memdump") { + dump_mem_file(); + } + else if (cmd == "regs") { dump_regs(); } else if (cmd == "step") { ppc_exec_single();