From 3d1e52e6e91207aedcddadff7257aed83a01bb97 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 20 Sep 2018 18:08:34 +0200 Subject: [PATCH] Slight changes to CPU and FPU instruction logging. --- src/cpu/386_dynarec.c | 2 +- src/cpu/386_dynarec_ops.c | 1 + src/cpu/x87.c | 42 ++++++++++++++++++++++------- src/cpu/x87_ops.h | 6 ++--- src/cpu/x87_ops_arith.h | 56 +++++++++++++++++++-------------------- 5 files changed, 65 insertions(+), 42 deletions(-) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index a3ff0c0ee..f7e5dea68 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -77,7 +77,7 @@ int x386_dynarec_do_log = ENABLE_386_DYNAREC_LOG; #endif -static void +void x386_dynarec_log(const char *fmt, ...) { #ifdef ENABLE_386_DYNAREC_LOG diff --git a/src/cpu/386_dynarec_ops.c b/src/cpu/386_dynarec_ops.c index d3dd4688d..a47095e88 100644 --- a/src/cpu/386_dynarec_ops.c +++ b/src/cpu/386_dynarec_ops.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/src/cpu/x87.c b/src/cpu/x87.c index d85cd54ce..b7de97394 100644 --- a/src/cpu/x87.c +++ b/src/cpu/x87.c @@ -1,9 +1,11 @@ -#include +#include #include +#include #include #include #define fplog 0 #include +#define HAVE_STDARG_H #include "../86box.h" #include "cpu.h" #include "../mem.h" @@ -15,6 +17,26 @@ #include "386_common.h" +#ifdef ENABLE_FPU_LOG +int fpu_do_log = ENABLE_FPU_LOG; +#endif + + +static void +fpu_log(const char *fmt, ...) +{ +#ifdef ENABLE_FPU_LOG + va_list ap; + + if (fpu_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +#endif +} + + uint16_t x87_gettag() { uint16_t ret = 0; @@ -47,28 +69,28 @@ void x87_dumpregs() { if (cpu_state.ismmx) { - pclog("MM0=%016llX\tMM1=%016llX\tMM2=%016llX\tMM3=%016llX\n", cpu_state.MM[0].q, cpu_state.MM[1].q, cpu_state.MM[2].q, cpu_state.MM[3].q); - pclog("MM4=%016llX\tMM5=%016llX\tMM6=%016llX\tMM7=%016llX\n", cpu_state.MM[4].q, cpu_state.MM[5].q, cpu_state.MM[6].q, cpu_state.MM[7].q); + fpu_log("MM0=%016llX\tMM1=%016llX\tMM2=%016llX\tMM3=%016llX\n", cpu_state.MM[0].q, cpu_state.MM[1].q, cpu_state.MM[2].q, cpu_state.MM[3].q); + fpu_log("MM4=%016llX\tMM5=%016llX\tMM6=%016llX\tMM7=%016llX\n", cpu_state.MM[4].q, cpu_state.MM[5].q, cpu_state.MM[6].q, cpu_state.MM[7].q); } else { - pclog("ST(0)=%f\tST(1)=%f\tST(2)=%f\tST(3)=%f\t\n",cpu_state.ST[cpu_state.TOP],cpu_state.ST[(cpu_state.TOP+1)&7],cpu_state.ST[(cpu_state.TOP+2)&7],cpu_state.ST[(cpu_state.TOP+3)&7]); - pclog("ST(4)=%f\tST(5)=%f\tST(6)=%f\tST(7)=%f\t\n",cpu_state.ST[(cpu_state.TOP+4)&7],cpu_state.ST[(cpu_state.TOP+5)&7],cpu_state.ST[(cpu_state.TOP+6)&7],cpu_state.ST[(cpu_state.TOP+7)&7]); + fpu_log("ST(0)=%f\tST(1)=%f\tST(2)=%f\tST(3)=%f\t\n",cpu_state.ST[cpu_state.TOP],cpu_state.ST[(cpu_state.TOP+1)&7],cpu_state.ST[(cpu_state.TOP+2)&7],cpu_state.ST[(cpu_state.TOP+3)&7]); + fpu_log("ST(4)=%f\tST(5)=%f\tST(6)=%f\tST(7)=%f\t\n",cpu_state.ST[(cpu_state.TOP+4)&7],cpu_state.ST[(cpu_state.TOP+5)&7],cpu_state.ST[(cpu_state.TOP+6)&7],cpu_state.ST[(cpu_state.TOP+7)&7]); } - pclog("Status = %04X Control = %04X Tag = %04X\n", cpu_state.npxs, cpu_state.npxc, x87_gettag()); + fpu_log("Status = %04X Control = %04X Tag = %04X\n", cpu_state.npxs, cpu_state.npxc, x87_gettag()); } void x87_print() { if (cpu_state.ismmx) { - pclog("\tMM0=%016llX\tMM1=%016llX\tMM2=%016llX\tMM3=%016llX\t", cpu_state.MM[0].q, cpu_state.MM[1].q, cpu_state.MM[2].q, cpu_state.MM[3].q); - pclog("MM4=%016llX\tMM5=%016llX\tMM6=%016llX\tMM7=%016llX\n", cpu_state.MM[4].q, cpu_state.MM[5].q, cpu_state.MM[6].q, cpu_state.MM[7].q); + fpu_log("\tMM0=%016llX\tMM1=%016llX\tMM2=%016llX\tMM3=%016llX\t", cpu_state.MM[0].q, cpu_state.MM[1].q, cpu_state.MM[2].q, cpu_state.MM[3].q); + fpu_log("MM4=%016llX\tMM5=%016llX\tMM6=%016llX\tMM7=%016llX\n", cpu_state.MM[4].q, cpu_state.MM[5].q, cpu_state.MM[6].q, cpu_state.MM[7].q); } else { - pclog("\tST(0)=%.20f\tST(1)=%.20f\tST(2)=%f\tST(3)=%f\t",cpu_state.ST[cpu_state.TOP&7],cpu_state.ST[(cpu_state.TOP+1)&7],cpu_state.ST[(cpu_state.TOP+2)&7],cpu_state.ST[(cpu_state.TOP+3)&7]); - pclog("ST(4)=%f\tST(5)=%f\tST(6)=%f\tST(7)=%f\tTOP=%i CR=%04X SR=%04X TAG=%04X\n",cpu_state.ST[(cpu_state.TOP+4)&7],cpu_state.ST[(cpu_state.TOP+5)&7],cpu_state.ST[(cpu_state.TOP+6)&7],cpu_state.ST[(cpu_state.TOP+7)&7], cpu_state.TOP, cpu_state.npxc, cpu_state.npxs, x87_gettag()); + fpu_log("\tST(0)=%.20f\tST(1)=%.20f\tST(2)=%f\tST(3)=%f\t",cpu_state.ST[cpu_state.TOP&7],cpu_state.ST[(cpu_state.TOP+1)&7],cpu_state.ST[(cpu_state.TOP+2)&7],cpu_state.ST[(cpu_state.TOP+3)&7]); + fpu_log("ST(4)=%f\tST(5)=%f\tST(6)=%f\tST(7)=%f\tTOP=%i CR=%04X SR=%04X TAG=%04X\n",cpu_state.ST[(cpu_state.TOP+4)&7],cpu_state.ST[(cpu_state.TOP+5)&7],cpu_state.ST[(cpu_state.TOP+6)&7],cpu_state.ST[(cpu_state.TOP+7)&7], cpu_state.TOP, cpu_state.npxc, cpu_state.npxs, x87_gettag()); } } diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index d1fd0b464..a5e42ce80 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -8,7 +8,7 @@ * * x87 FPU instructions core. * - * Version: @(#)x87_ops.h 1.0.5 2018/05/05 + * Version: @(#)x87_ops.h 1.0.6 2018/08/01 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -66,7 +66,7 @@ static int rounding_modes[4] = {FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZ dst = src1 / (double)src2; \ else \ { \ - pclog("FPU : divide by zero\n"); \ + x386_dynarec_log("FPU : divide by zero\n"); \ picint(1 << 13); \ } \ return 1; \ @@ -289,7 +289,7 @@ static __inline uint16_t x87_compare(double a, double b) { if (((a == INFINITY) || (a == -INFINITY)) && ((b == INFINITY) || (b == -INFINITY))) { - /* pclog("Comparing infinity\n"); */ + /* x386_dynarec_log("Comparing infinity\n"); */ #ifndef _MSC_VER __asm volatile ("" : : : "memory"); diff --git a/src/cpu/x87_ops_arith.h b/src/cpu/x87_ops_arith.h index f53ad9213..0e58db63c 100644 --- a/src/cpu/x87_ops_arith.h +++ b/src/cpu/x87_ops_arith.h @@ -111,7 +111,7 @@ static int opFADD(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FADD\n"); + x386_dynarec_log("FADD\n"); ST(0) = ST(0) + ST(fetchdat & 7); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -121,7 +121,7 @@ static int opFADDr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FADD\n"); + x386_dynarec_log("FADD\n"); ST(fetchdat & 7) = ST(fetchdat & 7) + ST(0); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -131,7 +131,7 @@ static int opFADDP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FADDP\n"); + x386_dynarec_log("FADDP\n"); ST(fetchdat & 7) = ST(fetchdat & 7) + ST(0); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -143,7 +143,7 @@ static int opFCOM(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FCOM\n"); + x386_dynarec_log("FCOM\n"); cpu_state.npxs &= ~(C0|C2|C3); if (ST(0) == ST(fetchdat & 7)) cpu_state.npxs |= C3; else if (ST(0) < ST(fetchdat & 7)) cpu_state.npxs |= C0; @@ -155,7 +155,7 @@ static int opFCOMP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FCOMP\n"); + x386_dynarec_log("FCOMP\n"); cpu_state.npxs &= ~(C0|C2|C3); cpu_state.npxs |= x87_compare(ST(0), ST(fetchdat & 7)); x87_pop(); @@ -168,7 +168,7 @@ static int opFCOMPP(uint32_t fetchdat) uint64_t *p, *q; FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FCOMPP\n"); + x386_dynarec_log("FCOMPP\n"); cpu_state.npxs &= ~(C0|C2|C3); p = (uint64_t *)&ST(0); q = (uint64_t *)&ST(1); @@ -186,7 +186,7 @@ static int opFUCOMPP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FUCOMPP\n", easeg, cpu_state.eaaddr); + x386_dynarec_log("FUCOMPP\n", easeg, cpu_state.eaaddr); cpu_state.npxs &= ~(C0|C2|C3); cpu_state.npxs |= x87_ucompare(ST(0), ST(1)); x87_pop(); @@ -199,7 +199,7 @@ static int opFCOMI(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FICOM\n"); + x386_dynarec_log("FICOM\n"); flags_rebuild(); flags &= ~(Z_FLAG | P_FLAG | C_FLAG); if (ST(0) == ST(fetchdat & 7)) flags |= Z_FLAG; @@ -211,7 +211,7 @@ static int opFCOMIP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FICOMP\n"); + x386_dynarec_log("FICOMP\n"); flags_rebuild(); flags &= ~(Z_FLAG | P_FLAG | C_FLAG); if (ST(0) == ST(fetchdat & 7)) flags |= Z_FLAG; @@ -225,7 +225,7 @@ static int opFDIV(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIV\n"); + x386_dynarec_log("FDIV\n"); x87_div(ST(0), ST(0), ST(fetchdat & 7)); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(73); @@ -235,7 +235,7 @@ static int opFDIVr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIV\n"); + x386_dynarec_log("FDIV\n"); x87_div(ST(fetchdat & 7), ST(fetchdat & 7), ST(0)); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(73); @@ -245,7 +245,7 @@ static int opFDIVP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIVP\n"); + x386_dynarec_log("FDIVP\n"); x87_div(ST(fetchdat & 7), ST(fetchdat & 7), ST(0)); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -257,7 +257,7 @@ static int opFDIVR(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIVR\n"); + x386_dynarec_log("FDIVR\n"); x87_div(ST(0), ST(fetchdat&7), ST(0)); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(73); @@ -267,7 +267,7 @@ static int opFDIVRr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIVR\n"); + x386_dynarec_log("FDIVR\n"); x87_div(ST(fetchdat & 7), ST(0), ST(fetchdat & 7)); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(73); @@ -277,7 +277,7 @@ static int opFDIVRP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FDIVR\n"); + x386_dynarec_log("FDIVR\n"); x87_div(ST(fetchdat & 7), ST(0), ST(fetchdat & 7)); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -289,7 +289,7 @@ static int opFMUL(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FMUL\n"); + x386_dynarec_log("FMUL\n"); ST(0) = ST(0) * ST(fetchdat & 7); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(16); @@ -299,7 +299,7 @@ static int opFMULr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FMUL\n"); + x386_dynarec_log("FMUL\n"); ST(fetchdat & 7) = ST(0) * ST(fetchdat & 7); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(16); @@ -309,7 +309,7 @@ static int opFMULP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FMULP\n"); + x386_dynarec_log("FMULP\n"); ST(fetchdat & 7) = ST(0) * ST(fetchdat & 7); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -321,7 +321,7 @@ static int opFSUB(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUB\n"); + x386_dynarec_log("FSUB\n"); ST(0) = ST(0) - ST(fetchdat & 7); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -331,7 +331,7 @@ static int opFSUBr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUB\n"); + x386_dynarec_log("FSUB\n"); ST(fetchdat & 7) = ST(fetchdat & 7) - ST(0); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -341,7 +341,7 @@ static int opFSUBP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUBP\n"); + x386_dynarec_log("FSUBP\n"); ST(fetchdat & 7) = ST(fetchdat & 7) - ST(0); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -353,7 +353,7 @@ static int opFSUBR(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUBR\n"); + x386_dynarec_log("FSUBR\n"); ST(0) = ST(fetchdat & 7) - ST(0); cpu_state.tag[cpu_state.TOP] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -363,7 +363,7 @@ static int opFSUBRr(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUBR\n"); + x386_dynarec_log("FSUBR\n"); ST(fetchdat & 7) = ST(0) - ST(fetchdat & 7); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; CLOCK_CYCLES(8); @@ -373,7 +373,7 @@ static int opFSUBRP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FSUBRP\n"); + x386_dynarec_log("FSUBRP\n"); ST(fetchdat & 7) = ST(0) - ST(fetchdat & 7); cpu_state.tag[(cpu_state.TOP + fetchdat) & 7] &= ~TAG_UINT64; x87_pop(); @@ -385,7 +385,7 @@ static int opFUCOM(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FUCOM\n"); + x386_dynarec_log("FUCOM\n"); cpu_state.npxs &= ~(C0|C2|C3); cpu_state.npxs |= x87_ucompare(ST(0), ST(fetchdat & 7)); CLOCK_CYCLES(4); @@ -396,7 +396,7 @@ static int opFUCOMP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FUCOMP\n"); + x386_dynarec_log("FUCOMP\n"); cpu_state.npxs &= ~(C0|C2|C3); cpu_state.npxs |= x87_ucompare(ST(0), ST(fetchdat & 7)); x87_pop(); @@ -408,7 +408,7 @@ static int opFUCOMI(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FUCOMI\n"); + x386_dynarec_log("FUCOMI\n"); flags_rebuild(); flags &= ~(Z_FLAG | P_FLAG | C_FLAG); if (ST(0) == ST(fetchdat & 7)) flags |= Z_FLAG; @@ -420,7 +420,7 @@ static int opFUCOMIP(uint32_t fetchdat) { FP_ENTER(); cpu_state.pc++; - if (fplog) pclog("FUCOMIP\n"); + x386_dynarec_log("FUCOMIP\n"); flags_rebuild(); flags &= ~(Z_FLAG | P_FLAG | C_FLAG); if (ST(0) == ST(fetchdat & 7)) flags |= Z_FLAG;