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
This commit is contained in:
Torsten Ruger 2018-03-28 13:00:03 +03:00
parent 7493d738e1
commit 606e3f8cb3
3 changed files with 11 additions and 5 deletions

View File

@ -47,11 +47,11 @@ module Arm
# but because of the arm "theoretical" 3- stage pipeline, # but because of the arm "theoretical" 3- stage pipeline,
# we have to subtract 2 words (fetch/decode) # we have to subtract 2 words (fetch/decode)
arg = Positioned.position(@first) - Positioned.position(self) - 8 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, # But, for methods, this happens to be the size of the object header,
# so there it balances out, but not blocks # so there it balances out, but not blocks
# have to use the code, not the mthod object for methods # 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 else
arg = @first arg = @first
end end

View File

@ -15,6 +15,14 @@ module Arm
code = @machine.call( -4 ,{} )#this jumps to the next instruction code = @machine.call( -4 ,{} )#this jumps to the next instruction
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
end 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 def test_swi
code = @machine.swi( 0x05 ) code = @machine.swi( 0x05 )
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05 assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05

View File

@ -29,13 +29,11 @@ module Risc
all << ins all << ins
end end
end end
def test_no_risc def test_no_risc #by assembling, risc doesnt have assemble method
@machine.position_all @machine.position_all
@machine.objects.each do |id , method| @machine.objects.each do |id , method|
next unless method.is_a? Parfait::TypedMethod next unless method.is_a? Parfait::TypedMethod
next unless method.name == :__init__
method.cpu_instructions.each do |ins| method.cpu_instructions.each do |ins|
puts "INS #{ins}:#{}"
begin begin
ins.assemble(DevNull.new) ins.assemble(DevNull.new)
rescue LinkException rescue LinkException