diff options
-rw-r--r-- | emulators/haxm/DESCR | 9 | ||||
-rw-r--r-- | emulators/haxm/Makefile | 58 | ||||
-rw-r--r-- | emulators/haxm/PLIST | 5 | ||||
-rw-r--r-- | emulators/haxm/distinfo | 11 | ||||
-rw-r--r-- | emulators/haxm/files/haxm-mknod | 25 | ||||
-rw-r--r-- | emulators/haxm/files/haxm-modload.in | 3 | ||||
-rw-r--r-- | emulators/haxm/files/haxm-modunload | 3 | ||||
-rw-r--r-- | emulators/haxm/patches/patch-core_ia32.c | 20 | ||||
-rw-r--r-- | emulators/haxm/patches/patch-core_ia32__ops.asm | 19 | ||||
-rw-r--r-- | emulators/haxm/patches/patch-core_include_ia32.h | 25 | ||||
-rw-r--r-- | emulators/haxm/patches/patch-core_include_vcpu.h | 16 | ||||
-rw-r--r-- | emulators/haxm/patches/patch-core_vcpu.c | 34 |
12 files changed, 228 insertions, 0 deletions
diff --git a/emulators/haxm/DESCR b/emulators/haxm/DESCR new file mode 100644 index 00000000000..adbfbcd88e4 --- /dev/null +++ b/emulators/haxm/DESCR @@ -0,0 +1,9 @@ +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. diff --git a/emulators/haxm/Makefile b/emulators/haxm/Makefile new file mode 100644 index 00000000000..0ef39c552f5 --- /dev/null +++ b/emulators/haxm/Makefile @@ -0,0 +1,58 @@ +# $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" diff --git a/emulators/haxm/PLIST b/emulators/haxm/PLIST new file mode 100644 index 00000000000..1c5ebf664d9 --- /dev/null +++ b/emulators/haxm/PLIST @@ -0,0 +1,5 @@ +@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 diff --git a/emulators/haxm/distinfo b/emulators/haxm/distinfo new file mode 100644 index 00000000000..524f2e7b60d --- /dev/null +++ b/emulators/haxm/distinfo @@ -0,0 +1,11 @@ +$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 diff --git a/emulators/haxm/files/haxm-mknod b/emulators/haxm/files/haxm-mknod new file mode 100644 index 00000000000..1a92fb9067a --- /dev/null +++ b/emulators/haxm/files/haxm-mknod @@ -0,0 +1,25 @@ +#!/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 ****" diff --git a/emulators/haxm/files/haxm-modload.in b/emulators/haxm/files/haxm-modload.in new file mode 100644 index 00000000000..617c9ded992 --- /dev/null +++ b/emulators/haxm/files/haxm-modload.in @@ -0,0 +1,3 @@ +#!/bin/sh + +modload @PREFIX@/stand/@MACHINE@/@OS_VERSION@/modules/haxm.kmod diff --git a/emulators/haxm/files/haxm-modunload b/emulators/haxm/files/haxm-modunload new file mode 100644 index 00000000000..9e2e279e337 --- /dev/null +++ b/emulators/haxm/files/haxm-modunload @@ -0,0 +1,3 @@ +#!/bin/sh + +modunload haxm diff --git a/emulators/haxm/patches/patch-core_ia32.c b/emulators/haxm/patches/patch-core_ia32.c new file mode 100644 index 00000000000..33e0e0f8848 --- /dev/null +++ b/emulators/haxm/patches/patch-core_ia32.c @@ -0,0 +1,20 @@ +$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(); diff --git a/emulators/haxm/patches/patch-core_ia32__ops.asm b/emulators/haxm/patches/patch-core_ia32__ops.asm new file mode 100644 index 00000000000..01ed0385e1e --- /dev/null +++ b/emulators/haxm/patches/patch-core_ia32__ops.asm @@ -0,0 +1,19 @@ +$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 diff --git a/emulators/haxm/patches/patch-core_include_ia32.h b/emulators/haxm/patches/patch-core_include_ia32.h new file mode 100644 index 00000000000..c5b782a94ad --- /dev/null +++ b/emulators/haxm/patches/patch-core_include_ia32.h @@ -0,0 +1,25 @@ +$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); diff --git a/emulators/haxm/patches/patch-core_include_vcpu.h b/emulators/haxm/patches/patch-core_include_vcpu.h new file mode 100644 index 00000000000..f9c27d0a914 --- /dev/null +++ b/emulators/haxm/patches/patch-core_include_vcpu.h @@ -0,0 +1,16 @@ +$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 diff --git a/emulators/haxm/patches/patch-core_vcpu.c b/emulators/haxm/patches/patch-core_vcpu.c new file mode 100644 index 00000000000..e0878e3e13f --- /dev/null +++ b/emulators/haxm/patches/patch-core_vcpu.c @@ -0,0 +1,34 @@ +$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: |