aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-11-29 20:48:41 +0100
committerErwan Velu <erwan.velu@free.fr>2009-12-04 10:11:15 +0100
commitfe2a772f7c354d00e1bd1c5d0cf101a17b249556 (patch)
tree825899aeca5dc1e64d5a2e994bada84d08c19dbb /com32
parent571cdb24787a1c9d5c73f6c831d5f5d8c9c130e6 (diff)
downloadsyslinux.git-fe2a772f7c354d00e1bd1c5d0cf101a17b249556.tar.gz
syslinux.git-fe2a772f7c354d00e1bd1c5d0cf101a17b249556.tar.xz
syslinux.git-fe2a772f7c354d00e1bd1c5d0cf101a17b249556.zip
Adding ifcpu.c32, removing ifcpuhvm
Impact: ifcpu holds more cases ifcpu allow users defining a set of required cpu features for booting an entry
Diffstat (limited to 'com32')
-rw-r--r--com32/modules/Makefile2
-rw-r--r--com32/modules/ifcpu.c165
-rw-r--r--com32/modules/ifcpuhvm.c90
3 files changed, 166 insertions, 91 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 05408bc4..35906587 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 ifcpuhvm.c32
+ kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32 ifcpu.c32
TESTFILES =
diff --git a/com32/modules/ifcpu.c b/com32/modules/ifcpu.c
new file mode 100644
index 00000000..8a9a5f4f
--- /dev/null
+++ b/com32/modules/ifcpu.c
@@ -0,0 +1,165 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * ifcpu.c
+ *
+ * Run one command (boot_entry_1) if the booted system match some CPU features
+ * and another (boot_entry_2) if it doesn't.
+ * Eventually this and other features should get folded into some kind
+ * of scripting engine.
+ *
+ * Usage:
+ *
+ * label test
+ * com32 ifcpu.c32
+ * append <option> <cpu_features> -- boot_entry_1 -- boot_entry_2
+ * label boot_entry_1
+ * kernel vmlinuz
+ * append ...
+ * label boot_entry_2
+ * kernel vmlinuz_64
+ * append ...
+ *
+ * options could be :
+ * debug : display some debugging messages
+ * dry-run : just do the detection, don't boot
+ *
+ * cpu_features could be:
+ * 64 : CPU have to be x86_64 compatible
+ * hvm : Processor must have hardware virtualization (hvm or svm)
+ * multicore : Processor must be multi-core
+ * smp : System have to be SMP
+ *
+ * if you want to match many cpu features, just separate them with a single space
+ */
+
+#include <alloca.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <cpuid.h>
+#include <syslinux/boot.h>
+#include <com32.h>
+#include <consoles.h>
+
+#define REG_AH(x) ((x).eax.b[1])
+#define REG_CX(x) ((x).ecx.w[0])
+#define REG_DX(x) ((x).edx.w[0])
+
+static unsigned char sleep(unsigned int msec)
+{
+ unsigned long micro = 1000 * msec;
+ com32sys_t inreg, outreg;
+
+ REG_AH(inreg) = 0x86;
+ REG_CX(inreg) = (micro >> 16);
+ REG_DX(inreg) = (micro & 0xFFFF);
+ __intcall(0x15, &inreg, &outreg);
+ return REG_AH(outreg);
+}
+
+/* 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);
+}
+
+#define show_bool(mybool) mybool ? "found":"not found"
+
+int main(int argc, char *argv[])
+{
+ char **args[3];
+ int i;
+ int n;
+ bool hardware_matches = true;
+ bool multicore = false;
+ bool dryrun = false;
+ bool debug = false;
+
+ s_cpu cpu;
+ console_ansi_raw();
+ detect_cpu(&cpu);
+ n = 0;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--")) {
+ argv[i] = NULL;
+ args[n++] = &argv[i + 1];
+ } else if (!strcmp(argv[i], "64")) {
+ if (debug)
+ printf(" 64bit : %s on this system\n",
+ show_bool(cpu.flags.lm));
+ hardware_matches = cpu.flags.lm && hardware_matches;
+ } else if (!strcmp(argv[i], "hvm")) {
+ if (debug)
+ printf(" hvm : %s on this system\n",
+ show_bool((cpu.flags.vmx || cpu.flags.svm)));
+ hardware_matches = (cpu.flags.vmx || cpu.flags.svm)
+ && hardware_matches;
+ } else if (!strcmp(argv[i], "multicore")) {
+ if (debug)
+ printf(" multicore : %d cores on this system\n", cpu.num_cores);
+ if (cpu.num_cores > 1)
+ multicore = true;
+ hardware_matches = multicore && hardware_matches;
+ } else if (!strcmp(argv[i], "smp")) {
+ if (debug)
+ printf(" smp : %s on this system\n", show_bool(cpu.flags.smp));
+ hardware_matches = cpu.flags.smp && hardware_matches;
+ } else if (!strcmp(argv[i], "dry-run")) {
+ dryrun = true;
+ } else if (!strcmp(argv[i], "debug")) {
+ debug = true;
+ }
+ if (n >= 2)
+ break;
+ }
+ while (n < 2) {
+ args[n] = args[n - 1];
+ n++;
+ }
+ if (debug) {
+ printf("\nBooting labels are : '%s' or '%s'\n", *args[0], *args[1]);
+ printf("Hardware requirements%smatch this system, let's booting '%s'\n",
+ hardware_matches ? " " : " doesn't ",
+ hardware_matches ? *args[0] : *args[1]);
+ printf("Sleeping 5sec before booting\n");
+ if (!dryrun)
+ sleep(5000);
+ }
+
+ if (!dryrun)
+ boot_args(hardware_matches ? args[0] : args[1]);
+ else
+ printf("Dry-run mode, let's exiting\n");
+
+ return -1;
+}
diff --git a/com32/modules/ifcpuhvm.c b/com32/modules/ifcpuhvm.c
deleted file mode 100644
index 4ddba184..00000000
--- a/com32/modules/ifcpuhvm.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- * 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
- * com32 ifcpuhvm.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;
-}