From db459fcd3d9c90a882871a0f5b3832d65bdfc3f7 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 19 Jun 2018 17:35:00 +0300 Subject: [PATCH] fix label loading in arm was still loading the integer address instead of the return address's address Hello World working --- lib/arm/instructions/logic_instruction.rb | 1 + lib/risc/position/position.rb | 2 +- test/arm/test_logic.rb | 4 +++- test/elf/test_hello.rb | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/arm/instructions/logic_instruction.rb b/lib/arm/instructions/logic_instruction.rb index 20fff7ef..77753f45 100644 --- a/lib/arm/instructions/logic_instruction.rb +++ b/lib/arm/instructions/logic_instruction.rb @@ -91,6 +91,7 @@ module Arm if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or (@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left))) left = @left + left = left.address if left.is_a?(Risc::Label) # do pc relative addressing with the difference to the instuction # 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute) right = Risc::Position.get(left) - 8 diff --git a/lib/risc/position/position.rb b/lib/risc/position/position.rb index bd800df4..2b963f0f 100644 --- a/lib/risc/position/position.rb +++ b/lib/risc/position/position.rb @@ -147,7 +147,7 @@ module Risc end def self.set?(object) - self.positions.has_key?(object) + self.positions[object] end # get a position from the cache (object -> position) diff --git a/test/arm/test_logic.rb b/test/arm/test_logic.rb index 2cb63adb..91b65a36 100644 --- a/test/arm/test_logic.rb +++ b/test/arm/test_logic.rb @@ -90,7 +90,9 @@ module Arm end def label( pos = 0x22 + 8) - label = Risc::Label.new("some" , "Label" , FakeAddress.new(pos)) + addr = FakeAddress.new(pos) + Risc::Position.new(addr).set(pos) + label = Risc::Label.new("some" , "Label" , addr) Risc::Position.create(label).set(pos) #Risc::Position.set(l , pos , @binary) label diff --git a/test/elf/test_hello.rb b/test/elf/test_hello.rb index b3bdc9a6..3074f3cf 100644 --- a/test/elf/test_hello.rb +++ b/test/elf/test_hello.rb @@ -12,7 +12,7 @@ class HelloTest < MiniTest::Test end def test_string_put - @input = "return 'Hello'.putstring" + @input = "return 'Hello World!\n'.putstring" check end end