From 232fe67c09a2fb812a8c92e0d111883072c9de07 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 12 May 2018 18:32:10 +0300 Subject: [PATCH] introduce platform to abstract cpu and load address --- lib/arm/arm_platform.rb | 14 ++++++++++++++ lib/risc.rb | 1 + lib/risc/platform.rb | 28 ++++++++++++++++++++++++++++ lib/rubyx.rb | 2 +- test/risc/test_platform.rb | 25 +++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 lib/arm/arm_platform.rb create mode 100644 lib/risc/platform.rb create mode 100644 test/risc/test_platform.rb diff --git a/lib/arm/arm_platform.rb b/lib/arm/arm_platform.rb new file mode 100644 index 00000000..3f34f8bf --- /dev/null +++ b/lib/arm/arm_platform.rb @@ -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 diff --git a/lib/risc.rb b/lib/risc.rb index 54d4aa9e..ebf84e76 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -21,6 +21,7 @@ end require_relative "risc/padding" require_relative "risc/position" +require_relative "risc/platform" require "parfait" require_relative "risc/machine" diff --git a/lib/risc/platform.rb b/lib/risc/platform.rb new file mode 100644 index 00000000..e7f75226 --- /dev/null +++ b/lib/risc/platform.rb @@ -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 diff --git a/lib/rubyx.rb b/lib/rubyx.rb index b85181b1..439f06a1 100644 --- a/lib/rubyx.rb +++ b/lib/rubyx.rb @@ -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" diff --git a/test/risc/test_platform.rb b/test/risc/test_platform.rb new file mode 100644 index 00000000..2381bea9 --- /dev/null +++ b/test/risc/test_platform.rb @@ -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