bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: a hack to change the default using external hw


From: Alessandro Rubini
Subject: FYI: a hack to change the default using external hw
Date: Tue, 24 Oct 2000 20:00:48 +0200

Since there was at least one person in this list who showed interest
in this kind of stuff, here's a dirty "only-for-my-own-use" hack to
read bits from the parallel port in order to choose the menu entry
to be invoked beforehand.

The printf's and the ioperm are just to ease testing. I am using
a BCD encoder and this works for me under debian/slink.

/alessandro

Index: stage2/builtins.c
===================================================================
RCS file: /cvs/grub/stage2/builtins.c,v
retrieving revision 1.84.2.4
diff -u -d -r1.84.2.4 builtins.c
--- stage2/builtins.c   2000/10/19 19:50:58     1.84.2.4
+++ stage2/builtins.c   2000/10/24 17:52:44
@@ -23,6 +23,7 @@
    WITHOUT_LIBC_STUBS here.  */
 #ifdef GRUB_UTIL
 # include <stdio.h>
+# include <sys/perm.h>
 #endif
 
 #include <shared.h>
@@ -3969,6 +3970,59 @@
   " installed.  Any system address range maps are discarded."
 };
 
+/*
+ * these are called inp and outp as inb/outb sometimes are there and
+ * sometimes are not there (as this file is compiled several times)
+ */
+static inline unsigned char inp(unsigned short port)
+{
+    unsigned char result;
+    __asm__ __volatile__("inb %w1,%0" : "=a" (result) : "Nd" (port));
+    return result;
+}
+static inline void outp(unsigned char value, unsigned short port)
+{
+    __asm__ __volatile__("outb %b0,%w1" : : "a" (value),  "Nd" (port));
+}
+
+/*
+ * defaultfromlpt:
+ * This command is a custom hack, not generic enough to be distributed.
+ */
+static int
+defaultfromlpt_func (char *arg, int flags)
+{
+    unsigned char val1, val2;
+    /*
+     * First check that something is connected to the parallel port. I don't
+     * know what happens if a printer is there: mine is either unused or with
+     * a boot-selector */
+#ifdef GRUB_UTIL
+    ioperm(0x378,4,1);
+#endif
+    outp(0x00, 0x378); val1 = inp(0x379);
+    outp(0xFF, 0x378); val2 = inp(0x379);
+    if (val1 == val2) {
+       grub_printf("nothing on lpt\n");
+       return 0;
+    }
+    /* re-read port after this small delay */
+    val1 = (inp(0x379) >> 4) ^ 7;
+    grub_printf("default is now %d\n", val1);
+    default_entry = val1;
+    return 0;
+}
+
+static struct builtin custom_defaultfromlpt =
+{
+  "defaultfromlpt",
+  defaultfromlpt_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU, /* use both, so I can test it */
+  "defaultfromlpt",
+  "Reads bits 4-7 of the printer port at 0x379; inverts the low "
+  "three bits and uses the result as default entry to boot."
+};
+
 
 /* The table of builtin commands. Sorted in dictionary order.  */
 struct builtin *builtin_table[] =
@@ -3985,6 +4039,7 @@
   &builtin_configfile,
   &builtin_debug,
   &builtin_default,
+  &custom_defaultfromlpt, /* they must be ordered. No comment */
 #ifdef GRUB_UTIL
   &builtin_device,
 #endif /* GRUB_UTIL */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]