Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm7tdmi, gba: lock bus during SWP instruction #1729

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ares/component/processor/arm7tdmi/arm7tdmi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct ARM7TDMI {
virtual auto get(u32 mode, n32 address) -> n32 = 0;
virtual auto getDebugger(u32 mode, n32 address) -> n32 { return get(mode, address); }
virtual auto set(u32 mode, n32 address, n32 word) -> void = 0;
virtual auto lock() -> void { return; }
virtual auto unlock() -> void { return; }

//arm7tdmi.cpp
ARM7TDMI();
Expand Down
2 changes: 2 additions & 0 deletions ares/component/processor/arm7tdmi/instructions-arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ auto ARM7TDMI::armInstructionLoadRegister

auto ARM7TDMI::armInstructionMemorySwap
(n4 m, n4 d, n4 n, n1 byte) -> void {
lock();
n32 word = load((byte ? Byte : Word) | Nonsequential, r(n));
store((byte ? Byte : Word) | Nonsequential, r(n), r(m));
r(d) = word;
unlock();
}

auto ARM7TDMI::armInstructionMoveHalfImmediate
Expand Down
9 changes: 9 additions & 0 deletions ares/gba/cpu/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ auto CPU::set(u32 mode, n32 address, n32 word) -> void {
openBus.set(mode, address, word);
}

auto CPU::lock() -> void {
dmaRun();
context.busLocked = true;
}

auto CPU::unlock() -> void {
context.busLocked = false;
}

auto CPU::_wait(u32 mode, n32 address) -> u32 {
if(address >= 0x1000'0000) return 1; //unmapped
if(address < 0x0200'0000) return 1;
Expand Down
2 changes: 1 addition & 1 deletion ares/gba/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ auto CPU::main() -> void {
}

auto CPU::dmaRun() -> void {
if(!context.dmaActive) {
if(!context.dmaActive && !context.busLocked) {
context.dmaActive = true;
while(dma[0].run() | dma[1].run() | dma[2].run() | dma[3].run());
if(context.dmaRan) {
Expand Down
3 changes: 3 additions & 0 deletions ares/gba/cpu/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct CPU : ARM7TDMI, Thread, IO {
auto get(u32 mode, n32 address) -> n32 override;
auto getDebugger(u32 mode, n32 address) -> n32 override;
auto set(u32 mode, n32 address, n32 word) -> void override;
auto lock() -> void override;
auto unlock() -> void override;
auto _wait(u32 mode, n32 address) -> u32;

//io.cpp
Expand Down Expand Up @@ -255,6 +257,7 @@ struct CPU : ARM7TDMI, Thread, IO {
n1 dmaRomAccess;
n1 dmaActive;
n1 timerLatched;
n1 busLocked;
} context;
};

Expand Down
1 change: 1 addition & 0 deletions ares/gba/cpu/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ auto CPU::serialize(serializer& s) -> void {
s(context.dmaRomAccess);
s(context.dmaActive);
s(context.timerLatched);
s(context.busLocked);
}
2 changes: 2 additions & 0 deletions ares/gba/display/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
auto Display::serialize(serializer& s) -> void {
Thread::serialize(s);

s(io.vblank);
s(io.hblank);
s(io.vcoincidence);
Expand Down
2 changes: 1 addition & 1 deletion ares/gba/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v141.4";
static const string SerializerVersion = "v141.5";

auto System::serialize(bool synchronize) -> serializer {
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);
Expand Down
Loading