Wed Feb 13 05:20:15 2019 UTC ()
emulators/haxm: import haxm-0.c072ad9b68e1d558a9fb791511468d10a1a9b319

HAXM is a cross-platform hardware-assisted virtualization engine (hypervisor),
widely used as an accelerator for Android Emulator and QEMU. It has always
supported running on Windows and macOS, and has been ported to other host
operating systems as well, such as Linux and NetBSD.

HAXM runs as a kernel-mode driver on the host operating system, and provides a
KVM-like interface to user space, thereby enabling applications like QEMU to
utilize the hardware virtualization capabilities built into modern Intel CPUs,
namely Intel Virtualization Technology.


(kamil)
diff -r0 -r1.1 pkgsrc/emulators/haxm/DESCR
diff -r0 -r1.1 pkgsrc/emulators/haxm/Makefile
diff -r0 -r1.1 pkgsrc/emulators/haxm/PLIST
diff -r0 -r1.1 pkgsrc/emulators/haxm/distinfo
diff -r0 -r1.1 pkgsrc/emulators/haxm/files/haxm-mknod
diff -r0 -r1.1 pkgsrc/emulators/haxm/files/haxm-modload.in
diff -r0 -r1.1 pkgsrc/emulators/haxm/files/haxm-modunload
diff -r0 -r1.1 pkgsrc/emulators/haxm/patches/patch-core_ia32.c
diff -r0 -r1.1 pkgsrc/emulators/haxm/patches/patch-core_ia32__ops.asm
diff -r0 -r1.1 pkgsrc/emulators/haxm/patches/patch-core_include_ia32.h
diff -r0 -r1.1 pkgsrc/emulators/haxm/patches/patch-core_include_vcpu.h
diff -r0 -r1.1 pkgsrc/emulators/haxm/patches/patch-core_vcpu.c

File Added: pkgsrc/emulators/haxm/DESCR
HAXM is a cross-platform hardware-assisted virtualization engine (hypervisor),
widely used as an accelerator for Android Emulator and QEMU. It has always
supported running on Windows and macOS, and has been ported to other host
operating systems as well, such as Linux and NetBSD.

HAXM runs as a kernel-mode driver on the host operating system, and provides a
KVM-like interface to user space, thereby enabling applications like QEMU to
utilize the hardware virtualization capabilities built into modern Intel CPUs,
namely Intel Virtualization Technology.

File Added: pkgsrc/emulators/haxm/Makefile
# $NetBSD: Makefile,v 1.1 2019/02/13 05:20:15 kamil Exp $

GITHUB_PROJECT=	haxm
GITHUB_TAG=	c072ad9b68e1d558a9fb791511468d10a1a9b319
DISTNAME=	haxm-0.${GITHUB_TAG}
CATEGORIES=	emulators
MASTER_SITES=	${MASTER_SITE_GITHUB:=intel/}

MAINTAINER=	kamil@NetBSD.org
HOMEPAGE=	https://github.com/intel/haxm/
COMMENT=	Intel Hardware Accelerated Execution Manager
LICENSE=	modified-bsd

WRKSRC=		${WRKDIR}/haxm-${GITHUB_TAG}

ONLY_FOR_PLATFORM=	NetBSD-*-x86_64
OSVERSION_SPECIFIC=	YES

BUILD_DIRS=	platforms/netbsd

BUILDLINK_PASSTHRU_DIRS+=	${BSDSRCDIR}/sys

BUILD_DEFS+=	BSDSRCDIR

.include "../../mk/compiler.mk"

.if !empty(PKGSRC_COMPILER:Mclang)
CFLAGS+=	-Wno-error=address-of-packed-member
.endif

KMOD=		haxm.kmod
KMODULEDIR=	stand/${MACHINE}/${OS_VERSION}/modules

INSTALLATION_DIRS+=	sbin		# auxiliary scripts
INSTALLATION_DIRS+=	${KMODULEDIR}

PLIST_SUBST+=	MACHINE=${MACHINE}

pre-configure:
.for file in haxm-mknod haxm-modunload
	${CP} ${FILESDIR}/${file} ${WRKSRC}
.endfor
	${SED} \
		-e 's|@PREFIX@|${PREFIX}|g' \
		-e 's|@MACHINE@|${MACHINE}|g' \
		-e 's|@OS_VERSION@|${OS_VERSION}|g' \
		${FILESDIR}/haxm-modload.in > ${WRKSRC}/haxm-modload

