From 3978e059090494534f9b7b936ce7f5e69b0ac7bc Mon Sep 17 00:00:00 2001 From: ripsaw8080 Date: Mon, 1 Apr 2019 22:06:11 +0000 Subject: [PATCH] Improve prefetch and simple cores to not switch to normal core on trap execution. Fixes the demo version of Prehistorik 2 and similar cases that use the trap flag and prefetch tricks. Thanks NewRisingSun. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4201 --- include/cpu.h | 1 + src/cpu/core_normal.cpp | 2 ++ src/cpu/core_normal/prefix_66.h | 12 ++++++------ src/cpu/core_normal/prefix_none.h | 12 ++++++------ src/cpu/core_prefetch.cpp | 2 ++ src/cpu/core_simple.cpp | 5 +++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/cpu.h b/include/cpu.h index 7478f4ca..ecbabd7c 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -71,6 +71,7 @@ extern CPU_Decoder * cpudecoder; Bits CPU_Core_Normal_Run(void); Bits CPU_Core_Normal_Trap_Run(void); Bits CPU_Core_Simple_Run(void); +Bits CPU_Core_Simple_Trap_Run(void); Bits CPU_Core_Full_Run(void); Bits CPU_Core_Dyn_X86_Run(void); Bits CPU_Core_Dyn_X86_Trap_Run(void); diff --git a/src/cpu/core_normal.cpp b/src/cpu/core_normal.cpp index 0049c2c2..0d9cfc39 100644 --- a/src/cpu/core_normal.cpp +++ b/src/cpu/core_normal.cpp @@ -58,6 +58,8 @@ extern Bitu cycle_count; #define CPU_PIC_CHECK 1 #define CPU_TRAP_CHECK 1 +#define CPU_TRAP_DECODER CPU_Core_Normal_Trap_Run + #define OPCODE_NONE 0x000 #define OPCODE_0F 0x100 #define OPCODE_SIZE 0x200 diff --git a/src/cpu/core_normal/prefix_66.h b/src/cpu/core_normal/prefix_66.h index baa295e5..0c9218c7 100644 --- a/src/cpu/core_normal/prefix_66.h +++ b/src/cpu/core_normal/prefix_66.h @@ -390,7 +390,7 @@ CPU_CALL(true,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -403,7 +403,7 @@ if (CPU_POPF(true)) RUNEXCEPTION(); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; goto decode_end; } #endif @@ -515,7 +515,7 @@ CPU_IRET(true,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -589,7 +589,7 @@ CPU_JMP(true,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -677,7 +677,7 @@ CPU_CALL(true,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -697,7 +697,7 @@ CPU_JMP(true,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif diff --git a/src/cpu/core_normal/prefix_none.h b/src/cpu/core_normal/prefix_none.h index 525c4b9b..5d59e80c 100644 --- a/src/cpu/core_normal/prefix_none.h +++ b/src/cpu/core_normal/prefix_none.h @@ -564,7 +564,7 @@ CPU_CALL(false,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -579,7 +579,7 @@ if (CPU_POPF(false)) RUNEXCEPTION(); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; goto decode_end; } #endif @@ -780,7 +780,7 @@ CPU_IRET(false,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -919,7 +919,7 @@ CPU_JMP(false,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -1132,7 +1132,7 @@ CPU_CALL(false,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif @@ -1153,7 +1153,7 @@ CPU_JMP(false,newcs,newip,GETIP); #if CPU_TRAP_CHECK if (GETFLAG(TF)) { - cpudecoder=CPU_Core_Normal_Trap_Run; + cpudecoder=CPU_TRAP_DECODER; return CBRET_NONE; } #endif diff --git a/src/cpu/core_prefetch.cpp b/src/cpu/core_prefetch.cpp index 58e2df76..f718cd56 100644 --- a/src/cpu/core_prefetch.cpp +++ b/src/cpu/core_prefetch.cpp @@ -59,6 +59,8 @@ extern Bitu cycle_count; #define CPU_PIC_CHECK 1 #define CPU_TRAP_CHECK 1 +#define CPU_TRAP_DECODER CPU_Core_Prefetch_Trap_Run + #define OPCODE_NONE 0x000 #define OPCODE_0F 0x100 #define OPCODE_SIZE 0x200 diff --git a/src/cpu/core_simple.cpp b/src/cpu/core_simple.cpp index 96748190..9f18c3bc 100644 --- a/src/cpu/core_simple.cpp +++ b/src/cpu/core_simple.cpp @@ -50,6 +50,8 @@ extern Bitu cycle_count; #define CPU_PIC_CHECK 1 #define CPU_TRAP_CHECK 1 +#define CPU_TRAP_DECODER CPU_Core_Simple_Trap_Run + #define OPCODE_NONE 0x000 #define OPCODE_0F 0x100 #define OPCODE_SIZE 0x200 @@ -185,13 +187,12 @@ decode_end: return CBRET_NONE; } -// not really used Bits CPU_Core_Simple_Trap_Run(void) { Bits oldCycles = CPU_Cycles; CPU_Cycles = 1; cpu.trap_skip = false; - Bits ret=CPU_Core_Normal_Run(); + Bits ret=CPU_Core_Simple_Run(); if (!cpu.trap_skip) CPU_HW_Interrupt(1); CPU_Cycles = oldCycles-1; cpudecoder = &CPU_Core_Simple_Run;