diff mbox

[002/111] linux-user: add qemu-wrapper

Message ID 1313614076-28878-3-git-send-email-blanham@gmail.com
State New
Headers show

Commit Message

Bryce Lanham Aug. 17, 2011, 8:46 p.m. UTC
From: Laurent Vivier <laurent@vivier.eu>

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 Makefile.target           |    8 +++-
 configure                 |    9 ++++
 linux-user/qemu-wrapper.c |   97 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 1 deletions(-)
 create mode 100644 linux-user/qemu-wrapper.c
diff mbox

Patch

diff --git a/Makefile.target b/Makefile.target
index 4aacc67..a486aa9 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -25,6 +25,7 @@  include $(SRC_PATH)/Makefile.objs
 ifdef CONFIG_USER_ONLY
 # user emulator name
 QEMU_PROG=qemu-$(TARGET_ARCH2)
+USER_TOOLS=$(TARGET_TOOLS)
 else
 # system emulator name
 ifeq ($(TARGET_ARCH), i386)
@@ -32,9 +33,10 @@  QEMU_PROG=qemu$(EXESUF)
 else
 QEMU_PROG=qemu-system-$(TARGET_ARCH2)$(EXESUF)
 endif
+USER_TOOLS=
 endif
 
-PROGS=$(QEMU_PROG)
+PROGS=$(QEMU_PROG) $(USER_TOOLS)
 STPFILES=
 
 ifndef CONFIG_HAIKU
@@ -64,6 +66,10 @@  else
 stap:
 endif
 
+qemu-wrapper.o: $(SRC_PATH)/linux-user/qemu-wrapper.c
+qemu-wrapper$(EXESUF): qemu-wrapper.o
+
+
 all: $(PROGS) stap
 
 # Dummy command so that make thinks it has done something
diff --git a/configure b/configure
index 0c67a4a..e85d2ca 100755
--- a/configure
+++ b/configure
@@ -2636,6 +2636,14 @@  if test "$softmmu" = yes ; then
     fi
   fi
 fi
+target_tools=
+if test "$linux_user" = yes ; then
+  for target in $target_list ; do
+    case $target in
+      *-linux-user) target_tools="qemu-wrapper\$(EXESUF) $target_tools" ;;
+    esac
+  done
+fi
 
 # Mac OS X ships with a broken assembler
 roms=
@@ -3079,6 +3087,7 @@  fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
 echo "TOOLS=$tools" >> $config_host_mak
+echo "TARGET_TOOLS=$target_tools" >> $config_host_mak
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "INSTALL=$install" >> $config_host_mak
diff --git a/linux-user/qemu-wrapper.c b/linux-user/qemu-wrapper.c
new file mode 100644
index 0000000..6926a6c
--- /dev/null
+++ b/linux-user/qemu-wrapper.c
@@ -0,0 +1,97 @@ 
+/*
+ * qemu-wrapper
+ *
+ * Copyright (c) 2011 Laurent Vivier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * HOWTO
+ *
+ * for instance, for m68k target.
+ *
+ * copy qemu-wrapper and qemu-m68 into the m68k filesystem:
+ *
+ *   cd m68k-linux-user
+ *   sudo cp qemu-m68k qemu-wrapper /m68k/usr/bin/qemu-wrapper
+ *
+ * update binfmts:
+ *
+ * update-binfmts --install m68k /usr/bin/qemu-wrapper \
+ *                 --magic \
+ * \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04 \
+ *                 --mask \
+ * \xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff
+ *
+ * chroot the m68k filesystem:
+ *
+ * sudo QEMU_CPU=m68020 chroot /m68k
+ *
+ *                ******** IMPORTANT NOTE ********
+ *
+ * qemu-m68k and qemu-wrapper must be linked staticaly:
+ *
+ *   ./configure --target-list=m68k-linux-user --static
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "config-target.h"
+
+int main(int argc, char **argv, char **envp) {
+	char *wrapper[argc + 7];
+	int current = 0;
+	char *cpu, *debug, *port;
+
+	wrapper[current] = argv[0];
+	current++;
+
+	cpu = getenv("QEMU_CPU");
+	if (cpu) {
+		wrapper[current] = (char*)"-cpu";
+		current++;
+		wrapper[current] = cpu;
+		current++;
+	}
+
+	debug = getenv("QEMU_DEBUG");
+	if (debug) {
+		wrapper[current] = (char*)"-d";
+		current++;
+		wrapper[current] = debug;
+		current++;
+	}
+	unsetenv("QEMU_DEBUG");
+
+	port = getenv("QEMU_GDB");
+	if (port) {
+		wrapper[current] = (char*)"-g";
+		current++;
+		wrapper[current] = port;
+		current++;
+	}
+	unsetenv("QEMU_GDB");
+
+	memcpy(&wrapper[current], &argv[1], sizeof(*argv) * (argc - 1));
+	current += argc - 1;
+
+	wrapper[current] = NULL;
+
+	return execve("/usr/bin/qemu-" TARGET_ARCH, wrapper, envp);
+}