[syslinux:master] ifplop.c32: Detect if PLoP USB/CD INT13h hook is enabled/disabled

syslinux-bot for Gert Hulselmans gerth at zytor.com
Thu Jul 1 13:42:25 PDT 2010


Commit-ID:  01dc2ad8336cc9dbd76f1e74cd4fec2e45334797
Gitweb:     http://syslinux.zytor.com/commit/01dc2ad8336cc9dbd76f1e74cd4fec2e45334797
Author:     Gert Hulselmans <gerth at zytor.com>
AuthorDate: Thu, 1 Jul 2010 17:57:44 +0200
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Thu, 1 Jul 2010 13:39:34 -0700

ifplop.c32: Detect if PLoP USB/CD INT13h hook is enabled/disabled

New module which detects if the PLoP Boot Loader already has booted a
CDROM or USB drive by checking for the presence of the PLoP INT13h hook.

The following assembly code (NASM) can detect the PLoP INT13h hook:

  mov eax,'PoLP'  ; Reverse of 'PLoP'
  mov ebp,'DKHC'  ; Reverse of 'CHKD'
  int 13h
  cmp eax,' sey'  ; Reverse of 'yes '
  jz plop_INT13h_active

Signed-off-by: Gert Hulselmans <gerth at zytor.com>
Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>


---
 NEWS                   |    2 +
 com32/modules/Makefile |    2 +-
 com32/modules/ifplop.c |  165 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+), 1 deletions(-)

diff --git a/NEWS b/NEWS
index 84b77c8..6fad010 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ Changes in 4.01:
 	* ISOLINUX: change the initialization sequence to avoid
 	  problems with certain (old) BIOSes.  Special thanks to
 	  Helmut Hullen for invaluable debugging support.
+	* ifplop.c32: new module which detects if the PLoP Boot Loader
+	  already has booted a CDROM or USB drive (Gert Hulselmans).
 
 Changes in 4.00:
 	* Major code base changes; all filesystem rewritten in C.
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 79018df..f42ce96 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -22,7 +22,7 @@ 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 host.c32 ls.c32 gpxecmd.c32 \
-	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32
+	    ifcpu.c32 cpuid.c32 cat.c32 pwd.c32 ifplop.c32
 
 TESTFILES =
 
