From 7d0e1b18f30f85484ac296267283fe7b24d21e6a Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 5 Dec 2023 18:03:48 +0000 Subject: [PATCH] Add `sw` instruction --- optimism/src/mips/interpreter.rs | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/optimism/src/mips/interpreter.rs b/optimism/src/mips/interpreter.rs index 68d23816b0..fc2633ac81 100644 --- a/optimism/src/mips/interpreter.rs +++ b/optimism/src/mips/interpreter.rs @@ -713,7 +713,43 @@ pub fn interpret_itype(env: &mut Env, instr: ITypeInstructi ITypeInstruction::LoadWordRight => (), ITypeInstruction::Store8 => (), ITypeInstruction::Store16 => (), - ITypeInstruction::Store32 => (), + ITypeInstruction::Store32 => { + let base = env.read_register(&rs); + let offset = env.sign_extend(&immediate, 16); + let addr = base.clone() + offset.clone(); + let value = env.read_register(&rt); + let [v0, v1, v2, v3] = { + [ + { + // FIXME: Requires a range check + let pos = env.alloc_scratch(); + unsafe { env.bitmask(&value, 32, 24, pos) } + }, + { + // FIXME: Requires a range check + let pos = env.alloc_scratch(); + unsafe { env.bitmask(&value, 24, 16, pos) } + }, + { + // FIXME: Requires a range check + let pos = env.alloc_scratch(); + unsafe { env.bitmask(&value, 16, 8, pos) } + }, + { + // FIXME: Requires a range check + let pos = env.alloc_scratch(); + unsafe { env.bitmask(&value, 8, 0, pos) } + }, + ] + }; + env.write_memory(&addr, v0); + env.write_memory(&(addr.clone() + Env::constant(1)), v1); + env.write_memory(&(addr.clone() + Env::constant(2)), v2); + env.write_memory(&(addr.clone() + Env::constant(3)), v3); + env.set_instruction_pointer(next_instruction_pointer.clone()); + env.set_next_instruction_pointer(next_instruction_pointer + Env::constant(4u32)); + return; + } ITypeInstruction::StoreWordLeft => (), ITypeInstruction::StoreWordRight => (), };