introduce platform to abstract cpu and load address
This commit is contained in:
parent
776a97986d
commit
232fe67c09
14
lib/arm/arm_platform.rb
Normal file
14
lib/arm/arm_platform.rb
Normal file
@ -0,0 +1,14 @@
|
||||
require_relative "translator"
|
||||
module Arm
|
||||
class ArmPlatform
|
||||
def translator
|
||||
Translator.new
|
||||
end
|
||||
def loaded_at
|
||||
0x10054
|
||||
end
|
||||
def padding
|
||||
0x11000 - loaded_at
|
||||
end
|
||||
end
|
||||
end
|
@ -21,6 +21,7 @@ end
|
||||
|
||||
require_relative "risc/padding"
|
||||
require_relative "risc/position"
|
||||
require_relative "risc/platform"
|
||||
|
||||
require "parfait"
|
||||
require_relative "risc/machine"
|
||||
|
28
lib/risc/platform.rb
Normal file
28
lib/risc/platform.rb
Normal file
@ -0,0 +1,28 @@
|
||||
module Risc
|
||||
# A platform is (or will be) something like the linux tripple
|
||||
#
|
||||
# Currently it just provides a Translator and binary start point
|
||||
#
|
||||
class Platform
|
||||
|
||||
# return the translator instance that traslates risc intructions into
|
||||
# platform specific ones
|
||||
def translator
|
||||
end
|
||||
|
||||
# return an integer where the binary is loaded
|
||||
def loaded_at
|
||||
end
|
||||
# Factory method to create a Platform object according to the platform
|
||||
# string given.
|
||||
# Currently only "Arm"
|
||||
def self.for( name )
|
||||
case name
|
||||
when "Arm"
|
||||
return Arm::ArmPlatform.new
|
||||
else
|
||||
raise "not recignized platform #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -13,6 +13,6 @@ require_relative "logging"
|
||||
require_relative "elf/object_writer"
|
||||
require_relative "risc"
|
||||
require_relative "arm/arm_machine"
|
||||
require_relative "arm/translator"
|
||||
require_relative "arm/arm_platform"
|
||||
require_relative "vool/vool_compiler"
|
||||
require_relative "mom/mom"
|
||||
|
25
test/risc/test_platform.rb
Normal file
25
test/risc/test_platform.rb
Normal file
@ -0,0 +1,25 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestPlaform < MiniTest::Test
|
||||
|
||||
def test_factory_exists
|
||||
assert Platform.for("Arm")
|
||||
end
|
||||
def test_factory_raise
|
||||
assert_raises{ Platform.for("NotArm")}
|
||||
end
|
||||
def test_platform_class
|
||||
arm = Platform.for("Arm")
|
||||
assert_equal Arm::ArmPlatform , arm.class
|
||||
end
|
||||
def test_platform_translator_class
|
||||
arm = Platform.for("Arm")
|
||||
assert_equal Arm::Translator , arm.translator.class
|
||||
end
|
||||
def test_platform_loaded_class
|
||||
arm = Platform.for("Arm")
|
||||
assert_equal Fixnum , arm.loaded_at.class
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user