do-install:
	${RUN} cd ${WRKSRC}/platforms/netbsd && \
		${INSTALL_PROGRAM} ${KMOD} ${DESTDIR}${PREFIX}/${KMODULEDIR}
.for file in haxm-modload haxm-modunload haxm-mknod
	${RUN} cd ${WRKSRC} && \
		${INSTALL_SCRIPT} ${file} ${DESTDIR}${PREFIX}/sbin
.endfor


.include "../../mk/bsd.pkg.mk"

File Added: pkgsrc/emulators/haxm/PLIST
@comment $NetBSD: PLIST,v 1.1 2019/02/13 05:20:15 kamil Exp $
sbin/haxm-mknod
sbin/haxm-modload
sbin/haxm-modunload
stand/${MACHINE}/${OS_VERSION}/modules/haxm.kmod

File Added: pkgsrc/emulators/haxm/distinfo
$NetBSD: distinfo,v 1.1 2019/02/13 05:20:15 kamil Exp $

SHA1 (haxm-0.c072ad9b68e1d558a9fb791511468d10a1a9b319-c072ad9b68e1d558a9fb791511468d10a1a9b319.tar.gz) = da6fe9b8c98292e8c4ca5f62ad6aa9a4a65c6bb1
RMD160 (haxm-0.c072ad9b68e1d558a9fb791511468d10a1a9b319-c072ad9b68e1d558a9fb791511468d10a1a9b319.tar.gz) = 6c1248be0b9ee775c9879627bf60d20eb3a94368
SHA512 (haxm-0.c072ad9b68e1d558a9fb791511468d10a1a9b319-c072ad9b68e1d558a9fb791511468d10a1a9b319.tar.gz) = df8e8b634fea18faa05ae57648dee6500a5b0d93fa081172835e1991ab3ae2b6ad0ad1a99d91d695f0a6656e79744445ff6f6f42947b311bb8245640dd8cff23
Size (haxm-0.c072ad9b68e1d558a9fb791511468d10a1a9b319-c072ad9b68e1d558a9fb791511468d10a1a9b319.tar.gz) = 233043 bytes
SHA1 (patch-core_ia32.c) = 6252b1b49d5198a9c16aa206cbfc1981c43c9b70
SHA1 (patch-core_ia32__ops.asm) = ca208e579a39a15f5c62322dcad595b4b0ac4a34
SHA1 (patch-core_include_ia32.h) = 3195558c44d1d196a7ac89aaa9b1931790395acc
SHA1 (patch-core_include_vcpu.h) = 9b9e020d4e15f9e310ef5d22fa41b2289813394f
SHA1 (patch-core_vcpu.c) = 068a20bf96c797cfd5f4629ce0e5cbb0104995a8

File Added: pkgsrc/emulators/haxm/files/haxm-mknod
#!/bin/sh

if [ -e /dev/HAX ]; then
	echo "ERR: HAXM devices have been already created"
	exit 1
fi

echo "*** Creating HAX devices ***"
mknod /dev/HAX c 220 0
mkdir /dev/hax_vm
for i in `seq 0 7`; do mkdir /dev/hax_vm0$i; done
for i in `seq 0 7`; do mknod /dev/hax_vm/vm0$i c 222 $i; done

echo "*** Creating VCPU Nodes ***"
i=0
while [ $i -lt 128 ]; do
        vm=$(echo "$i/16"|bc)
        vcpu=$(echo "$i%16"|bc)
        echo "i=$i vm=$vm vcpu=$vcpu"
        cmd=$(printf "mknod /dev/hax_vm%02d/vcpu%02d c 221 %d" $vm $vcpu $i)
        $cmd
        let "i+=1"
done

echo "*** Done ****"

File Added: pkgsrc/emulators/haxm/files/haxm-modload.in
#!/bin/sh

modload @PREFIX@/stand/@MACHINE@/@OS_VERSION@/modules/haxm.kmod

File Added: pkgsrc/emulators/haxm/files/haxm-modunload
#!/bin/sh

modunload haxm

File Added: pkgsrc/emulators/haxm/patches/Attic/patch-core_ia32.c
$NetBSD: patch-core_ia32.c,v 1.1 2019/02/13 05:20:15 kamil Exp $

Cherry-pick from upstream review:
 - Fix FPU DNA exception on NetBSD
   https://github.com/intel/haxm/pull/168

--- core/ia32.c.orig	2019-02-12 09:24:47.000000000 +0000
+++ core/ia32.c
@@ -81,6 +81,11 @@ uint64_t ia32_rdtsc(void)
 #endif
 }
 
