Skip to contentSkip to conversation

Use relocator framework for multiboot1

PATCH In review Vladimir 'phcoder' Serbinenko 2 participants 4 messages Aug 3, 2009 – Aug 7, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Use relocator framework for multiboot1

For now modules aren't in relocated buffer because memory management is unable to handle realloc with big size efficiently which may cause module command to fail

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
include/grub/i386/multiboot.h +3 -8
index 2dd7ec0..bd3c573 100644
@@ -27,16 +27,11 @@ void grub_multiboot2_real_boot (grub_addr_t entry,
 				struct grub_multiboot_info *mbi)
      __attribute__ ((noreturn));
 
-extern grub_addr_t grub_multiboot_payload_orig;
+extern grub_uint32_t grub_multiboot_payload_eip;
+extern char *grub_multiboot_payload_orig;
 extern grub_addr_t grub_multiboot_payload_dest;
 extern grub_size_t grub_multiboot_payload_size;
-extern grub_uint32_t grub_multiboot_payload_entry_offset;
 
-extern grub_uint8_t grub_multiboot_forward_relocator;
-extern grub_uint8_t grub_multiboot_forward_relocator_end;
-extern grub_uint8_t grub_multiboot_backward_relocator;
-extern grub_uint8_t grub_multiboot_backward_relocator_end;
-
-#define RELOCATOR_SIZEOF(x)	(&grub_multiboot_##x##_relocator_end - &grub_multiboot_##x##_relocator)
+#define GRUB_MULTIBOOT_STACK_SIZE 4096
 
 #endif /* ! GRUB_MULTIBOOT_CPU_HEADER */
loader/i386/multiboot.c +33 -31

120 lines not on this page · raw message

loader/i386/multiboot_elfxx.c +8 -6
index 77c4711..0b9820d 100644
@@ -32,6 +32,8 @@
 #error "I'm confused"
 #endif
 
+#include <grub/i386/relocator.h>
+
 #define CONCAT(a,b)	CONCAT_(a, b)
 #define CONCAT_(a,b)	a ## b
 
@@ -99,11 +101,12 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
   grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr;
 
   grub_multiboot_payload_size += code_size;
-  playground = grub_malloc (RELOCATOR_SIZEOF(forward) + grub_multiboot_payload_size + RELOCATOR_SIZEOF(backward));
-  if (! playground)
-    return grub_errno;
 
-  grub_multiboot_payload_orig = (long) playground + RELOCATOR_SIZEOF(forward);
+  grub_multiboot_payload_orig
+    = grub_relocator32_alloc (grub_multiboot_payload_size);
+
+  if (!grub_multiboot_payload_orig)
+    return grub_errno;
 
   /* Load every loadable segment in memory.  */
   for (i = 0; i < ehdr->e_phnum; i++)
@@ -135,8 +138,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
     if (phdr(i)->p_vaddr <= ehdr->e_entry
 	&& phdr(i)->p_vaddr + phdr(i)->p_memsz > ehdr->e_entry)
       {
-	grub_multiboot_payload_entry_offset = (ehdr->e_entry - phdr(i)->p_vaddr)
-	  + (phdr(i)->p_paddr  - phdr(lowest_segment)->p_paddr);
+	grub_multiboot_payload_eip = ehdr->e_entry;
 	break;
       }
 
loader/i386/multiboot_helper.S +0 -75

81 lines not on this page · raw message

#1 lore raw

Review

Quoted 3 lines · Vladimir 'phcoder' Serbinenko
(quoted diff) +2 -0
+#define GRUB_MULTIBOOT_STACK_SIZE 4096
[...]
+#define stack_addr(x)		((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct grub_multiboot_info) + mmap_length + GRUB_MULTIBOOT_STACK_SIZE))

What's this stack used for?

Signature · 5 lines
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."
#2 lore raw
Quoted 6 lines · Robert Millan

Review

Quoted 3 lines · Vladimir 'phcoder' Serbinenko
(quoted diff) +2 -0
+#define GRUB_MULTIBOOT_STACK_SIZE 4096
[...]
+#define stack_addr(x)                ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct grub_multiboot_info) + mmap_length + GRUB_MULTIBOOT_STACK_SIZE))

What's this stack used for?

Only to set %esp to something that can be used by OS for small things before they setup their own stack. By multiboot specification OS is required to setup its stack itself but I suppose many OSes may have done a mistake of having few push'es before real stack setup

Quoted 14 lines

--
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."

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#3 lore raw
Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Quoted 6 lines · Robert Millan

Review

Quoted 3 lines · Vladimir 'phcoder' Serbinenko
(quoted diff) +2 -0
+#define GRUB_MULTIBOOT_STACK_SIZE 4096
[...]
+#define stack_addr(x)                ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct grub_multiboot_info) + mmap_length + GRUB_MULTIBOOT_STACK_SIZE))

What's this stack used for?

Only to set %esp to something that can be used by OS for small things before they setup their own stack. By multiboot specification OS is required to setup its stack itself but I suppose many OSes may have done a mistake of having few push'es before real stack setup

Did you find code that has this problem?

Note it's much simpler for them to solve it on their side by allocating a stack in their BSS.

Signature · 5 lines
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."