Hello!

I'm attaching two patches.

compact.diff is based on my analysis of the linker cross-reference table
(pass -Wl,--cref to gcc to get it)
It disables some functons not used in stage2 and *stage1_5 and also
makes global variables in sms-imps.c static.

menu.diff introduces a new command "menu" <file>
This command can be used both from the command line to load the menu
dynamically and from another menus to emulate submenus.

ChangeLog:

        * stage2/asm.S [!STAGE1_5]: disable chain_stage2
        [STAGE1_5]: disable get_code_end
        * stage2/char_io.c: disable grub_strncat
        * stage2/common.c, stage2/shared.h [STAGE1_5]: disable
        saved_mem_upper
        stage2/smp-imps.c: remove imps_release_cpus, make other
        global variables static

        stage2/cmdline.c: new command "menu" <file>
        stage2/shared.h, stage2/stage2.c: new variable restart_menu
        If restart_menu is 1, restart the menu on CMDLINE_ABORT

Pavel Roskin
diff -ur stage2/cmdline.c stage2/cmdline.c
--- stage2/cmdline.c    Thu Sep  2 22:00:51 1999
+++ stage2/cmdline.c    Sat Sep  4 18:31:28 1999
@@ -77,7 +77,7 @@
 " Possible commands are: \"pause ...\", \"uppermem <kbytes>\", \"root <device>\",
   \"rootnoverify <device>\", \"chainloader <file>\", \"kernel <file> ...\",
   \"testload <file>\", \"read <addr>\", \"displaymem\", \"impsprobe\",
-  \"geometry <drive>\", \"hide <device>\", \"unhide <device>\",
+  \"geometry <drive>\", \"hide <device>\", \"unhide <device>\", \"menu <file>\",
   \"fstest\", \"debug\", \"module <file> ...\", \"modulenounzip <file> ...\",
   \"color <normal> [<highlight>]\", \"makeactive\", \"boot\", \"quit\" and
   \"install <stage1_file> [d] <dest_dev> <file> <addr> [p] [<config_file>]\"\n";
@@ -676,9 +676,17 @@
                               | ((normal_color & 0xf) << 4));
        }
     }
