not wrapping the cpu initial jump anymore
also introduce padding after cpu_init (wip)
This commit is contained in:
parent
232fe67c09
commit
2d901bf7b6
@ -21,26 +21,27 @@ module Risc
|
|||||||
@risc_init = nil
|
@risc_init = nil
|
||||||
@constants = []
|
@constants = []
|
||||||
end
|
end
|
||||||
attr_reader :constants , :cpu_init , :binary_init
|
attr_reader :constants , :cpu_init
|
||||||
attr_reader :booted , :translated
|
attr_reader :booted , :translated
|
||||||
|
attr_reader :platform
|
||||||
|
|
||||||
# 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
|
||||||
#
|
#
|
||||||
# currently we have no machanism to translate to other cpu's (nor such translators)
|
# currently we have no machanism to translate to other cpu's (nor such translators)
|
||||||
# but the mechanism is ready
|
# but the mechanism is ready
|
||||||
def translate_arm
|
def translate_arm
|
||||||
|
@platform = Platform.for("Arm")
|
||||||
@translated = true
|
@translated = true
|
||||||
translate(Arm::Translator.new)
|
translate(@platform.translator)
|
||||||
end
|
end
|
||||||
|
|
||||||
# translate code to whatever cpu the translator translates to
|
# 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
|
# and then translating all methods
|
||||||
def translate( translator )
|
def translate( translator )
|
||||||
methods = Parfait.object_space.get_all_methods
|
methods = Parfait.object_space.get_all_methods
|
||||||
translate_methods( methods , translator )
|
translate_methods( methods , translator )
|
||||||
@cpu_init = risc_init.to_cpu(translator)
|
@cpu_init = risc_init.to_cpu(translator)
|
||||||
@binary_init = Parfait::BinaryCode.new(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# go through all methods and translate them to cpu, given the translator
|
# go through all methods and translate them to cpu, given the translator
|
||||||
@ -77,9 +78,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
|
||||||
Position.set(binary_init,0)
|
Position.set(cpu_init , 0 , cpu_init)
|
||||||
Position.set(cpu_init , 12 , binary_init)
|
@code_start = position_objects( @platform.padding )
|
||||||
@code_start = position_objects( binary_init.padded_length )
|
|
||||||
# and then everything code
|
# and then everything code
|
||||||
position_code
|
position_code
|
||||||
end
|
end
|
||||||
@ -91,6 +91,7 @@ module Risc
|
|||||||
# want to have the objects first in the executable
|
# want to have the objects first in the executable
|
||||||
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 )
|
||||||
|
next if objekt.is_a?( Parfait::TypedMethod)
|
||||||
before = at
|
before = at
|
||||||
Position.set(objekt,at)
|
Position.set(objekt,at)
|
||||||
at += objekt.padded_length
|
at += objekt.padded_length
|
||||||
@ -111,15 +112,10 @@ module Risc
|
|||||||
objects.each do |id , method|
|
objects.each do |id , method|
|
||||||
next unless method.is_a? Parfait::TypedMethod
|
next unless method.is_a? Parfait::TypedMethod
|
||||||
before = at
|
before = at
|
||||||
|
Position.set(method,at)
|
||||||
|
at += method.padded_length
|
||||||
Position.set( method.binary , at , method)
|
Position.set( method.binary , at , method)
|
||||||
Position.set( method.cpu_instructions, at + 12 , method.binary)
|
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 "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)}"
|
log.debug "Instructions #{method.cpu_instructions.object_id.to_s(16)}:#{(before+12).to_s(16)}"
|
||||||
end
|
end
|
||||||
@ -139,7 +135,6 @@ module Risc
|
|||||||
writer.assemble(method.cpu_instructions)
|
writer.assemble(method.cpu_instructions)
|
||||||
end
|
end
|
||||||
log.debug "BinaryInit #{cpu_init.first.object_id.to_s(16)}"
|
log.debug "BinaryInit #{cpu_init.first.object_id.to_s(16)}"
|
||||||
BinaryWriter.new(binary_init).assemble(cpu_init)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
|
@ -15,8 +15,12 @@ module Risc
|
|||||||
@method = method
|
@method = method
|
||||||
end
|
end
|
||||||
def init(at)
|
def init(at)
|
||||||
return unless code.next
|
next_pos = at + code.padded_length
|
||||||
Position.set(code.next , at + code.padded_length, method)
|
if code.next
|
||||||
|
Position.set(code.next , next_pos, method)
|
||||||
|
else
|
||||||
|
Position.set(method , next_pos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def reset_to(pos)
|
def reset_to(pos)
|
||||||
super(pos)
|
super(pos)
|
||||||
|
@ -18,7 +18,7 @@ module Risc
|
|||||||
|
|
||||||
MARKER = 0xBAD4C0DE
|
MARKER = 0xBAD4C0DE
|
||||||
|
|
||||||
def initialize( machine)
|
def initialize(machine)
|
||||||
@machine = machine
|
@machine = machine
|
||||||
@load_at = 0x10054 # this is linux/arm
|
@load_at = 0x10054 # this is linux/arm
|
||||||
end
|
end
|
||||||
@ -29,7 +29,7 @@ module Risc
|
|||||||
# - all BinaryCode
|
# - all BinaryCode
|
||||||
def write_as_string
|
def write_as_string
|
||||||
@stream = StringIO.new
|
@stream = StringIO.new
|
||||||
write_init(@machine.binary_init)
|
write_init(@machine.cpu_init)
|
||||||
write_debug
|
write_debug
|
||||||
write_objects
|
write_objects
|
||||||
write_code
|
write_code
|
||||||
@ -150,15 +150,9 @@ 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
|
# first jump,
|
||||||
# the actual jump as the first
|
def write_init( cpu_init )
|
||||||
def write_init( code )
|
cpu_init.assemble(@stream)
|
||||||
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 "Init witten stream 0x#{@stream.length.to_s(16)}"
|
log.debug "Init witten stream 0x#{@stream.length.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ module Arm
|
|||||||
# the address is what an assembler calculates (a signed number for the amount of instructions),
|
# the address is what an assembler calculates (a signed number for the amount of instructions),
|
||||||
# ie the relative (to pc) address -8 (pipeline) /4 so save space
|
# ie the relative (to pc) address -8 (pipeline) /4 so save space
|
||||||
# so the cpu adds the value*4 and starts loading that (load, decode, execute)
|
# so the cpu adds the value*4 and starts loading that (load, decode, execute)
|
||||||
code = @machine.b( -4 ) #this jumps to the next instruction
|
code = @machine.b( 0 ) #this jumps to the next next instruction
|
||||||
assert_code code , :b , [0xff,0xff,0xff,0xea] #ea ff ff fe
|
assert_code code , :b , [0x0,0x0,0x0,0xea] #ea 00 00 00
|
||||||
end
|
end
|
||||||
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
|
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
|
||||||
code = @machine.call( -4 ,{} )#this jumps to the next instruction
|
code = @machine.call( -4 ,{} )#this jumps to the next instruction
|
||||||
|
@ -35,23 +35,14 @@ module Risc
|
|||||||
@machine.position_all
|
@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 "ea000fb4" , @machine.binary_init.get_word(1).to_s(16)
|
|
||||||
end
|
|
||||||
def test_pos_bin
|
|
||||||
assert_equal "0x0" , Position.get(@machine.binary_init).to_s
|
|
||||||
end
|
|
||||||
def test_pos_cpu
|
def test_pos_cpu
|
||||||
assert_equal 12 , Position.get(@machine.cpu_init).at
|
assert_equal 0 , Position.get(@machine.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
def test_cpu_at
|
||||||
assert_equal "0x3ee4" , Position.get(@machine.cpu_init.first).to_s
|
assert_equal "0x4d50" , Position.get(@machine.cpu_init.first).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_bin
|
def test_cpu_bin
|
||||||
assert_equal "0x3ed8" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
|
assert_equal "0x4d44" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
|
||||||
end
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class
|
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class
|
||||||
|
Loading…
Reference in New Issue
Block a user