use a constant for the binary code offset
where the instructions start
This commit is contained in:
@ -8,20 +8,22 @@ module Parfait
|
||||
#
|
||||
class BinaryCode < Data16
|
||||
attr_reader :next
|
||||
def self.offset
|
||||
2 * 4 # size of type (2, type+next) * word_size (4)
|
||||
end
|
||||
|
||||
def initialize(total_size)
|
||||
super()
|
||||
extend_to(total_size)
|
||||
extend_to(total_size )
|
||||
#puts "Init with #{total_size} for #{object_id}"
|
||||
(0 ..(data_length)).each{ |index| set_word(index , 0) }
|
||||
end
|
||||
def extend_to(total_size)
|
||||
if total_size > self.data_length
|
||||
extend_one unless @next
|
||||
@next.extend_to(total_size - data_length)
|
||||
end
|
||||
return unless total_size > self.data_length
|
||||
extend_one() unless @next
|
||||
@next.extend_to(total_size - data_length)
|
||||
end
|
||||
def extend_one
|
||||
def extend_one()
|
||||
@next = BinaryCode.new(1)
|
||||
#puts "extending #{total_size - data_length} in #{self}"
|
||||
Risc::Position.reset(self) if Risc::Position.set?(self)
|
||||
|
@ -14,7 +14,7 @@ module Risc
|
||||
# fire events for changed pc and register contents
|
||||
include Util::Eventable
|
||||
include Util::Logging
|
||||
log_level :info
|
||||
log_level :debug
|
||||
|
||||
attr_reader :instruction , :clock , :pc # current instruction and pc
|
||||
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
||||
@ -48,9 +48,11 @@ module Risc
|
||||
def set_pc( pos )
|
||||
raise "Not int #{pos}" unless pos.is_a? Numeric
|
||||
position = Position.at(pos)
|
||||
log.debug "Setting Position #{position}"
|
||||
if position.is_a?(Position::CodePosition)
|
||||
return set_pc(position.at + 12)
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.method}"
|
||||
return set_pc(position.at + Parfait::BinaryCode.offset)
|
||||
else
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
||||
end
|
||||
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
|
||||
set_instruction( position.instruction )
|
||||
@ -60,7 +62,7 @@ module Risc
|
||||
|
||||
def set_instruction( instruction )
|
||||
raise "set to same instruction #{instruction}:#{instruction.class}" if @instruction == instruction
|
||||
log.debug "Setting Instruction #{instruction}"
|
||||
log.debug "Setting Instruction #{instruction.class}"
|
||||
old = @instruction
|
||||
@instruction = instruction
|
||||
trigger(:instruction_changed, old , instruction)
|
||||
@ -97,7 +99,7 @@ module Risc
|
||||
return @clock
|
||||
end
|
||||
name = @instruction.class.name.split("::").last
|
||||
log.debug "#{@pc.to_s}:#{@clock.to_s(16)}: #{@instruction.to_s}"
|
||||
log.debug "#{@pc.to_s(16)}:#{@clock}: #{@instruction.to_s}"
|
||||
fetch = send "execute_#{name}"
|
||||
log.debug register_dump
|
||||
if fetch
|
||||
@ -214,7 +216,7 @@ module Risc
|
||||
meth = @instruction.method
|
||||
at = Position.get(meth.binary).at
|
||||
log.debug "Call to #{meth.name} at:#{at}"
|
||||
set_pc(at + 12)
|
||||
set_pc(at + BinaryCode.offset)
|
||||
#set_instruction @instruction.method.risc_instructions
|
||||
false
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ module Risc
|
||||
first_method = Parfait.object_space.types.values.first.methods
|
||||
before = at
|
||||
Position.set( first_method.binary , at , first_method)
|
||||
Position.set( first_method.cpu_instructions, at + 12 , first_method.binary)
|
||||
Position.set( first_method.cpu_instructions, at + Parfait::BinaryCode.offset , first_method.binary)
|
||||
log.debug "Method #{first_method.name}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+12).to_s(16)}"
|
||||
at
|
||||
|
Reference in New Issue
Block a user