update to use parfait not virtual
more ripples reverting to integers (not virtual::integer)
This commit is contained in:
parent
c28430698c
commit
a46b2d5c56
@ -8,6 +8,8 @@ module Arm
|
|||||||
# - Move
|
# - Move
|
||||||
# - Call class Instruction
|
# - Call class Instruction
|
||||||
class Instruction
|
class Instruction
|
||||||
|
include Positioned
|
||||||
|
|
||||||
def initialize options
|
def initialize options
|
||||||
@attributes = options
|
@attributes = options
|
||||||
end
|
end
|
||||||
@ -15,17 +17,7 @@ module Arm
|
|||||||
def opcode
|
def opcode
|
||||||
@attributes[:opcode]
|
@attributes[:opcode]
|
||||||
end
|
end
|
||||||
def position
|
|
||||||
raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def set_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 > 32)
|
|
||||||
raise "position set again #{pos}!=#{@position} for #{self}"
|
|
||||||
end
|
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
|
|
||||||
# this is giving read access to the attributes hash via .attibute syntax
|
# this is giving read access to the attributes hash via .attibute syntax
|
||||||
# so for an instruction pop you can write pop.opcode to get the :opcode attribute
|
# so for an instruction pop you can write pop.opcode to get the :opcode attribute
|
||||||
|
@ -33,33 +33,27 @@ module Arm
|
|||||||
when :b, :call
|
when :b, :call
|
||||||
arg = @first
|
arg = @first
|
||||||
#puts "BLAB #{arg.inspect}"
|
#puts "BLAB #{arg.inspect}"
|
||||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
if arg.is_a?(Virtual::Block) or arg.is_a?(Parfait::Method)
|
||||||
arg = Virtual::IntegerConstant.new( arg )
|
|
||||||
end
|
|
||||||
if arg.is_a?(Virtual::Block) or arg.is_a?(Virtual::CompiledMethodInfo)
|
|
||||||
#relative addressing for jumps/calls
|
#relative addressing for jumps/calls
|
||||||
diff = arg.position - self.position
|
diff = arg.position - self.position
|
||||||
# but because of the arm "theoretical" 3- stage pipeline, we have to subtract 2 words (fetch/decode)
|
# but because of the arm "theoretical" 3- stage pipeline, we have to subtract 2 words (fetch/decode)
|
||||||
# But, for methods, this happens to be the size of the object header, so there it balances out, but not blocks
|
# But, for methods, this happens to be the size of the object header, so there it balances out, but not blocks
|
||||||
diff -= 8 if arg.is_a?(Virtual::Block)
|
diff -= 8 if arg.is_a?(Virtual::Block)
|
||||||
arg = Virtual::IntegerConstant.new(diff)
|
arg = diff
|
||||||
end
|
end
|
||||||
if (arg.is_a?(Virtual::IntegerConstant))
|
if (arg.is_a?(Numeric))
|
||||||
jmp_val = arg.integer >> 2
|
jmp_val = arg >> 2
|
||||||
packed = [jmp_val].pack('l')
|
packed = [jmp_val].pack('l')
|
||||||
# signed 32-bit, condense to 24-bit
|
# signed 32-bit, condense to 24-bit
|
||||||
# TODO add check that the value fits into 24 bits
|
# TODO add check that the value fits into 24 bits
|
||||||
io << packed[0,3]
|
io << packed[0,3]
|
||||||
else
|
else
|
||||||
raise "else not coded arg =#{arg}: #{inspect}"
|
raise "else not coded arg =\n#{arg.to_s[0..1000]}: #{inspect[0..1000]}"
|
||||||
end
|
end
|
||||||
io.write_uint8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4)
|
io.write_uint8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4)
|
||||||
when :swi
|
when :swi
|
||||||
arg = @first
|
arg = @first
|
||||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
if (arg.is_a?(Numeric))
|
||||||
arg = Virtual::IntegerConstant.new( arg )
|
|
||||||
end
|
|
||||||
if (arg.is_a?(Virtual::IntegerConstant))
|
|
||||||
packed = [arg.integer].pack('L')[0,3]
|
packed = [arg.integer].pack('L')[0,3]
|
||||||
io << packed
|
io << packed
|
||||||
io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4)
|
io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4)
|
||||||
|
@ -21,16 +21,16 @@ module Arm
|
|||||||
immediate = @immediate
|
immediate = @immediate
|
||||||
|
|
||||||
arg = @right
|
arg = @right
|
||||||
if arg.is_a?(Virtual::ObjectConstant)
|
if arg.is_a?(Parfait::Object)
|
||||||
# do pc relative addressing with the difference to the instuction
|
# do pc relative addressing with the difference to the instuction
|
||||||
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
|
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
|
||||||
arg = Virtual::IntegerConstant.new( arg.position - self.position - 8 )
|
arg = arg.position - self.position - 8
|
||||||
rn = :pc
|
rn = :pc
|
||||||
end
|
end
|
||||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
if( arg.is_a? Symbol )
|
||||||
arg = Register::RegisterReference.new( arg )
|
arg = Register::RegisterReference.new( arg )
|
||||||
end
|
end
|
||||||
if (arg.is_a?(Virtual::IntegerConstant))
|
if (arg.is_a?(Numeric))
|
||||||
if (arg.fits_u8?)
|
if (arg.fits_u8?)
|
||||||
# no shifting needed
|
# no shifting needed
|
||||||
operand = arg.integer
|
operand = arg.integer
|
||||||
|
@ -10,7 +10,7 @@ module Arm
|
|||||||
super(attributes)
|
super(attributes)
|
||||||
@result = result
|
@result = result
|
||||||
@left = left
|
@left = left
|
||||||
@right = right.is_a?(Fixnum) ? Virtual::IntegerConstant.new(right) : right
|
@right = right
|
||||||
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
||||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||||
@operand = 0
|
@operand = 0
|
||||||
@ -27,17 +27,13 @@ module Arm
|
|||||||
immediate = @immediate
|
immediate = @immediate
|
||||||
|
|
||||||
right = @right
|
right = @right
|
||||||
if @left.is_a?(Virtual::ObjectConstant)
|
if @left.is_a?(Parfait::Object)
|
||||||
# do pc relative addressing with the difference to the instuction
|
# do pc relative addressing with the difference to the instuction
|
||||||
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
||||||
right = @left.position - self.position - 8
|
right = @left.position - self.position - 8
|
||||||
left = :pc
|
left = :pc
|
||||||
end
|
end
|
||||||
# automatic wrapping, for machine internal code and testing
|
if (right.is_a?(Numeric))
|
||||||
if( right.is_a? Fixnum )
|
|
||||||
right = Virtual::IntegerConstant.new( right )
|
|
||||||
end
|
|
||||||
if (right.is_a?(Virtual::IntegerConstant))
|
|
||||||
if (right.fits_u8?)
|
if (right.fits_u8?)
|
||||||
# no shifting needed
|
# no shifting needed
|
||||||
operand = right.integer
|
operand = right.integer
|
||||||
|
@ -46,14 +46,14 @@ module Arm
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif (arg.is_a?(Virtual::ObjectConstant) ) #use pc relative
|
elsif (arg.is_a?(Parfait::Object) ) #use pc relative
|
||||||
rn = :pc
|
rn = :pc
|
||||||
operand = arg.position - self.position - 8 #stringtable is after code
|
operand = arg.position - self.position - 8 #stringtable is after code
|
||||||
add_offset = 1
|
add_offset = 1
|
||||||
if (operand.abs > 4095)
|
if (operand.abs > 4095)
|
||||||
raise "reference offset too large/small (max 4095) #{arg} #{inspect}"
|
raise "reference offset too large/small (max 4095) #{arg} #{inspect}"
|
||||||
end
|
end
|
||||||
elsif( arg.is_a?(Virtual::IntegerConstant) )
|
elsif( arg.is_a?(Numeric) )
|
||||||
#TODO untested brach, probably not working
|
#TODO untested brach, probably not working
|
||||||
raise "is this working ?? #{arg} #{inspect}"
|
raise "is this working ?? #{arg} #{inspect}"
|
||||||
@pre_post_index = 1
|
@pre_post_index = 1
|
||||||
|
@ -36,7 +36,7 @@ module Arm
|
|||||||
operand = @operand
|
operand = @operand
|
||||||
immediate = @immediate
|
immediate = @immediate
|
||||||
right = @from
|
right = @from
|
||||||
if right.is_a?(Virtual::ObjectConstant)
|
if right.is_a?(Parfait::Object)
|
||||||
r_pos = right.position
|
r_pos = right.position
|
||||||
# do pc relative addressing with the difference to the instuction
|
# 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)
|
# 8 is for the funny pipeline adjustment (ie pc pointing to fetch and not execute)
|
||||||
@ -44,7 +44,7 @@ module Arm
|
|||||||
puts "Position #{r_pos} from #{self.position} = #{right}"
|
puts "Position #{r_pos} from #{self.position} = #{right}"
|
||||||
rn = :pc
|
rn = :pc
|
||||||
end
|
end
|
||||||
if (right.is_a?(Virtual::IntegerConstant))
|
if (right.is_a?(Numeric))
|
||||||
if (right.fits_u8?)
|
if (right.fits_u8?)
|
||||||
# no shifting needed
|
# no shifting needed
|
||||||
operand = right.integer
|
operand = right.integer
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require "parfait/value"
|
require "parfait/value"
|
||||||
|
require "parfait/integer"
|
||||||
require "parfait/object"
|
require "parfait/object"
|
||||||
require "parfait/module"
|
require "parfait/module"
|
||||||
require "parfait/class"
|
require "parfait/class"
|
||||||
|
Loading…
Reference in New Issue
Block a user