summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/arm7/arm7ops.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/cpu/arm7/arm7ops.cpp')
-rw-r--r--src/devices/cpu/arm7/arm7ops.cpp67
1 files changed, 49 insertions, 18 deletions
diff --git a/src/devices/cpu/arm7/arm7ops.cpp b/src/devices/cpu/arm7/arm7ops.cpp
index 9f6c998abed..3e0b9a599c2 100644
--- a/src/devices/cpu/arm7/arm7ops.cpp
+++ b/src/devices/cpu/arm7/arm7ops.cpp
@@ -66,18 +66,12 @@ uint32_t arm7_cpu_device::decodeShift(uint32_t insn, uint32_t *pCarry)
if ((insn & 0x80) == 0x80)
LOG(("%08x: RegShift ERROR (p36)\n", R15));
#endif
-
- // see p35 for check on this
- //k = GetRegister(k >> 1) & 0x1f;
-
// Keep only the bottom 8 bits for a Register Shift
k = GetRegister(k >> 1) & 0xff;
if (k == 0) /* Register shift by 0 is a no-op */
{
// LOG(("%08x: NO-OP Regshift\n", R15));
- /* TODO this is wrong for at least ROR by reg with lower
- * 5 bits 0 but lower 8 bits non zero */
if (pCarry)
*pCarry = GET_CPSR & C_MASK;
return rm;
@@ -145,11 +139,19 @@ uint32_t arm7_cpu_device::decodeShift(uint32_t insn, uint32_t *pCarry)
case 3: /* ROR and RRX */
if (k)
{
- while (k > 32)
- k -= 32;
- if (pCarry)
- *pCarry = rm & (1 << (k - 1));
- return ROR(rm, k);
+ k &= 31;
+ if (k)
+ {
+ if (pCarry)
+ *pCarry = rm & (1 << (k - 1));
+ return ROR(rm, k);
+ }
+ else
+ {
+ if (pCarry)
+ *pCarry = rm & SIGN_BIT;
+ return rm;
+ }
}
else
{
@@ -378,8 +380,8 @@ void arm7_cpu_device::HandleBranch(uint32_t insn, bool h_bit)
off |= (insn & 0x01000000) >> 23;
}
- /* Save PC into LR if this is a branch with link */
- if (insn & INSN_BL)
+ /* Save PC into LR if this is a branch with link or a BLX */
+ if ((insn & INSN_BL) || ((m_archRev >= 5) && ((insn & 0xfe000000) == 0xfa000000)))
{
SetRegister(14, R15 + 4);
}
@@ -490,8 +492,13 @@ void arm7_cpu_device::HandleMemSingle(uint32_t insn)
R15 = data - 4;
else
R15 = (R15 & ~0x03FFFFFC) /* N Z C V I F M1 M0 */ | ((data - 4) & 0x03FFFFFC);
- // LDR, PC takes 2S + 2N + 1I (5 total cycles)
+ // LDR, PC takes 2S + 2N + 1I (5 total cycles)
ARM7_ICOUNT -= 2;
+ if ((data & 1) && m_archRev >= 5)
+ {
+ set_cpsr(GET_CPSR | T_MASK);
+ R15--;
+ }
}
else
{
@@ -641,10 +648,10 @@ void arm7_cpu_device::HandleHalfWordDT(uint32_t insn)
// Signed Half Word?
if (insn & 0x20) {
- uint16_t signbyte, databyte;
- databyte = READ16(rnv) & 0xFFFF;
- signbyte = (databyte & 0x8000) ? 0xffff : 0;
- newval = (uint32_t)(signbyte << 16)|databyte;
+ uint32_t databyte = READ16(rnv);
+ uint32_t mask = 0x0000ffff;
+ mask >>= (rnv & 1) ? 8 : 0;
+ newval = databyte | ((databyte & ((mask + 1) >> 1)) ? ~mask : 0);
}
// Signed Byte
else {
@@ -1371,6 +1378,12 @@ void arm7_cpu_device::HandleMemBlock(uint32_t insn)
SwitchMode(temp & 3);
}
}
+ else
+ if ((R15 & 1) && m_archRev >= 5)
+ {
+ set_cpsr(GET_CPSR | T_MASK);
+ R15--;
+ }
// LDM PC - takes 2 extra cycles
ARM7_ICOUNT -= 2;
}
@@ -1428,6 +1441,12 @@ void arm7_cpu_device::HandleMemBlock(uint32_t insn)
SwitchMode(temp & 3);
}
}
+ else
+ if ((R15 & 1) && m_archRev >= 5)
+ {
+ set_cpsr(GET_CPSR | T_MASK);
+ R15--;
+ }
// LDM PC - takes 2 extra cycles
ARM7_ICOUNT -= 2;
}
@@ -1641,6 +1660,18 @@ void arm7_cpu_device::arm7ops_0123(uint32_t insn)
R15--;
}
}
+ else if ((insn & 0x0ff000f0) == 0x01200030) // BLX Rn - v5
+ {
+ // save link address
+ SetRegister(14, R15 + 4);
+
+ R15 = GetRegister(insn & 0x0f);
+ // If new PC address has A0 set, switch to Thumb mode
+ if (R15 & 1) {
+ set_cpsr(GET_CPSR|T_MASK);
+ R15--;
+ }
+ }
else if ((insn & 0x0ff000f0) == 0x01600010) // CLZ - v5
{
uint32_t rm = insn&0xf;