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,28 +17,18 @@ 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
|
||||||
|
|
||||||
# TODDO: review (don't remember what the "set_" stuff was for)
|
# TODDO: review (don't remember what the "set_" stuff was for)
|
||||||
def method_missing name , *args , &block
|
def method_missing name , *args , &block
|
||||||
return super unless (args.length <= 1) or block_given?
|
return super unless (args.length <= 1) or block_given?
|
||||||
set , attribute = name.to_s.split("set_")
|
set , attribute = name.to_s.split("set_")
|
||||||
if set == ""
|
if set == ""
|
||||||
@attributes[attribute.to_sym] = args[0] || 1
|
@attributes[attribute.to_sym] = args[0] || 1
|
||||||
return self
|
return self
|
||||||
else
|
else
|
||||||
return super
|
return super
|
||||||
end
|
end
|
||||||
|
@ -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)
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
module Arm
|
module Arm
|
||||||
class CompareInstruction < Instruction
|
class CompareInstruction < Instruction
|
||||||
include Arm::Constants
|
include Arm::Constants
|
||||||
|
|
||||||
def initialize(left , right , attributes)
|
def initialize(left , right , attributes)
|
||||||
super(attributes)
|
super(attributes)
|
||||||
@left = left
|
@left = left
|
||||||
@right = right.is_a?(Fixnum) ? IntegerConstant.new(right) : right
|
@right = right.is_a?(Fixnum) ? IntegerConstant.new(right) : right
|
||||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||||
@operand = 0
|
@operand = 0
|
||||||
@immediate = 0
|
@immediate = 0
|
||||||
@attributes[:update_status] = 1
|
@attributes[:update_status] = 1
|
||||||
@rn = left
|
@rn = left
|
||||||
@rd = :r0
|
@rd = :r0
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble(io)
|
def assemble(io)
|
||||||
# don't overwrite instance variables, to make assembly repeatable
|
# don't overwrite instance variables, to make assembly repeatable
|
||||||
rn = @rn
|
rn = @rn
|
||||||
@ -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
|
||||||
@ -54,7 +54,7 @@ module Arm
|
|||||||
# ror #0 == rrx
|
# ror #0 == rrx
|
||||||
raise "cannot rotate by zero #{arg} #{inspect}"
|
raise "cannot rotate by zero #{arg} #{inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
arg1 = arg.value
|
arg1 = arg.value
|
||||||
if (arg1.is_a?(Virtual::IntegerConstant))
|
if (arg1.is_a?(Virtual::IntegerConstant))
|
||||||
if (arg1.value >= 32)
|
if (arg1.value >= 32)
|
||||||
@ -72,16 +72,16 @@ module Arm
|
|||||||
raise "invalid operand argument #{arg.inspect} , #{inspect}"
|
raise "invalid operand argument #{arg.inspect} , #{inspect}"
|
||||||
end
|
end
|
||||||
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
||||||
val = (operand.is_a?(Symbol) or operand.is_a?(::Register::RegisterReference)) ? reg_code(operand) : operand
|
val = (operand.is_a?(Symbol) or operand.is_a?(::Register::RegisterReference)) ? reg_code(operand) : operand
|
||||||
val = 0 if val == nil
|
val = 0 if val == nil
|
||||||
val = shift(val , 0)
|
val = shift(val , 0)
|
||||||
raise inspect unless reg_code(@rd)
|
raise inspect unless reg_code(@rd)
|
||||||
val |= shift(reg_code(@rd) , 12)
|
val |= shift(reg_code(@rd) , 12)
|
||||||
val |= shift(reg_code(rn) , 12+4)
|
val |= shift(reg_code(rn) , 12+4)
|
||||||
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
||||||
val |= shift(op_bit_code , 12+4+4 +1)
|
val |= shift(op_bit_code , 12+4+4 +1)
|
||||||
val |= shift(immediate , 12+4+4 +1+4)
|
val |= shift(immediate , 12+4+4 +1+4)
|
||||||
val |= shift(instuction_class , 12+4+4 +1+4+1)
|
val |= shift(instuction_class , 12+4+4 +1+4+1)
|
||||||
val |= shift(cond_bit_code , 12+4+4 +1+4+1+2)
|
val |= shift(cond_bit_code , 12+4+4 +1+4+1+2)
|
||||||
io.write_uint32 val
|
io.write_uint32 val
|
||||||
end
|
end
|
||||||
|
@ -2,21 +2,21 @@ module Arm
|
|||||||
class LogicInstruction < Instruction
|
class LogicInstruction < Instruction
|
||||||
include Arm::Constants
|
include Arm::Constants
|
||||||
# result = left op right
|
# result = left op right
|
||||||
#
|
#
|
||||||
# Logic instruction are your basic operator implementation. But unlike the (normal) code we write
|
# Logic instruction are your basic operator implementation. But unlike the (normal) code we write
|
||||||
# these Instructions must have "place" to write their results. Ie when you write 4 + 5 in ruby
|
# these Instructions must have "place" to write their results. Ie when you write 4 + 5 in ruby
|
||||||
# the result is sort of up in the air, but with Instructions the result must be assigned
|
# the result is sort of up in the air, but with Instructions the result must be assigned
|
||||||
def initialize(result , left , right , attributes = {})
|
def initialize(result , left , right , attributes = {})
|
||||||
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
|
||||||
|
|
||||||
raise "Left arg must be given #{inspect}" unless @left
|
raise "Left arg must be given #{inspect}" unless @left
|
||||||
@immediate = 0
|
@immediate = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :result , :left , :right
|
attr_accessor :result , :left , :right
|
||||||
@ -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
|
||||||
@ -58,12 +54,12 @@ module Arm
|
|||||||
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
||||||
val = shift(operand , 0)
|
val = shift(operand , 0)
|
||||||
val |= shift(op , 0) # any barral action, is already shifted
|
val |= shift(op , 0) # any barral action, is already shifted
|
||||||
val |= shift(reg_code(@result) , 12)
|
val |= shift(reg_code(@result) , 12)
|
||||||
val |= shift(reg_code(left) , 12+4)
|
val |= shift(reg_code(left) , 12+4)
|
||||||
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
||||||
val |= shift(op_bit_code , 12+4+4 +1)
|
val |= shift(op_bit_code , 12+4+4 +1)
|
||||||
val |= shift(immediate , 12+4+4 +1+4)
|
val |= shift(immediate , 12+4+4 +1+4)
|
||||||
val |= shift(instuction_class , 12+4+4 +1+4+1)
|
val |= shift(instuction_class , 12+4+4 +1+4+1)
|
||||||
val |= shift(cond_bit_code , 12+4+4 +1+4+1+2)
|
val |= shift(cond_bit_code , 12+4+4 +1+4+1+2)
|
||||||
io.write_uint32 val
|
io.write_uint32 val
|
||||||
end
|
end
|
||||||
@ -71,7 +67,7 @@ module Arm
|
|||||||
raise "Not integer #{val}:#{val.class} #{inspect}" unless val.is_a? Fixnum
|
raise "Not integer #{val}:#{val.class} #{inspect}" unless val.is_a? Fixnum
|
||||||
val << by
|
val << by
|
||||||
end
|
end
|
||||||
|
|
||||||
def uses
|
def uses
|
||||||
ret = []
|
ret = []
|
||||||
ret << @left.register if @left and not @left.is_a? Constant
|
ret << @left.register if @left and not @left.is_a? Constant
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Arm
|
module Arm
|
||||||
# ADDRESSING MODE 2
|
# ADDRESSING MODE 2
|
||||||
# Implemented: immediate offset with offset=0
|
# Implemented: immediate offset with offset=0
|
||||||
|
|
||||||
class MemoryInstruction < Instruction
|
class MemoryInstruction < Instruction
|
||||||
include Arm::Constants
|
include Arm::Constants
|
||||||
def initialize result , left , right = nil , attributes = {}
|
def initialize result , left , right = nil , attributes = {}
|
||||||
@ -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
|
||||||
@ -75,7 +75,7 @@ module Arm
|
|||||||
byte_access = opcode.to_s[-1] == "b" ? 1 : 0 #B (byte) flag
|
byte_access = opcode.to_s[-1] == "b" ? 1 : 0 #B (byte) flag
|
||||||
instuction_class = 0b01 # OPC_MEMORY_ACCESS
|
instuction_class = 0b01 # OPC_MEMORY_ACCESS
|
||||||
if (operand.is_a?(Symbol) or operand.is_a?(::Register::RegisterReference))
|
if (operand.is_a?(Symbol) or operand.is_a?(::Register::RegisterReference))
|
||||||
val = reg_code(operand)
|
val = reg_code(operand)
|
||||||
@pre_post_index = 0
|
@pre_post_index = 0
|
||||||
i = 1 # not quite sure about this, but it gives the output of as. read read read.
|
i = 1 # not quite sure about this, but it gives the output of as. read read read.
|
||||||
else
|
else
|
||||||
@ -83,15 +83,15 @@ module Arm
|
|||||||
val = operand
|
val = operand
|
||||||
end
|
end
|
||||||
val = shift(val , 0 ) # for the test
|
val = shift(val , 0 ) # for the test
|
||||||
val |= shift(reg_code(@result) , 12 )
|
val |= shift(reg_code(@result) , 12 )
|
||||||
val |= shift(reg_code(rn) , 12+4) #16
|
val |= shift(reg_code(rn) , 12+4) #16
|
||||||
val |= shift(@is_load , 12+4 +4)
|
val |= shift(@is_load , 12+4 +4)
|
||||||
val |= shift(w , 12+4 +4+1)
|
val |= shift(w , 12+4 +4+1)
|
||||||
val |= shift(byte_access , 12+4 +4+1+1)
|
val |= shift(byte_access , 12+4 +4+1+1)
|
||||||
val |= shift(add_offset , 12+4 +4+1+1+1)
|
val |= shift(add_offset , 12+4 +4+1+1+1)
|
||||||
val |= shift(@pre_post_index, 12+4 +4+1+1+1+1)#24
|
val |= shift(@pre_post_index, 12+4 +4+1+1+1+1)#24
|
||||||
val |= shift(i , 12+4 +4+1+1+1+1 +1)
|
val |= shift(i , 12+4 +4+1+1+1+1 +1)
|
||||||
val |= shift(instuction_class,12+4 +4+1+1+1+1 +1+1)
|
val |= shift(instuction_class,12+4 +4+1+1+1+1 +1+1)
|
||||||
val |= shift(cond_bit_code , 12+4 +4+1+1+1+1 +1+1+2)
|
val |= shift(cond_bit_code , 12+4 +4+1+1+1+1 +1+1+2)
|
||||||
io.write_uint32 val
|
io.write_uint32 val
|
||||||
end
|
end
|
||||||
@ -109,4 +109,4 @@ module Arm
|
|||||||
[@result.register]
|
[@result.register]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user