Skip to content

Commit 9c6525a

Browse files
committed
simx86: FlagSync_All/RFL no longer work with TheCPU.eflags
Like the JIT, Exec_sim and Gen_sim no longer access the CC bits of TheCPU.eflags; they are passed via the *flg parameter of Exec_Sim. So FlagSync_All returns the CC bits and they are passed to FlagSync_RFL
1 parent e224ec5 commit 9c6525a

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/base/emu-i386/simx86/codegen-sim.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,25 @@ static inline int FlagSync_SZAPC (void)
264264
FlagSync_S() | FlagSync_P();
265265
}
266266

267-
void FlagSync_All (void)
267+
int FlagSync_All (void)
268268
{
269269
int nf = FlagSync_SZAPC() | FlagSync_O();
270270
if (debug_level('e')>1) e_printf("Sync ALL flags = %04x\n", nf);
271-
CPUWORD(Ofs_FLAGS) = (CPUWORD(Ofs_FLAGS) & ~EFLAGS_CC) | nf;
271+
return nf;
272272
}
273273

274274

275-
static void FlagSync_RFL (void)
275+
static void FlagSync_RFL (uint32_t flg)
276276
{
277277
/* encode all CC flags into RFL */
278-
uint32_t flg = CPULONG(Ofs_FLAGS);
278+
279279
/* AF/CF via rotation */
280280
uint32_t cout = ((flg << 31) | (flg >> 1)) & (LF_MASK_AF | LF_MASK_CF);
281281
/* PO derived from CF^OF */
282282
cout |= ((cout >> 1) ^ (flg << (LF_BIT_PO - X86_EFLAGS_OF_BIT))) & LF_MASK_PO;
283283
/* PF/SF in PD/SD; since parity of RFL.res is even, must flip PD */
284284
RFL.cout = cout | ((flg & (EFLAGS_SF|EFLAGS_PF)) ^ EFLAGS_PF);
285-
RFL.res = (!IS_ZF_SET) << 8;
285+
RFL.res = (!(flg & EFLAGS_ZF)) << 8;
286286
}
287287

288288
/////////////////////////////////////////////////////////////////////////////
@@ -1927,12 +1927,12 @@ unsigned int Gen_sim(const IGen *IG)
19271927
unsigned long stackm = CPULONG(Ofs_STACKM);
19281928
int ftmp;
19291929
GTRACE0("O_PUSHF");
1930-
FlagSync_All();
1930+
ftmp = (CPULONG(Ofs_FLAGS) & ~EFLAGS_CC) | FlagSync_All();
19311931
#if 0 // unused "extended PVI", if used should move to separate op
19321932
if (!V86MODE() && IOPL < 3 && (TheCPU.cr[4] & CR4_PVI))
19331933
ftmp = (ftmp & ~(EFLAGS_IF|EFLAGS_VIF)) | ((ftmp & EFLAGS_VIF) ? EFLAGS_IF : 0);
19341934
#endif
1935-
ftmp = CPULONG(Ofs_EFLAGS) & (RETURN_MASK|EFLAGS_IF);
1935+
ftmp &= (RETURN_MASK|EFLAGS_IF);
19361936
AR2.d = CPULONG(Ofs_XSS);
19371937
SR1.d = CPULONG(Ofs_ESP);
19381938
if (mode & DATA16) {
@@ -2452,10 +2452,7 @@ unsigned int Gen_sim(const IGen *IG)
24522452
}
24532453
else { /* SAHF */
24542454
GTRACE0("O_SAHF");
2455-
CPUWORD(Ofs_FLAGS) =
2456-
((FlagSync_O() | CPUBYTE(Ofs_AH)) & EFLAGS_CC) |
2457-
(CPUWORD(Ofs_FLAGS) & ~EFLAGS_CC);
2458-
FlagSync_RFL();
2455+
FlagSync_RFL(FlagSync_O() | CPUBYTE(Ofs_AH));
24592456
} }
24602457
break;
24612458
case O_SETFL: {
@@ -2805,16 +2802,15 @@ static unsigned Exec_sim(unsigned *mem_ref, unsigned long *flg,
28052802
IGen *IG = SeqStart;
28062803
unsigned int P0;
28072804

2808-
FlagSync_RFL();
2805+
FlagSync_RFL(*flg);
28092806
do {
28102807
currentIG = (unsigned char *)IG;
28112808
P0 = Gen_sim(IG);
28122809
IG++;
28132810
} while (P0 == (unsigned int)-1);
28142811
currentIG = NULL;
28152812
*mem_ref = TheCPU.mem_ref;
2816-
FlagSync_All();
2817-
*flg = EFLAGS & EFLAGS_CC;
2813+
*flg = FlagSync_All();
28182814

28192815
#ifdef DEBUG_MORE
28202816
if (debug_level('e')>1)
@@ -2861,6 +2857,7 @@ static void emu_pagefault_handler(dosaddr_t addr, int err, uint32_t op, int len)
28612857
LONG_CS = _LONG_CS;
28622858
unsigned int P0 = FindPC(currentIG);
28632859
TheCPU.eip = P0 - LONG_CS;
2860+
EFLAGS = (EFLAGS & ~EFLAGS_CC) | FlagSync_All();
28642861
longjmp(jmp_env, 2);
28652862
} else
28662863
/* for faulting sim_read/write directly from interp.c */

src/base/emu-i386/simx86/codegen-sim.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extern wkreg TR1; // "ecx"
8484
(s),showreg(r1),showreg(r2),(int)(a),(int)(b),showmode(mode))
8585
#define GTRACE5(s,r1,r2,a,b,c) if (debug_level('e')>2) e_printf("(G) %-12s %s %s %08x %08x %08x [%s]\n",\
8686
(s),showreg(r1),showreg(r2),(int)(a),(int)(b),(int)(c),showmode(mode))
87-
extern void FlagSync_All (void);
87+
extern int FlagSync_All (void);
8888
extern unsigned int Gen_sim(const IGen *IG);
8989
extern void InitGen_sim(void);
9090

src/base/emu-i386/simx86/cpatch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,9 @@ void rep_movs_stos(struct rep_stack *stack)
207207
IGen IG = (IGen){.op = O_MOVS_ScaD, .mode = repmod};
208208
Gen_sim(&IG);
209209
}
210-
FlagSync_All();
211210
stack->edi = EMU_BASE32(AR1.d);
212211
stack->ecx = TR1.d;
213-
stack->eflags = (stack->eflags & ~EFLAGS_CC) |
214-
(EFLAGS & EFLAGS_CC);
212+
stack->eflags = (stack->eflags & ~EFLAGS_CC) | FlagSync_All();
215213
goto done;
216214
}
217215
if (EFLAGS & EFLAGS_DF) addr -= len;

0 commit comments

Comments
 (0)