use a binary code for the first jump
This commit is contained in:
parent
00be522419
commit
34b16a2332
@ -21,12 +21,7 @@ module Risc
|
|||||||
# objects must be written in same order as positioned / assembled
|
# objects must be written in same order as positioned / assembled
|
||||||
def write_as_string
|
def write_as_string
|
||||||
@stream = StringIO.new
|
@stream = StringIO.new
|
||||||
Positioned.set_position(@machine.cpu_init.first , 0)
|
write_any(@machine.binary_init)
|
||||||
puts ":#{Positioned.position(@machine.cpu_init.first)}:"
|
|
||||||
@machine.cpu_init.assemble( @stream )
|
|
||||||
8.times do
|
|
||||||
@stream.write_unsigned_int_8(0)
|
|
||||||
end
|
|
||||||
write_debug
|
write_debug
|
||||||
write_objects
|
write_objects
|
||||||
write_code
|
write_code
|
||||||
@ -69,7 +64,7 @@ module Risc
|
|||||||
def write_any( obj )
|
def write_any( obj )
|
||||||
write_any_log( obj , "Write")
|
write_any_log( obj , "Write")
|
||||||
if @stream.length != Positioned.position(obj)
|
if @stream.length != Positioned.position(obj)
|
||||||
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at #{stream_position} not #{Positioned.position(obj)}"
|
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not 0x#{Positioned.position(obj).to_s(16)}"
|
||||||
end
|
end
|
||||||
write_any_out(obj)
|
write_any_out(obj)
|
||||||
write_any_log( obj , "Wrote")
|
write_any_log( obj , "Wrote")
|
||||||
@ -81,8 +76,11 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_any_out(obj)
|
def write_any_out(obj)
|
||||||
if obj.is_a?(Parfait::Word) or obj.is_a?(Symbol)
|
case obj
|
||||||
|
when Parfait::Word, Symbol
|
||||||
write_String obj
|
write_String obj
|
||||||
|
when Parfait::BinaryCode
|
||||||
|
write_BinaryCode obj
|
||||||
else
|
else
|
||||||
write_object obj
|
write_object obj
|
||||||
end
|
end
|
||||||
@ -102,7 +100,8 @@ module Risc
|
|||||||
|
|
||||||
def write_object_check(object)
|
def write_object_check(object)
|
||||||
log.debug "Write object #{object.class} #{object.inspect[0..100]}"
|
log.debug "Write object #{object.class} #{object.inspect[0..100]}"
|
||||||
unless @objects.has_key? object.object_id
|
#Only initially created codes are collected. Binary_init and method "tails" not
|
||||||
|
if !@objects.has_key?(object.object_id) and !object.is_a?(Parfait::BinaryCode)
|
||||||
log.debug "Object at 0x#{Positioned.position(object).to_s(16)}:#{object.get_type()}"
|
log.debug "Object at 0x#{Positioned.position(object).to_s(16)}:#{object.get_type()}"
|
||||||
raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}"
|
raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}"
|
||||||
end
|
end
|
||||||
@ -132,8 +131,14 @@ module Risc
|
|||||||
written
|
written
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_BinaryCode code
|
def write_BinaryCode( code )
|
||||||
write_String code
|
@stream.write_signed_int_32( MARKER )
|
||||||
|
write_ref_for( code.get_type )
|
||||||
|
write_ref_for( code.next )
|
||||||
|
code.each_word do |word|
|
||||||
|
@stream.write_unsigned_int_32( word || 0 )
|
||||||
|
end
|
||||||
|
log.debug "Code16 witten stream 0x#{@stream.length.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_String( string )
|
def write_String( string )
|
||||||
|
@ -20,7 +20,7 @@ module Risc
|
|||||||
@booted = false
|
@booted = false
|
||||||
@constants = []
|
@constants = []
|
||||||
end
|
end
|
||||||
attr_reader :constants , :risc_init , :cpu_init
|
attr_reader :constants , :risc_init , :cpu_init , :binary_init
|
||||||
attr_reader :booted , :translated
|
attr_reader :booted , :translated
|
||||||
|
|
||||||
# translate to arm, ie instantiate an arm translator and pass it to translate
|
# translate to arm, ie instantiate an arm translator and pass it to translate
|
||||||
@ -37,6 +37,7 @@ module Risc
|
|||||||
methods = Parfait.object_space.collect_methods
|
methods = Parfait.object_space.collect_methods
|
||||||
translate_methods( methods , translator )
|
translate_methods( methods , translator )
|
||||||
@cpu_init = translator.translate( @risc_init )
|
@cpu_init = translator.translate( @risc_init )
|
||||||
|
@binary_init = Parfait::BinaryCode.new(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_methods(methods , translator)
|
def translate_methods(methods , translator)
|
||||||
@ -55,8 +56,9 @@ module Risc
|
|||||||
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 )
|
cpu_init.set_position( 0 )
|
||||||
at = cpu_init.byte_length
|
Positioned.set_position(cpu_init.first , 0)
|
||||||
at = position_objects( at )
|
Positioned.set_position(binary_init,0)
|
||||||
|
at = position_objects( binary_init.padded_length )
|
||||||
# and then everything code
|
# and then everything code
|
||||||
position_code_from( at )
|
position_code_from( at )
|
||||||
end
|
end
|
||||||
@ -101,6 +103,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
|
||||||
|
BinaryWriter.new(binary_init).assemble(cpu_init)
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
|
Loading…
Reference in New Issue
Block a user