Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

idk if this is correct

Layle7e4196764521
diff --git a/crates/gekko/src/cpu.rs b/crates/gekko/src/cpu.rs
index 93cfe4e..ab6a787 100644
--- a/crates/gekko/src/cpu.rs
+++ b/crates/gekko/src/cpu.rs
@@ -26,6 +26,7 @@ pub struct Cpu {
// can change the flow of execution (e.g. for branches and jumps).
pub cia: u32, // Current Instruction Address
pub nia: u32, // Next Instruction Address
+ pub reserve_addr: Option<u32>, // lwarx/stwcx. reservation address
}
impl Cpu {
@@ -41,6 +42,7 @@ impl Cpu {
msr: msr::Msr::default(),
fpscr: 0,
sr: [sr::Sr::default(); 16],
+ reserve_addr: None,
}
}
diff --git a/crates/gekko/src/cpu/interpreter.rs b/crates/gekko/src/cpu/interpreter.rs
index e94ec93..be4ef9c 100644
--- a/crates/gekko/src/cpu/interpreter.rs
+++ b/crates/gekko/src/cpu/interpreter.rs
@@ -14,6 +14,6 @@ pub use compare::compare;
pub use cr_ops::cr_ops;
pub use fp_ops::fp_ops;
pub use rotate::rotate;
-pub use store_load::{store_load, store_load_fp};
+pub use store_load::{lwarx, store_load, store_load_fp, stwcx_dot};
pub use stubs::*;
pub use system::{mftb, msr, nop, segment, spr};
diff --git a/crates/gekko/src/cpu/interpreter/store_load.rs b/crates/gekko/src/cpu/interpreter/store_load.rs
index e63c4f0..57b207f 100644
--- a/crates/gekko/src/cpu/interpreter/store_load.rs
+++ b/crates/gekko/src/cpu/interpreter/store_load.rs
@@ -1,3 +1,5 @@
+use crate::cpu::condition::ConditionField;
+
pub fn store_load<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
match OP {
crate::cpu::lut::OP_STW | crate::cpu::lut::OP_STWU => {
@@ -147,6 +149,36 @@ pub fn store_load<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cp
}
}
+pub fn lwarx(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
+ let addr = ctx
+ .cpu
+ .read_gpr_or_zero(instr.ra())
+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));
+ let val = ctx.read_u32(addr);
+ ctx.cpu.write_gpr(instr.rd(), val);
+ ctx.cpu.reserve_addr = Some(addr);
+}
+
+pub fn stwcx_dot(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
+ let addr = ctx
+ .cpu
+ .read_gpr_or_zero(instr.ra())
+ .wrapping_add(ctx.cpu.read_gpr(instr.rb()));
+ let so = ctx.cpu.spr.xer.summary_overflow();
+ let store_performed = ctx.cpu.reserve_addr.is_some();
+ ctx.cpu.reserve_addr = None;
+ if store_performed {
+ ctx.write_u32(addr, ctx.cpu.read_gpr(instr.rs()));
+ ctx.cpu
+ .cr
+ .set_cr0(ConditionField::new().with_eq(true).with_so(so));
+ } else {
+ ctx.cpu
+ .cr
+ .set_cr0(ConditionField::new().with_so(so));
+ }
+}
+
pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
match OP {
crate::cpu::lut::OP_LFD | crate::cpu::lut::OP_LFDU => {
diff --git a/crates/gekko/src/cpu/interpreter/stubs.rs b/crates/gekko/src/cpu/interpreter/stubs.rs
index 41578f0..e2983d7 100644
--- a/crates/gekko/src/cpu/interpreter/stubs.rs
+++ b/crates/gekko/src/cpu/interpreter/stubs.rs
@@ -23,7 +23,6 @@ stub! {
ps_div, ps_sub, ps_add, ps_sel, ps_mul,
ps_msub, ps_madd, ps_nmsub, ps_nmadd,
sc, tw,
- lwarx, stwcx_dot,
mtsrin, mcrxr,
lwbrx, lswx, lswi, mfsrin,
stswx, stwbrx, stswi,