Skip to content

Commit 8754d25

Browse files
committed
simx86: DoExec/NodeLinker cleanups for F_SLFJ/MTRAP/loop
Using TheCPU.eip for the block we can reliably detect forever loops for the last block. The node linker doesn't need to care about blocks with F_SLFJ then any more. On the other hand it should never link blocks that set trap exceptions (mode & MTRAP). Flagging back refs in the node linker can then be limited to blocks with F_FPOP (the original purpose of that flagging). This all simplifies the fast loop in DoExec, it's only skipped for one-offs (F_SPEC/F_LEAV) or if we want debug logging.
1 parent 89b8386 commit 8754d25

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,10 @@ static unsigned int Exec_pre(unsigned char *ecpu)
579579
return flg;
580580
}
581581

582-
static void Exec_post(unsigned long flg, unsigned int mem_ref,
583-
unsigned short seqflg)
582+
static void Exec_post(unsigned long flg, unsigned int mem_ref)
584583
{
585584
EFLAGS = (EFLAGS & ~EFLAGS_CC) | (flg & EFLAGS_CC);
586585
TheCPU.mem_ref = mem_ref;
587-
/* checking for infinite loops, flagged in JumpGen() */
588-
if ((seqflg & F_SLFJ) && !(EFLAGS & (VIF|IF|TF))) {
589-
error("!Forever loop!\n");
590-
leavedos_main(0xebfe);
591-
}
592586
}
593587

594588
static unsigned ExecOne(TNode *G, unsigned *mem_ref, unsigned long *flg,
@@ -682,22 +676,20 @@ unsigned int DoExec(TNode *G, unsigned *pLastXKey)
682676
flg = Exec_pre(ecpu);
683677
#if !defined(ASM_DUMP) && !defined(SINGLESTEP)
684678
/* try fast inner loop if nothing special is going on */
685-
if (!(EFLAGS & TF) && !debug_level('e')) {
679+
if (!(seqflg & (F_SPEC|F_LEAV)) && !debug_level('e')) {
686680
while (1) {
687681
ePC = ExecOne(G, &mem_ref, &flg, ecpu, pLastXKey);
688-
if (TheCPU.err || exit_pending() ||
689-
(seqflg & (F_SLFJ|F_SPEC|F_LEAV)))
682+
if (TheCPU.err || exit_pending())
690683
break;
691684
G = FindTree(ePC);
692685
if (!G || !GoodNode(G))
693686
break;
694-
seqflg = G->flags;
695687
}
696688
} else
697689
#endif
698690
ePC = ExecOne(G, &mem_ref, &flg, ecpu, pLastXKey);
699691
// G is unreliable (maybe deleted) past this point!
700-
Exec_post(flg, mem_ref, seqflg);
692+
Exec_post(flg, mem_ref);
701693

702694
if (debug_level('e')) {
703695
#if PROFILE >= 2
@@ -721,8 +713,21 @@ unsigned int DoExec(TNode *G, unsigned *pLastXKey)
721713
/* exit_pending at this point is non-zero if there was ANY signal,
722714
* not just a SIGALRM
723715
*/
724-
if (!TheCPU.err && exit_pending())
716+
if (!TheCPU.err && exit_pending()) {
717+
/* checking for infinite loops, flagged in JumpGen() */
718+
/* TheCPU.eip points to the first instruction of the last
719+
executed block, except for real-mode retf, which cannot
720+
cause forever loops */
721+
if (!(EFLAGS & (VIF|IF|TF))) {
722+
TNode *LastG = FindTree(LONG_CS + TheCPU.eip);
723+
seqflg = LastG ? LastG->flags : 0;
724+
if (seqflg & F_SLFJ) {
725+
error("!Forever loop!\n");
726+
leavedos_main(0xebfe);
727+
}
728+
}
725729
HandleEmuSignals();
730+
}
726731

727732
#if defined(SINGLESTEP)
728733
InvalidateNodeRange(key, 1, NULL);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ static void linknode(TNode *LG, TNode *G, linkdesc *L, unsigned target_type)
751751

752752
// points to current node, which can't be a forever loop?
753753
if (L->target!=G->key || !(LG->unlinked_jmp_targets & target_type) ||
754-
(G->flags & F_SLFJ))
754+
(G->mode & MTRAP) || (LG->mode & MTRAP))
755755
return;
756756

757757
if (L->ref!=0) {
@@ -787,7 +787,7 @@ static void linknode(TNode *LG, TNode *G, linkdesc *L, unsigned target_type)
787787
G,G->key,G->addr,
788788
L->target, B->branch, G->nrefs, L->ref, *L->ref);
789789
}
790-
_nodeflagbackrefs(LG, G->flags);
790+
_nodeflagbackrefs(LG, G->flags & F_FPOP);
791791
if (debug_level('e')>8) {
792792
backref *bk = G->bkr.next;
793793
#ifdef DEBUG_LINKER

0 commit comments

Comments
 (0)