give arm own instruction base class back
This commit is contained in:
parent
4a26bec0f1
commit
c5b3c3f106
@ -38,6 +38,7 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
require_relative "constants"
|
require_relative "constants"
|
||||||
|
require_relative "instructions/instruction"
|
||||||
require_relative "instructions/call_instruction"
|
require_relative "instructions/call_instruction"
|
||||||
require_relative "instructions/compare_instruction"
|
require_relative "instructions/compare_instruction"
|
||||||
require_relative "instructions/logic_instruction"
|
require_relative "instructions/logic_instruction"
|
||||||
|
@ -9,9 +9,7 @@ module Arm
|
|||||||
# swi (SoftWareInterrupt) or system call is how we call the kernel.
|
# 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
|
# 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
|
# Riscs 0-6 hold the call values as for a normal c call
|
||||||
class CallInstruction < Risc::Branch
|
class CallInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
def initialize(first, attributes)
|
def initialize(first, attributes)
|
||||||
super(nil, nil)
|
super(nil, nil)
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
module Arm
|
module Arm
|
||||||
class CompareInstruction < Risc::Instruction
|
class CompareInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
def initialize(left , right , attributes)
|
def initialize(left , right , attributes)
|
||||||
super(nil)
|
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
|
module Arm
|
||||||
class LogicInstruction < Risc::Instruction
|
class LogicInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
# result = left op right #or constant loading
|
# 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,
|
# 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
|
# 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.
|
# some position handling and an @extra add instruction generated.
|
||||||
def handle_numeric(right)
|
def handle_numeric(right)
|
||||||
if (right.fits_u8?)
|
if (right.fits_u8?)
|
||||||
|
@ -2,9 +2,7 @@ module Arm
|
|||||||
# ADDRESSING MODE 2
|
# ADDRESSING MODE 2
|
||||||
# Implemented: immediate offset with offset=0
|
# Implemented: immediate offset with offset=0
|
||||||
|
|
||||||
class MemoryInstruction < Risc::Instruction
|
class MemoryInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
def initialize result , left , right = nil , attributes = {}
|
def initialize result , left , right = nil , attributes = {}
|
||||||
super(nil)
|
super(nil)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
module Arm
|
module Arm
|
||||||
class MoveInstruction < Risc::Instruction
|
class MoveInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
def initialize to , from , options = {}
|
def initialize( to , from , options = {})
|
||||||
super(nil)
|
super(nil)
|
||||||
@attributes = options
|
@attributes = options
|
||||||
if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) )
|
if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) )
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
module Arm
|
module Arm
|
||||||
# ADDRESSING MODE 4
|
# ADDRESSING MODE 4
|
||||||
|
|
||||||
class StackInstruction < Risc::Instruction
|
class StackInstruction < Instruction
|
||||||
include Constants
|
|
||||||
include Attributed
|
|
||||||
|
|
||||||
def initialize(first , attributes)
|
def initialize(first , attributes)
|
||||||
super(nil)
|
super(nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user