From 09b8876b7387a88655f8c71632cd208830ba72e9 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sun, 27 Sep 2020 13:51:17 -0700 Subject: [PATCH] early psr transfer implementation --- src/crab/arm/arm.cr | 2 ++ src/crab/arm/psr_transfer.cr | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/crab/arm/psr_transfer.cr diff --git a/src/crab/arm/arm.cr b/src/crab/arm/arm.cr index bbab8ff..3334249 100644 --- a/src/crab/arm/arm.cr +++ b/src/crab/arm/arm.cr @@ -69,6 +69,8 @@ module ARM # multiply long elsif idx & 0b111111001111 == 0b000000001001 # multiply + elsif idx & 0b110110010000 == 0b000100000000 + lut[idx] = ->arm_psr_transfer(Word) elsif idx & 0b110000000000 == 0b000000000000 lut[idx] = ->arm_data_processing(Word) else diff --git a/src/crab/arm/psr_transfer.cr b/src/crab/arm/psr_transfer.cr new file mode 100644 index 0000000..edde956 --- /dev/null +++ b/src/crab/arm/psr_transfer.cr @@ -0,0 +1,26 @@ +module ARM + def arm_psr_transfer(instr : Word) : Nil + # todo respect spsr + spsr = bit?(instr, 22) + msr = bit?(instr, 21) + if msr + all = bit?(instr, 16) + if all + rm = bits(instr, 0..3) + @cpsr.value = @r[rm] + else + imm_flag = bit?(instr, 25) + value = if imm_flag + immediate_offset bits(instr, 0..11) + else + rm = bits(instr, 0..3) + @r[rm] + end + @cpsr.value = (@cpsr.value & 0x0FFFFFFF) | (value & 0xF0000000) + end + else + rd = bits(instr, 12..15) + @r[rd] = @cpsr.value + end + end +end