From d09b777de8387d95611580a79275762f22dbd5b4 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 19 Jul 2009 20:14:09 +0000 Subject: [PATCH] dsp_base.inc: mail the exception instead of wr3 (no idea why that was there anyways). DSPSpy will report the exception now. DSPTool: incorporate printresult functionality. delete printresult.cpp DSPSpy: fix dumping of results git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3852 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/DSPSpy/DSPSpy.vcproj | 4 -- Source/DSPSpy/main_spy.cpp | 46 ++++++++++++++-------- Source/DSPSpy/tests/dsp_base.inc | 42 ++++++++++---------- Source/DSPSpy/util/printresult.cpp | 58 ---------------------------- Source/DSPTool/Src/main.cpp | 61 +++++++++++++++++++++++++++--- 5 files changed, 106 insertions(+), 105 deletions(-) delete mode 100644 Source/DSPSpy/util/printresult.cpp diff --git a/Source/DSPSpy/DSPSpy.vcproj b/Source/DSPSpy/DSPSpy.vcproj index 97f8e0c1bf..a38481c29f 100644 --- a/Source/DSPSpy/DSPSpy.vcproj +++ b/Source/DSPSpy/DSPSpy.vcproj @@ -165,10 +165,6 @@ RelativePath=".\util\dump_roms.ds" > - - = dsp_steps) + if (show_step >= dsp_steps) show_step = 0; UpdateLastMessage("OK"); } @@ -579,7 +593,7 @@ int main() #endif { show_step--; - if (show_step < 0) + if (show_step < 0) show_step = dsp_steps - 1; UpdateLastMessage("OK"); } diff --git a/Source/DSPSpy/tests/dsp_base.inc b/Source/DSPSpy/tests/dsp_base.inc index b05d06bc51..6860a64f96 100644 --- a/Source/DSPSpy/tests/dsp_base.inc +++ b/Source/DSPSpy/tests/dsp_base.inc @@ -29,8 +29,8 @@ MEM_LO: equ 0x0f7F ; Why do we have a main label here? main: - clr $ACC1 - clr $ACC0 + clr $acc1 + clr $acc0 ; get address of memory dump and copy it to DRAM @@ -40,11 +40,11 @@ main: si @DIRQ, #0x0001 call wait_for_cpu_mbox - lrs $AC0.M, @CMBL + lrs $ac0.m, @CMBL andi $ac1.m, #0x7fff - sr @MEM_HI, $AC1.M - sr @MEM_LO, $AC0.M + sr @MEM_HI, $ac1.m + sr @MEM_LO, $ac0.m lri $ax0.l, #0 lri $ax1.l, #0 ;(DSP_CR_IMEM | DSP_CR_TO_CPU) @@ -62,11 +62,11 @@ main: si @DIRQ, #0x0001 call wait_for_cpu_mbox - lrs $AC0.M, @CMBL + lrs $ac0.m, @CMBL andi $ac1.m, #0x7fff - sr @MEM_HI, $AC1.M - sr @MEM_LO, $AC0.M + sr @MEM_HI, $ac1.m + sr @MEM_LO, $ac0.m lri $ax0.l, #REGS_BASE lri $ax1.l, #0 ;(DSP_CR_IMEM | DSP_CR_TO_CPU) @@ -129,7 +129,7 @@ dead_loop: ; Utility function to do DMA. ; ac0.l:ac0.m - external address. -; ax0.l - address in DSP +; ax0.l - address in DSP do_dma: sr @DSMAH, $ac0.l sr @DSMAL, $ac0.m @@ -139,21 +139,21 @@ do_dma: ; Waits for said DMA to complete by watching a bit in DSCR. wait_dma: - LRS $AC1.M, @DSCR + lrs $ac1.m, @DSCR andcf $ac1.m, #0x0004 - JLZ wait_dma - RET + jlz wait_dma + ret ; This waits for a mail to arrive in the DSP in-mailbox. wait_for_dsp_mbox: - lrs $AC1.M, @DMBH + lrs $ac1.m, @DMBH andcf $ac1.m, #0x8000 jlz wait_for_dsp_mbox ret ; This waits for the CPU to grab a mail that we just sent from the DSP. wait_for_cpu_mbox: - lrs $AC1.M, @cmbh + lrs $ac1.m, @CMBH andcf $ac1.m, #0x8000 jlnz wait_for_cpu_mbox ret @@ -200,18 +200,18 @@ irq7: jmp irq irq: - lrs $AC1.M, @DMBH + lrs $ac1.m, @DMBH andcf $ac1.m, #0x8000 jlz irq - si @DMBH, #0x8BAD - sr @DMBL, $wr3 ; ??? - ;sr @DMBL, $ac0.m + si @DMBH, #0x8bad + ;sr @DMBL, $wr3 ; ??? + sr @DMBL, $ac0.m ; Exception number si @DIRQ, #0x0001 halt ; DMA:s the current state of the registers back to the PowerPC. To do this, ; it must write the contents of all regs to DRAM. -; Unfortunately, this loop uses AR0 so it's best to use AR1 and friends for testing +; Unfortunately, this loop uses ar0 so it's best to use AR1 and friends for testing ; when messing with indexing. send_back: ; make state safe. @@ -280,7 +280,7 @@ dma_copy: ; wait for the CPU to recieve our response before we execute the next op call wait_for_cpu_mbox - lrs $AC0.M, @CMBL + lrs $ac0.m, @CMBL andi $ac1.m, #0x7fff ; Restore all regs again so we're ready to execute another op. @@ -338,7 +338,7 @@ dump_memory: bloop $ar1, _fill_loop2 mrr $ar3, $ac0.m - nx'ld : $AX0.H, $AX1.H, @$AR0 + nx'ld : $ax0.h, $ax1.h, @$ar0 mrr $ac1.m, $ar0 mrr $ar0, $ar2 diff --git a/Source/DSPSpy/util/printresult.cpp b/Source/DSPSpy/util/printresult.cpp deleted file mode 100644 index 562032fc74..0000000000 --- a/Source/DSPSpy/util/printresult.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -typedef unsigned short u16; - -u16 reg_in[32], reg_out[1000][32]; - -inline u16 swap16(u16 s) { - return (s >> 8) | (s << 8); -} - -void printRegs(u16 *lastRegs, u16 *regs) { - for (int i = 0; i < 32; i++) { - if (! lastRegs || lastRegs[i] != regs[i]) { - printf("%02x %04x ", i, swap16(regs[i])); - } else { - printf(" "); - } - - if ((i+1) % 8 == 0) - printf("\n"); - } -} - -int main(int argc, char **argv) { - - if (argc != 2) { - fprintf(stderr, "Usage %s: \n", argv[0]); - exit(1); - } - - FILE *f = fopen(argv[1], "rb"); - int steps; - if (f) { - // read initial regs - fread(reg_in, 1, 32 * 2, f); - - // read initial regs (guess number of steps) - steps = fread(reg_out, 32 * 2, 1000, f); - fclose(f); - } else { - fprintf(stderr, "Error opening file %s\n", argv[1]); - exit(1); - } - - printf("Start with:\n"); - printRegs(NULL, reg_in); - - printf("\nStep 0:\n"); - printRegs(reg_in, reg_out[0]); - - for (int i=1;i < steps;i++) { - printf("\nStep %d:\n", i); - printRegs(reg_out[i-1], reg_out[i]); - } - - exit(0); -} diff --git a/Source/DSPTool/Src/main.cpp b/Source/DSPTool/Src/main.cpp index cea5c879f6..06ffb50b6a 100644 --- a/Source/DSPTool/Src/main.cpp +++ b/Source/DSPTool/Src/main.cpp @@ -17,6 +17,7 @@ #include "Common.h" #include "FileUtil.h" +#include "StringUtil.h" #include "DSPCodeUtil.h" // Stub out the dsplib host stuff, since this is just a simple cmdline tools. @@ -202,23 +203,25 @@ void RunAsmTests() // Disassemble a file, output to standard output: // dsptool -d asdf.bin // Assemble a file: -// dsptool -o asdf.bin asdf.txt +// dsptool [-f] -o asdf.bin asdf.txt // Assemble a file, output header: -// dsptool -h asdf.h asdf.txt -// dsptool -f errors are not critical +// dsptool [-f] -h asdf.h asdf.txt +// Print results from DSPSpy register dump +// dsptool -p dsp_dump0.bin // So far, all this binary can do is test partially that itself works correctly. int main(int argc, const char *argv[]) { if(argc == 1 || (argc == 2 && (!strcmp(argv[1], "--help") || (!strcmp(argv[1], "-?"))))) { - printf("USAGE: DSPTool [-?] [--help] [-d] [-m] [-o ] [-h ] \n"); + printf("USAGE: DSPTool [-?] [--help] [-f] [-d] [-m] [-p ] [-o ] [-h ] \n"); printf("-? / --help: Prints this message\n"); printf("-d: Disassemble\n"); printf("-m: Input file contains a list of files (Header assembly only)\n"); printf("-s: Print the final size in bytes (only)\n"); + printf("-f: Force assembly (errors are not critical)\n"); printf("-o : Results from stdout redirected to a file\n"); printf("-h
: Output assembly results to a header\n"); - printf("-f: Errors are not critical\n"); + printf("-p : Print results of DSPSpy register dump\n"); return 0; } @@ -232,7 +235,7 @@ int main(int argc, const char *argv[]) std::string output_header_name; std::string output_name; - bool disassemble = false, compare = false, multiple = false, outputSize = false, force = false; + bool disassemble = false, compare = false, multiple = false, outputSize = false, force = false, print_results = false; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d")) @@ -249,6 +252,8 @@ int main(int argc, const char *argv[]) multiple = true; else if (!strcmp(argv[i], "-f")) force = true; + else if (!strcmp(argv[i], "-p")) + print_results = true; else { if (!input_name.empty()) @@ -285,6 +290,50 @@ int main(int argc, const char *argv[]) return 0; } + if (print_results) + { + std::string dumpfile, results; + std::vector reg_vector; + + File::ReadFileToString(false, input_name.c_str(), dumpfile); + BinaryStringBEToCode(dumpfile, reg_vector); + + results.append("Start:\n"); + for (int initial_reg = 0; initial_reg < 32; initial_reg++) + { + results.append(StringFromFormat("%02x %04x ", initial_reg, reg_vector.at(initial_reg))); + if ((initial_reg + 1) % 8 == 0) + results.append("\n"); + } + results.append("\n"); + results.append("Step [number]:\n[Reg] [last value] [current value]\n\n"); + for (int step = 1; step < reg_vector.size()/32; step++) + { + bool changed = false; + results.append(StringFromFormat("Step %3d:\n", step)); + for (int reg = 0; reg < 32; reg++) + { + u16 last_reg = reg_vector.at((step*32-32)+reg); + u16 current_reg = reg_vector.at(step*32+reg); + if (last_reg != current_reg) + { + results.append(StringFromFormat("%02x %04x %04x\n", reg, last_reg, current_reg)); + changed = true; + } + } + if (!changed) + results.append("No Change\n\n"); + else + results.append("\n"); + } + + if (!output_name.empty()) + File::WriteStringToFile(true, results, output_name.c_str()); + else + printf(results.c_str()); + return 0; + } + if (disassemble) { if (input_name.empty())