Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
sh4: Fix sh4::Stop() if no interrupts are happening
Browse files Browse the repository at this point in the history
  • Loading branch information
skmp committed Jan 31, 2020
1 parent 17c569f commit 9ae4bee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion libswirl/hw/sh4/SuperH4_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ int UpdateSystem()
if (Sh4cntx.sh4_sched_next < 0)
sh4_sched_tick(SH4_TIMESLICE);

return Sh4cntx.interrupt_pend;
// Force an interrupt check if the cpu has been stopped
// ngen is required to only check the bCpuRun on interrupt processing
return Sh4cntx.interrupt_pend | (sh4_int_bCpuRun == false);
}

int UpdateSystem_INTC()
Expand Down
15 changes: 12 additions & 3 deletions libswirl/hw/sh4/interpr/sh4_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "types.h"

#include "../sh4_interpreter.h"
#include "../sh4_interrupts.h"
#include "../sh4_opcode_list.h"
#include "../sh4_core.h"
#include "hw/sh4/sh4_mem.h"
Expand Down Expand Up @@ -86,17 +87,25 @@ struct SH4IInterpreter : SuperH4Backend {

l -= CPU_RATIO;
} while (l > 0);

l += SH4_TIMESLICE;
UpdateSystem_INTC();

// model how the jit works
// only check for sh4_int_bCpuRun on interrupts
if (UpdateSystem()) {
UpdateINTC();
if (!sh4_int_bCpuRun)
break;
}

#if !defined(NO_MMU)
}
catch (SH4ThrownException& ex) {
Do_Exception(ex.epc, ex.expEvn, ex.callVect);
l -= CPU_RATIO * 5; // an exception requires the instruction pipeline to drain, so approx 5 cycles
}
#endif

} while (sh4_int_bCpuRun);
} while (true);
}

bool Init() { return true; }
Expand Down
1 change: 1 addition & 0 deletions libswirl/jit/backend/x64/rec_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class BlockCompiler : public Xbyak::CodeGenerator
emit_Skip(getSize());
}

//TODO: FIXME THIS DOES NOT CONFORM TO NGEN SPEC AROUND INTERRUPT HANDLING
void build_mainloop() {
Xbyak::Label run_loop, slice_loop, end_loop;
// Store callee saved registers (64 bytes) + align stack
Expand Down

0 comments on commit 9ae4bee

Please sign in to comment.