Skip to contentSkip to conversation

multiboot2 vs. grub2 implementation

DISCUSSION [email protected] 4 participants 8 messages Feb 3, 2008 – Feb 6, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered some places where the draft and the grub2 implementation differ.

* Multiboot Information Tags
* Start Tag

    The Draft says key is 0x0000, grub2 says 0x0001.
  * Boot Loader Name tag is different
    The Draft says 0x0001, grub2 says 0x0002.

* Module/Kernel Tags
These tags seem to have different keys and different data formats than the draft indicates.
* Memory Map Tag
Does not seem to be implemented.

Additionally, the word-length of the values does not seem consistent. bit 17 of the flags does not seem to affect the word size used in the Multiboot Information structure.

The Operating System Image header's load_addr and entry_addr fields do not seem to be recognized, even with bit 8 in the flags set. But I did use 64-bit values for the addresses, so this may be the same as the issue in the preceding paragraph.

The entry physical address field is very useful to the kernel I'm using, as the ELF64 entry address supplied by the kernel I'm working with is the virtual address, not the physical address.
The load address information in the ELF64 kernel I have are presently also virtual addresses though this could/should probably be changed in the linker script. The kernel command line,
as well as the memory map are also useful tags for this x86_64 kernel.

Jonathan Kollasch

#1 lore raw
Quoted 4 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Are you using grub2/cvs with or without Bean's latest multiboot patch? It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

#2 lore raw
Quoted 10 lines · walt
Quoted 5 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered
some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Are you using grub2/cvs with or without Bean's latest multiboot patch?

I tend not to be aware of these things. I'm using stock sources.

Quoted 2 lines

It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

Hmm.

Jonathan Kollasch

#3 lore raw
Quoted 10 lines · On Tue, 2008-02-05 at 14:23 -0600, [email protected] wrote:
Quoted 9 lines · walt
Quoted 5 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered
some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Quoted 8 lines
Quoted 1 line

Are you using grub2/cvs with or without Bean's latest multiboot patch?

I tend not to be aware of these things. I'm using stock sources.

Quoted 2 lines

It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

Hmm.

Agreed :o) Bean's patch had some whitespace corruption anyway, so here it is again, diffed against today's latest cvs grub2:
========================================================================

this is the patch, problems found:

1, the mbi structure is not initialized to all zeros, this means some important member, like mods_count, will contain trash.
2, the entry point in the header is virtual address, we need to translate it to physical address.

* loader/i386/pc/multiboot.c (grub_multiboot_load_elf32): Get
physical
address of entry.
(grub_multiboot_load_elf64): Likewise. (grub_multiboot): Initialize mbi structure.

Index: loader/i386/pc/multiboot.c
===================================================================
RCS file: /sources/grub/grub2/loader/i386/pc/multiboot.c,v retrieving revision 1.15

i386/pc/multiboot.c +20 -2
diff -u -r1.15 multiboot.c
@@ -96,6 +96,7 @@
 {
   Elf32_Ehdr *ehdr = (Elf32_Ehdr *) buffer;
   Elf32_Phdr *phdr;
+  grub_addr_t real_entry = 0;
   int i;
 
   if (ehdr->e_ident[EI_CLASS] != ELFCLASS32)
@@ -144,9 +145,16 @@
           if (phdr->p_filesz < phdr->p_memsz)
             grub_memset ((char *) phdr->p_paddr + phdr->p_filesz, 0,
 			 phdr->p_memsz - phdr->p_filesz);
+
+          if ((entry >= phdr->p_vaddr) &&
+	      (entry < phdr->p_vaddr + phdr->p_memsz))
+	    real_entry = entry + phdr->p_paddr - phdr->p_vaddr;
         }
     }
-  
+
+  if (real_entry)
+    entry = real_entry;
+
   return grub_errno;
 }
 
@@ -164,6 +172,7 @@
 {
   Elf64_Ehdr *ehdr = (Elf64_Ehdr *) buffer;
   Elf64_Phdr *phdr;
+  grub_addr_t real_entry = 0;
   int i;
 
   if (ehdr->e_ident[EI_CLASS] != ELFCLASS64)
@@ -226,9 +235,16 @@
 			  + phdr->p_filesz),
 			 0,
 			 phdr->p_memsz - phdr->p_filesz);
