From 956c2ebe547cfd5ba46e1f899417eb2fe38f818a Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 19 Jun 2018 10:51:03 +0300 Subject: [PATCH] make arm use branch_lsteners --- lib/arm/instructions/call_instruction.rb | 5 +++++ lib/elf/object_writer.rb | 1 + lib/risc/position/instruction_listener.rb | 1 + test/arm/test_call.rb | 9 +++++++++ 4 files changed, 16 insertions(+) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 50aeef03..fd75dad7 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -41,6 +41,11 @@ module Arm end end + # if branch_to is implemented it must return the label it branches to + def branch_to + @first unless opcode == :swi + end + def handle_call(io) case @first when Risc::Label diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 59cf4dc2..9684c2ce 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -38,6 +38,7 @@ module Elf @machine.object_positions.each do |slot , position| next if slot.is_a?(Parfait::BinaryCode) + next if slot.class.name.include?("Arm") if( slot.respond_to? :rxf_reference_name ) label = "#{slot.rxf_reference_name}" else diff --git a/lib/risc/position/instruction_listener.rb b/lib/risc/position/instruction_listener.rb index 9868527f..3c7f341a 100644 --- a/lib/risc/position/instruction_listener.rb +++ b/lib/risc/position/instruction_listener.rb @@ -97,6 +97,7 @@ module Risc instruction = instruction.next end branches.each do |branch| + next if branch.branch_to.nil? #nil allowed for when there is no branch label_pos = Position.get(branch.branch_to) label_pos.position_listener( BranchListener.new(branch) ) end diff --git a/test/arm/test_call.rb b/test/arm/test_call.rb index c5668276..e587712f 100644 --- a/test/arm/test_call.rb +++ b/test/arm/test_call.rb @@ -15,6 +15,15 @@ module Arm code = @machine.call( -4 ,{} )#this jumps to the next instruction assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe end + def test_has_branch_to + label = Risc::Label.new("HI","ho" , FakeAddress.new(0)) + code = @machine.b( label ) + assert_equal label , code.branch_to + end + def test_branch_to_for_swi + code = @machine.swi( 0x05 ) + assert_nil code.branch_to + end def test_method_call Risc.machine.boot bin = Parfait::BinaryCode.new(1)