From cd73c562eaae4629b6a6789e5fe27f2b22387f86 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 1 May 2013 23:08:22 -0700 Subject: [PATCH] Implement addressing mode 1 LSL/LSR with register --- src/arm/isa-arm.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/arm/isa-arm.c b/src/arm/isa-arm.c index 9ff2bdadf..b1a4a7dd0 100644 --- a/src/arm/isa-arm.c +++ b/src/arm/isa-arm.c @@ -24,7 +24,30 @@ static inline void _shiftLSL(struct ARMCore* cpu, uint32_t opcode) { static inline void _shiftLSLR(struct ARMCore* cpu, uint32_t opcode) { int rm = opcode & 0x0000000F; - ARM_STUB; + int rs = (opcode >> 8) & 0x0000000F; + ++cpu->cycles; + int shift = cpu->gprs[rs]; + if (rs == ARM_PC) { + shift += 4; + } + shift &= 0xFF; + int32_t shiftVal = cpu->gprs[rm]; + if (rm == ARM_PC) { + shiftVal += 4; + } + if (!shift) { + cpu->shifterOperand = shiftVal; + cpu->shifterCarryOut = cpu->cpsr.c; + } else if (shift < 32) { + cpu->shifterOperand = shiftVal << shift; + cpu->shifterCarryOut = (shiftVal >> (32 - shift)) & 1; + } else if (shift == 32) { + cpu->shifterOperand = 0; + cpu->shifterCarryOut = shiftVal & 1; + } else { + cpu->shifterOperand = 0; + cpu->shifterCarryOut = 0; + } } static inline void _shiftLSR(struct ARMCore* cpu, uint32_t opcode) { @@ -41,7 +64,30 @@ static inline void _shiftLSR(struct ARMCore* cpu, uint32_t opcode) { static inline void _shiftLSRR(struct ARMCore* cpu, uint32_t opcode) { int rm = opcode & 0x0000000F; - ARM_STUB; + int rs = (opcode >> 8) & 0x0000000F; + ++cpu->cycles; + int shift = cpu->gprs[rs]; + if (rs == ARM_PC) { + shift += 4; + } + shift &= 0xFF; + uint32_t shiftVal = cpu->gprs[rm]; + if (rm == ARM_PC) { + shiftVal += 4; + } + if (!shift) { + cpu->shifterOperand = shiftVal; + cpu->shifterCarryOut = cpu->cpsr.c; + } else if (shift < 32) { + cpu->shifterOperand = shiftVal >> shift; + cpu->shifterCarryOut = (shiftVal >> (shift - 1)) & 1; + } else if (shift == 32) { + cpu->shifterOperand = 0; + cpu->shifterCarryOut = shiftVal >> 31; + } else { + cpu->shifterOperand = 0; + cpu->shifterCarryOut = 0; + } } static inline void _shiftASR(struct ARMCore* cpu, uint32_t opcode) {