diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-03-05 14:00:51 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-03-05 14:00:51 +0600 |
commit | 257335197da3d6bb49d97515c82a5bb4a8fe1831 (patch) | |
tree | 2c4a6475cbaa32188d766f03e8db6c5a6d3f1ff7 | |
parent | 4e6920f5a2b7b830e56a2b89c82a9e0c214f1d1a (diff) | |
download | hvinfo-257335197da3d6bb49d97515c82a5bb4a8fe1831.tar.gz hvinfo-257335197da3d6bb49d97515c82a5bb4a8fe1831.zip |
Initial import of barely working stuff.
-rw-r--r-- | src/hvinfo.adb | 13 | ||||
-rw-r--r-- | src/hypervisor_check.adb | 38 | ||||
-rw-r--r-- | src/hypervisor_check.ads | 16 |
3 files changed, 67 insertions, 0 deletions
diff --git a/src/hvinfo.adb b/src/hvinfo.adb new file mode 100644 index 0000000..e87507e --- /dev/null +++ b/src/hvinfo.adb @@ -0,0 +1,13 @@ +with Interfaces; use Interfaces; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Ada.Text_IO; use Ada.Text_IO; + +with Hypervisor_Check; use Hypervisor_Check; + +procedure HVInfo is +begin + + Put_Line (To_String (Get_Vendor_String)); + +end HVInfo; + diff --git a/src/hypervisor_check.adb b/src/hypervisor_check.adb new file mode 100644 index 0000000..6a68df0 --- /dev/null +++ b/src/hypervisor_check.adb @@ -0,0 +1,38 @@ +package body Hypervisor_Check is + + function CPUID (Arg : Unsigned_32) return CPUID_Registers is + eax, ebx, ecx, edx : Unsigned_32; + begin + Asm("cpuid", + Outputs => (Unsigned_32'Asm_Output ("=a", eax), + Unsigned_32'Asm_Output ("=b", ebx), + Unsigned_32'Asm_Output ("=c", ecx), + Unsigned_32'Asm_Output ("=d", edx)), + Inputs => Unsigned_32'Asm_Input ("a", Arg)); + return (eax, ebx, ecx, edx); + end CPUID; + + function String_of_U32 (Arg : Unsigned_32) return Unbounded_String is + Word : Unsigned_32; + Result : Unbounded_String; + begin + Word := Arg; + while Word > 0 loop + Append (Result, Character'Val (Word and 16#FF#)); + Word := Shift_Right (Word, 8); + end loop; + return Result; + end String_of_U32; + + function Get_Vendor_String return Unbounded_String is + Vendor_String : Unbounded_String; + Registers : CPUID_Registers; + begin + Registers := CPUID (Hypervisor_Leaf); + Vendor_String := String_of_U32 (Registers(2)) & + String_of_U32 (Registers(3)) & + String_of_U32 (Registers(4)); + return Vendor_String; + end Get_Vendor_String; + +end Hypervisor_Check; diff --git a/src/hypervisor_check.ads b/src/hypervisor_check.ads new file mode 100644 index 0000000..35a22cd --- /dev/null +++ b/src/hypervisor_check.ads @@ -0,0 +1,16 @@ +with Interfaces; use Interfaces; +with System.Machine_Code; use System.Machine_Code; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; + +package Hypervisor_Check is + + Hypervisor_Leaf : constant := 16#40000000#; + type CPUID_Registers is array (1 .. 4) of Unsigned_32; + + function CPUID (Arg : Unsigned_32) return CPUID_Registers; + + function String_of_U32 (Arg : Unsigned_32) return Unbounded_String; + + function Get_Vendor_String return Unbounded_String; + +end Hypervisor_Check; |