--- hatari/src/falcon/dsp_disasm.c 2019/04/09 08:49:37 1.1.1.5 +++ hatari/src/falcon/dsp_disasm.c 2019/04/09 08:59:31 1.1.1.11 @@ -15,8 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + along with this program; if not, write to the Free Software Foundation, + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ #ifdef HAVE_CONFIG_H @@ -24,11 +24,14 @@ #endif #include +#include #include +#include #include "dsp_core.h" #include "dsp_cpu.h" #include "dsp_disasm.h" +#include "profile.h" /* More disasm infos, if wanted */ @@ -44,9 +47,9 @@ /* Current instruction */ static Uint32 cur_inst; -static Uint32 disasm_cur_inst_len; -static char str_instr[50]; -static char str_instr2[100]; +static Uint16 disasm_cur_inst_len; +static char str_instr[80]; +static char str_instr2[120]; static char parallelmove_name[64]; /* Previous instruction */ @@ -411,7 +414,7 @@ void dsp56k_disasm_reg_save(void) #endif } -void dsp56k_disasm_reg_compare(void) +void dsp56k_disasm_reg_compare(FILE *fp) { int i; bool bRegA = false; @@ -427,7 +430,7 @@ void dsp56k_disasm_reg_compare(void) case DSP_REG_X1: case DSP_REG_Y0: case DSP_REG_Y1: - fprintf(stderr,"\tReg: %s $%06x -> $%06x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); + fprintf(fp, "\tReg: %s $%06x -> $%06x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); break; case DSP_REG_R0: case DSP_REG_R1: @@ -456,19 +459,19 @@ void dsp56k_disasm_reg_compare(void) case DSP_REG_SR: case DSP_REG_LA: case DSP_REG_LC: - fprintf(stderr,"\tReg: %s $%04x -> $%04x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); + fprintf(fp, "\tReg: %s $%04x -> $%04x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); break; case DSP_REG_OMR: case DSP_REG_SP: case DSP_REG_SSH: case DSP_REG_SSL: - fprintf(stderr,"\tReg: %s $%02x -> $%02x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); + fprintf(fp, "\tReg: %s $%02x -> $%02x\n", registers_name[i], registers_save[i], dsp_core.registers[i]); break; case DSP_REG_A0: case DSP_REG_A1: case DSP_REG_A2: if (bRegA == false) { - fprintf(stderr,"\tReg: a $%02x:%06x:%06x -> $%02x:%06x:%06x\n", + fprintf(fp, "\tReg: a $%02x:%06x:%06x -> $%02x:%06x:%06x\n", registers_save[DSP_REG_A2], registers_save[DSP_REG_A1], registers_save[DSP_REG_A0], dsp_core.registers[DSP_REG_A2], dsp_core.registers[DSP_REG_A1], dsp_core.registers[DSP_REG_A0] ); @@ -479,7 +482,7 @@ void dsp56k_disasm_reg_compare(void) case DSP_REG_B1: case DSP_REG_B2: if (bRegB == false) { - fprintf(stderr,"\tReg: b $%02x:%06x:%06x -> $%02x:%06x:%06x\n", + fprintf(fp, "\tReg: b $%02x:%06x:%06x -> $%02x:%06x:%06x\n", registers_save[DSP_REG_B2], registers_save[DSP_REG_B1], registers_save[DSP_REG_B0], dsp_core.registers[DSP_REG_B2], dsp_core.registers[DSP_REG_B1], dsp_core.registers[DSP_REG_B0] ); @@ -491,12 +494,12 @@ void dsp56k_disasm_reg_compare(void) #if DSP_DISASM_REG_PC if (pc_save != dsp_core.pc) { - fprintf(stderr,"\tReg: pc $%04x -> $%04x\n", pc_save, dsp_core.pc); + fprintf(fp, "\tReg: pc $%04x -> $%04x\n", pc_save, dsp_core.pc); } #endif } -Uint16 dsp56k_disasm(dsp_trace_disasm_t mode) +Uint16 dsp56k_disasm(dsp_trace_disasm_t mode, FILE *fp) { Uint32 value; @@ -504,7 +507,7 @@ Uint16 dsp56k_disasm(dsp_trace_disasm_t isInDisasmMode = false; if (prev_inst_pc == dsp_core.pc) { if (!isLooping) { - fprintf(stderr, "Looping on DSP instruction at PC = $%04x\n", prev_inst_pc); + fprintf(fp, "Looping on DSP instruction at PC = $%04x\n", prev_inst_pc); isLooping = true; } return 0; @@ -538,16 +541,25 @@ Uint16 dsp56k_disasm(dsp_trace_disasm_t */ const char* dsp56k_getInstructionText(void) { + const int len = 50; + Uint64 count, cycles; + Uint16 cycle_diff; + float percentage; + int offset; + if (isLooping) { *str_instr2 = 0; } - else if (disasm_cur_inst_len == 1) { - sprintf(str_instr2, "p:%04x %06x (%02d cyc) %s\n", prev_inst_pc, cur_inst, dsp_core.instr_cycle, str_instr); - } - else { - sprintf(str_instr2, "p:%04x %06x %06x (%02d cyc) %s\n", prev_inst_pc, cur_inst, read_memory(prev_inst_pc + 1), dsp_core.instr_cycle, str_instr); + if (disasm_cur_inst_len == 1) { + offset = sprintf(str_instr2, "p:%04x %06x (%02d cyc) %-*s\n", prev_inst_pc, cur_inst, dsp_core.instr_cycle, len, str_instr); + } else { + offset = sprintf(str_instr2, "p:%04x %06x %06x (%02d cyc) %-*s\n", prev_inst_pc, cur_inst, read_memory(prev_inst_pc + 1), dsp_core.instr_cycle, len, str_instr); + } + if (offset > 2 && Profile_DspAddressData(prev_inst_pc, &percentage, &count, &cycles, &cycle_diff)) { + offset -= 2; + sprintf(str_instr2+offset, "%5.2f%% (%"PRId64", %"PRId64", %d)\n", + percentage, count, cycles, cycle_diff); } - return str_instr2; } @@ -666,6 +678,9 @@ static void opcode8h_0(void) case 0x00008c: dsp_enddo(); break; + default: + dsp_undefined(); + break; } } @@ -724,7 +739,7 @@ static void dsp_bchg_ea(void) { /* bchg #n,x:ea */ /* bchg #n,y:ea */ - char name[16], addr_name[16]; + char name[18], addr_name[16]; Uint32 memspace, value, numbit; memspace = (cur_inst>>6) & 1; @@ -796,7 +811,7 @@ static void dsp_bclr_ea(void) { /* bclr #n,x:ea */ /* bclr #n,y:ea */ - char name[16], addr_name[16]; + char name[18], addr_name[16]; Uint32 memspace, value, numbit; memspace = (cur_inst>>6) & 1; @@ -868,7 +883,7 @@ static void dsp_bset_ea(void) { /* bset #n,x:ea */ /* bset #n,y:ea */ - char name[16], addr_name[16]; + char name[18], addr_name[16]; Uint32 memspace, value, numbit; memspace = (cur_inst>>6) & 1; @@ -940,7 +955,7 @@ static void dsp_btst_ea(void) { /* btst #n,x:ea */ /* btst #n,y:ea */ - char name[16], addr_name[16]; + char name[18], addr_name[16]; Uint32 memspace, value, numbit; memspace = (cur_inst>>6) & 1; @@ -1041,7 +1056,7 @@ static void dsp_do_imm(void) static void dsp_do_ea(void) { - char addr_name[16], name[16]; + char addr_name[16], name[18]; Uint32 ea_mode; disasm_cur_inst_len++; @@ -1135,7 +1150,7 @@ static void dsp_jclr_ea(void) { /* jclr #n,x:ea,p:xx */ /* jclr #n,y:ea,p:xx */ - char srcname[16], addr_name[16]; + char srcname[18], addr_name[16]; Uint32 memspace, value, numbit; disasm_cur_inst_len++; @@ -1270,7 +1285,7 @@ static void dsp_jsclr_ea(void) { /* jsclr #n,x:ea,p:xx */ /* jsclr #n,y:ea,p:xx */ - char srcname[16], addr_name[16]; + char srcname[18], addr_name[16]; Uint32 memspace, value, numbit; disasm_cur_inst_len++; @@ -1367,7 +1382,7 @@ static void dsp_jset_ea(void) { /* jset #n,x:ea,p:xx */ /* jset #n,y:ea,p:xx */ - char srcname[16], addr_name[16]; + char srcname[18], addr_name[16]; Uint32 memspace, value, numbit; disasm_cur_inst_len++; @@ -1478,7 +1493,7 @@ static void dsp_jsset_ea(void) { /* jsset #n,x:ea,p:xx */ /* jsset #n,y:ea,p:xx */ - char srcname[16], addr_name[16]; + char srcname[18], addr_name[16]; Uint32 memspace, value, numbit; disasm_cur_inst_len++; @@ -1624,7 +1639,7 @@ static void dsp_movec_imm(void) static void dsp_movec_ea(void) { const char *spacename; - char srcname[16], dstname[16], addr_name[16]; + char srcname[18], dstname[18], addr_name[16]; Uint32 numreg, ea_mode; int retour; @@ -1665,7 +1680,7 @@ static void dsp_movem_aa(void) { /* S,p:aa */ /* p:aa,D */ - char addr_name[16], srcname[16], dstname[16]; + char addr_name[16], srcname[18], dstname[18]; Uint32 numreg; sprintf(addr_name, "$%04x",(cur_inst>>8) & BITMASK(6)); @@ -1687,7 +1702,7 @@ static void dsp_movem_ea(void) { /* S,p:ea */ /* p:ea,D */ - char addr_name[16], srcname[16], dstname[16]; + char addr_name[16], srcname[18], dstname[18]; Uint32 ea_mode, numreg; ea_mode = (cur_inst>>8) & BITMASK(6); @@ -1747,7 +1762,7 @@ static void dsp_movep_0(void) static void dsp_movep_1(void) { - char srcname[16]="",dstname[16]="",name[16]=""; + char srcname[18] = "", dstname[18] = "", name[16] = ""; Uint32 addr, memspace; /* p:ea,x:pp */ @@ -1786,7 +1801,7 @@ static void dsp_movep_1(void) static void dsp_movep_23(void) { - char srcname[16]="",dstname[16]="",name[16]=""; + char srcname[18] = "", dstname[18] = "", name[16] = ""; Uint32 addr, memspace, easpace, retour; /* x:ea,x:pp */ @@ -1901,7 +1916,7 @@ static void dsp_rep_imm(void) static void dsp_rep_ea(void) { - char name[16],addr_name[16]; + char name[18], addr_name[16]; /* x:ea */ /* y:ea */