diff -rub grub-0.96-orig/stage2/builtins.c grub-0.96/stage2/builtins.c
--- grub-0.96-orig/stage2/builtins.c	2004-06-20 15:33:04.000000000 +0200
+++ grub-0.96/stage2/builtins.c	2005-03-19 18:32:04.000000000 +0100
@@ -58,6 +58,12 @@
 int debug = 0;
 /* The default entry.  */
 int default_entry = 0;
+/* OnPortSel variables.  */
+int onportsel_entry = -1;
+int onportsel_addr = 0x379;
+unsigned char onportsel_mask = 0xFF;
+unsigned char onportsel_value = 0xFF;
+
 /* The fallback entry.  */
 int fallback_entryno;
 int fallback_entries[MAX_FALLBACK_ENTRIES];
@@ -97,6 +103,10 @@
 init_config (void)
 {
   default_entry = 0;
+  onportsel_entry = -1;
+  onportsel_addr = 0x379;
+  onportsel_mask = 0xFF;
+  onportsel_value = 0xFF;
   password = 0;
   fallback_entryno = -1;
   fallback_entries[0] = -1;
@@ -788,6 +798,101 @@
 };
 
 
+/* portout */
+static int
+portout_func (char *arg, int flags)
+{
+  int i = 0, addr;
+  unsigned char value;
+  while (1)
+  {
+    switch(i) {
+    case 0:
+      if(!safe_parse_maxint (&arg, &addr)) return 1;
+      break;
+
+    case 1:
+      if(!safe_parse_maxint (&arg, &value)) return 1;
+      break;
+    }
+    
+    i++;
+    arg = skip_to (0, arg);
+    if(arg[0]=='\0') break;
+  }
+  
+  portout(addr, value);
+  
+  return 0;
+}
+
+static struct builtin builtin_portout =
+{
+  "portout",
+  portout_func,
+  BUILTIN_MENU,
+  "portout PORT VALUE",
+  "Write a VALUE to a hardware address (PORT)"
+};
+
+
+/* onportsel */
+static int
+onportsel_func (char *arg, int flags)
+{
+  int i = 0;
+  while (1)
+  {
+    switch(i) {
+    case 0:
+      if(!safe_parse_maxint (&arg, &onportsel_entry)) return 1;
+      break;
+
+    case 1:
+      if(!safe_parse_maxint (&arg, &onportsel_addr)) {onportsel_entry=-1; return 1;}
+      break;
+      
+    case 2:
+      onportsel_mask = onportsel_value = 0;
+      int pos;
+      for(pos=0;pos<8;pos++) {
+        switch(arg[pos]) {
+        case '0':
+	  onportsel_mask |= (0x80>>pos);
+	  break;
+	case '1':
+	  onportsel_value |= (0x80>>pos);
+	  onportsel_mask |= (0x80>>pos);
+	  break;
+	case 'x':case 'X':
+	  //actually nothing to do
+	  break;
+	case '\0':
+	  return 1; //err
+	}
+      }
+      break;
+    }
+    
+    i++;
+    arg = skip_to (0, arg);
+    if(arg[0]=='\0') break;
+  }
+  
+  return 0;
+}
+
+static struct builtin builtin_onportsel =
+{
+  "onportsel",
+  onportsel_func,
+  BUILTIN_MENU,
+  "onportsel NUM PORT MASK",
+  "Set the selection to entry number NUM if the value"
+  " on PORT matches the MASK"
+};
+
+
 #ifdef GRUB_UTIL
 /* device */
 static int
@@ -4831,11 +4936,13 @@
 #endif /* USE_MD5_PASSWORDS */
   &builtin_module,
   &builtin_modulenounzip,
+  &builtin_onportsel,
   &builtin_pager,
   &builtin_partnew,
   &builtin_parttype,
   &builtin_password,
   &builtin_pause,
+  &builtin_portout,
 #ifdef GRUB_UTIL
   &builtin_quit,
 #endif /* GRUB_UTIL */
