give arm own instruction base class back
This commit is contained in:
parent
4a26bec0f1
commit
c5b3c3f106
@ -38,6 +38,7 @@ module Arm
|
||||
end
|
||||
|
||||
require_relative "constants"
|
||||
require_relative "instructions/instruction"
|
||||
require_relative "instructions/call_instruction"
|
||||
require_relative "instructions/compare_instruction"
|
||||
require_relative "instructions/logic_instruction"
|
||||
|
@ -9,9 +9,7 @@ module Arm
|
||||
# swi (SoftWareInterrupt) or system call is how we call the kernel.
|
||||
# in Arm the register layout is different and so we have to place the syscall code into register 7
|
||||
# Riscs 0-6 hold the call values as for a normal c call
|
||||
class CallInstruction < Risc::Branch
|
||||
include Constants
|
||||
include Attributed
|
||||
class CallInstruction < Instruction
|
||||
|
||||
def initialize(first, attributes)
|
||||
super(nil, nil)
|
||||
|
@ -1,7 +1,5 @@
|
||||
module Arm
|
||||
class CompareInstruction < Risc::Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
class CompareInstruction < Instruction
|
||||
|
||||
def initialize(left , right , attributes)
|
||||
super(nil)
|
||||
|
35
lib/arm/instructions/instruction.rb
Normal file
35
lib/arm/instructions/instruction.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require "util/list"
|
||||
module Arm
|
||||
# Arm instruction base class
|
||||
# Mostly linked list functionality that all instructions have
|
||||
class Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
include Util::List
|
||||
|
||||
def initialize( source , nekst = nil )
|
||||
@source = source
|
||||
@next = nekst
|
||||
return unless source
|
||||
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction)
|
||||
end
|
||||
attr_reader :source
|
||||
|
||||
def total_byte_length
|
||||
ret = 0
|
||||
self.each{|ins| ret += ins.byte_length}
|
||||
ret
|
||||
end
|
||||
|
||||
def set_position( position )
|
||||
Positioned.set_position(self,position)
|
||||
position += byte_length
|
||||
if self.next
|
||||
self.next.set_position( position )
|
||||
else
|
||||
position
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,7 +1,5 @@
|
||||
module Arm
|
||||
class LogicInstruction < Risc::Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
class LogicInstruction < Instruction
|
||||
|
||||
# result = left op right #or constant loading
|
||||
#
|
||||
@ -62,7 +60,7 @@ module Arm
|
||||
|
||||
# Arm can't load any large (over 1024) numbers, or larger with fancy shifting,
|
||||
# but then the lower bits must be 0's. Especially in constant loading random large numbers
|
||||
# happen, and so they are split into two instructions. An exection is thrown, that triggers
|
||||
# happen, and so they are split into two instructions. An exeption is thrown, that triggers
|
||||
# some position handling and an @extra add instruction generated.
|
||||
def handle_numeric(right)
|
||||
if (right.fits_u8?)
|
||||
|
@ -2,9 +2,7 @@ module Arm
|
||||
# ADDRESSING MODE 2
|
||||
# Implemented: immediate offset with offset=0
|
||||
|
||||
class MemoryInstruction < Risc::Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
class MemoryInstruction < Instruction
|
||||
|
||||
def initialize result , left , right = nil , attributes = {}
|
||||
super(nil)
|
||||
@ -46,7 +44,7 @@ module Arm
|
||||
# but gnu as produces same output for auto_inc or not, so that seems broken
|
||||
# luckily auto_inc is not used and even if it clobbers unused reg in soml, but still
|
||||
|
||||
val = shift(val , 0 )
|
||||
val = shift(val , 0 )
|
||||
val |= shift(reg_code(arg) , 16)
|
||||
val |= shift(i , 25)
|
||||
write_val(val, io)
|
||||
|
@ -1,9 +1,7 @@
|
||||
module Arm
|
||||
class MoveInstruction < Risc::Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
class MoveInstruction < Instruction
|
||||
|
||||
def initialize to , from , options = {}
|
||||
def initialize( to , from , options = {})
|
||||
super(nil)
|
||||
@attributes = options
|
||||
if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) )
|
||||
|
@ -1,9 +1,7 @@
|
||||
module Arm
|
||||
# ADDRESSING MODE 4
|
||||
|
||||
class StackInstruction < Risc::Instruction
|
||||
include Constants
|
||||
include Attributed
|
||||
class StackInstruction < Instruction
|
||||
|
||||
def initialize(first , attributes)
|
||||
super(nil)
|
||||
|
Loading…
Reference in New Issue
Block a user