From 85bdc136388b07d039610df97362f07fe6529e2c Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 1 Apr 2016 16:45:09 +0600 Subject: Crude support for building on non-x86 architectures. Right now the CPUID procedure is made to return zeroes on non-x86 platforms through conditional compilation. A cleaner solution would be to use separate procedures and specify implementation through gprbuild directives. --- Makefile | 3 +++ hvinfo.def | 1 + hvinfo.gpr | 5 +++++ mkconfig.sh | 10 ++++++++++ src/hypervisor_check.adb | 4 ++++ 5 files changed, 23 insertions(+) create mode 100644 hvinfo.def diff --git a/Makefile b/Makefile index 9893b1a..783d4f3 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ BINDIR = bin BUILD_DIR = build +CONFIG = config.def + DESTDIR = "" GPRBUILD = gprbuild @@ -51,6 +53,7 @@ clean: $(GPRCLEAN); \ rm -rf $(BUILD_DIR);\ fi + rm -f $(CONFIG) install: $(INSTALL) -d $(DESTDIR)/$(PREFIX)/$(BINDIR) diff --git a/hvinfo.def b/hvinfo.def new file mode 100644 index 0000000..1b562e8 --- /dev/null +++ b/hvinfo.def @@ -0,0 +1 @@ +* "config.def" -u diff --git a/hvinfo.gpr b/hvinfo.gpr index 00c0463..227c236 100644 --- a/hvinfo.gpr +++ b/hvinfo.gpr @@ -5,5 +5,10 @@ project hvinfo is for Object_Dir use "build"; for Main use ("hvinfo.adb"); + package Compiler is + for Switches ("Ada") use + ("-gnatep=" & hvinfo'Project_Dir & "hvinfo.def", "-I" & hvinfo'Project_Dir); + end Compiler; + end hvinfo; diff --git a/mkconfig.sh b/mkconfig.sh index d8d0eaf..54a91c2 100755 --- a/mkconfig.sh +++ b/mkconfig.sh @@ -21,6 +21,8 @@ HVINFO_FREEBSD=False VERSION=$(cat VERSION) +CONFIG=config.def + OS=$(uname) case $OS in Linux) @@ -34,6 +36,14 @@ case $OS in exit 1 esac +# Create the gnatprep defs file +# Determine the arch +rm -f $CONFIG +ARCH=$(uname -m) +if [ $(expr $ARCH : 'i*86') -o $(expr $ARCH : 'amd64') -o $(expr $ARCH : 'x86_64') ]; then + echo "X86 := True" >> $CONFIG +fi + $GNATPREP -D LINUX=$HVINFO_LINUX \ -D FREEBSD=$HVINFO_FREEBSD \ -D VERSION=\"$VERSION\" \ diff --git a/src/hypervisor_check.adb b/src/hypervisor_check.adb index b6c8719..4d87cb0 100644 --- a/src/hypervisor_check.adb +++ b/src/hypervisor_check.adb @@ -22,6 +22,7 @@ package body Hypervisor_Check is function CPUID (Arg : Unsigned_32) return CPUID_Registers is eax, ebx, ecx, edx : Unsigned_32; begin + #if X86 then Asm("cpuid", Outputs => (Unsigned_32'Asm_Output ("=a", eax), Unsigned_32'Asm_Output ("=b", ebx), @@ -29,6 +30,9 @@ package body Hypervisor_Check is Unsigned_32'Asm_Output ("=d", edx)), Inputs => Unsigned_32'Asm_Input ("a", Arg)); return (eax, ebx, ecx, edx); + #else + return (0, 0, 0, 0); + #end if; end CPUID; -- Convert an unsigned 32-bit integer to a string of 4 characters -- cgit v1.2.3