diff -rub grub-0.96-orig/stage2/char_io.c grub-0.96/stage2/char_io.c
--- grub-0.96-orig/stage2/char_io.c	2004-05-23 18:45:43.000000000 +0200
+++ grub-0.96/stage2/char_io.c	2005-03-19 18:20:01.000000000 +0100
@@ -237,9 +237,12 @@
 init_page (void)
 {
   cls ();
+  char *apnd = "";
+  if(onportsel_entry >= 0)
+    if(mbi.lpt_val) apnd = "  OnPort(==)"; else apnd = "  OnPort(!=)";
 
-  grub_printf ("\n    GNU GRUB  version %s  (%dK lower / %dK upper memory)\n\n",
-	  version_string, mbi.mem_lower, mbi.mem_upper);
+  grub_printf ("\n    GNU GRUB  version %s  (%dK lower / %dK upper memory)%s\n\n",
+	  version_string, mbi.mem_lower, mbi.mem_upper, apnd);
 }
 
 /* The number of the history entries.  */
diff -rub grub-0.96-orig/stage2/mb_info.h grub-0.96/stage2/mb_info.h
--- grub-0.96-orig/stage2/mb_info.h	2003-07-09 13:45:53.000000000 +0200
+++ grub-0.96/stage2/mb_info.h	2005-03-19 18:20:01.000000000 +0100
@@ -170,6 +170,9 @@
   unsigned short vbe_interface_seg;
   unsigned short vbe_interface_off;
   unsigned short vbe_interface_len;
+  
+  /* LPT */
+  unsigned char lpt_val;
 };
 
 /*
diff -rub grub-0.96-orig/stage2/shared.h grub-0.96/stage2/shared.h
--- grub-0.96-orig/stage2/shared.h	2004-06-19 18:40:09.000000000 +0200
+++ grub-0.96/stage2/shared.h	2005-03-19 18:20:01.000000000 +0100
@@ -593,6 +593,10 @@
 extern int fallback_entries[MAX_FALLBACK_ENTRIES];
 extern int fallback_entryno;
 extern int default_entry;
+extern int onportsel_entry;
+extern int onportsel_addr;
+extern unsigned char onportsel_mask;
+extern unsigned char onportsel_value;
 extern int current_entryno;
 
 /* The constants for password types.  */
@@ -810,6 +814,18 @@
 	      int sector, int nsec, int segment);
 void stop_floppy (void);
 
+/* Port I/O */
+static inline unsigned char portin(unsigned int port) {
+ unsigned char value;
+ __asm__ __volatile__("inb %w1,%b0" : "=a"(value) : "d"(port));
+ return value;
+}
+
+static inline unsigned char portout(unsigned int port, unsigned char value) {
+ __asm__ __volatile__("outb %%al,%%dx"::"a" (value),"d" (port));
+ return value;
+}
+
 /* Command-line interface functions. */
 #ifndef STAGE1_5
 
diff -rub grub-0.96-orig/stage2/stage2.c grub-0.96/stage2/stage2.c
--- grub-0.96-orig/stage2/stage2.c	2004-07-24 20:53:47.000000000 +0200
+++ grub-0.96/stage2/stage2.c	2005-03-19 18:20:01.000000000 +0100
@@ -239,6 +239,16 @@
    */
 
 restart:
+  //check onportsel:
+  if(onportsel_entry >= 0)
+    {
+      unsigned char portval = portin(onportsel_addr);
+      if( (portval & onportsel_mask) == (onportsel_value & onportsel_mask) )
+        { entryno = onportsel_entry; mbi.lpt_val = 1; }
+      else
+        mbi.lpt_val = 0;
+    }
+  
   /* Dumb terminal always use all entries for display 
      invariant for TERM_DUMB: first_entry == 0  */
   if (! (current_term->flags & TERM_DUMB))
@@ -697,6 +707,13 @@
 		  enter_cmdline (heap, 0);
 		  goto restart;
 		}
+	      if (c == 'x')
+		{
+		  cls();
+		  grub_printf("onportsel_addr == %d\nonportsel_mask == %d\nonportsel_value == %d\nonportsel_entry == %d\nPort[0x%x] == %d\n",onportsel_addr,onportsel_mask,onportsel_value,onportsel_entry,onportsel_addr, portin(onportsel_addr));
+		  getkey();
+		  goto restart;
+		}
 #ifdef GRUB_UTIL
 	      if (c == 'q')
 		{