+void hax_clts(void)
+{
+    asm_clts();
+}
+
 void hax_fxinit(void)
 {
     asm_fxinit();

File Added: pkgsrc/emulators/haxm/patches/Attic/patch-core_ia32__ops.asm
$NetBSD: patch-core_ia32__ops.asm,v 1.1 2019/02/13 05:20:15 kamil Exp $

Cherry-pick from upstream review:
 - Fix FPU DNA exception on NetBSD
   https://github.com/intel/haxm/pull/168

--- core/ia32_ops.asm.orig	2019-02-12 09:24:47.000000000 +0000
+++ core/ia32_ops.asm
@@ -213,6 +213,10 @@ function asm_enable_irq, 0
     sti
     ret
 
+function asm_clts, 0
+    clts
+    ret
+
 function asm_fxinit, 0
     finit
     ret

File Added: pkgsrc/emulators/haxm/patches/Attic/patch-core_include_ia32.h
$NetBSD: patch-core_include_ia32.h,v 1.1 2019/02/13 05:20:15 kamil Exp $

Cherry-pick from upstream review:
 - Fix FPU DNA exception on NetBSD
   https://github.com/intel/haxm/pull/168

--- core/include/ia32.h.orig	2019-02-12 09:24:47.000000000 +0000
+++ core/include/ia32.h
@@ -72,6 +72,7 @@ void ASMCALL set_kernel_fs(uint16_t val)
 
 void ASMCALL asm_btr(uint8_t *addr, uint bit);
 void ASMCALL asm_bts(uint8_t *addr, uint bit);
+void ASMCALL asm_clts(void);
 void ASMCALL asm_fxinit(void);
 void ASMCALL asm_fxsave(mword *addr);
 void ASMCALL asm_fxrstor(mword *addr);
@@ -85,6 +86,8 @@ void ia32_wrmsr(uint32_t reg, uint64_t v
 
 uint64_t ia32_rdtsc(void);
 
+void hax_clts(void);
+
 void hax_fxinit(void);
 void hax_fxsave(mword *addr);
 void hax_fxrstor(mword *addr);

File Added: pkgsrc/emulators/haxm/patches/Attic/patch-core_include_vcpu.h
$NetBSD: patch-core_include_vcpu.h,v 1.1 2019/02/13 05:20:15 kamil Exp $

Cherry-pick from upstream review:
 - Fix FPU DNA exception on NetBSD
   https://github.com/intel/haxm/pull/168

--- core/include/vcpu.h.orig	2019-02-12 09:24:47.000000000 +0000
+++ core/include/vcpu.h
@@ -238,6 +238,7 @@ struct vcpu_t {
 #ifdef CONFIG_HAX_EPT2
     struct mmio_fetch_cache mmio_fetch;
 #endif  // CONFIG_HAX_EPT2
+    int cr0_ts;
 };
 
 #define vmx(v, field) v->vmx.field

File Added: pkgsrc/emulators/haxm/patches/Attic/patch-core_vcpu.c
$NetBSD: patch-core_vcpu.c,v 1.1 2019/02/13 05:20:15 kamil Exp $

Cherry-pick from upstream review:
 - Fix FPU DNA exception on NetBSD
   https://github.com/intel/haxm/pull/168

--- core/vcpu.c.orig	2019-02-12 09:24:47.000000000 +0000
+++ core/vcpu.c
@@ -2041,6 +2041,10 @@ static void vcpu_enter_fpu_state(struct 
     struct fx_layout *hfx = (struct fx_layout *)hax_page_va(hstate->hfxpage);
     struct fx_layout *gfx = (struct fx_layout *)hax_page_va(gstate->gfxpage);
 
+    vcpu->cr0_ts = !!(get_cr0() & CR0_TS);
+
+    hax_clts();
+
     hax_fxsave((mword *)hfx);
     hax_fxrstor((mword *)gfx);
 }
@@ -2052,8 +2056,14 @@ static void vcpu_exit_fpu_state(struct v
     struct fx_layout *hfx = (struct fx_layout *)hax_page_va(hstate->hfxpage);
     struct fx_layout *gfx = (struct fx_layout *)hax_page_va(gstate->gfxpage);
 
+    hax_clts();
+
     hax_fxsave((mword *)gfx);
     hax_fxrstor((mword *)hfx);
+
+    if (vcpu->cr0_ts) {
+        set_cr0(get_cr0() | CR0_TS);
+    }
 }
 
 // Instructions are never longer than 15 bytes: