2014-05-10 14:59:46 +02:00
|
|
|
require "vm/instruction"
|
|
|
|
require_relative "constants"
|
2014-05-03 14:13:15 +02:00
|
|
|
|
2014-05-03 21:18:04 +02:00
|
|
|
module Arm
|
2014-05-03 14:13:15 +02:00
|
|
|
# ADDRESSING MODE 4
|
2014-05-03 21:18:04 +02:00
|
|
|
class StackInstruction < Vm::StackInstruction
|
2014-05-05 21:21:11 +02:00
|
|
|
include Arm::Constants
|
|
|
|
|
|
|
|
# arm intrucioons are pretty sensible, and always 4 bytes (thumb not supported)
|
|
|
|
def length
|
|
|
|
4
|
|
|
|
end
|
|
|
|
|
2014-05-16 09:42:25 +02:00
|
|
|
def initialize(first , attributes)
|
|
|
|
super(first , attributes)
|
2014-05-16 18:56:13 +02:00
|
|
|
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
2014-05-14 09:47:30 +02:00
|
|
|
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
2014-05-10 14:59:46 +02:00
|
|
|
@attributes[:opcode] = attributes[:opcode]
|
2014-05-05 21:21:11 +02:00
|
|
|
@operand = 0
|
2014-05-03 14:13:15 +02:00
|
|
|
|
2014-05-16 18:56:13 +02:00
|
|
|
@attributes[:update_status]= 0
|
2014-05-06 11:42:43 +02:00
|
|
|
@rn = :r0 # register zero = zero bit pattern
|
2014-05-03 14:13:15 +02:00
|
|
|
# downward growing, decrement before memory access
|
|
|
|
# official ARM style stack as used by gas
|
|
|
|
end
|
|
|
|
|
|
|
|
def assemble(io)
|
|
|
|
build
|
2014-05-10 14:59:46 +02:00
|
|
|
write_base = 1
|
|
|
|
if (opcode == :push)
|
|
|
|
pre_post_index = 1
|
|
|
|
up_down = 0
|
|
|
|
is_pop = 0
|
|
|
|
else #pop
|
|
|
|
pre_post_index = 0
|
|
|
|
up_down = 1
|
|
|
|
is_pop = 1
|
|
|
|
end
|
2014-05-03 14:13:15 +02:00
|
|
|
instuction_class = 0b10 # OPC_STACK
|
2014-05-10 14:59:46 +02:00
|
|
|
cond = @attributes[:condition_code].is_a?(Symbol) ? COND_CODES[@attributes[:condition_code]] : @attributes[:condition_code]
|
2014-05-06 11:42:43 +02:00
|
|
|
@rn = :sp # sp register
|
2014-05-03 14:13:15 +02:00
|
|
|
#assemble of old
|
2014-05-06 11:42:43 +02:00
|
|
|
val = @operand
|
|
|
|
val |= (reg_code(@rn) << 16)
|
2014-05-03 14:13:15 +02:00
|
|
|
val |= (is_pop << 16+4) #20
|
|
|
|
val |= (write_base << 16+4+ 1)
|
2014-05-16 18:56:13 +02:00
|
|
|
val |= (@attributes[:update_status] << 16+4+ 1+1)
|
2014-05-03 14:13:15 +02:00
|
|
|
val |= (up_down << 16+4+ 1+1+1)
|
|
|
|
val |= (pre_post_index << 16+4+ 1+1+1+1)#24
|
|
|
|
val |= (instuction_class << 16+4+ 1+1+1+1 +2)
|
|
|
|
val |= (cond << 16+4+ 1+1+1+1 +2+2)
|
|
|
|
io.write_uint32 val
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
# Build representation for source value
|
|
|
|
def build
|
2014-05-16 09:42:25 +02:00
|
|
|
regs = @first
|
2014-05-10 14:47:27 +02:00
|
|
|
if (regs.is_a?(Array))
|
2014-05-03 14:13:15 +02:00
|
|
|
@operand = 0
|
2014-05-10 14:47:27 +02:00
|
|
|
regs.each do |reg |
|
2014-05-06 11:42:43 +02:00
|
|
|
next unless reg
|
|
|
|
@operand |= (1 << reg_code(reg))
|
2014-05-03 14:13:15 +02:00
|
|
|
end
|
|
|
|
else
|
2014-05-10 14:47:27 +02:00
|
|
|
raise "invalid operand argument #{regs.inspect} #{inspect}"
|
2014-05-03 14:13:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|