]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
EFI support
authorphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Thu, 3 Sep 2009 17:19:59 +0000 (19:19 +0200)
committerphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Thu, 3 Sep 2009 17:19:59 +0000 (19:19 +0200)
include/grub/autoefi.h
include/grub/efi/api.h
include/grub/efi/efi.h
kern/efi/efi.c
loader/i386/xnu.c

index 4f5e262f0874e1853aac4ed9037df73cf1850518..245bc08026b8ebcf25145e57e79c871ead1420e0 100644 (file)
@@ -27,6 +27,7 @@
 # include <grub/efi/efi.h>
 # define grub_autoefi_get_memory_map grub_efi_get_memory_map
 # define grub_autoefi_finish_boot_services grub_efi_finish_boot_services
+# define grub_autoefi_exit_boot_services grub_efi_exit_boot_services
 # define grub_autoefi_system_table grub_efi_system_table
 # define grub_autoefi_mmap_iterate grub_machine_mmap_iterate
 # define grub_autoefi_set_virtual_address_map grub_efi_set_virtual_address_map
@@ -55,6 +56,7 @@ static inline grub_err_t grub_autoefi_prepare (void)
 # include <grub/efiemu/efiemu.h>
 # define grub_autoefi_get_memory_map grub_efiemu_get_memory_map
 # define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services
+# define grub_autoefi_exit_boot_services grub_efiemu_exit_boot_services
 # define grub_autoefi_system_table grub_efiemu_system_table
 # define grub_autoefi_mmap_iterate grub_efiemu_mmap_iterate
 # define grub_autoefi_prepare grub_efiemu_prepare
index e870eab410156edce9c67a10f5635a716ab9895c..32904150ee145dcacb9ffa29d7c3a63b64e0f842 100644 (file)
@@ -21,6 +21,7 @@
 #define GRUB_EFI_API_HEADER    1
 
 #include <grub/types.h>
+#include <grub/symbol.h>
 
 /* For consistency and safety, we name the EFI-defined types differently.
    All names are transformed into lower case, _t appended, and
index 754c4a7cbdc4cf708e3c161dace8fcd06cdefda5..97051f2977022728ca27f03a02a6f41ea85511b7 100644 (file)
@@ -57,10 +57,10 @@ int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 int EXPORT_FUNC (grub_efi_finish_boot_services) (void);
-grub_err_t EXPORT_FUNC (grub_efiemu_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
-                                                             grub_efi_uintn_t descriptor_size,
-                                                             grub_efi_uint32_t descriptor_version,
-                                                             grub_efi_memory_descriptor_t *virtual_map);
+grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
+                                                          grub_efi_uintn_t descriptor_size,
+                                                          grub_efi_uint32_t descriptor_version,
+                                                          grub_efi_memory_descriptor_t *virtual_map);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);
index 630f012b654914fd16a201f817a4811afc42afb1..279d1d61b8b37a260ba18102722b65583bf6c2af 100644 (file)
@@ -189,10 +189,10 @@ grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
 }
 
 grub_err_t
-grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
-                                    grub_efi_uintn_t descriptor_size,
-                                    grub_efi_uint32_t descriptor_version,
-                                    grub_efi_memory_descriptor_t *virtual_map)
+grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
+                                 grub_efi_uintn_t descriptor_size,
+                                 grub_efi_uint32_t descriptor_version,
+                                 grub_efi_memory_descriptor_t *virtual_map)
 {
   grub_efi_runtime_services_t *r;
   grub_efi_status_t status;
@@ -204,7 +204,7 @@ grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
   if (status == GRUB_EFI_SUCCESS)
     return GRUB_ERR_NONE;
 
-  return grub_errno (GRUB_ERR_IO, "set_virtual_address_map failed");
+  return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed");
 }
 
 grub_uint32_t
index 0b110bab6a6eb10e3683d169ee53ac27d9d70a7e..59721155a0bc48363981159096fc081de6f4ee4f 100644 (file)
@@ -452,28 +452,53 @@ grub_xnu_boot (void)
   descriptor_size = 0;
   descriptor_version = 0;
 
+  grub_dprintf ("xnu", "eip=%x\n", grub_xnu_entry_point);
+
+  const char *debug = grub_env_get ("debug");
+
+  if (debug && (grub_strword (debug, "all") || grub_strword (debug, "xnu")))
+    {
+      grub_printf ("Press any key to launch xnu\n");
+      grub_getkey ();
+    }
+
+  /* Relocate the boot parameters to heap. */
+  bootparams_relloc = grub_xnu_heap_malloc (sizeof (*bootparams_relloc));
+  if (! bootparams_relloc)
+    return grub_errno;
+  bootparams_relloc_off = (grub_uint8_t *) bootparams_relloc
+    - (grub_uint8_t *) grub_xnu_heap_start;
+
+  /* Set video. */
+  err = grub_xnu_set_video (bootparams_relloc);
+  if (err != GRUB_ERR_NONE)
+    {
+      grub_print_error ();
+      grub_errno = GRUB_ERR_NONE;
+      grub_printf ("Booting in blind mode\n");
+
+      bootparams_relloc->lfb_mode = 0;
+      bootparams_relloc->lfb_width = 0;
+      bootparams_relloc->lfb_height = 0;
+      bootparams_relloc->lfb_depth = 0;
+      bootparams_relloc->lfb_line_len = 0;
+      bootparams_relloc->lfb_base = 0;
+    }
+
   if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
                                   &map_key, &descriptor_size,
                                   &descriptor_version) < 0)
     return grub_errno;
 
