diff --git a/src/386.c b/src/386.c index 4568199..8b81393 100644 --- a/src/386.c +++ b/src/386.c @@ -12,53 +12,25 @@ #include "nmi.h" #include "386_common.h" +#include "codegen.h" +#undef CPU_BLOCK_END #define CPU_BLOCK_END() -extern int codegen_flags_changed; - -extern int nmi_enable; - uint32_t use32; int stack32; int optype; -uint32_t oldpc2; - int trap; - - -extern int cpl_override; - -int has_fpu; -extern int fpucount; -uint16_t ea_rseg; - -int is486; -int cgate32; - - - -uint8_t romext[32768]; -uint8_t *ram,*rom; - uint32_t rmdat; -uint32_t backupregs[16]; -extern int oddeven; -int inttype; - - -uint32_t oldecx; - uint32_t *eal_r, *eal_w; static inline void fetch_ea_32_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; if (cpu_rm == 4) { uint8_t sib = rmdat >> 8; @@ -85,7 +57,6 @@ static inline void fetch_ea_32_long(uint32_t rmdat) else if ((sib & 6) == 4 && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } if (((sib >> 3) & 7) != 4) @@ -99,7 +70,6 @@ static inline void fetch_ea_32_long(uint32_t rmdat) if (cpu_rm == 5 && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } if (cpu_mod == 1) @@ -131,8 +101,7 @@ static inline void fetch_ea_16_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; - if (!cpu_mod && cpu_rm == 6) + if (!cpu_mod && cpu_rm == 6) { cpu_state.eaaddr = getword(); } @@ -154,7 +123,6 @@ static inline void fetch_ea_16_long(uint32_t rmdat) if (mod1seg[cpu_rm] == &ss && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } cpu_state.eaaddr &= 0xFFFF; @@ -178,19 +146,7 @@ static inline void fetch_ea_16_long(uint32_t rmdat) #define getwordf() ((uint16_t)(fetchdat)); cpu_state.pc+=2 #define getbyte2f() ((uint8_t)(fetchdat>>8)); cpu_state.pc++ #define getword2f() ((uint16_t)(fetchdat>>8)); cpu_state.pc+=2 -extern int xout; -int oldi; - -uint32_t testr[9]; -extern int dontprint; - -#undef NOTRM -#define NOTRM if (!(msw & 1) || (eflags & VM_FLAG))\ - { \ - x86_int(6); \ - return 0; \ - } #define OP_TABLE(name) ops_ ## name @@ -199,13 +155,6 @@ extern int dontprint; #include "x86_ops.h" -#undef NOTRM -#define NOTRM if (!(msw & 1) || (eflags & VM_FLAG))\ - { \ - x86_int(6); \ - break; \ - } - void exec386(int cycs) { uint8_t temp; @@ -226,16 +175,9 @@ void exec386(int cycs) // pclog("%i %02X\n", ins, ram[8]); while (cycdiff < cycle_period) { - /* testr[0]=EAX; testr[1]=EBX; testr[2]=ECX; testr[3]=EDX; - testr[4]=ESI; testr[5]=EDI; testr[6]=EBP; testr[7]=ESP;*/ -/* testr[8]=flags;*/ -// oldpc2=oldpc; - cpu_state.oldpc = cpu_state.pc; cpu_state.op32 = use32; -dontprint=0; - cpu_state.ea_seg = &cpu_state.seg_ds; cpu_state.ssegs = 0; @@ -262,15 +204,6 @@ dontprint=0; flags_rebuild(); // pclog("Abort\n"); // if (CS == 0x228) pclog("Abort at %04X:%04X - %i %i %i\n",CS,pc,notpresent,nullseg,abrt); -/* if (testr[0]!=EAX) pclog("EAX corrupted %08X\n",pc); - if (testr[1]!=EBX) pclog("EBX corrupted %08X\n",pc); - if (testr[2]!=ECX) pclog("ECX corrupted %08X\n",pc); - if (testr[3]!=EDX) pclog("EDX corrupted %08X\n",pc); - if (testr[4]!=ESI) pclog("ESI corrupted %08X\n",pc); - if (testr[5]!=EDI) pclog("EDI corrupted %08X\n",pc); - if (testr[6]!=EBP) pclog("EBP corrupted %08X\n",pc); - if (testr[7]!=ESP) pclog("ESP corrupted %08X\n",pc);*/ -/* if (testr[8]!=flags) pclog("FLAGS corrupted %08X\n",pc);*/ tempi = cpu_state.abrt; cpu_state.abrt = 0; x86_doabrt(tempi); diff --git a/src/386_common.h b/src/386_common.h index cf12239..e49bdda 100644 --- a/src/386_common.h +++ b/src/386_common.h @@ -1,14 +1,9 @@ -extern uint16_t ea_rseg; - -#undef readmemb -#undef writememb - - #define readmemb(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1)?readmembl((s)+(a)): *(uint8_t *)(readlookup2[(uint32_t)((s)+(a))>>12] + (uint32_t)((s) + (a))) ) +#define readmemw(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 1))?readmemwl((s)+(a)):*(uint16_t *)(readlookup2[(uint32_t)((s)+(a))>>12]+(uint32_t)((s)+(a)))) +#define readmeml(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 3))?readmemll((s)+(a)):*(uint32_t *)(readlookup2[(uint32_t)((s)+(a))>>12]+(uint32_t)((s)+(a)))) #define readmemq(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 7))?readmemql((s)+(a)):*(uint64_t *)(readlookup2[(uint32_t)((s)+(a))>>12]+(uint32_t)((s)+(a)))) #define writememb(s,a,v) if (writelookup2[(uint32_t)((s)+(a))>>12]==-1) writemembl((s)+(a),v); else *(uint8_t *)(writelookup2[(uint32_t)((s) + (a)) >> 12] + (uint32_t)((s) + (a))) = v - #define writememw(s,a,v) if (writelookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 1)) writememwl((s)+(a),v); else *(uint16_t *)(writelookup2[(uint32_t)((s) + (a)) >> 12] + (uint32_t)((s) + (a))) = v #define writememl(s,a,v) if (writelookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 3)) writememll((s)+(a),v); else *(uint32_t *)(writelookup2[(uint32_t)((s) + (a)) >> 12] + (uint32_t)((s) + (a))) = v #define writememq(s,a,v) if (writelookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 7)) writememql((s)+(a),v); else *(uint64_t *)(writelookup2[(uint32_t)((s) + (a)) >> 12] + (uint32_t)((s) + (a))) = v @@ -183,7 +178,6 @@ static inline uint16_t geteaw() { if (cpu_mod == 3) return cpu_state.regs[cpu_rm].w; -// cycles-=3; if (eal_r) return *(uint16_t *)eal_r; return readmemw(easeg,cpu_state.eaaddr); @@ -193,7 +187,6 @@ static inline uint32_t geteal() { if (cpu_mod == 3) return cpu_state.regs[cpu_rm].l; -// cycles-=3; if (eal_r) return *eal_r; return readmeml(easeg,cpu_state.eaaddr); @@ -237,6 +230,3 @@ static inline void seteaq(uint64_t v) #define getwordf() ((uint16_t)(fetchdat)); cpu_state.pc+=2 #define getbyte2f() ((uint8_t)(fetchdat>>8)); cpu_state.pc++ #define getword2f() ((uint16_t)(fetchdat>>8)); cpu_state.pc+=2 - - -void x86_int(int num); diff --git a/src/386_dynarec.c b/src/386_dynarec.c index 43388fc..3f9f3f8 100644 --- a/src/386_dynarec.c +++ b/src/386_dynarec.c @@ -31,37 +31,15 @@ int cpu_block_end = 0; int nmi_enable = 1; -uint32_t oldpc2; - -int trap; - - - int cpl_override=0; -int has_fpu; int fpucount=0; -uint16_t ea_rseg; -int is486; -int cgate32; - - -uint8_t romext[32768]; -uint8_t *ram,*rom; - -uint32_t backupregs[16]; -int oddeven=0; -int inttype; - - -uint32_t oldecx; static inline void fetch_ea_32_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; if (cpu_rm == 4) { uint8_t sib = rmdat >> 8; @@ -88,7 +66,6 @@ static inline void fetch_ea_32_long(uint32_t rmdat) else if ((sib & 6) == 4 && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } if (((sib >> 3) & 7) != 4) @@ -102,7 +79,6 @@ static inline void fetch_ea_32_long(uint32_t rmdat) if (cpu_rm == 5 && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } if (cpu_mod == 1) @@ -134,8 +110,7 @@ static inline void fetch_ea_16_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; - if (!cpu_mod && cpu_rm == 6) + if (!cpu_mod && cpu_rm == 6) { cpu_state.eaaddr = getword(); } @@ -157,7 +132,6 @@ static inline void fetch_ea_16_long(uint32_t rmdat) if (mod1seg[cpu_rm] == &ss && !cpu_state.ssegs) { easeg = ss; - ea_rseg = SS; cpu_state.ea_seg = &cpu_state.seg_ss; } cpu_state.eaaddr &= 0xFFFF; @@ -423,9 +397,6 @@ int checkio(int port) return d&(1<<(port&7)); } -int xout=0; - - #define divexcp() { \ pclog("Divide exception at %04X(%06X):%04X\n",CS,cs,cpu_state.pc); \ x86_int(0); \ @@ -482,11 +453,6 @@ void cpu_386_flags_rebuild() flags_rebuild(); } -int oldi; - -uint32_t testr[9]; -int dontprint=0; - #define OP_TABLE(name) ops_ ## name #define CLOCK_CYCLES(c) cycles -= (c) #define CLOCK_CYCLES_ALWAYS(c) cycles -= (c) diff --git a/src/386_dynarec_ops.c b/src/386_dynarec_ops.c index 1b77f71..249909f 100644 --- a/src/386_dynarec_ops.c +++ b/src/386_dynarec_ops.c @@ -18,7 +18,6 @@ static inline void fetch_ea_32_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; if (easeg != 0xFFFFFFFF && ((easeg + cpu_state.eaaddr) & 0xFFF) <= 0xFFC) { uint32_t addr = easeg + cpu_state.eaaddr; @@ -33,7 +32,6 @@ static inline void fetch_ea_16_long(uint32_t rmdat) { eal_r = eal_w = NULL; easeg = cpu_state.ea_seg->base; - ea_rseg = cpu_state.ea_seg->seg; if (easeg != 0xFFFFFFFF && ((easeg + cpu_state.eaaddr) & 0xFFF) <= 0xFFC) { uint32_t addr = easeg + cpu_state.eaaddr; diff --git a/src/808x.c b/src/808x.c index fa83679..f53b3df 100644 --- a/src/808x.c +++ b/src/808x.c @@ -40,8 +40,6 @@ void FETCHCOMPLETE(); #define IRQTEST ((cpu_state.flags & I_FLAG) && (pic.pend&~pic.mask) && !noint) -#undef readmemb -#undef readmemw uint8_t readmemb(uint32_t a) { if (a!=(cs+cpu_state.pc)) memcycs+=4; @@ -479,8 +477,6 @@ void makeznptable() } int timetolive=0; -extern uint32_t oldpc2; - int indump = 0; void dumpregs() @@ -568,7 +564,7 @@ void dumpregs() else printf("AX=%04X BX=%04X CX=%04X DX=%04X DI=%04X SI=%04X BP=%04X SP=%04X\n",AX,BX,CX,DX,DI,SI,BP,SP); printf("PC=%04X CS=%04X DS=%04X ES=%04X SS=%04X FLAGS=%04X\n",cpu_state.pc,CS,DS,ES,SS,cpu_state.flags); - printf("%04X %04X\n",cpu_state.oldpc, oldpc2); + printf("%04X\n",cpu_state.oldpc); printf("%i ins\n",ins); if (is386) printf("In %s mode\n",(msw&1)?((cpu_state.eflags&VM_FLAG)?"V86":"protected"):"real"); diff --git a/src/cpu.c b/src/cpu.c index accff09..29d4da2 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -102,6 +102,8 @@ int is386; uint64_t tsc = 0; +int is486; + int timing_rr; int timing_mr, timing_mrl; int timing_rm, timing_rml; diff --git a/src/ibm.h b/src/ibm.h index 9b3a07a..7978dc2 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -32,10 +32,6 @@ int writelnext; extern int mmu_perm; -#define readmemb(a) ((readlookup2[(a)>>12]==-1)?readmembl(a):*(uint8_t *)(readlookup2[(a) >> 12] + (a))) -#define readmemw(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 1))?readmemwl((s)+(a)):*(uint16_t *)(readlookup2[(uint32_t)((s)+(a))>>12]+(uint32_t)((s)+(a)))) -#define readmeml(s,a) ((readlookup2[(uint32_t)((s)+(a))>>12]==-1 || (((s)+(a)) & 3))?readmemll((s)+(a)):*(uint32_t *)(readlookup2[(uint32_t)((s)+(a))>>12]+(uint32_t)((s)+(a)))) - uint8_t readmembl(uint32_t addr); void writemembl(uint32_t addr, uint8_t val); uint16_t readmemwl(uint32_t addr); diff --git a/src/pc.c b/src/pc.c index d574087..f770211 100644 --- a/src/pc.c +++ b/src/pc.c @@ -913,7 +913,6 @@ void saveconfig(char *fn) config_set_int(CFG_MACHINE, NULL, "video_speed", video_speed); config_set_string(CFG_MACHINE, NULL, "sndcard", sound_card_get_internal_name(sound_card_current)); config_set_int(CFG_MACHINE, NULL, "cpu_speed", cpuspeed); - config_set_int(CFG_MACHINE, NULL, "has_fpu", hasfpu); config_set_string(CFG_MACHINE, NULL, "disc_a", discfns[0]); config_set_string(CFG_MACHINE, NULL, "disc_b", discfns[1]); config_set_string(CFG_MACHINE, NULL, "hdd_controller", hdd_controller_name); diff --git a/src/x86.h b/src/x86.h index 5f0be4d..a656124 100644 --- a/src/x86.h +++ b/src/x86.h @@ -7,6 +7,8 @@ extern int oldcpl; extern int nmi_enable; +extern int trap; + extern int output; extern int timetolive; @@ -88,6 +90,8 @@ void loadcscall(uint16_t seg, uint32_t old_pc); void loadcsjmp(uint16_t seg, uint32_t old_pc); void pmoderetf(int is32, uint16_t off); void pmodeiret(int is32); + +void x86_int(int num); void x86_int_sw(int num); int x86_int_sw_rm(int num); diff --git a/src/x86_ops_rep.h b/src/x86_ops_rep.h index 4adfcb1..d19a8f2 100644 --- a/src/x86_ops_rep.h +++ b/src/x86_ops_rep.h @@ -1,5 +1,3 @@ -extern int trap; - #define REP_OPS(size, CNT_REG, SRC_REG, DEST_REG) \ static int opREP_INSB_ ## size(uint32_t fetchdat) \ { \