debugging positions
This commit is contained in:
parent
d49d2665c5
commit
43d5521cfc
@ -1 +1 @@
|
||||
2.3.4
|
||||
2.3.7
|
||||
|
@ -51,8 +51,8 @@ module Arm
|
||||
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 = Positioned.position(@first) - Positioned.position(self)
|
||||
# have to use the code, not the method object for methods
|
||||
arg = Positioned.position(@first) - Positioned.position(self) + 4
|
||||
else
|
||||
arg = @first
|
||||
end
|
||||
|
@ -21,11 +21,16 @@ module Arm
|
||||
ret
|
||||
end
|
||||
|
||||
def set_position( position )
|
||||
def set_position( position , count )
|
||||
Positioned.set_position(self,position)
|
||||
position += byte_length
|
||||
if self.next
|
||||
self.next.set_position( position )
|
||||
count += 1 #assumes 4 byte instructions, as does the whole setup
|
||||
if( 0 == count % 12) # 12 is the amount of instructions that fit into a BinaryCode
|
||||
count = 0
|
||||
position += 12 # 12=3*4 , 3 for marker,type,next words to jump over
|
||||
end
|
||||
self.next.set_position( position , count )
|
||||
else
|
||||
position
|
||||
end
|
||||
|
@ -45,9 +45,9 @@ module Risc
|
||||
end
|
||||
|
||||
# labels have the same position as their next
|
||||
def set_position( position )
|
||||
def set_position( position , count = 0)
|
||||
Positioned.set_position(self,position)
|
||||
self.next.set_position(position) if self.next
|
||||
self.next.set_position(position,count) if self.next
|
||||
end
|
||||
|
||||
# shame we need this, just for logging
|
||||
|
@ -14,7 +14,7 @@ module Risc
|
||||
|
||||
class Machine
|
||||
include Logging
|
||||
log_level :info
|
||||
log_level :debug
|
||||
|
||||
def initialize
|
||||
@booted = false
|
||||
@ -77,9 +77,8 @@ module Risc
|
||||
def position_all
|
||||
translate_arm unless @translated
|
||||
#need the initial jump at 0 and then functions
|
||||
cpu_init.set_position( 0 )
|
||||
#Positioned.set_position(cpu_init.first , 0)
|
||||
Positioned.set_position(binary_init,0)
|
||||
cpu_init.set_position( 12 ,0)
|
||||
@code_start = position_objects( binary_init.padded_length )
|
||||
# and then everything code
|
||||
position_code
|
||||
@ -93,7 +92,9 @@ module Risc
|
||||
objects.each do | id , objekt|
|
||||
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
||||
Positioned.set_position(objekt,at)
|
||||
before = at
|
||||
at += objekt.padded_length
|
||||
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
end
|
||||
at
|
||||
end
|
||||
@ -109,8 +110,7 @@ module Risc
|
||||
at = @code_start
|
||||
objects.each do |id , method|
|
||||
next unless method.is_a? Parfait::TypedMethod
|
||||
log.debug "POS1 #{method.name}:#{at.to_s(16)}"
|
||||
method.cpu_instructions.set_position( at )
|
||||
method.cpu_instructions.set_position( at + 12)
|
||||
before = at
|
||||
nekst = method.binary
|
||||
while(nekst)
|
||||
@ -118,7 +118,8 @@ module Risc
|
||||
at += nekst.padded_length
|
||||
nekst = nekst.next
|
||||
end
|
||||
log.debug "POS2 #{method.name}:#{at.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
log.debug "Method #{method.name}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
log.debug "Instructions #{method.cpu_instructions.object_id.to_s(16)}:#{(before+12).to_s(16)}"
|
||||
end
|
||||
at
|
||||
end
|
||||
@ -136,6 +137,7 @@ module Risc
|
||||
return do_create_binary
|
||||
rescue LinkException
|
||||
not_ok += 1
|
||||
log.debug "Relink #{not_ok}"
|
||||
position_code
|
||||
end
|
||||
end
|
||||
@ -150,6 +152,7 @@ module Risc
|
||||
writer = BinaryWriter.new(method.binary)
|
||||
writer.assemble(method.cpu_instructions)
|
||||
end
|
||||
log.debug "BinaryInit #{cpu_init.first.object_id.to_s(16)}"
|
||||
BinaryWriter.new(binary_init).assemble(cpu_init)
|
||||
end
|
||||
|
||||
|
@ -6,6 +6,11 @@ module Risc
|
||||
# This class serves to write all the objects of the machine (wich also contain the code)
|
||||
# into one stream or binary text object. This is then written to an ELF text section.
|
||||
#
|
||||
# A word about positions: The c world has a thing called position independent code, and
|
||||
# baically we follw that idea. Code (ie jumps and constant loads) are all relative.
|
||||
# But we have pointers. In C the linker takes care of bending those, we have to
|
||||
# do that ourselves, in write_ref. That's why we need the load adddess and basically
|
||||
# we just add it to pointers.
|
||||
|
||||
class TextWriter
|
||||
include Logging
|
||||
|
@ -21,7 +21,7 @@ module Arm
|
||||
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]
|
||||
assert_code code , :call, [0x09,0x0,0x0,0xeb]
|
||||
end
|
||||
def test_swi
|
||||
code = @machine.swi( 0x05 )
|
||||
|
@ -99,7 +99,7 @@ module Arm
|
||||
|
||||
def test_move_object
|
||||
code = @machine.add( :r1 , label)
|
||||
code.set_position(0)
|
||||
code.set_position(0,0)
|
||||
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||
end
|
||||
|
||||
|
@ -37,6 +37,6 @@ class TestPositioned < MiniTest::Test
|
||||
|
||||
def test_pos_arm
|
||||
mov = Arm::ArmMachine.mov :r1, 128
|
||||
mov.set_position(0)
|
||||
mov.set_position(0,0)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user