diff --git a/com32/modules/ifplop.c b/com32/modules/ifplop.c
new file mode 100644
index 0000000..c6286d9
--- /dev/null
+++ b/com32/modules/ifplop.c
@@ -0,0 +1,165 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2010 Gert Hulselmans - 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * ifplop.c
+ *
+ * This COM32 module detects if the PLoP Boot Manager was used to boot a CDROM
+ * drive or USB drive, by checking for the presence of the PLoP INT13h hook.
+ *
+ * Usage:   ifplop.c32 [<plop_detected>] -- [<plop_not_detected>]
+ * Example: ifplop.c32 menu.c32 another.cfg -- plpbt.bin hiddenusb usb1=2
+ *
+ * A possible config file could be:
+ *
+ * ===========================================================================
+ *  DEFAULT plopcheck
+ *
+ *  # Check for the presence of PLoP (run by default)
+ *  #   When PLoP INT13h hook is found, run the first command (plop_detected)
+ *  #   When PLoP INT13h hook isn't found, run the second command (plop_not_detected)
+ *  LABEL plopcheck
+ *      COM32 ifplop.c32
+ *      APPEND plop_detected -- plop_not_detected
+ *
+ *  # When PLoP INT13h hook was found, boot the menu system.
+ *  # PLoP can have added USB 2.0 speed, so the entries we want to boot
+ *  # will be read from disk much faster (supposing that we have a BIOS
+ *  # that only supports USB 1.1 speed, but a mobo with USB 2.0 controllers).
+ *  LABEL plop_detected
+ *      COM32 menu.c32
+ *      APPEND another.cfg
+ *
+ *  # PLoP INT13h hook wasn't found, so we boot PLoP, so it can add USB 2.0 support
+ *  LABEL plop_not_detected
+ *      LINUX plpbt.bin hiddenusb usb1=2
+ *
+ * ===========================================================================
+ *
+ * Why is/can this module be useful?
+ *
+ * You may want to boot PLoP by default from Syslinux when you boot from your
+ * USB stick/drive:
+ *   1. PLoP can upgrade USB 1.1 speed offered by the BIOS to USB 2.0 speed
+ *      if you have USB 2.0 controllers on your mobo.
+ *   2. Some BIOSes only can acees the first 128GiB (137GB) on USB drives, while
+ *      internal hard drives don't neseccarily suffer from this 128GiB problem.
+ *      Using PLoPs USB capabilities, you can access the whole drive.
+ *
+ * When you select the "USB" entry in PLoP, it will boot your USB stick/drive
+ * again and it will boot PLoP again when you have set booting PLoP as DEFAULT
+ * boot option in your Syslinux configuration file.
+ *
+ * By using ifplop.c32 you can specify which action you want to do the second
+ * time your USB stick/drive is booted. So you can load another config file or
+ * boot a large hard disk image or whathever you want.
+ *
+ * PLoP Boot Manager website: http://www.plop.at/en/bootmanager.html
+ */
+
+#include <com32.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <alloca.h>
+#include <console.h>
+#include <syslinux/boot.h>
+
+static bool plop_INT13h_check(void)
+{
+    com32sys_t inregs, outregs;
+
+    /* Prepare the register set */
+    memset(&inregs, 0, sizeof inregs);
+
+    /*
+     * Check if PLoP already has booted a CDROM or USB drive by checking
+     * for the presence of the PLoP INT13h hook.
+     *
+     * The following assembly code (NASM) can detect the PLoP INT13h hook:
+     *
+     *   mov eax,'PoLP'  ; Reverse of 'PLoP'
+     *   mov ebp,'DKHC'  ; Reverse of 'CHKD'
+     *   int 13h
+     *   cmp eax,' sey'  ; Reverse of 'yes '
+     *   jz plop_INT13h_active
+     */
+
+    inregs.eax.l = 0x504c6f50;	/* "PLoP" */
+    inregs.ebp.l = 0x43484b44;	/* "CHKD" */
+
+    __intcall(0x13, &inregs, &outregs);
+
+    /* eax will contain "yes " if PLoP INT13h hook is available */
+    if (outregs.eax.l == 0x79657320)
+	return true;
+
+    return false;
+}
+
+/* XXX: this really should be librarized */
+static void boot_args(char **args)
+{
+    int len = 0, a = 0;
+    char **pp;
+    const char *p;
+    char c, *q, *str;
+
+    for (pp = args; *pp; pp++)
+	len += strlen(*pp) + 1;
+
+    q = str = alloca(len);
+    for (pp = args; *pp; pp++) {
+	p = *pp;
+	while ((c = *p++))
+	    *q++ = c;
+	*q++ = ' ';
+	a = 1;
+    }
+    q -= a;
+    *q = '\0';
+
+    if (!str[0])
+	syslinux_run_default();
+    else
+	syslinux_run_command(str);
+}
+
+int main(int argc, char *argv[])
+{
+    char **args[2];
+    int arg = 0;
+
+    openconsole(&dev_null_r, &dev_stdcon_w);
+
+    if (argc)
+	arg++;
+    args[0] = &argv[arg];
+    args[1] = NULL;
+    while (arg < argc) {
+	if (!strcmp(argv[arg], "--")) {
+	    argv[arg] = NULL;
+	    args[1] = &argv[arg + 1];
+	    break;
+	}
+	arg++;
+    }
+    if (args[1] != NULL) {
+	boot_args(plop_INT13h_check()? args[0] : args[1]);
+    } else {
+	fprintf(stderr,
+		"Usage:   ifplop.c32 [<plop_detected>] -- [<plop_not_detected>]\n"
+		"Example: ifplop.c32 menu.c32 another.cfg -- plpbt.bin hiddenusb usb1=2\n");
+    }
+
+    return 0;
+}



More information about the Syslinux-commits mailing list