From 606e3f8cb39daaa1f0c9a127a7bd51ab54ef5318 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 28 Mar 2018 13:00:03 +0300 Subject: [PATCH] fix calling to binaries used to be to the method, but we assemble the method to its own position. Throw in a test for binary calling --- lib/arm/instructions/call_instruction.rb | 4 ++-- test/arm/test_call.rb | 8 ++++++++ test/risc/test_translator.rb | 4 +--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 1cbdea9a..a950ec6b 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -47,11 +47,11 @@ module Arm # but because of the arm "theoretical" 3- stage pipeline, # we have to subtract 2 words (fetch/decode) arg = Positioned.position(@first) - Positioned.position(self) - 8 - when Parfait::TypedMethod + when Parfait::BinaryCode # But, for methods, this happens to be the size of the object header, # so there it balances out, but not blocks # have to use the code, not the mthod object for methods - arg = arg.binary.position - self.position + arg = Positioned.position(@first) - Positioned.position(self) else arg = @first end diff --git a/test/arm/test_call.rb b/test/arm/test_call.rb index 1136407c..6d4e2bc2 100644 --- a/test/arm/test_call.rb +++ b/test/arm/test_call.rb @@ -15,6 +15,14 @@ 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_method_call + Risc.machine.boot + bin = Parfait::BinaryCode.new(1) + Positioned.set_position(bin , 0x20) + code = @machine.call( bin ,{} )#this jumps to the next instruction + Positioned.set_position(code , 0) + assert_code code , :call, [0x08,0x0,0x0,0xeb] + end def test_swi code = @machine.swi( 0x05 ) assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 diff --git a/test/risc/test_translator.rb b/test/risc/test_translator.rb index 75459dd1..1b833dbe 100644 --- a/test/risc/test_translator.rb +++ b/test/risc/test_translator.rb @@ -29,13 +29,11 @@ module Risc all << ins end end - def test_no_risc + def test_no_risc #by assembling, risc doesnt have assemble method @machine.position_all @machine.objects.each do |id , method| next unless method.is_a? Parfait::TypedMethod - next unless method.name == :__init__ method.cpu_instructions.each do |ins| - puts "INS #{ins}:#{}" begin ins.assemble(DevNull.new) rescue LinkException