mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-22 19:27:21 +01:00
thumb move/compare/add/subtract, fix thumb conditional branch bug
This commit is contained in:
parent
7d8e2dccef
commit
99bdf3ec86
3 changed files with 19 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
module THUMB
|
module THUMB
|
||||||
def thumb_conditional_branch(instr : Word) : Nil
|
def thumb_conditional_branch(instr : Word) : Nil
|
||||||
cond = bits(instr, 8..11)
|
cond = bits(instr, 8..11)
|
||||||
offset = bits(instr, 0..8).to_i8!
|
offset = bits(instr, 0..7).to_i8!
|
||||||
if cond
|
if cond
|
||||||
@r[15] &+= (offset * 2)
|
@r[15] &+= (offset * 2)
|
||||||
clear_pipeline
|
clear_pipeline
|
||||||
|
|
17
src/crab/thumb/move_compare_add_subtract.cr
Normal file
17
src/crab/thumb/move_compare_add_subtract.cr
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module THUMB
|
||||||
|
def thumb_move_compare_add_subtract(instr : Word) : Nil
|
||||||
|
op = bits(instr, 11..12)
|
||||||
|
rd = bits(instr, 8..10)
|
||||||
|
offset = bits(instr, 0..7)
|
||||||
|
# todo handle carry flag on all ops
|
||||||
|
case op
|
||||||
|
when 0b00 then res = @r[rd] = offset
|
||||||
|
when 0b01 then res = @r[rd] &- offset
|
||||||
|
when 0b10 then res = @r[rd] &+= offset
|
||||||
|
when 0b11 then res = @r[rd] &-= offset
|
||||||
|
else raise "Invalid move/compare/add/subtract op: #{op}"
|
||||||
|
end
|
||||||
|
@cpsr.zero = res == 0
|
||||||
|
@cpsr.negative = bit?(res, 31)
|
||||||
|
end
|
||||||
|
end
|
|
@ -39,7 +39,7 @@ module THUMB
|
||||||
elsif idx & 0b11111100 == 0b01000000
|
elsif idx & 0b11111100 == 0b01000000
|
||||||
# alu operations
|
# alu operations
|
||||||
elsif idx & 0b11100000 == 0b00100000
|
elsif idx & 0b11100000 == 0b00100000
|
||||||
# move/compare/add/subtract immediate
|
lut[idx] = ->thumb_move_compare_add_subtract(Word)
|
||||||
elsif idx & 0b11111100 == 0b00011000
|
elsif idx & 0b11111100 == 0b00011000
|
||||||
# add/subtract
|
# add/subtract
|
||||||
elsif idx & 0b11100000 == 0b00000000
|
elsif idx & 0b11100000 == 0b00000000
|
||||||
|
|
Loading…
Reference in a new issue