Impl arm SWP

Also ran some rustfmt


Former-commit-id: 30480e79d7f2926d5a5f15db20427179a672a78c
This commit is contained in:
Michel Heily 2019-07-27 20:20:58 +03:00
parent e06c77b6fd
commit 44426b5f0e
3 changed files with 44 additions and 4 deletions

View file

@ -167,7 +167,14 @@ impl Core {
(((val as u32) >> 1) as i32 | (old_c << 31)) as u32 (((val as u32) >> 1) as i32 | (old_c << 31)) as u32
} }
pub fn ror(&mut self, val: u32, amount: u32, carry_in: bool, immediate: bool, rrx: bool) -> u32 { pub fn ror(
&mut self,
val: u32,
amount: u32,
carry_in: bool,
immediate: bool,
rrx: bool,
) -> u32 {
match amount { match amount {
0 => { 0 => {
if immediate & rrx { if immediate & rrx {

View file

@ -356,7 +356,11 @@ impl ArmInstruction {
f, f,
"{sign}{mnem}{S}{cond}\t{RdLo}, {RdHi}, {Rm}, {Rs}", "{sign}{mnem}{S}{cond}\t{RdLo}, {RdHi}, {Rm}, {Rs}",
sign = self.sign_mark(), sign = self.sign_mark(),
mnem = if self.accumulate_flag() { "mlal" } else { "mull" }, mnem = if self.accumulate_flag() {
"mlal"
} else {
"mull"
},
S = self.set_cond_mark(), S = self.set_cond_mark(),
cond = self.cond, cond = self.cond,
RdLo = reg_string(self.rd_lo()), RdLo = reg_string(self.rd_lo()),
@ -390,6 +394,18 @@ impl ArmInstruction {
comm = self.swi_comment() comm = self.swi_comment()
) )
} }
fn fmt_swp(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"swp{B}{cond}\t{Rd}, {Rm}, [{Rn}]",
B = if self.transfer_size() == 1 { "b" } else { "" },
cond = self.cond,
Rd = reg_string(self.rd()),
Rm = reg_string(self.rm()),
Rn = reg_string(self.rn()),
)
}
} }
impl fmt::Display for ArmInstruction { impl fmt::Display for ArmInstruction {
@ -409,6 +425,7 @@ impl fmt::Display for ArmInstruction {
LDR_STR_HS_IMM => self.fmt_ldr_str_hs(f), LDR_STR_HS_IMM => self.fmt_ldr_str_hs(f),
LDR_STR_HS_REG => self.fmt_ldr_str_hs(f), LDR_STR_HS_REG => self.fmt_ldr_str_hs(f),
SWI => self.fmt_swi(f), SWI => self.fmt_swi(f),
SWP => self.fmt_swp(f),
_ => write!(f, "({:?})", self), _ => write!(f, "({:?})", self),
} }
} }

View file

@ -29,6 +29,7 @@ impl Core {
ArmFormat::MSR_FLAGS => self.exec_msr_flags(bus, insn), ArmFormat::MSR_FLAGS => self.exec_msr_flags(bus, insn),
ArmFormat::MUL_MLA => self.exec_mul_mla(bus, insn), ArmFormat::MUL_MLA => self.exec_mul_mla(bus, insn),
ArmFormat::MULL_MLAL => self.exec_mull_mlal(bus, insn), ArmFormat::MULL_MLAL => self.exec_mull_mlal(bus, insn),
ArmFormat::SWP => self.exec_arm_swp(bus, insn),
_ => Err(CpuError::UnimplementedCpuInstruction( _ => Err(CpuError::UnimplementedCpuInstruction(
insn.pc, insn.pc,
insn.raw, insn.raw,
@ -498,4 +499,19 @@ impl Core {
Ok(()) Ok(())
} }
fn exec_arm_swp(&mut self, sb: &mut Bus, insn: ArmInstruction) -> CpuExecResult {
let base_addr = self.get_reg(insn.rn());
if insn.transfer_size() == 1 {
let t = self.load_8(base_addr, sb);
self.store_8(base_addr, self.get_reg(insn.rm()) as u8, sb);
self.set_reg(insn.rd(), t as u32);
} else {
let t = self.load_32(base_addr, sb);
self.store_32(base_addr, self.get_reg(insn.rm()), sb);
self.set_reg(insn.rd(), t as u32);
}
Ok(())
}
} }