On Tue, Aug 12, 2008 at 04:48:29PM +0000, Jonathan A. Kollasch wrote:
> hi,
> 
> Robert noted that I should mention this:
> 
> The ELF section header table MBI seems to not be implemented in grub2.
> NetBSD/i386 uses this to find symbol names in it's kernel debugger.

For the record (Jonathan already knows), I made this patch, which is supposed
to implement it using code from GRUB Legacy.

It needs some cleanup, but since I have no readily available testcase (NetBSD's
kernel seems to have some trouble involving MBI corruption), I can't finish it
yet.

I'm sending it here for reference.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
diff -ur grub2.old/include/grub/multiboot.h grub2/include/grub/multiboot.h
--- grub2.old/include/grub/multiboot.h	2008-09-07 19:02:04.000000000 +0200
+++ grub2/include/grub/multiboot.h	2008-09-08 15:35:44.000000000 +0200
@@ -1,7 +1,7 @@
 /* multiboot.h - multiboot header file with grub definitions. */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003,2007,2008  Free Software Foundation, Inc.
+ *  Copyright (C) 2000,2003,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -73,8 +73,27 @@
   grub_uint32_t mods_count;
   grub_uint32_t mods_addr;
   
-  grub_uint32_t syms[4];
-  
+  union
+  {
+    struct
+    {
+      /* a.out payload symbol table info */
+      grub_uint32_t tabsize;
+      grub_uint32_t strsize;
+      grub_uint32_t addr;
+      grub_uint32_t pad;
+    } aout;
+
+    struct
+    {
+      /* ELF payload section header table */
+      grub_uint32_t num;
+      grub_uint32_t size;
+      grub_uint32_t addr;
+      grub_uint32_t shndx;
+    } elf;
+  } syms;
+
   /* Memory Mapping buffer */
   grub_uint32_t mmap_length;
   grub_uint32_t mmap_addr;
diff -ur grub2.old/loader/i386/pc/multiboot.c grub2/loader/i386/pc/multiboot.c
--- grub2.old/loader/i386/pc/multiboot.c	2008-09-07 19:03:20.000000000 +0200
+++ grub2/loader/i386/pc/multiboot.c	2008-09-08 15:35:44.000000000 +0200
@@ -21,7 +21,7 @@
  *  FIXME: The following features from the Multiboot specification still
  *         need to be implemented:
  *  - VBE support
- *  - symbol table
+ *  - a.out symbol table
  *  - drives table
  *  - ROM configuration table
  *  - APM table
@@ -204,6 +204,60 @@
 
 #undef phdr
 
+  mbi->syms.elf.num = ehdr->e_shnum;
+  mbi->syms.elf.size = ehdr->e_shentsize;
+  mbi->syms.elf.shndx = ehdr->e_shstrndx;
+
+  grub_file_seek (file, ehdr->e_shoff);
+
+  /* FIXME: move to the relocatable block */
+  mbi->syms.elf.addr = (grub_uint32_t) grub_malloc (sizeof (Elf32_Shdr) * ehdr->e_shnum);
+
+  /* FIXME: get rid of cur_addr;  use proper types? */
+  grub_uint32_t cur_addr = mbi->syms.elf.addr;
+
+  grub_file_read (file, (void *) cur_addr, ehdr->e_shentsize * ehdr->e_shnum);
+  cur_addr += ehdr->e_shentsize * ehdr->e_shnum;
+
+  /* FIXME: does this belong here? */
+  grub_printf (", shtab=0x%x\n", cur_addr);
+
+  Elf32_Shdr *shdr = (Elf32_Shdr *) mbi->syms.elf.addr;
+
+  for (i = 0; i < ehdr->e_shnum; i++)
+    {
+      /* This section is a loaded section, so we don't care.  */
+      if (shdr[i].sh_addr != 0)
+	continue;
+
+      /* This section is empty, so we don't care.  */
+      if (shdr[i].sh_size == 0)
+	continue;
+
+      /* Align the section to a sh_addralign bits boundary.  */
+      cur_addr = ((cur_addr + shdr[i].sh_addralign) &
+		  - (int) shdr[i].sh_addralign);
+
+      grub_file_seek (file, shdr[i].sh_offset);
+
+      /* FIXME: is this useful? */
+#if 0
+      if (! (memcheck (cur_addr, shdr[i].sh_size)
+	     && (grub_read ((char *) RAW_ADDR (cur_addr),
+			    shdr[i].sh_size)
+		 == shdr[i].sh_size)))
+	{
+	  symtab_err = 1;
+	  break;
+	}
+#endif
+
+      shdr[i].sh_addr = cur_addr;
+      cur_addr += shdr[i].sh_size;
+    }
+
+  mbi->flags |= MULTIBOOT_INFO_ELF_SHDR;
+
   return grub_errno;
 }
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to