fix arm (assembled) indexing
by having a dummy 0 index in salaam. when assembled
This commit is contained in:
parent
9a2fe42167
commit
8e82da0b61
@ -1,6 +1,6 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: git://github.com/salama/salama-arm.git
|
remote: git://github.com/salama/salama-arm.git
|
||||||
revision: 00b175d354046a6228f66a980822eae974ca807a
|
revision: 72fcf371bc42279676533142c82e34713e77ea75
|
||||||
specs:
|
specs:
|
||||||
salama-arm (0.3.0)
|
salama-arm (0.3.0)
|
||||||
|
|
||||||
|
@ -17,12 +17,11 @@ module Arm
|
|||||||
|
|
||||||
# arm indexes are
|
# arm indexes are
|
||||||
# in bytes, so *4
|
# in bytes, so *4
|
||||||
# 0 based , so -1
|
# if an instruction is passed in we get the index with index function
|
||||||
# if an instruction is passed in we ge the index with inex function
|
|
||||||
def arm_index index
|
def arm_index index
|
||||||
index = index.index if index.is_a?(Register::Instruction)
|
index = index.index if index.is_a?(Register::Instruction)
|
||||||
raise "index error 0" if index == 0
|
raise "index error 0" if index == 0
|
||||||
(index - 1) * 4
|
index * 4
|
||||||
end
|
end
|
||||||
# Arm stores the return address in a register (not on the stack)
|
# Arm stores the return address in a register (not on the stack)
|
||||||
# The register is called link , or lr for short .
|
# The register is called link , or lr for short .
|
||||||
|
@ -13,6 +13,8 @@ module Register
|
|||||||
include Logging
|
include Logging
|
||||||
log_level :info
|
log_level :info
|
||||||
|
|
||||||
|
MARKER = 0xA51AF00D
|
||||||
|
|
||||||
def initialize machine
|
def initialize machine
|
||||||
@machine = machine
|
@machine = machine
|
||||||
@load_at = 0x8054 # this is linux/arm
|
@load_at = 0x8054 # this is linux/arm
|
||||||
@ -35,7 +37,7 @@ module Register
|
|||||||
@machine.objects.each do |id , objekt|
|
@machine.objects.each do |id , objekt|
|
||||||
next unless objekt.is_a? Parfait::Method
|
next unless objekt.is_a? Parfait::Method
|
||||||
objekt.binary.position = at
|
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
|
len = objekt.instructions.total_byte_length
|
||||||
log.debug "CODE #{objekt.name} at #{objekt.binary.position} len: #{len}"
|
log.debug "CODE #{objekt.name} at #{objekt.binary.position} len: #{len}"
|
||||||
objekt.binary.set_length(len , 0)
|
objekt.binary.set_length(len , 0)
|
||||||
@ -137,7 +139,8 @@ module Register
|
|||||||
unless @machine.objects.has_key? object.object_id
|
unless @machine.objects.has_key? object.object_id
|
||||||
raise "Object(#{object.object_id}) not linked #{object.inspect}"
|
raise "Object(#{object.object_id}) not linked #{object.inspect}"
|
||||||
end
|
end
|
||||||
written = 0
|
@stream.write_sint32( MARKER )
|
||||||
|
written = 0 # compensate for the "secrect" marker
|
||||||
object.get_instance_variables.each do |var|
|
object.get_instance_variables.each do |var|
|
||||||
inst = object.get_instance_variable(var)
|
inst = object.get_instance_variable(var)
|
||||||
#puts "Nil for #{object.class}.#{var}" unless inst
|
#puts "Nil for #{object.class}.#{var}" unless inst
|
||||||
@ -154,7 +157,7 @@ module Register
|
|||||||
end
|
end
|
||||||
log.debug "layout #{lay_len} , total #{written} (array #{written - lay_len})"
|
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
|
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
|
object.position
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -169,10 +172,11 @@ module Register
|
|||||||
end
|
end
|
||||||
str = string.to_s if string.is_a? Symbol
|
str = string.to_s if string.is_a? Symbol
|
||||||
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
|
log.debug "#{string.class} is #{string} at #{string.position} length #{string.length}"
|
||||||
|
@stream.write_sint32( MARKER )
|
||||||
write_ref_for( string.get_layout ) #ref
|
write_ref_for( string.get_layout ) #ref
|
||||||
@stream.write_sint32( str.length ) #int
|
@stream.write_sint32( str.length ) #int
|
||||||
@stream.write str
|
@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}"
|
log.debug "String (#{string.length}) stream #{@stream.length}"
|
||||||
end
|
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
|
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
|
||||||
def pad_after length
|
def pad_after length
|
||||||
before = stream_position
|
before = stream_position
|
||||||
pad = padding_for(length)
|
pad = padding_for(length) - 4 # four is for the MARKER we write
|
||||||
pad.times do
|
pad.times do
|
||||||
@stream.write_uint8(0)
|
@stream.write_uint8(0)
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
module Padding
|
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
|
def padded len
|
||||||
a = 32 * (1 + (len - 1)/32 )
|
a = 32 * (1 + (len + 3)/32 )
|
||||||
#puts "#{a} for #{len}"
|
#puts "#{a} for #{len}"
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
@ -10,17 +10,17 @@ class TestPadding < MiniTest::Test
|
|||||||
@pad = Padded.new
|
@pad = Padded.new
|
||||||
end
|
end
|
||||||
def test_small
|
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}"
|
assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_medium
|
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}"
|
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def test_large
|
def test_large
|
||||||
[65,88].each do |p|
|
[61,65,88].each do |p|
|
||||||
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user