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
|
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 method object for methods
|
||||||
arg = Positioned.position(@first) - Positioned.position(self)
|
arg = Positioned.position(@first) - Positioned.position(self) + 4
|
||||||
else
|
else
|
||||||
arg = @first
|
arg = @first
|
||||||
end
|
end
|
||||||
|
@ -21,11 +21,16 @@ module Arm
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_position( position )
|
def set_position( position , count )
|
||||||
Positioned.set_position(self,position)
|
Positioned.set_position(self,position)
|
||||||
position += byte_length
|
position += byte_length
|
||||||
if self.next
|
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
|
else
|
||||||
position
|
position
|
||||||
end
|
end
|
||||||
|
@ -45,9 +45,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# labels have the same position as their next
|
# labels have the same position as their next
|
||||||
def set_position( position )
|
def set_position( position , count = 0)
|
||||||
Positioned.set_position(self,position)
|
Positioned.set_position(self,position)
|
||||||
self.next.set_position(position) if self.next
|
self.next.set_position(position,count) if self.next
|
||||||
end
|
end
|
||||||
|
|
||||||
# shame we need this, just for logging
|
# shame we need this, just for logging
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
|
|
||||||
class Machine
|
class Machine
|
||||||
include Logging
|
include Logging
|
||||||
log_level :info
|
log_level :debug
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@booted = false
|
@booted = false
|
||||||
@ -77,9 +77,8 @@ module Risc
|
|||||||
def position_all
|
def position_all
|
||||||
translate_arm unless @translated
|
translate_arm unless @translated
|
||||||
#need the initial jump at 0 and then functions
|
#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)
|
Positioned.set_position(binary_init,0)
|
||||||
|
cpu_init.set_position( 12 ,0)
|
||||||
@code_start = position_objects( binary_init.padded_length )
|
@code_start = position_objects( binary_init.padded_length )
|
||||||
# and then everything code
|
# and then everything code
|
||||||
position_code
|
position_code
|
||||||
@ -93,7 +92,9 @@ module Risc
|
|||||||
objects.each do | id , objekt|
|
objects.each do | id , objekt|
|
||||||
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
||||||
Positioned.set_position(objekt,at)
|
Positioned.set_position(objekt,at)
|
||||||
|
before = at
|
||||||
at += objekt.padded_length
|
at += objekt.padded_length
|
||||||
|
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||||
end
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
@ -109,8 +110,7 @@ module Risc
|
|||||||
at = @code_start
|
at = @code_start
|
||||||
objects.each do |id , method|
|
objects.each do |id , method|
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
log.debug "POS1 #{method.name}:#{at.to_s(16)}"
|
method.cpu_instructions.set_position( at + 12)
|
||||||
method.cpu_instructions.set_position( at )
|
|
||||||
before = at
|
before = at
|
||||||
nekst = method.binary
|
nekst = method.binary
|
||||||
while(nekst)
|
while(nekst)
|
||||||
@ -118,7 +118,8 @@ module Risc
|
|||||||
at += nekst.padded_length
|
at += nekst.padded_length
|
||||||
nekst = nekst.next
|
nekst = nekst.next
|
||||||
end
|
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
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
@ -136,6 +137,7 @@ module Risc
|
|||||||
return do_create_binary
|
return do_create_binary
|
||||||
rescue LinkException
|
rescue LinkException
|
||||||
not_ok += 1
|
not_ok += 1
|
||||||
|
log.debug "Relink #{not_ok}"
|
||||||
position_code
|
position_code
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -150,6 +152,7 @@ module Risc
|
|||||||
writer = BinaryWriter.new(method.binary)
|
writer = BinaryWriter.new(method.binary)
|
||||||
writer.assemble(method.cpu_instructions)
|
writer.assemble(method.cpu_instructions)
|
||||||
end
|
end
|
||||||
|
log.debug "BinaryInit #{cpu_init.first.object_id.to_s(16)}"
|
||||||
BinaryWriter.new(binary_init).assemble(cpu_init)
|
BinaryWriter.new(binary_init).assemble(cpu_init)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,6 +6,11 @@ module Risc
|
|||||||
# This class serves to write all the objects of the machine (wich also contain the code)
|
# 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.
|
# 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
|
class TextWriter
|
||||||
include Logging
|
include Logging
|
||||||
|
@ -21,7 +21,7 @@ module Arm
|
|||||||
Positioned.set_position(bin , 0x20)
|
Positioned.set_position(bin , 0x20)
|
||||||
code = @machine.call( bin ,{} )#this jumps to the next instruction
|
code = @machine.call( bin ,{} )#this jumps to the next instruction
|
||||||
Positioned.set_position(code , 0)
|
Positioned.set_position(code , 0)
|
||||||
assert_code code , :call, [0x08,0x0,0x0,0xeb]
|
assert_code code , :call, [0x09,0x0,0x0,0xeb]
|
||||||
end
|
end
|
||||||
def test_swi
|
def test_swi
|
||||||
code = @machine.swi( 0x05 )
|
code = @machine.swi( 0x05 )
|
||||||
|
@ -99,7 +99,7 @@ module Arm
|
|||||||
|
|
||||||
def test_move_object
|
def test_move_object
|
||||||
code = @machine.add( :r1 , label)
|
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
|
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,6 +37,6 @@ class TestPositioned < MiniTest::Test
|
|||||||
|
|
||||||
def test_pos_arm
|
def test_pos_arm
|
||||||
mov = Arm::ArmMachine.mov :r1, 128
|
mov = Arm::ArmMachine.mov :r1, 128
|
||||||
mov.set_position(0)
|
mov.set_position(0,0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user