mirror of
https://github.com/mattrberry/crab.git
synced 2024-11-16 19:49:30 +01:00
arm branch exchange impl
This commit is contained in:
parent
e238d297cc
commit
9eca952a78
4 changed files with 27 additions and 4 deletions
|
@ -62,7 +62,7 @@ module ARM
|
|||
elsif idx & 0b111001001001 == 0b000000001001
|
||||
# halfword data transfer register offset
|
||||
elsif idx & 0b111111111111 == 0b000100100001
|
||||
# branch exchange
|
||||
lut[idx] = ->arm_branch_exchange(Word)
|
||||
elsif idx & 0b111110111111 == 0b000100001001
|
||||
# single data swap
|
||||
elsif idx & 0b111110001111 == 0b000010001001
|
||||
|
|
12
src/crab/arm/branch_exchange.cr
Normal file
12
src/crab/arm/branch_exchange.cr
Normal file
|
@ -0,0 +1,12 @@
|
|||
module ARM
|
||||
def arm_branch_exchange(instr : Word) : Nil
|
||||
rn = bits(instr, 0..3)
|
||||
if bit?(@r[rn], 0)
|
||||
@cpsr.thumb = true
|
||||
@r[15] = @r[rn] & ~1
|
||||
else
|
||||
@r[15] = @r[rn] & ~3
|
||||
end
|
||||
clear_pipeline
|
||||
end
|
||||
end
|
|
@ -21,6 +21,11 @@ class Bus
|
|||
(self[index + 3].to_u32 << 24)
|
||||
end
|
||||
|
||||
def read_half(index : Int) : Word
|
||||
self[index].to_u32 |
|
||||
(self[index + 1].to_u32 << 8)
|
||||
end
|
||||
|
||||
def []=(index : Int, value : Byte) : Nil
|
||||
log "write #{hex_str index.to_u32} -> #{hex_str value}"
|
||||
case index
|
||||
|
|
|
@ -30,9 +30,15 @@ class CPU
|
|||
|
||||
def fill_pipeline : Nil
|
||||
while @pipeline.size < 2
|
||||
log "Fetch pc: #{hex_str @r[15]}, instr: #{hex_str @gba.bus.read_word @r[15]}"
|
||||
@pipeline << @gba.bus.read_word @r[15]
|
||||
@r[15] &+= 4
|
||||
if @cpsr.thumb
|
||||
log "Fetch pc: #{hex_str @r[15]}, instr: #{hex_str @gba.bus.read_half(@r[15]).to_u16}"
|
||||
@pipeline << @gba.bus.read_half @r[15]
|
||||
@r[15] &+= 2
|
||||
else
|
||||
log "Fetch pc: #{hex_str @r[15]}, instr: #{hex_str @gba.bus.read_word @r[15]}"
|
||||
@pipeline << @gba.bus.read_word @r[15]
|
||||
@r[15] &+= 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue