use a constant for the binary code offset
where the instructions start
This commit is contained in:
parent
8ca70a6835
commit
0293320bb8
@ -8,20 +8,22 @@ module Parfait
|
|||||||
#
|
#
|
||||||
class BinaryCode < Data16
|
class BinaryCode < Data16
|
||||||
attr_reader :next
|
attr_reader :next
|
||||||
|
def self.offset
|
||||||
|
2 * 4 # size of type (2, type+next) * word_size (4)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(total_size)
|
def initialize(total_size)
|
||||||
super()
|
super()
|
||||||
extend_to(total_size)
|
extend_to(total_size )
|
||||||
#puts "Init with #{total_size} for #{object_id}"
|
#puts "Init with #{total_size} for #{object_id}"
|
||||||
(0 ..(data_length)).each{ |index| set_word(index , 0) }
|
(0 ..(data_length)).each{ |index| set_word(index , 0) }
|
||||||
end
|
end
|
||||||
def extend_to(total_size)
|
def extend_to(total_size)
|
||||||
if total_size > self.data_length
|
return unless total_size > self.data_length
|
||||||
extend_one unless @next
|
extend_one() unless @next
|
||||||
@next.extend_to(total_size - data_length)
|
@next.extend_to(total_size - data_length)
|
||||||
end
|
end
|
||||||
end
|
def extend_one()
|
||||||
def extend_one
|
|
||||||
@next = BinaryCode.new(1)
|
@next = BinaryCode.new(1)
|
||||||
#puts "extending #{total_size - data_length} in #{self}"
|
#puts "extending #{total_size - data_length} in #{self}"
|
||||||
Risc::Position.reset(self) if Risc::Position.set?(self)
|
Risc::Position.reset(self) if Risc::Position.set?(self)
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
# fire events for changed pc and register contents
|
# fire events for changed pc and register contents
|
||||||
include Util::Eventable
|
include Util::Eventable
|
||||||
include Util::Logging
|
include Util::Logging
|
||||||
log_level :info
|
log_level :debug
|
||||||
|
|
||||||
attr_reader :instruction , :clock , :pc # current instruction and pc
|
attr_reader :instruction , :clock , :pc # current instruction and pc
|
||||||
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
||||||
@ -48,9 +48,11 @@ module Risc
|
|||||||
def set_pc( pos )
|
def set_pc( pos )
|
||||||
raise "Not int #{pos}" unless pos.is_a? Numeric
|
raise "Not int #{pos}" unless pos.is_a? Numeric
|
||||||
position = Position.at(pos)
|
position = Position.at(pos)
|
||||||
log.debug "Setting Position #{position}"
|
|
||||||
if position.is_a?(Position::CodePosition)
|
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
|
end
|
||||||
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
|
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
|
||||||
set_instruction( position.instruction )
|
set_instruction( position.instruction )
|
||||||
@ -60,7 +62,7 @@ module Risc
|
|||||||
|
|
||||||
def set_instruction( instruction )
|
def set_instruction( instruction )
|
||||||
raise "set to same instruction #{instruction}:#{instruction.class}" if @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
|
old = @instruction
|
||||||
@instruction = instruction
|
@instruction = instruction
|
||||||
trigger(:instruction_changed, old , instruction)
|
trigger(:instruction_changed, old , instruction)
|
||||||
@ -97,7 +99,7 @@ module Risc
|
|||||||
return @clock
|
return @clock
|
||||||
end
|
end
|
||||||
name = @instruction.class.name.split("::").last
|
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}"
|
fetch = send "execute_#{name}"
|
||||||
log.debug register_dump
|
log.debug register_dump
|
||||||
if fetch
|
if fetch
|
||||||
@ -214,7 +216,7 @@ module Risc
|
|||||||
meth = @instruction.method
|
meth = @instruction.method
|
||||||
at = Position.get(meth.binary).at
|
at = Position.get(meth.binary).at
|
||||||
log.debug "Call to #{meth.name} at:#{at}"
|
log.debug "Call to #{meth.name} at:#{at}"
|
||||||
set_pc(at + 12)
|
set_pc(at + BinaryCode.offset)
|
||||||
#set_instruction @instruction.method.risc_instructions
|
#set_instruction @instruction.method.risc_instructions
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -108,7 +108,7 @@ module Risc
|
|||||||
first_method = Parfait.object_space.types.values.first.methods
|
first_method = Parfait.object_space.types.values.first.methods
|
||||||
before = at
|
before = at
|
||||||
Position.set( first_method.binary , at , first_method)
|
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 "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)}"
|
log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+12).to_s(16)}"
|
||||||
at
|
at
|
||||||
|
@ -3,16 +3,16 @@ require_relative "helper"
|
|||||||
module Risc
|
module Risc
|
||||||
class TestInterpreterBasics < MiniTest::Test
|
class TestInterpreterBasics < MiniTest::Test
|
||||||
|
|
||||||
def test_class
|
def pest_class
|
||||||
assert_equal Risc::Interpreter , Interpreter.new.class
|
assert_equal Risc::Interpreter , Interpreter.new.class
|
||||||
end
|
end
|
||||||
def test_starts_stopped
|
def pest_starts_stopped
|
||||||
assert_equal :stopped , Interpreter.new.state
|
assert_equal :stopped , Interpreter.new.state
|
||||||
end
|
end
|
||||||
def test_has_regs
|
def pest_has_regs
|
||||||
assert_equal 12 , Interpreter.new.registers.length
|
assert_equal 12 , Interpreter.new.registers.length
|
||||||
end
|
end
|
||||||
def test_has_r0
|
def pest_has_r0
|
||||||
assert_equal :r0 , Interpreter.new.registers.keys.first
|
assert_equal :r0 , Interpreter.new.registers.keys.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -23,14 +23,14 @@ module Risc
|
|||||||
@machine.position_all
|
@machine.position_all
|
||||||
@interpreter = Interpreter.new
|
@interpreter = Interpreter.new
|
||||||
end
|
end
|
||||||
def test_starts
|
def pest_starts
|
||||||
assert_equal 0 , @interpreter.start_machine
|
assert_equal 0 , @interpreter.start_machine
|
||||||
end
|
end
|
||||||
def test_started
|
def pest_started
|
||||||
@interpreter.start_machine
|
@interpreter.start_machine
|
||||||
assert_equal :running , @interpreter.state
|
assert_equal :running , @interpreter.state
|
||||||
end
|
end
|
||||||
def test_pos
|
def pest_pos
|
||||||
@interpreter.start_machine
|
@interpreter.start_machine
|
||||||
assert_equal 1 , @interpreter.clock
|
assert_equal 1 , @interpreter.clock
|
||||||
end
|
end
|
||||||
@ -43,30 +43,33 @@ module Risc
|
|||||||
@interpreter = Interpreter.new
|
@interpreter = Interpreter.new
|
||||||
@interpreter.start_machine
|
@interpreter.start_machine
|
||||||
end
|
end
|
||||||
def test_tick1
|
def pest_tick1
|
||||||
assert_equal 2 , @interpreter.tick
|
assert_equal 2 , @interpreter.tick
|
||||||
end
|
end
|
||||||
def test_clock1
|
def pest_clock1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 2 , @interpreter.clock
|
assert_equal 2 , @interpreter.clock
|
||||||
end
|
end
|
||||||
def test_pc1
|
def pest_pc1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 19484 , @interpreter.pc
|
assert_equal 19484 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick2
|
def pest_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 3 , @interpreter.tick
|
assert_equal 3 , @interpreter.tick
|
||||||
end
|
end
|
||||||
def test_clock2
|
def pest_clock2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 3 , @interpreter.clock
|
assert_equal 3 , @interpreter.clock
|
||||||
end
|
end
|
||||||
def test_pc2
|
def pest_pc2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 19488 , @interpreter.pc
|
assert_equal 19488 , @interpreter.pc
|
||||||
end
|
end
|
||||||
|
def test_tick_15
|
||||||
|
15.times {@interpreter.tick}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user