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
|
||||
index * 4
|
||||
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 )
|
||||
# Risc machine convention is from => to
|
||||
|
@ -9,6 +9,8 @@ module Elf
|
||||
class ObjectWriter
|
||||
def initialize( machine )
|
||||
@machine = machine
|
||||
@machine.position_all
|
||||
@machine.create_binary
|
||||
target = Elf::Constants::TARGET_ARM
|
||||
@object = Elf::ObjectFile.new(target)
|
||||
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)
|
||||
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
|
||||
end
|
||||
# To create binaries, objects (and labels) need to have a position
|
||||
|
@ -11,7 +11,7 @@ module Positioned
|
||||
if pos == nil
|
||||
str = "position accessed but not set, "
|
||||
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
|
||||
end
|
||||
pos
|
||||
|
@ -9,9 +9,9 @@ module Risc
|
||||
|
||||
class TextWriter
|
||||
include Logging
|
||||
log_level :info
|
||||
log_level :debug
|
||||
|
||||
MARKER = 0xA51AF00D
|
||||
MARKER = 0xBAD4C0DE
|
||||
|
||||
def initialize( machine)
|
||||
@machine = machine
|
||||
@ -25,7 +25,7 @@ module Risc
|
||||
# - all BinaryCode
|
||||
def write_as_string
|
||||
@stream = StringIO.new
|
||||
write_any(@machine.binary_init)
|
||||
write_init(@machine.binary_init)
|
||||
write_debug
|
||||
write_objects
|
||||
write_code
|
||||
@ -146,6 +146,18 @@ module Risc
|
||||
log.debug "Data4 witten stream 0x#{@stream.length.to_s(16)}"
|
||||
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 )
|
||||
@stream.write_signed_int_32( MARKER )
|
||||
write_ref_for( code.get_type )
|
||||
|
@ -85,6 +85,13 @@ module Parfait
|
||||
@code.each_word{ len += 1}
|
||||
assert_equal 13 , len
|
||||
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
|
||||
assert_equal 1 , @code.set_word(1 , 1)
|
||||
end
|
||||
|
@ -28,9 +28,18 @@ module Risc
|
||||
assert Positioned.position(obj)
|
||||
end
|
||||
end
|
||||
|
||||
def test_binary
|
||||
end
|
||||
class TestMachineInit < MiniTest::Test
|
||||
def setup
|
||||
@machine = Risc.machine.boot
|
||||
@machine.position_all
|
||||
@machine.create_binary
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user