diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-03-05 17:37:00 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-03-05 17:37:00 +0600 |
commit | 3a79fd6be852275c052deb97c8dd67abbb7a2545 (patch) | |
tree | 5d984d93c27301283e0794ea7d5ecb7277cc5b27 /src | |
parent | a9ec68e3afbc971f3d0d68f3064a395ab9c135a6 (diff) | |
download | hvinfo-3a79fd6be852275c052deb97c8dd67abbb7a2545.tar.gz hvinfo-3a79fd6be852275c052deb97c8dd67abbb7a2545.zip |
Add a function that maps vendor strings to names.
Also, don't overuse global use clauses.
Diffstat (limited to 'src')
-rw-r--r-- | src/hvinfo.adb | 9 | ||||
-rw-r--r-- | src/hypervisor_check.adb | 31 | ||||
-rw-r--r-- | src/hypervisor_check.ads | 11 |
3 files changed, 40 insertions, 11 deletions
diff --git a/src/hvinfo.adb b/src/hvinfo.adb index e87507e..7825210 100644 --- a/src/hvinfo.adb +++ b/src/hvinfo.adb @@ -3,11 +3,14 @@ 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)); - + -- Try CPUID checks first + if Hypervisor_Present then + Put_Line (To_String (Get_Vendor_Name)); + else + null; + end if; end HVInfo; diff --git a/src/hypervisor_check.adb b/src/hypervisor_check.adb index ff89dc5..b92f7d9 100644 --- a/src/hypervisor_check.adb +++ b/src/hypervisor_check.adb @@ -12,13 +12,13 @@ package body Hypervisor_Check is return (eax, ebx, ecx, edx); end CPUID; - function String_of_U32 (Arg : Unsigned_32) return Unbounded_String is + function String_of_U32 (Arg : Unsigned_32) return US.Unbounded_String is Word : Unsigned_32; - Result : Unbounded_String; + Result : US.Unbounded_String; begin Word := Arg; while Word > 0 loop - Append (Result, Character'Val (Word and 16#FF#)); + US.Append (Result, Character'Val (Word and 16#FF#)); Word := Shift_Right (Word, 8); end loop; return Result; @@ -38,8 +38,9 @@ package body Hypervisor_Check is end if; end Hypervisor_Present; - function Get_Vendor_String return Unbounded_String is - Vendor_String : Unbounded_String; + function Get_Vendor_String return US.Unbounded_String is + use US; + Vendor_String : US.Unbounded_String; Registers : CPUID_Registers; begin Registers := CPUID (Hypervisor_Leaf); @@ -49,4 +50,24 @@ package body Hypervisor_Check is return Vendor_String; end Get_Vendor_String; + function Get_Vendor_Name return US.Unbounded_String is + use US; + Vendor_String, Vendor_Name : Unbounded_String; + begin + Vendor_String := Get_Vendor_String; + if Vendor_String = "KVMKVMKVM" then + Vendor_Name := To_Unbounded_String ("KVM"); + elsif Vendor_String = "XenVMMXenVMM" then + Vendor_Name := To_Unbounded_String ("Xen"); + elsif Vendor_String = "VMwareVMware" then + Vendor_Name := To_Unbounded_String ("VMWare"); + elsif Vendor_String = "Microsoft Hv" then + Vendor_Name := To_Unbounded_String ("Microsoft Hyper-V"); + else + Vendor_Name := To_Unbounded_String ("Unknown hypervisor"); + end if; + return Vendor_Name; + end Get_Vendor_Name; + + end Hypervisor_Check; diff --git a/src/hypervisor_check.ads b/src/hypervisor_check.ads index e69f9f5..dea832e 100644 --- a/src/hypervisor_check.ads +++ b/src/hypervisor_check.ads @@ -1,18 +1,23 @@ with Interfaces; use Interfaces; with System.Machine_Code; use System.Machine_Code; -with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +--with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Ada.Strings.Unbounded; package Hypervisor_Check is + package US renames Ada.Strings.Unbounded; + 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 String_of_U32 (Arg : Unsigned_32) return US.Unbounded_String; function Hypervisor_Present return Boolean; - function Get_Vendor_String return Unbounded_String; + function Get_Vendor_String return US.Unbounded_String; + + function Get_Vendor_Name return US.Unbounded_String; end Hypervisor_Check; |