summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-11-27 22:12:40 +0100
committerErwan Velu <erwan.velu@free.fr>2009-12-04 10:11:15 +0100
commit3793baa71f572cf7ade1fd7eb8af2b090cbebada (patch)
tree873422fda9f6ad36f7c0603bad32c3c50fc17a43
parentda3946e043519e8e329bee8154279f0873716491 (diff)
downloadsyslinux-3793baa71f572cf7ade1fd7eb8af2b090cbebada.tar.gz
Adding ifcpuhvm.c32
Impact: new module to boot hvm systems This module allow users to define a boot entry regarding if the cpu is supporting hvm (vmx|svm). This could used to boot xen, or any hypervisor
-rw-r--r--com32/modules/Makefile2
-rw-r--r--com32/modules/ifcpuhvm.c90
2 files changed, 91 insertions, 1 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 52327b61..05408bc4 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -21,7 +21,7 @@ include ../MCONFIG
MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \
disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
- kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32
+ kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32 ifcpuhvm.c32
TESTFILES =
diff --git a/com32/modules/ifcpuhvm.c b/com32/modules/ifcpuhvm.c
new file mode 100644
index 00000000..be50887d
--- /dev/null
+++ b/com32/modules/ifcpuhvm.c
@@ -0,0 +1,90 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Erwan Velu - All Rights Reserved
+ *
+ * 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, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * ifcpuhvm.c
+ *
+ * Run one command if the CPU has hardware virtualisation support,
+ * and another if it doesn't.
+ * Eventually this and other features should get folded into some kind
+ * of scripting engine.
+ *
+ * Usage:
+ *
+ * label boot_kernel
+ * kernel ifvhm.c32
+ * append boot_kernel_xen -- boot_kernel_regular
+ * label boot_kernel_xen
+ * kernel mboot.c32
+ * append xen.gz dom0_mem=262144 -- vmlinuz-xen console=tty0 root=/dev/hda1 ro --- initrd.img-xen
+ * label boot_kernel_regular
+ * kernel vmlinuz_64
+ * append ...
+ */
+
+#include <alloca.h>
+#include <stdlib.h>
+#include <string.h>
+#include <cpuid.h>
+#include <syslinux/boot.h>
+
+/* XXX: this really should be librarized */
+static void boot_args(char **args)
+{
+ int len = 0;
+ char **pp;
+ const char *p;
+ char c, *q, *str;
+
+ for (pp = args; *pp; pp++)
+ len += strlen(*pp);
+
+ q = str = alloca(len + 1);
+ for (pp = args; *pp; pp++) {
+ p = *pp;
+ while ((c = *p++))
+ *q++ = c;
+ }
+ *q = '\0';
+
+ if (!str[0])
+ syslinux_run_default();
+ else
+ syslinux_run_command(str);
+}
+
+int main(int argc, char *argv[])
+{
+ char **args[3];
+ int i;
+ int n;
+ s_cpu cpu;
+ detect_cpu(&cpu);
+
+ args[0] = &argv[1];
+ n = 1;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--")) {
+ argv[i] = NULL;
+ args[n++] = &argv[i + 1];
+ }
+ if (n >= 3)
+ break;
+ }
+ while (n < 3) {
+ args[n] = args[n - 1];
+ n++;
+ }
+
+ boot_args((cpu.flags.vmx || cpu.flags.svm) ? args[0] : args[1]);
+ return -1;
+}