diff --git a/src/cpu/core_normal/table_ea.h b/src/cpu/core_normal/table_ea.h index 279e0ee79..a01de57b3 100644 --- a/src/cpu/core_normal/table_ea.h +++ b/src/cpu/core_normal/table_ea.h @@ -174,8 +174,6 @@ static GetEAHandler EATable[512]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -extern bool do_seg_limits; - #define GetEADirect(sz) \ PhysPt eaa; \ if (TEST_PREFIX_ADDR) \ diff --git a/src/cpu/core_normal_286.cpp b/src/cpu/core_normal_286.cpp index b8e5b0ab4..ed1cf84f8 100644 --- a/src/cpu/core_normal_286.cpp +++ b/src/cpu/core_normal_286.cpp @@ -29,6 +29,14 @@ bool CPU_WRMSR(); bool CPU_SYSENTER(); bool CPU_SYSEXIT(); +/* wrap original variable name in inline function prior to #define, use inline function name in redefine of do_seg_limits */ +static inline bool _seg_limit_check(void) { + return do_seg_limits; +} + +/* Do not emulate segment limit exceptions on 80186, DO emulate on 286. */ +#define do_seg_limits (_seg_limit_check() && CPU_ArchitectureType >= CPU_ARCHTYPE_286) + #define PRE_EXCEPTION { } #define CPU_CORE CPU_ARCHTYPE_286 diff --git a/src/cpu/core_normal_8086.cpp b/src/cpu/core_normal_8086.cpp index 0bfc15a4d..40d36937d 100644 --- a/src/cpu/core_normal_8086.cpp +++ b/src/cpu/core_normal_8086.cpp @@ -22,6 +22,10 @@ #include "pic.h" #include "fpu.h" +/* Do not emulate segment limit exceptions on 8086. This turns the if() statements into if (0) + * and the C++ compiler optimizer should then completely omit the code for the 8086 cputype. */ +#define do_seg_limits (0) + /* 8086: Apparently exceptions like DIVIDE BY ZERO are given a return address of the next instruction */ #define PRE_EXCEPTION SAVEIP diff --git a/src/cpu/core_prefetch_286.cpp b/src/cpu/core_prefetch_286.cpp index 64d965ad8..f9b094149 100644 --- a/src/cpu/core_prefetch_286.cpp +++ b/src/cpu/core_prefetch_286.cpp @@ -34,6 +34,14 @@ bool CPU_WRMSR(); bool CPU_SYSENTER(); bool CPU_SYSEXIT(); +/* wrap original variable name in inline function prior to #define, use inline function name in redefine of do_seg_limits */ +static inline bool _seg_limit_check(void) { + return do_seg_limits; +} + +/* Do not emulate segment limit exceptions on 80186, DO emulate on 286. */ +#define do_seg_limits (_seg_limit_check() && CPU_ArchitectureType >= CPU_ARCHTYPE_286) + #define PRE_EXCEPTION { } #define CPU_CORE CPU_ARCHTYPE_286 diff --git a/src/cpu/core_prefetch_8086.cpp b/src/cpu/core_prefetch_8086.cpp index 4da287615..cbd4c1c1d 100644 --- a/src/cpu/core_prefetch_8086.cpp +++ b/src/cpu/core_prefetch_8086.cpp @@ -29,6 +29,10 @@ using namespace std; #include +/* Do not emulate segment limit exceptions on 8086. This turns the if() statements into if (0) + * and the C++ compiler optimizer should then completely omit the code for the 8086 cputype. */ +#define do_seg_limits (0) + /* 8086: Apparently exceptions like DIVIDE BY ZERO are given a return address of the next instruction */ #define PRE_EXCEPTION SAVEIP