Implement thumb17 (Swi)

Former-commit-id: 62d7e14e9b84e74d9236e1f0a5e961ae805f861c
This commit is contained in:
Michel Heily 2019-07-22 01:15:58 +03:00
parent eea26d2393
commit 7501adfd12
4 changed files with 17 additions and 8 deletions

View file

@ -3,7 +3,6 @@ use crate::bit::BitIndex;
use crate::core::arm7tdmi::alu::*;
use crate::core::arm7tdmi::bus::Bus;
use crate::core::arm7tdmi::cpu::{Core, CpuExecResult};
use crate::core::arm7tdmi::exception::Exception;
use crate::core::arm7tdmi::psr::RegPSR;
use crate::core::arm7tdmi::{
Addr, CpuError, CpuMode, CpuResult, CpuState, DecodedInstruction, REG_PC,
@ -20,7 +19,7 @@ impl Core {
ArmFormat::BX => self.exec_bx(bus, insn),
ArmFormat::B_BL => self.exec_b_bl(bus, insn),
ArmFormat::DP => self.exec_data_processing(bus, insn),
ArmFormat::SWI => self.exec_swi(bus, insn),
ArmFormat::SWI => self.exec_swi(),
ArmFormat::LDR_STR => self.exec_ldr_str(bus, insn),
ArmFormat::LDR_STR_HS_IMM => self.exec_ldr_str_hs(bus, insn),
ArmFormat::LDR_STR_HS_REG => self.exec_ldr_str_hs(bus, insn),
@ -70,12 +69,6 @@ impl Core {
self.branch_exchange(self.get_reg(insn.rn()))
}
fn exec_swi(&mut self, _bus: &mut Bus, _insn: ArmInstruction) -> CpuExecResult {
self.exception(Exception::SoftwareInterrupt);
self.flush_pipeline();
Ok(())
}
fn exec_mrs(&mut self, _bus: &mut Bus, insn: ArmInstruction) -> CpuExecResult {
let mode = self.cpsr.mode();
let result = if insn.spsr_flag() {

View file

@ -240,6 +240,12 @@ impl Core {
}
}
pub fn exec_swi(&mut self) -> CpuExecResult {
self.exception(Exception::SoftwareInterrupt);
self.flush_pipeline();
Ok(())
}
fn step_arm_exec(&mut self, insn: u32, sb: &mut Bus) -> CpuResult<()> {
let pc = self.pc;
match self.pipeline_state {

View file

@ -261,6 +261,14 @@ impl ThumbInstruction {
)
}
fn fmt_thumb_swi(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"swi\t{value:#x}",
value = self.raw & 0xff,
)
}
fn fmt_thumb_branch(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
@ -304,6 +312,7 @@ impl fmt::Display for ThumbInstruction {
ThumbFormat::PushPop => self.fmt_thumb_push_pop(f),
ThumbFormat::LdmStm => self.fmt_thumb_ldm_stm(f),
ThumbFormat::BranchConditional => self.fmt_thumb_branch_with_cond(f),
ThumbFormat::Swi => self.fmt_thumb_swi(f),
ThumbFormat::Branch => self.fmt_thumb_branch(f),
ThumbFormat::BranchLongWithLink => self.fmt_thumb_branch_long_with_link(f),
_ => write!(f, "({:?})", self),

View file

@ -436,6 +436,7 @@ impl Core {
ThumbFormat::PushPop => self.exec_thumb_push_pop(bus, insn),
ThumbFormat::LdmStm => self.exec_thumb_ldm_stm(bus, insn),
ThumbFormat::BranchConditional => self.exec_thumb_branch_with_cond(bus, insn),
ThumbFormat::Swi => self.exec_swi(),
ThumbFormat::Branch => self.exec_thumb_branch(bus, insn),
ThumbFormat::BranchLongWithLink => self.exec_thumb_branch_long_with_link(bus, insn),
_ => unimplemented!("thumb not implemented {:#x?}", insn),