+  else if (substring ("menu", cur_heap) < 1)
+    {
+      char *new_file = config_file;
+      while ((*(new_file ++) = *(cur_cmdline ++)) != 0);
+      restart_menu = 1;
+      return CMDLINE_ABORT;
+    }
   else if (substring ("quit", cur_heap) < 1)
     {
 #ifdef GRUB_UTIL
+      restart_menu = 0;
       return CMDLINE_ABORT;
 #else
       grub_printf (" The quit command is ignored in Stage2\n");
diff -ur stage2/shared.h stage2/shared.h
--- stage2/shared.h     Sat Sep  4 16:48:24 1999
+++ stage2/shared.h     Sat Sep  4 18:06:54 1999
@@ -497,6 +497,8 @@
 
 /* Command-line interface functions. */
 #ifndef STAGE1_5
+/* if 1, just restart the menu on CMDLINE_ABORT */
+extern int restart_menu;
 char *skip_to (int after_equal, char *cmdline);
 void init_cmdline (void);
 
diff -ur stage2/stage2.c stage2/stage2.c
--- stage2/stage2.c     Sat Sep  4 13:18:49 1999
+++ stage2/stage2.c     Sat Sep  4 18:24:08 1999
@@ -19,6 +19,9 @@
 
 #include "shared.h"
 
+/* if 1, just restart the menu on CMDLINE_ABORT */
+int restart_menu = 0;
+
 static char *
 get_entry(char *list, int num, int nested)
 {
@@ -467,7 +470,7 @@
                  /* Call the command-line interface, and if it aborts
                     (by ``quit'' command), then return.  */
                  if (enter_cmdline (NULL, heap) == CMDLINE_ABORT)
-                   return MENU_ABORT;
+                   return restart_menu ? MENU_OK : MENU_ABORT;
                  
                  goto restart;
                }
@@ -516,7 +519,7 @@
 
   /* If aborted, then return.  */
   if (c == CMDLINE_ABORT)
-    return MENU_ABORT;
+    return restart_menu ? MENU_OK : MENU_ABORT;
   
   /* Both the entry and the fallback failed, so wait for input. */
   printf ("      Press any key to continue...");
@@ -698,7 +701,8 @@
          while (enter_cmdline (NULL, config_entries) != CMDLINE_ABORT)
            ;
 
-         return;
+         if (!restart_menu)
+           return;
        }
       else
        {
diff -ur stage2/asm.S stage2/asm.S
--- stage2/asm.S        Thu Aug  5 17:33:17 1999
+++ stage2/asm.S        Sat Sep  4 15:47:52 1999
@@ -175,6 +175,7 @@
 #endif /* STAGE1_5 */
 
 
+#ifdef STAGE1_5
 /*
  * chain_stage2(segment, offset)
  *
@@ -212,6 +213,7 @@
        DATA32  ADDR32  ljmp    (offset)
 
        .code32
+#endif /* STAGE1_5 */
 
 /*
  *  These next two routines, "real_to_prot" and "prot_to_real" are structured
@@ -766,6 +768,7 @@
        pop     %ebp
        ret
 
+#ifndef STAGE1_5
 /* get_code_end() :  return the address of the end of the code
  * This is here so that it can be replaced by asmstub.c.
  */
@@ -775,6 +778,7 @@
        incl    %eax
        shll    $2, %eax
        ret
+#endif /* STAGE1_5 */
 
 /*
  *
diff -ur stage2/char_io.c stage2/char_io.c
--- stage2/char_io.c    Sat Sep  4 13:18:49 1999
+++ stage2/char_io.c    Sat Sep  4 15:44:02 1999
@@ -505,7 +505,7 @@
 }
 
 
-#ifndef STAGE1_5
+#if 0
 int
 grub_strncat (char *s1, const char *s2, int n)
 {
@@ -524,8 +524,10 @@
 
   return 1;
 }
+#endif
 
 
+#ifndef STAGE1_5
 int
 grub_strcmp (const char *s1, const char *s2)
 {
diff -ur stage2/common.c stage2/common.c
--- stage2/common.c     Thu Jun 24 04:03:12 1999
+++ stage2/common.c     Sat Sep  4 15:51:56 1999
@@ -28,7 +28,9 @@
 struct multiboot_info mbi;
 unsigned long saved_drive;
 unsigned long saved_partition;
+#ifndef STAGE1_5
 unsigned long saved_mem_upper;
+#endif /* STAGE1_5 */
 
 /*
  *  Error code stuff.
@@ -194,7 +196,9 @@
       mbi.mem_upper = memtmp;
     }
 
+#ifndef STAGE1_5
   saved_mem_upper = mbi.mem_upper;
+#endif /* STAGE1_5 */
 
   /*
    *  Initialize other Multiboot Info flags.
diff -ur stage2/shared.h stage2/shared.h
--- stage2/shared.h     Mon Aug 30 13:07:22 1999
+++ stage2/shared.h     Sat Sep  4 15:49:26 1999
@@ -393,7 +393,9 @@
 extern struct multiboot_info mbi;
 extern unsigned long saved_drive;
 extern unsigned long saved_partition;
+#ifndef STAGE1_5
 extern unsigned long saved_mem_upper;
+#endif /* STAGE1_5 */
 
 /*
  *  Error variables.
diff -ur stage2/smp-imps.c stage2/smp-imps.c
--- stage2/smp-imps.c   Thu Jul 15 17:13:37 1999
+++ stage2/smp-imps.c   Sat Sep  4 15:45:52 1999
@@ -249,13 +249,12 @@
  *  Exported globals here.
  */
 
-int imps_any_new_apics = 0;
-volatile int imps_release_cpus = 0;
-int imps_enabled = 0;
-int imps_num_cpus = 1;
-unsigned imps_lapic_addr = ((unsigned) (&lapic_dummy)) - LAPIC_ID;
-unsigned char imps_cpu_apic_map[IMPS_MAX_CPUS];
-unsigned char imps_apic_cpu_map[IMPS_MAX_CPUS];
+static int imps_any_new_apics = 0;
+static int imps_enabled = 0;
+static int imps_num_cpus = 1;
+static unsigned imps_lapic_addr = ((unsigned) (&lapic_dummy)) - LAPIC_ID;
+static unsigned char imps_cpu_apic_map[IMPS_MAX_CPUS];
+static unsigned char imps_apic_cpu_map[IMPS_MAX_CPUS];
 
 
 /*

Reply via email to