e30274a
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e30274a
From: Peter Jones <pjones@redhat.com>
e30274a
Date: Thu, 13 Sep 2018 14:42:34 -0400
e30274a
Subject: [PATCH] x86-efi: Re-arrange grub_cmd_linux() a little bit.
e30274a
e30274a
This just helps the next patch be easier to read.
e30274a
e30274a
Signed-off-by: Peter Jones <pjones@redhat.com>
e30274a
---
e30274a
 grub-core/loader/i386/efi/linux.c | 75 +++++++++++++++++++++------------------
e30274a
 1 file changed, 41 insertions(+), 34 deletions(-)
e30274a
e30274a
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
e30274a
index 06d19b9fc0e..de5f839ff0f 100644
e30274a
--- a/grub-core/loader/i386/efi/linux.c
e30274a
+++ b/grub-core/loader/i386/efi/linux.c
e30274a
@@ -250,32 +250,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
e30274a
       goto fail;
e30274a
     }
e30274a
 
e30274a
-  params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
e30274a
-					BYTES_TO_PAGES(sizeof(*params)));
e30274a
-  if (!params)
e30274a
-    params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
e30274a
-					  BYTES_TO_PAGES(sizeof(*params)));
e30274a
-  if (! params)
e30274a
-    {
e30274a
-      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
e30274a
-      goto fail;
e30274a
-    }
e30274a
+  lh = (struct linux_i386_kernel_header *)kernel;
e30274a
+  grub_dprintf ("linux", "original lh is at %p\n", kernel);
e30274a
 
e30274a
-  grub_dprintf ("linux", "params = %p\n", params);
e30274a
-
e30274a
-  grub_memset (params, 0, sizeof(*params));
e30274a
-
e30274a
-  setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
e30274a
-  grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
e30274a
-		MIN((grub_size_t)0x202+setup_header_end_offset,
e30274a
-		    sizeof (*params)) - 0x1f1,
e30274a
-		(grub_uint8_t *)kernel + 0x1f1,
e30274a
-		(grub_uint8_t *)params + 0x1f1);
e30274a
-  grub_memcpy ((grub_uint8_t *)params + 0x1f1,
e30274a
-	       (grub_uint8_t *)kernel + 0x1f1,
e30274a
-		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
e30274a
-  lh = (struct linux_i386_kernel_header *)params;
e30274a
-  grub_dprintf ("linux", "lh is at %p\n", lh);
e30274a
   grub_dprintf ("linux", "checking lh->boot_flag\n");
e30274a
   if (lh->boot_flag != grub_cpu_to_le16 (0xaa55))
e30274a
     {
e30274a
@@ -323,6 +300,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
e30274a
     }
e30274a
 #endif
e30274a
 
e30274a
+  params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS,
e30274a
+					BYTES_TO_PAGES(sizeof(*params)));
e30274a
+  if (!params)
e30274a
+    params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS,
e30274a
+					  BYTES_TO_PAGES(sizeof(*params)));
e30274a
+  if (! params)
e30274a
+    {
e30274a
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
e30274a
+      goto fail;
e30274a
+    }
e30274a
+
e30274a
+  grub_dprintf ("linux", "params = %p\n", params);
e30274a
+
e30274a
+  grub_memset (params, 0, sizeof(*params));
e30274a
+
e30274a
+  setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
e30274a
+  grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
e30274a
+		MIN((grub_size_t)0x202+setup_header_end_offset,
e30274a
+		    sizeof (*params)) - 0x1f1,
e30274a
+		(grub_uint8_t *)kernel + 0x1f1,
e30274a
+		(grub_uint8_t *)params + 0x1f1);
e30274a
+  grub_memcpy ((grub_uint8_t *)params + 0x1f1,
e30274a
+	       (grub_uint8_t *)kernel + 0x1f1,
e30274a
+		MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1);
e30274a
+
e30274a
+  lh = (struct linux_i386_kernel_header *)params;
e30274a
+  grub_dprintf ("linux", "new lh is at %p\n", lh);
e30274a
+
e30274a
   grub_dprintf ("linux", "setting up cmdline\n");
e30274a
   linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS,
e30274a
 					      BYTES_TO_PAGES(lh->cmdline_size + 1));
e30274a
@@ -347,8 +352,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
e30274a
   grub_dprintf ("linux", "setting lh->cmd_line_ptr\n");
e30274a
   lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
e30274a
 
e30274a
-  grub_dprintf ("linux", "computing handover offset\n");
e30274a
   handover_offset = lh->handover_offset;
e30274a
+  grub_dprintf("linux", "handover_offset: %08x\n", handover_offset);
e30274a
 
e30274a
   start = (lh->setup_sects + 1) * 512;
e30274a
 
e30274a
@@ -365,26 +370,28 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
e30274a
       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
e30274a
       goto fail;
e30274a
     }
e30274a
-
e30274a
-  grub_dprintf ("linux", "kernel_mem = %lx\n", (unsigned long) kernel_mem);
e30274a
+  grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem);
e30274a
 
e30274a
   grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
e30274a
-  loaded=1;
e30274a
+
e30274a
+  loaded = 1;
e30274a
+
e30274a
   grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem);
e30274a
   lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem;
e30274a
 
e30274a
   grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start);
e30274a
 
e30274a
-  grub_dprintf ("linux", "setting lh->type_of_loader\n");
e30274a
   lh->type_of_loader = 0x6;
e30274a
+  grub_dprintf ("linux", "setting lh->type_of_loader = 0x%02x\n",
e30274a
+		lh->type_of_loader);
e30274a
 
e30274a
-  grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n");
e30274a
   params->ext_loader_type = 0;
e30274a
   params->ext_loader_ver = 2;
e30274a
-  grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n",
e30274a
-	       kernel_mem, handover_offset);
e30274a
+  grub_dprintf ("linux",
e30274a
+		"setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n",
e30274a
+		params->ext_loader_type, params->ext_loader_ver);
e30274a
 
e30274a
- fail:
e30274a
+fail:
e30274a
   if (file)
e30274a
     grub_file_close (file);
e30274a