diff --git a/src/device/cpu_instructions.rs b/src/device/cpu_instructions.rs index afc55d5d..24b39211 100644 --- a/src/device/cpu_instructions.rs +++ b/src/device/cpu_instructions.rs @@ -975,22 +975,21 @@ pub fn jr(device: &mut device::Device, opcode: u32) { } pub fn jalr(device: &mut device::Device, opcode: u32) { - let target = device.cpu.gpr[rs(opcode) as usize]; let in_delay_slot_taken = device::cpu::in_delay_slot_taken(device); + if !in_delay_slot_taken { + check_relative_idle_loop(device, opcode); + device.cpu.branch_state.state = device::cpu::State::Take; + device.cpu.branch_state.pc = device.cpu.gpr[rs(opcode) as usize]; + } else if !device::cpu::in_delay_slot(device) { + device.cpu.branch_state.state = device::cpu::State::NotTaken; + } + if in_delay_slot_taken { device.cpu.gpr[rd(opcode) as usize] = device.cpu.branch_state.pc + 4 } else { device.cpu.gpr[rd(opcode) as usize] = device.cpu.pc + 8 } - - if !in_delay_slot_taken { - check_relative_idle_loop(device, opcode); - device.cpu.branch_state.state = device::cpu::State::Take; - device.cpu.branch_state.pc = target; - } else if !device::cpu::in_delay_slot(device) { - device.cpu.branch_state.state = device::cpu::State::NotTaken; - } } pub fn sync(_device: &mut device::Device, _opcode: u32) {} diff --git a/src/device/rsp_su_instructions.rs b/src/device/rsp_su_instructions.rs index 8976dd05..697e2e9e 100644 --- a/src/device/rsp_su_instructions.rs +++ b/src/device/rsp_su_instructions.rs @@ -306,22 +306,21 @@ pub fn jr(device: &mut device::Device, opcode: u32) { } pub fn jalr(device: &mut device::Device, opcode: u32) { - let target = device.rsp.cpu.gpr[rs(opcode) as usize]; let in_delay_slot_taken = device::rsp_cpu::in_delay_slot_taken(device); + if !in_delay_slot_taken { + device.rsp.cpu.branch_state.state = device::cpu::State::Take; + device.rsp.cpu.branch_state.pc = device.rsp.cpu.gpr[rs(opcode) as usize] + } else if !device::rsp_cpu::in_delay_slot(device) { + device.rsp.cpu.branch_state.state = device::cpu::State::NotTaken; + } + if in_delay_slot_taken { device.rsp.cpu.gpr[rd(opcode) as usize] = (device.rsp.cpu.branch_state.pc + 4) & 0xFFF } else { device.rsp.cpu.gpr[rd(opcode) as usize] = (device.rsp.regs2[device::rsp_interface::SP_PC_REG as usize] + 8) & 0xFFF } - - if !in_delay_slot_taken { - device.rsp.cpu.branch_state.state = device::cpu::State::Take; - device.rsp.cpu.branch_state.pc = target - } else if !device::rsp_cpu::in_delay_slot(device) { - device.rsp.cpu.branch_state.state = device::cpu::State::NotTaken; - } } pub fn break_(device: &mut device::Device, _opcode: u32) {