summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2018-07-10 19:40:20 +0200
committerRichard Braun <rbraun@sceen.net>2018-07-10 21:46:41 +0200
commitc2bd2fdd98d68d37982f95e813c83c1688311f9e (patch)
treed1d8a727ca16a65911e53a18a568479ec19fb882 /arch
parent9ea1595a9156f2818b216d883e25f63bd74459c0 (diff)
x86: add portable architecture-specific qemu make target
This target makes running QEMU simpler on non-x86 hosts.
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/Makefile9
-rwxr-xr-xarch/x86/tools/qemu.sh41
2 files changed, 50 insertions, 0 deletions
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 4ae88532..e0220f84 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -1,3 +1,12 @@
+define run_qemu_x86
+ $(call xbuild_action,QEMU,$@) \
+ $(SRCDIR)/arch/x86/tools/qemu.sh "$(OBJCOPY)"
+endef
+
+.PHONY: qemu
+qemu: x15
+ $(call run_qemu_x86)
+
ifeq ($(shell uname -m),x86_64)
KCONFIG_DEFCONFIG := amd64_defconfig
else
diff --git a/arch/x86/tools/qemu.sh b/arch/x86/tools/qemu.sh
new file mode 100755
index 00000000..c7488792
--- /dev/null
+++ b/arch/x86/tools/qemu.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# Amount of physical memory
+RAM=1024
+
+# Number of processors. Keep this below the number of physical processors
+# because the kernel doesn't replace spinning with sleeping from within
+# a virtual machine, which causes performance to collapse.
+NR_CPUS=4
+
+
+# Don't change from here unless you know what you're doing
+
+# QEMU system emulator
+QEMU_EXE=qemu-system-x86_64
+
+OBJCOPY="$1"
+NATIVE_ARCH=$(uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/)
+
+if [ "$NATIVE_ARCH" != x86 ]; then
+ KVM=
+elif lsmod | grep -q '^kvm'; then
+ KVM="-enable-kvm -cpu host"
+fi
+
+X15=$PWD/x15
+TMPDIR=$(mktemp -d)
+
+$OBJCOPY -O elf32-i386 $X15 $TMPDIR/x15
+
+cd $TMPDIR
+$QEMU_EXE $KVM \
+ -ctrl-grab \
+ -gdb tcp::1234 \
+ -m $RAM \
+ -smp $NR_CPUS \
+ -monitor stdio \
+ -kernel x15 \
+ -append "console=atcons"
+
+rm -rf $TMPDIR