fix arm (assembled) indexing

by having a dummy 0 index in salaam. when assembled
This commit is contained in:
Torsten Ruger 2015-11-15 20:42:07 +02:00
parent 9a2fe42167
commit 8e82da0b61
5 changed files with 18 additions and 14 deletions

View File

@ -1,6 +1,6 @@
GIT
remote: git://github.com/salama/salama-arm.git
revision: 00b175d354046a6228f66a980822eae974ca807a
revision: 72fcf371bc42279676533142c82e34713e77ea75
specs:
salama-arm (0.3.0)

View File

@ -17,12 +17,11 @@ module Arm
# arm indexes are
# in bytes, so *4
# 0 based , so -1
# if an instruction is passed in we ge the index with inex function
# if an instruction is passed in we get the index with index function
def arm_index index
index = index.index if index.is_a?(Register::Instruction)
raise "index error 0" if index == 0
(index - 1) * 4
index * 4
end
# Arm stores the return address in a register (not on the stack)
# The register is called link , or lr for short .

View File

@ -13,6 +13,8 @@ module Register
include Logging
log_level :info
MARKER = 0xA51AF00D
def initialize machine
@machine = machine
@load_at = 0x8054 # this is linux/arm
@ -35,7 +37,7 @@ module Register
@machine.objects.each do |id , objekt|
next unless objekt.is_a? Parfait::Method
objekt.binary.position = at
objekt.instructions.set_position at + 8 # BinaryCode header
objekt.instructions.set_position at + 12 # BinaryCode header
len = objekt.instructions.total_byte_length
log.debug "CODE #{objekt.name} at #{objekt.binary.position} len: #{len}"
objekt.binary.set_length(len , 0)
@ -137,7 +139,8 @@ module Register
unless @machine.objects.has_key? object.object_id
raise "Object(#{object.object_id}) not linked #{object.inspect}"
end
written = 0
@stream.write_sint32( MARKER )
written = 0 # compensate for the "secrect" marker
object.get_instance_variables.each do |var|
inst = object.get_instance_variable(var)
#puts "Nil for #{object.class}.#{var}" unless inst
@ -154,7 +157,7 @@ module Register
end
log.debug "layout #{lay_len} , total #{written} (array #{written - lay_len})"
log.debug "Len = #{object.get_length} , inst = #{object.get_layout.instance_length}" if object.is_a? Parfait::Layout
pad_after( written )
pad_after( written )
object.position
end
@ -169,10 +172,11 @@ module Register
end
str = string.to_s if string.is_a? Symbol
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
@stream.write_sint32( MARKER )
write_ref_for( string.get_layout ) #ref
@stream.write_sint32( str.length ) #int
@stream.write str
pad_after(str.length + 8)
pad_after(str.length + 8 ) # layout , length *4 == 12
log.debug "String (#{string.length}) stream #{@stream.length}"
end
@ -198,7 +202,7 @@ module Register
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
def pad_after length
before = stream_position
pad = padding_for(length)
pad = padding_for(length) - 4 # four is for the MARKER we write
pad.times do
@stream.write_uint8(0)
end

View File

@ -1,9 +1,10 @@
module Padding
# objects only come in lengths of multiple of 8 words
# objects only come in lengths of multiple of 8 words / 32 bytes
# and there is a "hidden" 1 word that is used for debug/check memory corruption
def padded len
a = 32 * (1 + (len - 1)/32 )
a = 32 * (1 + (len + 3)/32 )
#puts "#{a} for #{len}"
a
end

View File

@ -10,17 +10,17 @@ class TestPadding < MiniTest::Test
@pad = Padded.new
end
def test_small
[6,27,28,32].each do |p|
[6,27,28].each do |p|
assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}"
end
end
def test_medium
[33,40,57,60,64].each do |p|
[29,33,40,57,60].each do |p|
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
end
end
def test_large
[65,88].each do |p|
[61,65,88].each do |p|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
end
end