debugging binaries, initial jump issues
This commit is contained in:
parent
d84d208192
commit
1acd231a33
@ -24,13 +24,6 @@ module Arm
|
|||||||
raise "index error 0" if index == 0
|
raise "index error 0" if index == 0
|
||||||
index * 4
|
index * 4
|
||||||
end
|
end
|
||||||
# Arm stores the return address in a register (not on the stack)
|
|
||||||
# The register is called link , or lr for short .
|
|
||||||
# Maybe because it provides the "link" back to the caller
|
|
||||||
# the vm defines a register for the location, so we store it there.
|
|
||||||
def translate_SaveReturn( code )
|
|
||||||
ArmMachine.str( :lr , code.register , arm_index(code) )
|
|
||||||
end
|
|
||||||
|
|
||||||
def translate_Transfer( code )
|
def translate_Transfer( code )
|
||||||
# Risc machine convention is from => to
|
# Risc machine convention is from => to
|
||||||
|
@ -9,6 +9,8 @@ module Elf
|
|||||||
class ObjectWriter
|
class ObjectWriter
|
||||||
def initialize( machine )
|
def initialize( machine )
|
||||||
@machine = machine
|
@machine = machine
|
||||||
|
@machine.position_all
|
||||||
|
@machine.create_binary
|
||||||
target = Elf::Constants::TARGET_ARM
|
target = Elf::Constants::TARGET_ARM
|
||||||
@object = Elf::ObjectFile.new(target)
|
@object = Elf::ObjectFile.new(target)
|
||||||
sym_strtab = Elf::StringTableSection.new(".strtab")
|
sym_strtab = Elf::StringTableSection.new(".strtab")
|
||||||
|
@ -57,7 +57,7 @@ module Risc
|
|||||||
|
|
||||||
# add a constant (which get created during compilatio and need to be linked)
|
# add a constant (which get created during compilatio and need to be linked)
|
||||||
def add_constant(const)
|
def add_constant(const)
|
||||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
||||||
@constants << const
|
@constants << const
|
||||||
end
|
end
|
||||||
# To create binaries, objects (and labels) need to have a position
|
# To create binaries, objects (and labels) need to have a position
|
||||||
|
@ -11,7 +11,7 @@ module Positioned
|
|||||||
if pos == nil
|
if pos == nil
|
||||||
str = "position accessed but not set, "
|
str = "position accessed but not set, "
|
||||||
str += "0x#{object.object_id.to_s(16)}\n"
|
str += "0x#{object.object_id.to_s(16)}\n"
|
||||||
str += "for #{object.class} byte_length #{object.byte_length if object.respond_to?(:byte_length)} for #{object.inspect[0...100]}"
|
str += "for #{object.class} byte_length #{object.byte_length if object.respond_to?(:byte_length)} for #{object.inspect[0...130]}"
|
||||||
raise str
|
raise str
|
||||||
end
|
end
|
||||||
pos
|
pos
|
||||||
|
@ -9,9 +9,9 @@ module Risc
|
|||||||
|
|
||||||
class TextWriter
|
class TextWriter
|
||||||
include Logging
|
include Logging
|
||||||
log_level :info
|
log_level :debug
|
||||||
|
|
||||||
MARKER = 0xA51AF00D
|
MARKER = 0xBAD4C0DE
|
||||||
|
|
||||||
def initialize( machine)
|
def initialize( machine)
|
||||||
@machine = machine
|
@machine = machine
|
||||||
@ -25,7 +25,7 @@ module Risc
|
|||||||
# - all BinaryCode
|
# - all BinaryCode
|
||||||
def write_as_string
|
def write_as_string
|
||||||
@stream = StringIO.new
|
@stream = StringIO.new
|
||||||
write_any(@machine.binary_init)
|
write_init(@machine.binary_init)
|
||||||
write_debug
|
write_debug
|
||||||
write_objects
|
write_objects
|
||||||
write_code
|
write_code
|
||||||
@ -146,6 +146,18 @@ module Risc
|
|||||||
log.debug "Data4 witten stream 0x#{@stream.length.to_s(16)}"
|
log.debug "Data4 witten stream 0x#{@stream.length.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# first jump, treated as a binary code, but this one needs
|
||||||
|
# the actual jump as the first
|
||||||
|
def write_init( code )
|
||||||
|
code.each_word do |word|
|
||||||
|
@stream.write_unsigned_int_32( word || 0 )
|
||||||
|
end
|
||||||
|
write_ref_for( code.next )
|
||||||
|
write_ref_for( code.get_type )
|
||||||
|
@stream.write_signed_int_32( MARKER )
|
||||||
|
log.debug "Code16 witten stream 0x#{@stream.length.to_s(16)}"
|
||||||
|
end
|
||||||
|
|
||||||
def write_BinaryCode( code )
|
def write_BinaryCode( code )
|
||||||
@stream.write_signed_int_32( MARKER )
|
@stream.write_signed_int_32( MARKER )
|
||||||
write_ref_for( code.get_type )
|
write_ref_for( code.get_type )
|
||||||
|
@ -85,6 +85,13 @@ module Parfait
|
|||||||
@code.each_word{ len += 1}
|
@code.each_word{ len += 1}
|
||||||
assert_equal 13 , len
|
assert_equal 13 , len
|
||||||
end
|
end
|
||||||
|
def test_each_set
|
||||||
|
(1..13).each{|i| @code.set_word(i,i)}
|
||||||
|
all = []
|
||||||
|
@code.each_word{ |w| all << w}
|
||||||
|
assert_equal 1 , all.first
|
||||||
|
assert_equal 13 , all.last
|
||||||
|
end
|
||||||
def test_set_word
|
def test_set_word
|
||||||
assert_equal 1 , @code.set_word(1 , 1)
|
assert_equal 1 , @code.set_word(1 , 1)
|
||||||
end
|
end
|
||||||
|
@ -28,9 +28,18 @@ module Risc
|
|||||||
assert Positioned.position(obj)
|
assert Positioned.position(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
def test_binary
|
class TestMachineInit < MiniTest::Test
|
||||||
|
def setup
|
||||||
|
@machine = Risc.machine.boot
|
||||||
|
@machine.position_all
|
||||||
@machine.create_binary
|
@machine.create_binary
|
||||||
end
|
end
|
||||||
|
def test_has_binary
|
||||||
|
assert_equal Parfait::BinaryCode , @machine.binary_init.class
|
||||||
|
end
|
||||||
|
def test_has_jump
|
||||||
|
assert_equal "1" , @machine.binary_init.get_word(1).to_s(16)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user