From 367b578d9f77fe2a47f9df960fefd48f6409b188 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sun, 11 Oct 2020 10:29:22 -0700 Subject: [PATCH] clear pipeline if rd==15 in thumb hi-reg bx, load/store imm, load/store reg --- src/crab/thumb/hi_reg_branch_exchange.cr | 1 + src/crab/thumb/load_store_immediate_offset.cr | 13 ++++++--- src/crab/thumb/load_store_register_offset.cr | 29 ++++++++++--------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/crab/thumb/hi_reg_branch_exchange.cr b/src/crab/thumb/hi_reg_branch_exchange.cr index cff78df..83b876e 100644 --- a/src/crab/thumb/hi_reg_branch_exchange.cr +++ b/src/crab/thumb/hi_reg_branch_exchange.cr @@ -22,5 +22,6 @@ module THUMB end clear_pipeline end + clear_pipeline if rd == 15 end end diff --git a/src/crab/thumb/load_store_immediate_offset.cr b/src/crab/thumb/load_store_immediate_offset.cr index 2efa54c..9541933 100644 --- a/src/crab/thumb/load_store_immediate_offset.cr +++ b/src/crab/thumb/load_store_immediate_offset.cr @@ -5,11 +5,16 @@ module THUMB rb = bits(instr, 3..5) rd = bits(instr, 0..2) imm = offset << 2 + address = @r[rb] &+ (offset << 2) case byte_quantity_and_load - when 0b00 then @gba.bus[@r[rb] + imm] = @r[rd] - when 0b01 then @r[rd] = @gba.bus.read_word(@r[rb] + imm) - when 0b10 then @gba.bus[@r[rb] + imm] = @r[rd].to_u8! - when 0b11 then @r[rd] = @gba.bus[@r[rb] + imm].to_u32 + when 0b00 then @gba.bus[address] = @r[rd] + when 0b01 + @r[rd] = @gba.bus.read_word(address) + clear_pipeline if rd == 15 + when 0b10 then @gba.bus[address] = 0xFF_u8 & @r[rd] + when 0b11 + @r[rd] = 0xFFFFFFFF_u32 & @gba.bus[address] + clear_pipeline if rd == 15 end end end diff --git a/src/crab/thumb/load_store_register_offset.cr b/src/crab/thumb/load_store_register_offset.cr index f9f8adc..36ce091 100644 --- a/src/crab/thumb/load_store_register_offset.cr +++ b/src/crab/thumb/load_store_register_offset.cr @@ -1,16 +1,19 @@ module THUMB - def thumb_load_store_register_offset(instr : Word) : Nil - load_and_byte_quantity = bits(instr, 10..11) - ro = bits(instr, 6..8) - rb = bits(instr, 3..5) - rd = bits(instr, 0..2) - address = @r[rb] &+ @r[ro] - case load_and_byte_quantity - when 0b00 then @gba.bus[address] = @r[rd] - when 0b01 then @gba.bus[address] = 0xFF_u8 & @r[rd] - when 0b10 then @r[rd] = @gba.bus.read_word address - when 0b11 then @r[rd] = 0xFFFFFFFF_u32 & @gba.bus[address] - end + def thumb_load_store_register_offset(instr : Word) : Nil + load_and_byte_quantity = bits(instr, 10..11) + ro = bits(instr, 6..8) + rb = bits(instr, 3..5) + rd = bits(instr, 0..2) + address = @r[rb] &+ @r[ro] + case load_and_byte_quantity + when 0b00 then @gba.bus[address] = @r[rd] + when 0b01 then @gba.bus[address] = 0xFF_u8 & @r[rd] + when 0b10 + @r[rd] = @gba.bus.read_word address + clear_pipeline if rd == 15 + when 0b11 + @r[rd] = 0xFFFFFFFF_u32 & @gba.bus[address] + clear_pipeline if rd == 15 end end - \ No newline at end of file +end