diff options
Diffstat (limited to 'src')
-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; |