small arm fixes etc
This commit is contained in:
parent
d7b3368b28
commit
4ab6d62acf
@ -91,10 +91,10 @@ module Arm
|
|||||||
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
|
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
|
||||||
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
||||||
left = @left
|
left = @left
|
||||||
left = @left.address if left.is_a?(Risc::Label)
|
|
||||||
# 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 = Risc::Position.get(left) - Risc::Position.get(self) - 8
|
right = Risc::Position.get(left) - 8
|
||||||
|
right -= Risc::Position.get(self).at
|
||||||
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
|
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
|
||||||
right *= -1 # this works as we never issue sub only add
|
right *= -1 # this works as we never issue sub only add
|
||||||
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode
|
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode
|
||||||
|
@ -46,6 +46,11 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_next
|
||||||
|
extend_one unless @next
|
||||||
|
@next
|
||||||
|
end
|
||||||
|
|
||||||
def each_block( &block )
|
def each_block( &block )
|
||||||
block.call( self )
|
block.call( self )
|
||||||
@next.each_block( &block ) if @next
|
@next.each_block( &block ) if @next
|
||||||
|
@ -39,9 +39,33 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def position_changed(position)
|
def position_changed(position)
|
||||||
|
fix_binary
|
||||||
my_pos = Position.get(@instruction)
|
my_pos = Position.get(@instruction)
|
||||||
my_pos.set(position.at + position.object.byte_length)
|
my_pos.set(position.at + position.object.byte_length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check that the binary we use is the one where the current position falls
|
||||||
|
# if not move up and register/unregister (soon)
|
||||||
|
def fix_binary
|
||||||
|
return if Position.get(@instruction).at == -1
|
||||||
|
count = 0
|
||||||
|
org_pos = Position.get(@binary)
|
||||||
|
return if org_pos.at == -1
|
||||||
|
while( !pos_in_binary)
|
||||||
|
@binary = @binary.ensure_next
|
||||||
|
count += 1
|
||||||
|
raise "Positions messed #{Position.get(@instruction)}:#{org_pos}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pos_in_binary
|
||||||
|
me = Position.get(@instruction)
|
||||||
|
bin = Position.get(@binary)
|
||||||
|
return false if me < bin
|
||||||
|
return false if me > (bin + @binary.padded_length)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
# initialize the dependency graph for instructions
|
# initialize the dependency graph for instructions
|
||||||
#
|
#
|
||||||
# starting from the given instruction, create Positions
|
# starting from the given instruction, create Positions
|
||||||
|
@ -73,6 +73,17 @@ module Risc
|
|||||||
offset = offset.at if offset.is_a?(Position)
|
offset = offset.at if offset.is_a?(Position)
|
||||||
@at - offset
|
@at - offset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def <(right)
|
||||||
|
right = right.at if right.is_a?(Position)
|
||||||
|
@at < right
|
||||||
|
end
|
||||||
|
|
||||||
|
def >(right)
|
||||||
|
right = right.at if right.is_a?(Position)
|
||||||
|
@at > right
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"0x#{@at.to_s(16)}"
|
"0x#{@at.to_s(16)}"
|
||||||
end
|
end
|
||||||
@ -129,7 +140,7 @@ module Risc
|
|||||||
@reverse_cache.delete(position.at) unless position.object.is_a?(Label)
|
@reverse_cache.delete(position.at) unless position.object.is_a?(Label)
|
||||||
testing = self.at( position.at ) unless position.at < 0
|
testing = self.at( position.at ) unless position.at < 0
|
||||||
if testing and testing.object.class != position.object.class
|
if testing and testing.object.class != position.object.class
|
||||||
raise "Mismatch (at #{pos.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}"
|
raise "Mismatch (at #{to.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}"
|
||||||
end
|
end
|
||||||
self.positions[position.object] = position
|
self.positions[position.object] = position
|
||||||
@reverse_cache[to] = position unless position.object.is_a?(Label)
|
@reverse_cache[to] = position unless position.object.is_a?(Label)
|
||||||
|
@ -90,16 +90,15 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def label( pos = 0x12 + 8)
|
def label( pos = 0x12 + 8)
|
||||||
addr = Risc::Position.new(FakeAddress.new(2) , 2)
|
label = Risc::Label.new("some" , "Label" , FakeAddress.new(pos))
|
||||||
l = Risc::Label.new("some" , "Label" , addr.object)
|
Risc::Position.new(label , pos)
|
||||||
Risc::Position.new(l , 0x22 + 8)
|
|
||||||
#Risc::Position.set(l , pos , @binary)
|
#Risc::Position.set(l , pos , @binary)
|
||||||
l
|
label
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_move_object
|
def test_move_object
|
||||||
code = @machine.add( :r1 , label)
|
code = @machine.add( :r1 , label)
|
||||||
Risc::Position.new(code,0)
|
Risc::Position.new(code,12)
|
||||||
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,6 +23,10 @@ module Parfait
|
|||||||
def test_next_nil
|
def test_next_nil
|
||||||
assert_nil @code.next
|
assert_nil @code.next
|
||||||
end
|
end
|
||||||
|
def test_ensure_next
|
||||||
|
assert BinaryCode , @code.ensure_next.class
|
||||||
|
assert @code.next
|
||||||
|
end
|
||||||
def test_data_length
|
def test_data_length
|
||||||
assert_equal 13 , @code.data_length
|
assert_equal 13 , @code.data_length
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
@binary = Parfait::BinaryCode.new(1)
|
@binary = Parfait::BinaryCode.new(1)
|
||||||
|
@bin_pos = Position.new(@binary,0)
|
||||||
@instruction = DummyInstruction.new(DummyInstruction.new)
|
@instruction = DummyInstruction.new(DummyInstruction.new)
|
||||||
@position = InstructionListener.init(@instruction , @binary)
|
@position = InstructionListener.init(@instruction , @binary)
|
||||||
end
|
end
|
||||||
@ -41,13 +42,34 @@ module Risc
|
|||||||
Position.get(label).set(10)
|
Position.get(label).set(10)
|
||||||
assert_equal 10 , Position.get(@instruction).at
|
assert_equal 10 , Position.get(@instruction).at
|
||||||
end
|
end
|
||||||
def test_label_at
|
def test_label_at_branch
|
||||||
branch = Branch.new("b" , @label)
|
label = Label.new("Hi","Ho" , FakeAddress.new(5) , @instruction)
|
||||||
Position.new(@label , 8 )
|
branch = Branch.new("b" , label)
|
||||||
|
Position.new(label , 8 )
|
||||||
Position.new(branch , 8 )
|
Position.new(branch , 8 )
|
||||||
at_8 = Position.at(8)
|
at_8 = Position.at(8)
|
||||||
assert_equal Position , at_8.class
|
assert_equal Position , at_8.class
|
||||||
assert_equal Branch , at_8.object.class
|
assert_equal Branch , at_8.object.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
class TestInstructionListenerBig < MiniTest::Test
|
||||||
|
def setup
|
||||||
|
Risc.machine.boot
|
||||||
|
@binary = Parfait::BinaryCode.new(1)
|
||||||
|
@bin_pos = Position.new(@binary,0)
|
||||||
|
@instruction = DummyInstruction.new
|
||||||
|
13.times {@instruction.last.insert(DummyInstruction.new) }
|
||||||
|
@position = InstructionListener.init(@instruction , @binary)
|
||||||
|
@position.set(8)
|
||||||
|
end
|
||||||
|
def test_padding
|
||||||
|
assert_equal 64 , @binary.padded_length
|
||||||
|
end
|
||||||
|
def test_last
|
||||||
|
assert_equal 72 , Position.get(@instruction.last).at
|
||||||
|
end
|
||||||
|
def test_next
|
||||||
|
assert @binary.next
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,6 +49,9 @@ module Risc
|
|||||||
res = @pos - Position.new(@pos,4)
|
res = @pos - Position.new(@pos,4)
|
||||||
assert_equal 1 , res
|
assert_equal 1 , res
|
||||||
end
|
end
|
||||||
|
def test_lg
|
||||||
|
assert @pos > Position.new(@pos,4)
|
||||||
|
end
|
||||||
def test_tos
|
def test_tos
|
||||||
assert_equal "0x5" , @pos.to_s
|
assert_equal "0x5" , @pos.to_s
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user