aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-03-31 05:29:08 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-03-31 05:29:08 -0700
commit53e2478e75b40c8d4153e181b7e8a1024e2f3021 (patch)
tree2bb5ef5fc6e0e289284380a38fd479c9c3edfff3 /com32/modules
parent1a8b87b10c173c2be5f384d68cf75395483a3230 (diff)
parent667f827e31d7b2a0ce1e5b352acdf12848f53a97 (diff)
downloadsyslinux.git-53e2478e75b40c8d4153e181b7e8a1024e2f3021.tar.gz
syslinux.git-53e2478e75b40c8d4153e181b7e8a1024e2f3021.tar.xz
syslinux.git-53e2478e75b40c8d4153e181b7e8a1024e2f3021.zip
Merge commit 'origin/gpxe-added' into gpxe-addedsyslinux-3.70-pre8
Diffstat (limited to 'com32/modules')
-rw-r--r--com32/modules/Makefile3
-rw-r--r--com32/modules/sanboot.c140
2 files changed, 142 insertions, 1 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 8a127e62..8a8827e5 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -52,7 +52,8 @@ INCDIR = /usr/include
COM32DIR = $(AUXDIR)/com32
MODULES = chain.c32 ethersel.c32 mboot.c32 dmitest.c32 cpuidtest.c32 \
- pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 meminfo.c32
+ pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 meminfo.c32 \
+ sanboot.c32
TESTFILES =
all: $(MODULES) $(TESTFILES)
diff --git a/com32/modules/sanboot.c b/com32/modules/sanboot.c
new file mode 100644
index 00000000..b8bfe25e
--- /dev/null
+++ b/com32/modules/sanboot.c
@@ -0,0 +1,140 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2008 H. Peter Anvin - 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * sanboot.c
+ *
+ * Invoke the gPXE "sanboot" command, if available.
+ */
+
+#include <alloca.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <console.h>
+#include <com32.h>
+#include <stdbool.h>
+#include <string.h>
+#include <syslinux/config.h>
+
+struct segoff16 {
+ uint16_t offs, seg;
+};
+
+struct s_PXENV_FILE_CHECK_API {
+ uint16_t Status;
+ uint16_t Size;
+ uint32_t Magic;
+ uint32_t Provider;
+ uint32_t APIMask;
+ uint32_t Flags;
+};
+
+static bool is_gpxe(void)
+{
+ const struct syslinux_version *sv;
+ com32sys_t reg;
+ struct s_PXENV_FILE_CHECK_API *fca;
+
+ sv = syslinux_version();
+ if (sv->filesystem != SYSLINUX_FS_PXELINUX)
+ return false; /* Not PXELINUX */
+
+ fca = __com32.cs_bounce;
+ memset(fca, 0, sizeof *fca);
+ fca->Size = sizeof *fca;
+ fca->Magic = 0x91d447b2;
+
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */
+ reg.edi.w[0] = OFFS(fca);
+ reg.es = SEG(fca);
+
+ __intcall(0x22, &reg, &reg);
+
+ if (reg.eflags.l & EFLAGS_CF)
+ return false; /* Cannot invoke PXE stack */
+
+ if (reg.eax.w[0] || fca->Status)
+ return false; /* PXE failure */
+
+ if (fca->Magic != 0xe9c17b20)
+ return false; /* Incorrect magic */
+
+ if (fca->Size < sizeof *fca)
+ return false; /* Short return */
+
+ if (!(fca->APIMask & (1 << 5)))
+ return false; /* No FILE EXEC */
+
+ return true;
+}
+
+struct s_PXENV_FILE_EXEC {
+ uint16_t Status;
+ struct segoff16 Command;
+};
+
+static void sanboot(const char **args)
+{
+ char *q;
+ struct s_PXENV_FILE_EXEC *fx;
+ com32sys_t reg;
+
+ memset(&reg, 0, sizeof reg);
+
+ fx = __com32.cs_bounce;
+ q = (char *)(fx+1);
+
+ fx->Status = 1;
+ fx->Command.offs = OFFS(q);
+ fx->Command.seg = SEG(q);
+
+ q = stpcpy(q, "sanboot");
+
+ while (*args) {
+ *q++ = ' ';
+ q = stpcpy(q, *args);
+ args++;
+ }
+
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
+ reg.edi.w[0] = OFFS(fx);
+ reg.es = SEG(fx);
+
+ __intcall(0x22, &reg, &reg);
+
+ /* This should not return... */
+}
+
+int main(int argc, const char *argv[])
+{
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc < 2) {
+ printf("Usage: sanboot rootpath\n");
+ return 1;
+ }
+
+ if (!is_gpxe()) {
+ printf("sanboot: gPXE API not detected\n");
+ return 1;
+ }
+
+ sanboot(argv+1);
+
+ /* sanboot() should not return... */
+ printf("SAN boot failed.\n");
+ return 1;
+}