+  /* We will do few allocations later. Reserve some space for possible
+     memory map growth.  */
+  memory_map_size += 20 * descriptor_size;
   memory_map = grub_xnu_heap_malloc (memory_map_size);
   if (! memory_map)
     return grub_errno;
-
-  if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
-                                  &map_key, &descriptor_size,
-                                  &descriptor_version) <= 0)
-    return grub_errno;
   mmap_relloc_off = (grub_uint8_t *) memory_map
     - (grub_uint8_t *) grub_xnu_heap_start;
 
-  /* Relocate the boot parameters to heap. */
-  bootparams_relloc = grub_xnu_heap_malloc (sizeof (*bootparams_relloc));
-  if (! bootparams_relloc)
-    return grub_errno;
-  bootparams_relloc_off = (grub_uint8_t *) bootparams_relloc
-    - (grub_uint8_t *) grub_xnu_heap_start;
   err = grub_xnu_writetree_toheap (&devtree, &devtreelen);
   if (err)
     return err;
@@ -487,18 +512,20 @@ grub_xnu_boot (void)
     + grub_xnu_heap_will_be_at;
   bootparams_relloc->devtreelen = devtreelen;
 
-  bootparams_relloc->efi_system_table
-    = PTR_TO_UINT32 (grub_autoefi_system_table);
-  bootparams_relloc->efi_mmap = grub_xnu_heap_will_be_at + mmap_relloc_off;
-  bootparams_relloc->efi_mmap_size = memory_map_size;
-  bootparams_relloc->efi_mem_desc_size = descriptor_size;
-  bootparams_relloc->efi_mem_desc_version = descriptor_version;
-
   memory_map = (grub_efi_memory_descriptor_t *)
     ((grub_uint8_t *) grub_xnu_heap_start + mmap_relloc_off);
   firstruntimeaddr = ALIGN_UP (((grub_addr_t) grub_xnu_heap_start
                                + grub_xnu_heap_size + 4096), 4096);
   curruntimeaddr = firstruntimeaddr;
+
+  if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
+                                  &map_key, &descriptor_size,
+                                  &descriptor_version) <= 0)
+    return grub_errno;
+
+  bootparams_relloc->efi_system_table
+    = PTR_TO_UINT32 (grub_autoefi_system_table);
+
   for (i = 0; (unsigned) i < memory_map_size / descriptor_size; i++)
     {
       grub_efi_memory_descriptor_t *curdesc = (grub_efi_memory_descriptor_t *)
@@ -525,6 +552,11 @@ grub_xnu_boot (void)
 
   lastruntimeaddr = curruntimeaddr;
 
+  bootparams_relloc->efi_mmap = grub_xnu_heap_will_be_at + mmap_relloc_off;
+  bootparams_relloc->efi_mmap_size = memory_map_size;
+  bootparams_relloc->efi_mem_desc_size = descriptor_size;
+  bootparams_relloc->efi_mem_desc_version = descriptor_version;
+
   bootparams_relloc->heap_start = grub_xnu_heap_will_be_at;
   bootparams_relloc->heap_size = grub_xnu_heap_size;
   bootparams_relloc->efi_runtime_first_page = firstruntimeaddr
@@ -545,39 +577,13 @@ grub_xnu_boot (void)
   grub_xnu_launch = (void (*) (void))
     (grub_xnu_heap_start + grub_xnu_heap_size);
 #endif
-  grub_dprintf ("xnu", "eip=%x\n", grub_xnu_entry_point);
-  grub_dprintf ("xnu", "launch=%p\n", grub_xnu_launch);
-
-  const char *debug = grub_env_get ("debug");
-
-  if (debug && (grub_strword (debug, "all") || grub_strword (debug, "xnu")))
-    {
-      grub_printf ("Press any key to launch xnu\n");
-      grub_getkey ();
-    }
-
-  /* Set video. */
-  err = grub_xnu_set_video (bootparams_relloc);
-  if (err != GRUB_ERR_NONE)
-    {
-      grub_print_error ();
-      grub_errno = GRUB_ERR_NONE;
-      grub_printf ("Booting in blind mode\n");
-
-      bootparams_relloc->lfb_mode = 0;
-      bootparams_relloc->lfb_width = 0;
-      bootparams_relloc->lfb_height = 0;
-      bootparams_relloc->lfb_depth = 0;
-      bootparams_relloc->lfb_line_len = 0;
-      bootparams_relloc->lfb_base = 0;
-    }
 
   grub_memcpy (grub_xnu_heap_start + grub_xnu_heap_size,
               grub_xnu_launcher_start,
               grub_xnu_launcher_end - grub_xnu_launcher_start);
 
 
-  if (! grub_autoefi_finish_boot_services ())
+  if (! grub_autoefi_exit_boot_services (map_key))
     return grub_error (GRUB_ERR_IO, "can't exit boot services");
 
   grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,