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