+
+	  if ((entry >= phdr->p_vaddr) &&
+	      (entry < phdr->p_vaddr + phdr->p_memsz))
+	    real_entry = entry + phdr->p_paddr - phdr->p_vaddr;
         }
     }
-  
+
+  if (real_entry)
+    entry = real_entry;
+
   return grub_errno;
 }
 
@@ -306,6 +322,8 @@
   if (! mbi)
     goto fail;
 
+  grub_memset (mbi, 0, sizeof (struct grub_multiboot_info));
+
   mbi->flags = MULTIBOOT_INFO_MEMORY;
 
   /* Convert from bytes to kilobytes.  */
#4 lore raw
Quoted 16 lines · walt
Quoted 14 lines · On Tue, 2008-02-05 at 14:23 -0600, [email protected] wrote:
Quoted 10 lines · walt
Quoted 5 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered
some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Are you using grub2/cvs with or without Bean's latest multiboot patch?

I tend not to be aware of these things. I'm using stock sources.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

Hmm.

Agreed :o) Bean's patch had some whitespace corruption anyway, so here it is again, diffed against today's latest cvs grub2:

If you just fixed whitespace, it is better if we just use patch -l or Bean fixes it. Otherwise it means more paperwork and legal stuff :-/

Bean, where you going to commit that patch?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#5 lore raw
Quoted 22 lines · Robert Millan
Quoted 21 lines · walt
Quoted 18 lines · On Tue, 2008-02-05 at 14:23 -0600, [email protected] wrote:
Quoted 10 lines · walt
Quoted 5 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered
some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Are you using grub2/cvs with or without Bean's latest multiboot patch?

I tend not to be aware of these things. I'm using stock sources.

Quoted 2 lines

It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

Hmm.

Quoted 7 lines
Quoted 2 lines

Agreed :o) Bean's patch had some whitespace corruption anyway, so here it is again, diffed against today's latest cvs grub2:

If you just fixed whitespace, it is better if we just use patch -l or Bean fixes it. Otherwise it means more paperwork and legal stuff :-/

Bean, where you going to commit that patch?

if the patch is ok, i can check it in.

Signature · 1 line
Bean
#6 lore raw
Quoted 26 lines · Bean
Quoted 25 lines · Robert Millan
Quoted 23 lines · walt
Quoted 10 lines · On Tue, 2008-02-05 at 14:23 -0600, [email protected] wrote:
Quoted 9 lines · walt
Quoted 5 lines · [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered
some places where the draft and the grub2 implementation differ...

Hi Jonathan,

Quoted 8 lines
Quoted 1 line

Are you using grub2/cvs with or without Bean's latest multiboot patch?

I tend not to be aware of these things. I'm using stock sources.

Quoted 2 lines

It still hasn't been committed, and I was about to ask about it anyway. Without that patch, multiboot doesn't work.

Hmm.

Agreed :o) Bean's patch had some whitespace corruption anyway, so here it is again, diffed against today's latest cvs grub2:

Quoted 6 lines
Quoted 4 lines

If you just fixed whitespace, it is better if we just use patch -l or Bean fixes it. Otherwise it means more paperwork and legal stuff :-/

Bean, where you going to commit that patch?

if the patch is ok, i can check it in.

Ok I just replied in the other thread.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#7 lore raw
In reply to [email protected]
Quoted 7 lines · On Sun, Feb 03, 2008 at 10:39:33AM -0600, [email protected] wrote:

Hi,

In the course of actually trying to use the MultibootDraft, I've discovered some places where the draft and the grub2 implementation differ.

* Multiboot Information Tags
* Start Tag

Quoted 8 lines
    The Draft says key is 0x0000, grub2 says 0x0001.
  * Boot Loader Name tag is different
    The Draft says 0x0001, grub2 says 0x0002.

* Module/Kernel Tags
These tags seem to have different keys and different data formats than the draft indicates.
* Memory Map Tag
Does not seem to be implemented.

Bean just committed his fix. Please, can you check if this addressed all the discordances?

Quoted 1 line

The entry physical address field [...]

I think that was fixed as well. Could you check?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)