FPU Fixing + Preparing for more debugging

This commit is contained in:
dingusdev 2020-01-11 18:43:47 -07:00
parent add0d5877c
commit c5ac0a2420
4 changed files with 55 additions and 12 deletions

View File

@ -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();

View File

@ -269,8 +269,9 @@ static std::unordered_map<uint16_t, PPCOpcode> 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<uint16_t, PPCOpcode> 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},

View File

@ -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(){

View File

@ -9,6 +9,7 @@
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <map>
#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();