at least its in shape to start debugging again (that must count as half full)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require_relative "instruction"
|
||||
require_relative "nodes"
|
||||
|
||||
module Arm
|
||||
# There are only three call instructions in arm branch (b), call (bl) and syscall (swi)
|
||||
@@ -14,33 +15,54 @@ module Arm
|
||||
# Registers 0-6 hold the call values as for a normal c call
|
||||
|
||||
class CallInstruction < Vm::CallInstruction
|
||||
include Arm::Constants
|
||||
|
||||
# arm intrucioons are pretty sensible, and always 4 bytes (thumb not supported)
|
||||
def length
|
||||
4
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
super(options)
|
||||
@update_status_flag = 0
|
||||
@condition_code = :al
|
||||
@opcode = options[:opcode]
|
||||
@args = [options[:left] , options[:right] , options[:extra]]
|
||||
@operand = 0
|
||||
end
|
||||
|
||||
def assemble(io)
|
||||
case opcode
|
||||
case @opcode
|
||||
when :b, :bl
|
||||
arg = args[0]
|
||||
if arg.is_a? Block
|
||||
diff = arg.position - self.position - 8
|
||||
arg = NumLiteral.new(diff)
|
||||
arg = @args[0]
|
||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
||||
arg = Arm::NumLiteral.new( arg )
|
||||
end
|
||||
if (arg.is_a?(Asm::NumLiteral))
|
||||
if arg.is_a? Vm::Code
|
||||
diff = arg.position - self.position - 8
|
||||
arg = Arm::NumLiteral.new(diff)
|
||||
end
|
||||
if (arg.is_a?(Arm::NumLiteral))
|
||||
jmp_val = arg.value >> 2
|
||||
packed = [jmp_val].pack('l')
|
||||
# signed 32-bit, condense to 24-bit
|
||||
# TODO add check that the value fits into 24 bits
|
||||
io << packed[0,3]
|
||||
else
|
||||
raise "else not coded #{arg.inspect}"
|
||||
raise "else not coded #{inspect}"
|
||||
end
|
||||
io.write_uint8 OPCODES[opcode] | (COND_CODES[@condition_code] << 4)
|
||||
when :swi
|
||||
arg = args[0]
|
||||
if (arg.is_a?(Asm::NumLiteral))
|
||||
arg = @args[0]
|
||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
||||
arg = Arm::NumLiteral.new( arg )
|
||||
end
|
||||
if (arg.is_a?(Arm::NumLiteral))
|
||||
packed = [arg.value].pack('L')[0,3]
|
||||
io << packed
|
||||
io.write_uint8 0b1111 | (COND_CODES[@condition_code] << 4)
|
||||
else
|
||||
raise Asm::AssemblyError.new("invalid operand argument expected literal not #{arg}")
|
||||
raise "invalid operand argument expected literal not #{arg} #{inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user