not wrapping the cpu initial jump anymore
also introduce padding after cpu_init (wip)
This commit is contained in:
@ -21,26 +21,27 @@ module Risc
|
||||
@risc_init = nil
|
||||
@constants = []
|
||||
end
|
||||
attr_reader :constants , :cpu_init , :binary_init
|
||||
attr_reader :constants , :cpu_init
|
||||
attr_reader :booted , :translated
|
||||
attr_reader :platform
|
||||
|
||||
# translate to arm, ie instantiate an arm translator and pass it to translate
|
||||
#
|
||||
# currently we have no machanism to translate to other cpu's (nor such translators)
|
||||
# but the mechanism is ready
|
||||
def translate_arm
|
||||
@platform = Platform.for("Arm")
|
||||
@translated = true
|
||||
translate(Arm::Translator.new)
|
||||
translate(@platform.translator)
|
||||
end
|
||||
|
||||
# translate code to whatever cpu the translator translates to
|
||||
# this means translating the initial jump (cpu_init into binary_init)
|
||||
# this means translating the initial jump
|
||||
# and then translating all methods
|
||||
def translate( translator )
|
||||
methods = Parfait.object_space.get_all_methods
|
||||
translate_methods( methods , translator )
|
||||
@cpu_init = risc_init.to_cpu(translator)
|
||||
@binary_init = Parfait::BinaryCode.new(1)
|
||||
end
|
||||
|
||||
# go through all methods and translate them to cpu, given the translator
|
||||
@ -77,9 +78,8 @@ module Risc
|
||||
def position_all
|
||||
translate_arm unless @translated
|
||||
#need the initial jump at 0 and then functions
|
||||
Position.set(binary_init,0)
|
||||
Position.set(cpu_init , 12 , binary_init)
|
||||
@code_start = position_objects( binary_init.padded_length )
|
||||
Position.set(cpu_init , 0 , cpu_init)
|
||||
@code_start = position_objects( @platform.padding )
|
||||
# and then everything code
|
||||
position_code
|
||||
end
|
||||
@ -91,6 +91,7 @@ module Risc
|
||||
# want to have the objects first in the executable
|
||||
objects.each do | id , objekt|
|
||||
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
||||
next if objekt.is_a?( Parfait::TypedMethod)
|
||||
before = at
|
||||
Position.set(objekt,at)
|
||||
at += objekt.padded_length
|
||||
@ -111,15 +112,10 @@ module Risc
|
||||
objects.each do |id , method|
|
||||
next unless method.is_a? Parfait::TypedMethod
|
||||
before = at
|
||||
Position.set(method,at)
|
||||
at += method.padded_length
|
||||
Position.set( method.binary , at , method)
|
||||
Position.set( method.cpu_instructions, at + 12 , method.binary)
|
||||
# before = at
|
||||
# nekst = method.binary
|
||||
# while(nekst)
|
||||
# Position.set(nekst , at , method)
|
||||
# at += nekst.padded_length
|
||||
# nekst = nekst.next
|
||||
# end
|
||||
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
|
||||
@ -139,7 +135,6 @@ module Risc
|
||||
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
|
||||
|
||||
def boot
|
||||
|
@ -15,8 +15,12 @@ module Risc
|
||||
@method = method
|
||||
end
|
||||
def init(at)
|
||||
return unless code.next
|
||||
Position.set(code.next , at + code.padded_length, method)
|
||||
next_pos = at + code.padded_length
|
||||
if code.next
|
||||
Position.set(code.next , next_pos, method)
|
||||
else
|
||||
Position.set(method , next_pos)
|
||||
end
|
||||
end
|
||||
def reset_to(pos)
|
||||
super(pos)
|
||||
|
@ -18,7 +18,7 @@ module Risc
|
||||
|
||||
MARKER = 0xBAD4C0DE
|
||||
|
||||
def initialize( machine)
|
||||
def initialize(machine)
|
||||
@machine = machine
|
||||
@load_at = 0x10054 # this is linux/arm
|
||||
end
|
||||
@ -29,7 +29,7 @@ module Risc
|
||||
# - all BinaryCode
|
||||
def write_as_string
|
||||
@stream = StringIO.new
|
||||
write_init(@machine.binary_init)
|
||||
write_init(@machine.cpu_init)
|
||||
write_debug
|
||||
write_objects
|
||||
write_code
|
||||
@ -150,15 +150,9 @@ 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 )
|
||||
# first jump,
|
||||
def write_init( cpu_init )
|
||||
cpu_init.assemble(@stream)
|
||||
log.debug "Init witten stream 0x#{@stream.length.to_s(16)}"
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user