more work on large moves, including the notion of linking again
This commit is contained in:
parent
4af93493fb
commit
49b6b99ab9
@ -13,37 +13,18 @@ module Arm
|
|||||||
@immediate = 0
|
@immediate = 0
|
||||||
@rn = :r0 # register zero = zero bit pattern
|
@rn = :r0 # register zero = zero bit pattern
|
||||||
@from = Virtual::IntegerConstant.new( @from ) if( @from.is_a? Fixnum )
|
@from = Virtual::IntegerConstant.new( @from ) if( @from.is_a? Fixnum )
|
||||||
|
@extra = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# arm intrucions are pretty sensible, and always 4 bytes (thumb not supported)
|
# arm intrucions are pretty sensible, and always 4 bytes (thumb not supported)
|
||||||
# but not all constants fit into the part of the instruction that is left after the instruction code,
|
# but not all constants fit into the part of the instruction that is left after the instruction code,
|
||||||
# so large moves have to be split into two instrucitons. we handle this here, just this instruciton looks
|
# so large moves have to be split into two instructions.
|
||||||
# longer
|
# we handle this "transparently", just this instruction looks longer
|
||||||
|
# alas, full transparency is not achieved as we only know when to use 2 instruction once we know where def the
|
||||||
|
# other object is, and that position is only set after code positions have been determined (in link) and so
|
||||||
|
# see below in assemble
|
||||||
def mem_length
|
def mem_length
|
||||||
return 4
|
@extra ? 8 : 4
|
||||||
is_simple ? 4 : 8
|
|
||||||
end
|
|
||||||
|
|
||||||
# a constant (the one we want to move) can either be < 256 or be rotated in a funny arm way
|
|
||||||
# if neither works (not simple !) we need two instructions to make the move
|
|
||||||
def is_simple
|
|
||||||
right = @from
|
|
||||||
if right.is_a?(Virtual::ObjectConstant)
|
|
||||||
r_pos = right.position
|
|
||||||
# do pc relative addressing with the difference to the instuction
|
|
||||||
# 8 is for the funny pipeline adjustment (ie pc pointing to fetch and not execute)
|
|
||||||
right = Virtual::IntegerConstant.new( r_pos - self.position - 8 )
|
|
||||||
end
|
|
||||||
if (right.is_a?(Virtual::IntegerConstant))
|
|
||||||
if (right.fits_u8?)
|
|
||||||
return true
|
|
||||||
elsif (calculate_u8_with_rr(right))
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble(io)
|
def assemble(io)
|
||||||
@ -72,10 +53,15 @@ module Arm
|
|||||||
immediate = 1
|
immediate = 1
|
||||||
raise "hmm"
|
raise "hmm"
|
||||||
else
|
else
|
||||||
operand = right.integer / 256
|
# and so it continues: when we notice that the const doesn't fit, first time we raise an
|
||||||
immediate = 1
|
# error,but set the extra flag, to say the instruction is now 8 bytes
|
||||||
|
# then on subsequent assemlies we can assemble
|
||||||
raise "cannot fit numeric literal argument in operand #{right.inspect}"
|
unless @extra
|
||||||
|
@extra = 1
|
||||||
|
raise ::Register::LinkException.new("cannot fit numeric literal argument in operand #{right.inspect}")
|
||||||
|
end
|
||||||
|
# now we can do the actual breaking of instruction
|
||||||
|
raise "at leat we got here"
|
||||||
end
|
end
|
||||||
elsif (right.is_a?(Symbol) or right.is_a?(Virtual::Integer))
|
elsif (right.is_a?(Symbol) or right.is_a?(Virtual::Integer))
|
||||||
operand = reg_code(right) #integer means the register the integer is in (otherwise constant)
|
operand = reg_code(right) #integer means the register the integer is in (otherwise constant)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module Register
|
module Register
|
||||||
|
class LinkException < Exception
|
||||||
|
end
|
||||||
# Assmble the object space into a binary.
|
# Assmble the object space into a binary.
|
||||||
# Link first to get positions, then assemble
|
# Link first to get positions, then assemble
|
||||||
# link and assemble functions for each class are close to each other, so to get them the same.
|
# link and assemble functions for each class are close to each other, so to get them the same.
|
||||||
@ -36,6 +37,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble
|
def assemble
|
||||||
|
begin
|
||||||
link
|
link
|
||||||
@stream = StringIO.new
|
@stream = StringIO.new
|
||||||
mid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
|
mid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
|
||||||
@ -51,6 +53,10 @@ module Register
|
|||||||
next if objekt.is_a? Virtual::CompiledMethod
|
next if objekt.is_a? Virtual::CompiledMethod
|
||||||
assemble_object( objekt )
|
assemble_object( objekt )
|
||||||
end
|
end
|
||||||
|
rescue LinkException => e
|
||||||
|
puts "coought #{e}"
|
||||||
|
retry
|
||||||
|
end
|
||||||
puts "Assembled #{@stream.length.to_s(16)}"
|
puts "Assembled #{@stream.length.to_s(16)}"
|
||||||
return @stream.string
|
return @stream.string
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
require_relative "code"
|
|
||||||
module Register
|
module Register
|
||||||
|
|
||||||
# The register machine model is close to current hardware and has following instruction classes
|
# The register machine model is close to current hardware and has following instruction classes
|
||||||
|
@ -56,6 +56,10 @@ module Virtual
|
|||||||
def mem_length
|
def mem_length
|
||||||
padded(1 + string.length)
|
padded(1 + string.length)
|
||||||
end
|
end
|
||||||
|
def set_position pos
|
||||||
|
puts "STRING #{pos} #{string}"
|
||||||
|
super
|
||||||
|
end
|
||||||
def position
|
def position
|
||||||
return @position if @position
|
return @position if @position
|
||||||
return @string.position if @string.position
|
return @string.position if @string.position
|
||||||
|
@ -26,7 +26,10 @@ module Virtual
|
|||||||
@position
|
@position
|
||||||
end
|
end
|
||||||
def set_position pos
|
def set_position pos
|
||||||
raise "position set again #{pos}!=#{@position} for #{self}" if @position != nil and (@position != pos)
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures
|
||||||
|
if @position != nil and ((@position - pos).abs > 15)
|
||||||
|
raise "position set again #{pos}!=#{@position} for #{self}"
|
||||||
|
end
|
||||||
@position = pos
|
@position = pos
|
||||||
end
|
end
|
||||||
def inspect
|
def inspect
|
||||||
|
Loading…
Reference in New Issue
Block a user