use a constant for the binary code offset

where the instructions start
This commit is contained in:
Torsten Ruger
2018-05-23 21:35:22 +03:00
parent 8ca70a6835
commit 0293320bb8
4 changed files with 33 additions and 26 deletions

View File

@ -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

View File

@ -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