Skip to contentSkip to conversation

efi: Implement generic EFI boot for x86_64

PATCH Superseded Ard Biesheuvel 2 participants 10 messages May 9, 2023 – May 11, 2023

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover efi: Implement generic EFI boot for x86_64

Switch the x86_64-efi build to the generic EFI loader, which enters the Linux kernel via the EFI stub and provides the initrd via the LoadFile2 protocol. This unifies x86_64 with other EFI architectures, and removes the dependency on the setup header and struct bootparams.

Do some preparatory cleanup first, so we no longer need to rely on the MS to SysV calling convention translation code.

Ard Biesheuvel (5):
efi: Make EFI PXE protocol methods non-callable
efi: Add calling convention annotation to all prototypes
efi: Drop all uses of efi_call_XX wrappers
efi: Remove x86_64 call wrappers
efi: Use generic EFI loader for x86_64

 grub-core/Makefile.core.def          |   7 +-
 grub-core/commands/acpi.c            |   8 +-
 grub-core/commands/efi/efitextmode.c |   8 +-
 grub-core/commands/efi/lsefi.c       |   5 +-
 grub-core/commands/efi/tpm.c         |  21 +-
 grub-core/disk/efi/efidisk.c         |   7 +-
 grub-core/kern/arm/efi/init.c        |  12 +-
 grub-core/kern/efi/efi.c             |  56 +-
 grub-core/kern/efi/init.c            |  15 +-
 grub-core/kern/efi/mm.c              |  19 +-
 grub-core/kern/i386/efi/tsc.c        |   2 +-
 grub-core/kern/ia64/efi/init.c       |  15 +-
 grub-core/kern/x86_64/efi/callwrap.S | 129 ----
 grub-core/lib/efi/datetime.c         |   9 +-
 grub-core/lib/efi/halt.c             |   4 +-
 grub-core/lib/efi/relocator.c        |   6 +-
 grub-core/loader/efi/appleloader.c   |   8 +-
 grub-core/loader/efi/chainloader.c   |  20 +-
 grub-core/loader/efi/linux.c         |  12 +
 grub-core/mmap/efi/mmap.c            |  16 +-
 grub-core/net/drivers/efi/efinet.c   |  26 +-
 grub-core/term/efi/console.c         |  29 +-
 grub-core/term/efi/serial.c          |  18 +-
 grub-core/video/efi_gop.c            |  18 +-
 grub-core/video/efi_uga.c            |   8 +-
 include/grub/efi/api.h               | 666 +++++++++-----------
 include/grub/efi/efi.h               |   2 +
 include/grub/efi/tpm.h               | 149 +++--
 28 files changed, 562 insertions(+), 733 deletions(-)
 delete mode 100644 grub-core/kern/x86_64/efi/callwrap.S
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/5 efi: Make EFI PXE protocol methods non-callable

The grub_efi_pxe_t struct definition has placeholders for the various protocol method pointers, given that they are never called in the code, and the prototypes have been omitted, and therefore do not comply with the UEFI spec.

So let's convert them into void* pointers, so they cannot be called inadvertently.

---
 include/grub/efi/api.h | 24 ++++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)
include/grub/efi/api.h +12 -12
index b4c4646651cd53f5..da1a80ca3a94fe1c 100644
@@ -1539,18 +1539,18 @@ typedef struct grub_efi_pxe_mode
 typedef struct grub_efi_pxe
 {
   grub_uint64_t rev;
-  void (*start) (void);
-  void (*stop) (void);
-  void (*dhcp) (void);
-  void (*discover) (void);
-  void (*mftp) (void);
-  void (*udpwrite) (void);
-  void (*udpread) (void);
-  void (*setipfilter) (void);
-  void (*arp) (void);
-  void (*setparams) (void);
-  void (*setstationip) (void);
-  void (*setpackets) (void);
+  void *start;
+  void *stop;
+  void *dhcp;
+  void *discover;
+  void *mftp;
+  void *udpwrite;
+  void *udpread;
+  void *setipfilter;
+  void *arp;
+  void *setparams;
+  void *setstationip;
+  void *setpackets;
   struct grub_efi_pxe_mode *mode;
 } grub_efi_pxe_t;
 
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/5 efi: Add calling convention annotation to all prototypes

In reply to Ard Biesheuvel

UEFI mandates MS calling convention on x86_64, which was not supported on GCC when UEFI support was first introduced into GRUB. However, now we can use the ms_abi function type attribute to annotate functions and function pointers as adhering to the MS calling convention, and the compiler will generate the correct instruction sequence for us.

So let's add the appropriate annotation to all the function prototypes. This will allow us to drop the special call wrappers in a subsequent patch.

---
 grub-core/kern/arm/efi/init.c |   2 +-
 include/grub/efi/api.h        | 569 ++++++++++----------
 include/grub/efi/tpm.h        | 149 +++--
 3 files changed, 373 insertions(+), 347 deletions(-)
grub-core/kern/arm/efi/init.c +1 -1
index 7fcf91bf41168d4a..ab48342f3cda116d 100644
@@ -34,7 +34,7 @@ grub_efi_get_time_ms (void)
   return tmr;
 }
 
-static void
+static void __grub_efi_api
 increment_timer (grub_efi_event_t event __attribute__ ((unused)),
 		 void *context __attribute__ ((unused)))
 {
include/grub/efi/api.h +299 -270

781 lines not on this page · raw message

include/grub/efi/tpm.h +73 -76

161 lines not on this page · raw message

Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/5 efi: Drop all uses of efi_call_XX wrappers

In reply to Ard Biesheuvel

Now that GCC can generate function calls using the correct calling convention for us, we can stop using the efi_call_XX () wrappers, and just dereference the function pointers directly.

This avoids the untyped variadic wrapper routines, which means better type checking for the method calls.

---
 grub-core/commands/acpi.c            |  8 +--
 grub-core/commands/efi/efitextmode.c |  8 ++-
 grub-core/commands/efi/lsefi.c       |  5 +-
 grub-core/commands/efi/tpm.c         | 21 ++++----
 grub-core/disk/efi/efidisk.c         |  7 +--
 grub-core/kern/arm/efi/init.c        | 10 ++--
 grub-core/kern/efi/efi.c             | 56 ++++++++++----------
 grub-core/kern/efi/init.c            | 15 +++---
 grub-core/kern/efi/mm.c              | 17 +++---
 grub-core/kern/i386/efi/tsc.c        |  2 +-
 grub-core/kern/ia64/efi/init.c       | 15 +++---
 grub-core/lib/efi/datetime.c         |  9 ++--
 grub-core/lib/efi/halt.c             |  4 +-
 grub-core/lib/efi/relocator.c        |  6 +--
 grub-core/loader/efi/appleloader.c   |  8 +--
 grub-core/loader/efi/chainloader.c   | 20 +++----
 grub-core/mmap/efi/mmap.c            | 16 +++---
 grub-core/net/drivers/efi/efinet.c   | 26 ++++-----
 grub-core/term/efi/console.c         | 29 +++++-----
 grub-core/term/efi/serial.c          | 18 +++----
 grub-core/video/efi_gop.c            | 18 +++----
 grub-core/video/efi_uga.c            |  8 +--
 22 files changed, 161 insertions(+), 165 deletions(-)
grub-core/commands/acpi.c +4 -4
index fda62f4ea98a6da8..ab067ae6e51d43af 100644
@@ -762,10 +762,10 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
     struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
     struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
 
-    efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
-      &acpi20, grub_acpi_get_rsdpv2 ());
-    efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table,
-      &acpi, grub_acpi_get_rsdpv1 ());
+    grub_efi_system_table->boot_services->install_configuration_table (&acpi20,
+								       grub_acpi_get_rsdpv2 ());
+    grub_efi_system_table->boot_services->install_configuration_table (&acpi,
+								       grub_acpi_get_rsdpv1 ());
   }
 #endif
 
grub-core/commands/efi/efitextmode.c +3 -5
index 3679f6b4d8028bc7..198bc694d3fc3c3b 100644
@@ -36,7 +36,7 @@ grub_efi_set_mode (grub_efi_simple_text_output_interface_t *o,
 
   if (mode != o->mode->mode)
     {
-      status = efi_call_2 (o->set_mode, o, mode);
+      status = o->set_mode (o, mode);
       if (status == GRUB_EFI_SUCCESS)
 	;
       else if (status == GRUB_EFI_DEVICE_ERROR)
@@ -79,8 +79,7 @@ grub_cmd_efitextmode (grub_command_t cmd __attribute__ ((unused)),
       grub_printf_ (N_("Available modes for console output device.\n"));
 
       for (i = 0; i < o->mode->max_mode; i++)
-	if (GRUB_EFI_SUCCESS == efi_call_4 (o->query_mode, o, i,
-					    &columns, &rows))
+	if (GRUB_EFI_SUCCESS == o->query_mode (o, i, &columns, &rows))
 	  grub_printf_ (N_(" [%" PRIuGRUB_EFI_UINT32_T "]  Col %5"
 			   PRIuGRUB_EFI_UINTN_T " Row %5" PRIuGRUB_EFI_UINTN_T
 			   " %c\n"),
@@ -129,8 +128,7 @@ grub_cmd_efitextmode (grub_command_t cmd __attribute__ ((unused)),
 			   N_("non-numeric or invalid rows number `%s'"), args[1]);
 
       for (i = 0; i < o->mode->max_mode; i++)
-	if (GRUB_EFI_SUCCESS == efi_call_4 (o->query_mode, o, i,
-					    &columns, &rows))
+	if (GRUB_EFI_SUCCESS == o->query_mode (o, i, &columns, &rows))
 	  if (u_columns == columns && u_rows == rows)
 	    return grub_efi_set_mode (o, (grub_efi_int32_t) i);
 
grub-core/commands/efi/lsefi.c +3 -2
index c304d25ccdd6f32b..53970149785a28f8 100644
@@ -108,8 +108,9 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
 	  grub_efi_print_device_path (dp);
 	}
 
-      status = efi_call_3 (grub_efi_system_table->boot_services->protocols_per_handle,
-			   handle, &protocols, &num_protocols);
+      status = grub_efi_system_table->boot_services->protocols_per_handle (handle,
+									   &protocols,
+									   &num_protocols);
       if (status != GRUB_EFI_SUCCESS) {
 	grub_printf ("Unable to retrieve protocols\n");
 	continue;
grub-core/commands/efi/tpm.c +10 -11
index e1f343fea3ff3503..4213552048aebad6 100644
@@ -53,8 +53,7 @@ grub_tpm1_present (grub_efi_tpm_protocol_t *tpm)
 
   caps.Size = (grub_uint8_t) sizeof (caps);
 
-  status = efi_call_5 (tpm->status_check, tpm, &caps, &flags, &eventlog,
-		       &lastevent);
+  status = tpm->status_check (tpm, &caps, &flags, &eventlog, &lastevent);
 
   if (status != GRUB_EFI_SUCCESS || caps.TPMDeactivatedFlag
       || !caps.TPMPresentFlag)
@@ -78,7 +77,7 @@ grub_tpm2_present (grub_efi_tpm2_protocol_t *tpm)
   if (tpm2_present != -1)
     return (grub_efi_boolean_t) tpm2_present;
 
-  status = efi_call_2 (tpm->get_capability, tpm, &caps);
+  status = tpm->get_capability (tpm, &caps);
 
   if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag)
     tpm2_present = 0;
@@ -180,8 +179,8 @@ grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,
   grub_strcpy ((char *) event->Event, description);
 
   algorithm = TCG_ALG_SHA;
-  status = efi_call_7 (tpm->log_extend_event, tpm, (grub_addr_t) buf, (grub_uint64_t) size,
-		       algorithm, event, &eventnum, &lastevent);
+  status = tpm->log_extend_event (tpm, (grub_addr_t) buf, (grub_uint64_t) size,
+				  algorithm, event, &eventnum, &lastevent);
   grub_free (event);
 
   return grub_efi_log_event_status (status);
@@ -216,8 +215,8 @@ grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,
     sizeof (*event) - sizeof (event->Event) + grub_strlen (description) + 1;
   grub_strcpy ((char *) event->Event, description);
 
-  status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (grub_addr_t) buf,
-		       (grub_uint64_t) size, event);
+  status = tpm->hash_log_extend_event (tpm, 0, (grub_addr_t) buf,
+				       (grub_uint64_t) size, event);
   grub_free (event);
 
   return grub_efi_log_event_status (status);
@@ -236,7 +235,7 @@ grub_cc_log_event (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
   if (cc == NULL)
     return;
 
-  status = efi_call_3 (cc->map_pcr_to_mr_index, cc, pcr, &mr);
+  status = cc->map_pcr_to_mr_index (cc, pcr, &mr);
   if (status != GRUB_EFI_SUCCESS)
     {
       grub_efi_log_event_status (status);
@@ -258,9 +257,9 @@ grub_cc_log_event (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
   event->Size = sizeof (*event) + grub_strlen (description) + 1;
   grub_strcpy ((char *) event->Event, description);
 
-  status = efi_call_5 (cc->hash_log_extend_event, cc, 0,
-		       (grub_efi_physical_address_t)(grub_addr_t) buf,
-		       (grub_efi_uint64_t) size, event);
+  status = cc->hash_log_extend_event (cc, 0,
+				      (grub_efi_physical_address_t)(grub_addr_t) buf,
+				      (grub_efi_uint64_t) size, event);
   grub_free (event);
 
   if (status != GRUB_EFI_SUCCESS)
grub-core/disk/efi/efidisk.c +4 -3
index d7540040ed067063..ad025010a06bd338 100644
@@ -579,9 +579,10 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector,
       aligned_buf = buf;
     }
 
-  status =  efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio,
-			bio->media->media_id, (grub_efi_uint64_t) sector,
-			(grub_efi_uintn_t) num_bytes, aligned_buf);
+  status =  (wr ? bio->write_blocks : bio->read_blocks) (bio, bio->media->media_id,
+							 (grub_efi_uint64_t) sector,
+							 (grub_efi_uintn_t) num_bytes,
+							 aligned_buf);
 
   if ((grub_addr_t) buf & (io_align - 1))
     {
grub-core/kern/arm/efi/init.c +5 -5
index ab48342f3cda116d..809f69c8cfc8727e 100644
@@ -50,9 +50,9 @@ grub_machine_init (void)
 
   b = grub_efi_system_table->boot_services;
 
-  efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
-	      GRUB_EFI_TPL_CALLBACK, increment_timer, NULL, &tmr_evt);
-  efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
+  b->create_event (GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
+		   GRUB_EFI_TPL_CALLBACK, increment_timer, NULL, &tmr_evt);
+  b->set_timer (tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
 
   grub_install_get_time_ms (grub_efi_get_time_ms);
 }
@@ -67,8 +67,8 @@ grub_machine_fini (int flags)
 
   b = grub_efi_system_table->boot_services;
 
-  efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
-  efi_call_1 (b->close_event, tmr_evt);
+  b->set_timer (tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
+  b->close_event (tmr_evt);
 
   grub_efi_fini ();
 
grub-core/kern/efi/efi.c +29 -27

138 lines not on this page · raw message

grub-core/kern/efi/init.c +7 -8
index b67bc73a1b0102a8..e873ef5298ff3a5b 100644
@@ -56,11 +56,11 @@ __stack_chk_fail (void)
    * the serial console, at least on EDK2.
    */
   o = grub_efi_system_table->con_out;
-  efi_call_2 (o->output_string, o, stack_chk_fail_msg);
+  o->output_string (o, stack_chk_fail_msg);
 
-  efi_call_1 (grub_efi_system_table->boot_services->stall, 5000000);
-  efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
-	      GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_ABORTED, 0, NULL);
+  grub_efi_system_table->boot_services->stall (5000000);
+  grub_efi_system_table->runtime_services->reset_system (GRUB_EFI_RESET_SHUTDOWN,
+							 GRUB_EFI_ABORTED, 0, NULL);
 
   /*
    * We shouldn't get here. It's unsafe to return because the stack
@@ -86,8 +86,8 @@ stack_protector_init (void)
     {
       grub_efi_status_t status;
 
-      status = efi_call_4 (rng->get_rng, rng, NULL, sizeof (stack_chk_guard_buf),
-			   stack_chk_guard_buf);
+      status = rng->get_rng (rng, NULL, sizeof (stack_chk_guard_buf),
+			     stack_chk_guard_buf);
       if (status == GRUB_EFI_SUCCESS)
 	grub_memcpy (&__stack_chk_guard, stack_chk_guard_buf, sizeof (__stack_chk_guard));
     }
@@ -124,8 +124,7 @@ grub_efi_init (void)
       grub_shim_lock_verifier_setup ();
     }
 
-  efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
-	      0, 0, 0, NULL);
+  grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
 
   grub_efidisk_init ();
 }
grub-core/kern/efi/mm.c +8 -9
index 3705b8b1b465d00e..09225a7c08e4d066 100644
@@ -69,8 +69,8 @@ grub_efi_store_alloc (grub_efi_physical_address_t address,
   grub_efi_status_t status;
 
   b = grub_efi_system_table->boot_services;
-  status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
-                           sizeof(*alloc), (void**)&alloc);
+  status = b->allocate_pool (GRUB_EFI_LOADER_DATA,
+			     sizeof(*alloc), (void**)&alloc);
 
   if (status == GRUB_EFI_SUCCESS)
     {
@@ -105,7 +105,7 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
         efi_allocated_memory = ea->next;
 
       /* Then free the memory backing it. */
-      efi_call_1 (b->free_pool, ea);
+      b->free_pool (ea);
 
       /* And leave, we're done. */
       break;
@@ -137,7 +137,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
     }
 
   b = grub_efi_system_table->boot_services;
-  status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
+  status = b->allocate_pages (alloctype, memtype, pages, &address);
   if (status != GRUB_EFI_SUCCESS)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
@@ -149,7 +149,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
       /* Uggh, the address 0 was allocated... This is too annoying,
 	 so reallocate another one.  */
       address = GRUB_EFI_MAX_USABLE_ADDRESS;
-      status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
+      status = b->allocate_pages (alloctype, memtype, pages, &address);
       grub_efi_free_pages (0, pages);
       if (status != GRUB_EFI_SUCCESS)
 	{
@@ -188,7 +188,7 @@ grub_efi_free_pages (grub_efi_physical_address_t address,
   grub_efi_boot_services_t *b;
 
   b = grub_efi_system_table->boot_services;
-  efi_call_2 (b->free_pages, address, pages);
+  b->free_pages (address, pages);
 
   grub_efi_drop_alloc (address, pages);
 }
@@ -267,8 +267,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
 	}
 
       b = grub_efi_system_table->boot_services;
-      status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
-			   finish_key);
+      status = b->exit_boot_services (grub_efi_image_handle, finish_key);
       if (status == GRUB_EFI_SUCCESS)
 	break;
 
@@ -381,7 +380,7 @@ grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size,
     descriptor_size = &size;
 
   b = grub_efi_system_table->boot_services;
-  status = efi_call_5 (b->get_memory_map, memory_map_size, memory_map, map_key,
+  status = b->get_memory_map (memory_map_size, memory_map, map_key,
 			      descriptor_size, descriptor_version);
   if (*descriptor_size == 0)
     *descriptor_size = sizeof (grub_efi_memory_descriptor_t);
grub-core/kern/i386/efi/tsc.c +1 -1
index 4b93ba8e1b5f377c..e41dc6526dda08d7 100644
@@ -33,7 +33,7 @@ grub_tsc_calibrate_from_efi (void)
   grub_uint64_t start_tsc, end_tsc;
   /* Use EFI Time Service to calibrate TSC */
   start_tsc = grub_get_tsc ();
-  efi_call_1 (grub_efi_system_table->boot_services->stall, 1000);
+  grub_efi_system_table->boot_services->stall (1000);
   end_tsc = grub_get_tsc ();
   grub_tsc_rate = grub_divmod64 ((1ULL << 32), end_tsc - start_tsc, 0);
   return 1;
grub-core/kern/ia64/efi/init.c +8 -7
index f1965571b1dc0dce..f12c632386be5dcd 100644
@@ -51,16 +51,17 @@ grub_machine_init (void)
   grub_efi_uintn_t idx;
   grub_efi_init ();
 
-  efi_call_5 (grub_efi_system_table->boot_services->create_event,
-	      GRUB_EFI_EVT_TIMER, GRUB_EFI_TPL_CALLBACK, 0, 0, &event);
+  grub_efi_system_table->boot_services->create_event (GRUB_EFI_EVT_TIMER,
+						      GRUB_EFI_TPL_CALLBACK,
+						      0, 0, &event);
 
   before = get_itc ();
-  efi_call_3 (grub_efi_system_table->boot_services->set_timer, event,
-	      GRUB_EFI_TIMER_RELATIVE, 200000);
-  efi_call_3 (grub_efi_system_table->boot_services->wait_for_event, 1,
-	      &event, &idx);
+  grub_efi_system_table->boot_services->set_timer (event,
+						   GRUB_EFI_TIMER_RELATIVE,
+						   200000);
+  grub_efi_system_table->boot_services->wait_for_event (1, &event, &idx);
   after = get_itc ();
-  efi_call_1 (grub_efi_system_table->boot_services->close_event, event);
+  grub_efi_system_table->boot_services->close_event (event);
   divisor = (after - before + 5) / 20;
   if (divisor == 0)
     divisor = 800000;
grub-core/lib/efi/datetime.c +3 -6
index 0fd1b5fbd615cfec..b03e4df5ecc1e98b 100644
@@ -32,8 +32,7 @@ grub_get_datetime (struct grub_datetime *datetime)
   grub_efi_status_t status;
   struct grub_efi_time efi_time;
 
-  status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
-                       &efi_time, 0);
+  status = grub_efi_system_table->runtime_services->get_time (&efi_time, 0);
 
   if (status)
     return grub_error (GRUB_ERR_INVALID_COMMAND,
@@ -57,8 +56,7 @@ grub_set_datetime (struct grub_datetime *datetime)
   grub_efi_status_t status;
   struct grub_efi_time efi_time;
 
-  status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
-                       &efi_time, 0);
+  status = grub_efi_system_table->runtime_services->get_time (&efi_time, 0);
 
   if (status)
     return grub_error (GRUB_ERR_INVALID_COMMAND,
@@ -71,8 +69,7 @@ grub_set_datetime (struct grub_datetime *datetime)
   efi_time.minute = datetime->minute;
   efi_time.second = datetime->second;
 
-  status = efi_call_1 (grub_efi_system_table->runtime_services->set_time,
-                       &efi_time);
+  status = grub_efi_system_table->runtime_services->set_time (&efi_time);
 
   if (status)
     return grub_error (GRUB_ERR_INVALID_COMMAND,
grub-core/lib/efi/halt.c +2 -2
index 29d41364168eaeba..6a391624b1ce2717 100644
@@ -34,8 +34,8 @@ grub_halt (void)
     !defined(__riscv)
   grub_acpi_halt ();
 #endif
-  efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
-              GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+  grub_efi_system_table->runtime_services->reset_system (GRUB_EFI_RESET_SHUTDOWN,
+							 GRUB_EFI_SUCCESS, 0, NULL);
 
   while (1);
 }
grub-core/lib/efi/relocator.c +3 -3
index 84da70a86cf7b992..b4518d0002485511 100644
@@ -101,8 +101,8 @@ grub_relocator_firmware_alloc_region (grub_addr_t start, grub_size_t size)
 		(unsigned long long) start, (unsigned long long) size);
 #endif
   b = grub_efi_system_table->boot_services;
-  status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ADDRESS,
-		       GRUB_EFI_LOADER_DATA, size >> 12, &address);
+  status = b->allocate_pages (GRUB_EFI_ALLOCATE_ADDRESS,
+			      GRUB_EFI_LOADER_DATA, size >> 12, &address);
   return (status == GRUB_EFI_SUCCESS);
 }
 
@@ -115,5 +115,5 @@ grub_relocator_firmware_free_region (grub_addr_t start, grub_size_t size)
     return;
 
   b = grub_efi_system_table->boot_services;
-  efi_call_2 (b->free_pages, start, size >> 12);
+  b->free_pages (start, size >> 12);
 }
grub-core/loader/efi/appleloader.c +4 -4
index fc89e23bdc6f6ab3..a0b61a240b73af10 100644
@@ -40,7 +40,7 @@ grub_appleloader_unload (void)
   grub_efi_boot_services_t *b;
 
   b = grub_efi_system_table->boot_services;
-  efi_call_1 (b->unload_image, image_handle);
+  b->unload_image (image_handle);
 
   grub_free (cmdline);
   cmdline = 0;
@@ -55,7 +55,7 @@ grub_appleloader_boot (void)
   grub_efi_boot_services_t *b;
 
   b = grub_efi_system_table->boot_services;
-  efi_call_3 (b->start_image, image_handle, 0, 0);
+  b->start_image (image_handle, 0, 0);
 
   grub_appleloader_unload ();
 
@@ -165,8 +165,8 @@ grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)),
   b = grub_efi_system_table->boot_services;
 
   for (pdev = devs ; pdev->devpath ; pdev++)
-    if (efi_call_6 (b->load_image, 0, grub_efi_image_handle, pdev->devpath,
-                    NULL, 0, &image_handle) == GRUB_EFI_SUCCESS)
+    if (b->load_image (0, grub_efi_image_handle, pdev->devpath,
+                       NULL, 0, &image_handle) == GRUB_EFI_SUCCESS)
       break;
 
   if (! pdev->devpath)
grub-core/loader/efi/chainloader.c +10 -10
index 7557eb269be34888..1759af632fe90b01 100644
@@ -56,7 +56,7 @@ grub_chainloader_unload (void *context)
     grub_free (loaded_image->load_options);
 
   b = grub_efi_system_table->boot_services;
-  efi_call_1 (b->unload_image, image_handle);
+  b->unload_image (image_handle);
 
   grub_dl_unref (my_mod);
   return GRUB_ERR_NONE;
@@ -72,7 +72,7 @@ grub_chainloader_boot (void *context)
   grub_efi_char16_t *exit_data = NULL;
 
   b = grub_efi_system_table->boot_services;
-  status = efi_call_3 (b->start_image, image_handle, &exit_data_size, &exit_data);
+  status = b->start_image (image_handle, &exit_data_size, &exit_data);
   if (status != GRUB_EFI_SUCCESS)
     {
       if (exit_data)
@@ -94,7 +94,7 @@ grub_chainloader_boot (void *context)
     }
 
   if (exit_data)
-    efi_call_1 (b->free_pool, exit_data);
+    b->free_pool (exit_data);
 
   grub_loader_unset ();
 
@@ -289,7 +289,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
     }
   pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12);
 
-  status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,
+  status = b->allocate_pages (GRUB_EFI_ALLOCATE_ANY_PAGES,
 			      GRUB_EFI_LOADER_CODE,
 			      pages, &address);
   if (status != GRUB_EFI_SUCCESS)
@@ -346,9 +346,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
     }
 #endif
 
-  status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path,
-		       boot_image, size,
-		       &image_handle);
+  status = b->load_image (0, grub_efi_image_handle, file_path,
+			  boot_image, size,
+			  &image_handle);
   if (status != GRUB_EFI_SUCCESS)
     {
       if (status == GRUB_EFI_OUT_OF_RESOURCES)
@@ -403,7 +403,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
   grub_device_close (dev);
 
   /* We're finished with the source image buffer and file path now. */
-  efi_call_2 (b->free_pages, address, pages);
+  b->free_pages (address, pages);
   grub_free (file_path);
 
   grub_loader_set_ex (grub_chainloader_boot, grub_chainloader_unload, image_handle, 0);
@@ -421,10 +421,10 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
   grub_free (file_path);
 
   if (address)
-    efi_call_2 (b->free_pages, address, pages);
+    b->free_pages (address, pages);
 
   if (image_handle != NULL)
-    efi_call_1 (b->unload_image, image_handle);
+    b->unload_image (image_handle);
 
   grub_dl_unref (my_mod);
 
grub-core/mmap/efi/mmap.c +8 -8
index bd495a184811445b..2f0ec4d037f02279 100644
@@ -203,14 +203,14 @@ grub_mmap_register (grub_uint64_t start, grub_uint64_t size, int type)
   b = grub_efi_system_table->boot_services;
   address = start & (~0xfffULL);
   pages = (end - address + 0xfff) >> 12;
-  status = efi_call_2 (b->free_pages, address, pages);
+  status = b->free_pages (address, pages);
   if (status != GRUB_EFI_SUCCESS && status != GRUB_EFI_NOT_FOUND)
     {
       grub_free (curover);
       return 0;
     }
-  status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ADDRESS,
-		       make_efi_memtype (type), pages, &address);
+  status = b->allocate_pages (GRUB_EFI_ALLOCATE_ADDRESS,
+			      make_efi_memtype (type), pages, &address);
   if (status != GRUB_EFI_SUCCESS)
     {
       grub_free (curover);
@@ -239,7 +239,7 @@ grub_mmap_unregister (int handle)
     {
       if (curover->handle == handle)
 	{
-	  efi_call_2 (b->free_pages, curover->address, curover->pages);
+	  b->free_pages (curover->address, curover->pages);
 	  if (prevover != 0)
 	    prevover->next = curover->next;
 	  else
@@ -281,8 +281,8 @@ grub_mmap_malign_and_register (grub_uint64_t align __attribute__ ((unused)),
 #endif
 
   pages = (size + 0xfff) >> 12;
-  status = efi_call_4 (b->allocate_pages, atype,
-		       make_efi_memtype (type), pages, &address);
+  status = b->allocate_pages (atype,
+			      make_efi_memtype (type), pages, &address);
   if (status != GRUB_EFI_SUCCESS)
     {
       grub_free (curover);
@@ -294,8 +294,8 @@ grub_mmap_malign_and_register (grub_uint64_t align __attribute__ ((unused)),
       /* Uggh, the address 0 was allocated... This is too annoying,
 	 so reallocate another one.  */
       address = 0xffffffff;
-      status = efi_call_4 (b->allocate_pages, atype,
-			   make_efi_memtype (type), pages, &address);
+      status = b->allocate_pages (atype,
+				  make_efi_memtype (type), pages, &address);
       grub_efi_free_pages (0, pages);
       if (status != GRUB_EFI_SUCCESS)
 	return 0;
grub-core/net/drivers/efi/efinet.c +13 -13
index 5adf5f40f4924b2e..56a1797093f6cee1 100644
@@ -46,7 +46,7 @@ send_card_buffer (struct grub_net_card *dev,
     while (1)
       {
 	txbuf = NULL;
-	st = efi_call_3 (net->get_status, net, 0, &txbuf);
+	st = net->get_status (net, 0, &txbuf);
 	if (st != GRUB_EFI_SUCCESS)
 	  return grub_error (GRUB_ERR_IO,
 			     N_("couldn't send network packet"));
@@ -74,8 +74,8 @@ send_card_buffer (struct grub_net_card *dev,
 
   grub_memcpy (dev->txbuf, pack->data, dev->last_pkt_size);
 
-  st = efi_call_7 (net->transmit, net, 0, dev->last_pkt_size,
-		   dev->txbuf, NULL, NULL, NULL);
+  st = net->transmit (net, 0, dev->last_pkt_size,
+		      dev->txbuf, NULL, NULL, NULL);
   if (st != GRUB_EFI_SUCCESS)
     return grub_error (GRUB_ERR_IO, N_("couldn't send network packet"));
 
@@ -88,7 +88,7 @@ send_card_buffer (struct grub_net_card *dev,
      Perhaps a timeout in the FW has discarded the recycle buffer.
    */
   txbuf = NULL;
-  st = efi_call_3 (net->get_status, net, 0, &txbuf);
+  st = net->get_status (net, 0, &txbuf);
   dev->txbusy = !(st == GRUB_EFI_SUCCESS && txbuf);
 
   return GRUB_ERR_NONE;
@@ -114,8 +114,8 @@ get_card_packet (struct grub_net_card *dev)
       if (!dev->rcvbuf)
 	return NULL;
 
-      st = efi_call_7 (net->receive, net, NULL, &bufsize,
-		       dev->rcvbuf, NULL, NULL, NULL);
+      st = net->receive (net, NULL, &bufsize,
+		         dev->rcvbuf, NULL, NULL, NULL);
       if (st != GRUB_EFI_BUFFER_TOO_SMALL)
 	break;
       dev->rcvbufsize = 2 * ALIGN_UP (dev->rcvbufsize > bufsize
@@ -168,7 +168,7 @@ open_card (struct grub_net_card *dev)
   if (net != NULL)
     {
       if (net->mode->state == GRUB_EFI_NETWORK_STOPPED
-	  && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS)
+	  && net->start (net) != GRUB_EFI_SUCCESS)
 	return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net start failed",
 			   dev->name);
 
@@ -177,7 +177,7 @@ open_card (struct grub_net_card *dev)
 			   dev->name);
 
       if (net->mode->state == GRUB_EFI_NETWORK_STARTED
-	  && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS)
+	  && net->initialize (net, 0, 0) != GRUB_EFI_SUCCESS)
 	return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net initialize failed",
 			   dev->name);
 
@@ -201,7 +201,7 @@ open_card (struct grub_net_card *dev)
 	    filters |= (net->mode->receive_filter_mask &
 			GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS);
 
-	  efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL);
+	  net->receive_filters (net, filters, 0, 0, 0, NULL);
 	}
 
       dev->efi_net = net;
@@ -216,8 +216,8 @@ open_card (struct grub_net_card *dev)
 static void
 close_card (struct grub_net_card *dev)
 {
-  efi_call_1 (dev->efi_net->shutdown, dev->efi_net);
-  efi_call_1 (dev->efi_net->stop, dev->efi_net);
+  dev->efi_net->shutdown (dev->efi_net);
+  dev->efi_net->stop (dev->efi_net);
   grub_efi_close_protocol (dev->efi_handle, &net_io_guid);
 }
 
@@ -286,14 +286,14 @@ grub_efinet_findcards (void)
 	continue;
 
       if (net->mode->state == GRUB_EFI_NETWORK_STOPPED
-	  && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS)
+	  && net->start (net) != GRUB_EFI_SUCCESS)
 	continue;
 
       if (net->mode->state == GRUB_EFI_NETWORK_STOPPED)
 	continue;
 
       if (net->mode->state == GRUB_EFI_NETWORK_STARTED
-	  && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS)
+	  && net->initialize (net, 0, 0) != GRUB_EFI_SUCCESS)
 	continue;
 
       card = grub_zalloc (sizeof (struct grub_net_card));
grub-core/term/efi/console.c +14 -15
index 532948a8e19fc9de..9a7bc0fcf9d16707 100644
@@ -107,14 +107,13 @@ grub_console_setcolorstate (struct grub_term_output *term
 
   switch (state) {
     case GRUB_TERM_COLOR_STANDARD:
-      efi_call_2 (o->set_attributes, o, GRUB_TERM_DEFAULT_STANDARD_COLOR
-		  & 0x7f);
+      o->set_attributes (o, GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f);
       break;
     case GRUB_TERM_COLOR_NORMAL:
-      efi_call_2 (o->set_attributes, o, grub_term_normal_color & 0x7f);
+      o->set_attributes (o, grub_term_normal_color & 0x7f);
       break;
     case GRUB_TERM_COLOR_HIGHLIGHT:
-      efi_call_2 (o->set_attributes, o, grub_term_highlight_color & 0x7f);
+      o->set_attributes (o, grub_term_highlight_color & 0x7f);
       break;
     default:
       break;
@@ -135,7 +134,7 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
     }
 
   o = grub_efi_system_table->con_out;
-  efi_call_2 (o->enable_cursor, o, on);
+  o->enable_cursor (o, on);
 }
 
 static grub_err_t
@@ -189,10 +188,10 @@ grub_console_putchar (struct grub_term_output *term,
 
   /* Should this test be cached?  */
   if ((c->base > 0x7f || c->ncomb)
-      && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS)
+      && o->test_string (o, str) != GRUB_EFI_SUCCESS)
     return;
 
-  efi_call_2 (o->output_string, o, str);
+  o->output_string (o, str);
 }
 
 const unsigned efi_codes[] =
@@ -242,7 +241,7 @@ grub_console_getkey_con (struct grub_term_input *term __attribute__ ((unused)))
   grub_efi_status_t status;
 
   i = grub_efi_system_table->con_in;
-  status = efi_call_2 (i->read_key_stroke, i, &key);
+  status = i->read_key_stroke (i, &key);
 
   if (status != GRUB_EFI_SUCCESS)
     return GRUB_TERM_NO_KEY;
@@ -270,7 +269,7 @@ grub_console_read_key_stroke (
 
   key = grub_efi_translate_key (key_data.key);
   if (key == GRUB_TERM_NO_KEY) {
-    status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data);
+    status = text_input->read_key_stroke (text_input, &key_data);
     if (status != GRUB_EFI_SUCCESS)
       return GRUB_ERR_EOF;
 
@@ -391,8 +390,8 @@ grub_console_getwh (struct grub_term_output *term)
 
   o = grub_efi_system_table->con_out;
   if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE ||
-      efi_call_4 (o->query_mode, o, o->mode->mode,
-		  &columns, &rows) != GRUB_EFI_SUCCESS)
+      o->query_mode (o, o->mode->mode,
+		     &columns, &rows) != GRUB_EFI_SUCCESS)
     {
       /* Why does this fail?  */
       columns = 80;
@@ -424,7 +423,7 @@ grub_console_gotoxy (struct grub_term_output *term,
     return;
 
   o = grub_efi_system_table->con_out;
-  efi_call_3 (o->set_cursor_position, o, pos.x, pos.y);
+  o->set_cursor_position (o, pos.x, pos.y);
 }
 
 static void
@@ -438,9 +437,9 @@ grub_console_cls (struct grub_term_output *term __attribute__ ((unused)))
 
   o = grub_efi_system_table->con_out;
   orig_attr = o->mode->attribute;
-  efi_call_2 (o->set_attributes, o, GRUB_EFI_BACKGROUND_BLACK);
-  efi_call_1 (o->clear_screen, o);
-  efi_call_2 (o->set_attributes, o, orig_attr);
+  o->set_attributes (o, GRUB_EFI_BACKGROUND_BLACK);
+  o->clear_screen (o);
+  o->set_attributes (o, orig_attr);
 }
 
 static grub_err_t
grub-core/term/efi/serial.c +9 -9
index 4c94723c57e7458f..e86ebce3f8bf68cf 100644
@@ -51,16 +51,16 @@ do_real_config (struct grub_serial_port *port)
   if (port->configured)
     return;
 
-  status = efi_call_7 (port->interface->set_attributes, port->interface,
-		       port->config.speed,
-		       0, 0, parities[port->config.parity],
-		       port->config.word_len,
-		       stop_bits[port->config.stop_bits]);
+  status = port->interface->set_attributes (port->interface,
+					    port->config.speed,
+					    0, 0, parities[port->config.parity],
+					    port->config.word_len,
+					    stop_bits[port->config.stop_bits]);
   if (status != GRUB_EFI_SUCCESS)
     port->broken = 1;
 
-  status = efi_call_2 (port->interface->set_control_bits, port->interface,
-		       port->config.rtscts ? 0x4002 : 0x2);
+  status = port->interface->set_control_bits (port->interface,
+					      port->config.rtscts ? 0x4002 : 0x2);
 
   port->configured = 1;
 }
@@ -76,7 +76,7 @@ serial_hw_fetch (struct grub_serial_port *port)
   if (port->broken)
     return -1;
 
-  status = efi_call_3 (port->interface->read, port->interface, &bufsize, &c);
+  status = port->interface->read (port->interface, &bufsize, &c);
   if (status != GRUB_EFI_SUCCESS || bufsize == 0)
     return -1;
 
@@ -95,7 +95,7 @@ serial_hw_put (struct grub_serial_port *port, const int c)
   if (port->broken)
     return;
 
-  efi_call_3 (port->interface->write, port->interface, &bufsize, &c0);
+  port->interface->write (port->interface, &bufsize, &c0);
 }
 
 /* Initialize a serial device. PORT is the port number for a serial device.
grub-core/video/efi_gop.c +9 -9
index 7a50546318d62f40..9c79010384312dd3 100644
@@ -110,7 +110,7 @@ grub_video_gop_fini (void)
 {
   if (restore_needed)
     {
-      efi_call_2 (gop->set_mode, gop, old_mode);
+      gop->set_mode (gop, old_mode);
       restore_needed = 0;
     }
   grub_free (framebuffer.offscreen);
@@ -274,7 +274,7 @@ grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, vo
       struct grub_efi_gop_mode_info *info = NULL;
       struct grub_video_mode_info mode_info;
 
-      status = efi_call_4 (gop->query_mode, gop, mode, &size, &info);
+      status = gop->query_mode (gop, mode, &size, &info);
 
       if (status)
 	{
@@ -400,7 +400,7 @@ grub_video_gop_setup (unsigned int width, unsigned int height,
 	  grub_efi_uintn_t size;
 	  grub_efi_status_t status;
 
-	  status = efi_call_4 (gop->query_mode, gop, mode, &size, &info);
+	  status = gop->query_mode (gop, mode, &size, &info);
 	  if (status)
 	    {
 	      info = 0;
@@ -461,7 +461,7 @@ grub_video_gop_setup (unsigned int width, unsigned int height,
 	  old_mode = gop->mode->mode;
 	  restore_needed = 1;
 	}
-      efi_call_2 (gop->set_mode, gop, best_mode);
+      gop->set_mode (gop, best_mode);
     }
 
   info = gop->mode->info;
@@ -523,10 +523,10 @@ grub_video_gop_swap_buffers (void)
 {
   if (framebuffer.offscreen)
     {
-      efi_call_10 (gop->blt, gop, framebuffer.offscreen,
-		   GRUB_EFI_BLT_BUFFER_TO_VIDEO, 0, 0, 0, 0,
-		   framebuffer.mode_info.width, framebuffer.mode_info.height,
-		   framebuffer.mode_info.width * 4);
+      gop->blt (gop, framebuffer.offscreen,
+		GRUB_EFI_BLT_BUFFER_TO_VIDEO, 0, 0, 0, 0,
+		framebuffer.mode_info.width, framebuffer.mode_info.height,
+		framebuffer.mode_info.width * 4);
     }
   return GRUB_ERR_NONE;
 }
@@ -613,7 +613,7 @@ GRUB_MOD_FINI(efi_gop)
 {
   if (restore_needed)
     {
-      efi_call_2 (gop->set_mode, gop, old_mode);
+      gop->set_mode (gop, old_mode);
       restore_needed = 0;
     }
   if (gop)
grub-core/video/efi_uga.c +4 -4
index e74d6c235000d611..25d22c8a3cd07845 100644
@@ -186,13 +186,13 @@ check_protocol (void)
       grub_uint32_t width, height, depth, rate, pixel;
       int ret;
 
-      if (efi_call_5 (c->get_mode, c, &width, &height, &depth, &rate))
+      if (c->get_mode (c, &width, &height, &depth, &rate))
 	return 0;
 
       grub_efi_set_text_mode (0);
       pixel = RGB_MAGIC;
-      efi_call_10 (c->blt, c, (struct grub_efi_uga_pixel *) &pixel,
-		   GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0);
+      c->blt (c, (struct grub_efi_uga_pixel *) &pixel,
+	      GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0);
       ret = find_framebuf (&uga_fb, &uga_pitch);
       grub_efi_set_text_mode (1);
 
@@ -236,7 +236,7 @@ grub_video_uga_setup (unsigned int width, unsigned int height,
     grub_uint32_t d;
     grub_uint32_t r;
 
-    if ((! efi_call_5 (uga->get_mode, uga, &w, &h, &d, &r)) &&
+    if ((! uga->get_mode (uga, &w, &h, &d, &r)) &&
 	((! width) || (width == w)) &&
 	((! height) || (height == h)) &&
 	((! depth) || (depth == d)))
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/5 efi: Remove x86_64 call wrappers

In reply to Ard Biesheuvel

The call wrappers are no longer needed now that GCC can generate function calls using MS calling convention, so let's get rid of them.

---
 grub-core/Makefile.core.def          |   1 -
 grub-core/kern/x86_64/efi/callwrap.S | 129 --------------------
 include/grub/efi/api.h               |  73 -----------
 3 files changed, 203 deletions(-)
grub-core/Makefile.core.def +0 -1
index 801df7c21de663ec..c17d022195b3fdca 100644
@@ -231,7 +231,6 @@ kernel = {
 
   x86_64 = kern/x86_64/dl.c;
   x86_64_xen = kern/x86_64/dl.c;
-  x86_64_efi = kern/x86_64/efi/callwrap.S;
   x86_64_efi = kern/i386/efi/init.c;
   x86_64_efi = bus/pci.c;
 
grub-core/kern/x86_64/efi/callwrap.S deleted +0 -129

129 lines not on this page · raw message

include/grub/efi/api.h +0 -73

77 lines not on this page · raw message

Signature · 1 line
2.39.2
#5 lore raw

PATCH 5/5 efi: Use generic EFI loader for x86_64

In reply to Ard Biesheuvel

Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot.

---
 grub-core/Makefile.core.def  |  6 +-----
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/loader/efi/linux.c | 12 ++++++++++++
 include/grub/efi/efi.h       |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)
grub-core/Makefile.core.def +1 -5
index c17d022195b3fdca..f9e89a0cc4389dd0 100644
@@ -1822,7 +1822,6 @@ module = {
 
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;
@@ -1832,11 +1831,8 @@ module = {
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm_coreboot = loader/arm/linux.c;
-  arm_efi = loader/efi/linux.c;
+  efi = loader/efi/linux.c;
   arm_uboot = loader/arm/linux.c;
-  arm64 = loader/efi/linux.c;
-  riscv32 = loader/efi/linux.c;
-  riscv64 = loader/efi/linux.c;
   emu = loader/emu/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;
grub-core/kern/efi/mm.c +1 -1
index 09225a7c08e4d066..9ba0b8814fe16cc9 100644
@@ -653,7 +653,7 @@ grub_efi_mm_init (void)
   grub_mm_add_region_fn = grub_efi_mm_add_regions;
 }
 
-#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
+#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) || defined(__x86_64__)
 grub_err_t
 grub_efi_get_ram_base(grub_addr_t *base_addr)
 {
grub-core/loader/efi/linux.c +12 -0
index 15e0686549d7ecca..3cf596f56e8eac4f 100644
@@ -125,6 +125,7 @@ grub_arch_efi_linux_load_image_header (grub_file_t file,
   return GRUB_ERR_NONE;
 }
 
+#ifndef __x86_64__
 static grub_err_t
 finalize_params_linux (void)
 {
@@ -169,6 +170,7 @@ failure:
   grub_fdt_unload();
   return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
 }
+#endif
 
 grub_err_t
 grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
@@ -231,8 +233,10 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
 static grub_err_t
 grub_linux_boot (void)
 {
+#ifndef __x86_64__
   if (finalize_params_linux () != GRUB_ERR_NONE)
     return grub_errno;
+#endif
 
   return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
                                           kernel_size, linux_args));
@@ -253,7 +257,9 @@ grub_linux_unload (void)
   if (kernel_addr)
     grub_efi_free_pages ((grub_addr_t) kernel_addr,
 			 GRUB_EFI_BYTES_TO_PAGES (kernel_size));
+#ifndef __x86_64__
   grub_fdt_unload ();
+#endif
 
   if (initrd_lf2_handle != NULL)
     {
@@ -391,6 +397,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
       return GRUB_ERR_NONE;
     }
 
+#ifdef __x86_64__
+  grub_error (GRUB_ERR_INVALID_COMMAND,
+              N_("selected Linux kernel does not support loadfile2 initrd loading"));
+  goto fail;
+#endif
+
   initrd_size = grub_get_initrd_size (&initrd_ctx);
   grub_dprintf ("linux", "Loading initrd\n");
 
include/grub/efi/efi.h +2 -0
index 444bf5b0b53e31fe..c56abfbd6ba45ab8 100644
@@ -112,6 +112,8 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
 
 #if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
 void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
+#endif
+#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__x86_64__)
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
 #include <grub/file.h>
 grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file,
Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64

Quoted 28 lines · Ard Biesheuvel

Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot.

---
 grub-core/Makefile.core.def  |  6 +-----
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/loader/efi/linux.c | 12 ++++++++++++
 include/grub/efi/efi.h       |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)
grub-core/Makefile.core.def +0 -1
index c17d022195b3fdca..f9e89a0cc4389dd0 100644
@@ -1822,7 +1822,6 @@ module = {
 
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;

grub-core/Makefile.core.def module = { · line 1834

Quoted 5 lines
grub-core/Makefile.core.def +1 -1
@@ -1832,11 +1831,8 @@ module = {
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm_coreboot = loader/arm/linux.c;
-  arm_efi = loader/efi/linux.c;
+  efi = loader/efi/linux.c;

This change breaks the build for i386_efi. Any suggestions on how to rephrase this?

Quoted 90 lines
grub-core/Makefile.core.def +0 -3
   arm_uboot = loader/arm/linux.c;
-  arm64 = loader/efi/linux.c;
-  riscv32 = loader/efi/linux.c;
-  riscv64 = loader/efi/linux.c;
   emu = loader/emu/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;
grub-core/kern/efi/mm.c +1 -1
index 09225a7c08e4d066..9ba0b8814fe16cc9 100644
@@ -653,7 +653,7 @@ grub_efi_mm_init (void)
   grub_mm_add_region_fn = grub_efi_mm_add_regions;
 }
 
-#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
+#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) || defined(__x86_64__)
 grub_err_t
 grub_efi_get_ram_base(grub_addr_t *base_addr)
 {
grub-core/loader/efi/linux.c +12 -0
index 15e0686549d7ecca..3cf596f56e8eac4f 100644
@@ -125,6 +125,7 @@ grub_arch_efi_linux_load_image_header (grub_file_t file,
   return GRUB_ERR_NONE;
 }
 
+#ifndef __x86_64__
 static grub_err_t
 finalize_params_linux (void)
 {
@@ -169,6 +170,7 @@ failure:
   grub_fdt_unload();
   return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
 }
+#endif
 
 grub_err_t
 grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
@@ -231,8 +233,10 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
 static grub_err_t
 grub_linux_boot (void)
 {
+#ifndef __x86_64__
   if (finalize_params_linux () != GRUB_ERR_NONE)
     return grub_errno;
+#endif
 
   return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
                                           kernel_size, linux_args));
@@ -253,7 +257,9 @@ grub_linux_unload (void)
   if (kernel_addr)
     grub_efi_free_pages ((grub_addr_t) kernel_addr,
                         GRUB_EFI_BYTES_TO_PAGES (kernel_size));
+#ifndef __x86_64__
   grub_fdt_unload ();
+#endif
 
   if (initrd_lf2_handle != NULL)
     {
@@ -391,6 +397,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
       return GRUB_ERR_NONE;
     }
 
+#ifdef __x86_64__
+  grub_error (GRUB_ERR_INVALID_COMMAND,
+              N_("selected Linux kernel does not support loadfile2 initrd loading"));
+  goto fail;
+#endif
+
   initrd_size = grub_get_initrd_size (&initrd_ctx);
   grub_dprintf ("linux", "Loading initrd\n");
 
include/grub/efi/efi.h +2 -1
index 444bf5b0b53e31fe..c56abfbd6ba45ab8 100644
@@ -112,6 +112,8 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
 
 #if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
 void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
+#endif
+#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__x86_64__)
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
 #include <grub/file.h>
 grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file,
--

2.39.2

#7 lore raw

Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64

Quoted 22 lines · Ard Biesheuvel
Quoted 21 lines · Ard Biesheuvel

Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot.

---
 grub-core/Makefile.core.def  |  6 +-----
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/loader/efi/linux.c | 12 ++++++++++++
 include/grub/efi/efi.h       |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)
grub-core/Makefile.core.def +0 -0
index c17d022195b3fdca..f9e89a0cc4389dd0 100644
@@ -1822,7 +1822,6 @@ module = {
 
Quoted 15 lines

grub-core/Makefile.core.def module = { · line 1834

Quoted 12 lines
grub-core/Makefile.core.def +1 -2
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;
@@ -1832,11 +1831,8 @@ module = {
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm_coreboot = loader/arm/linux.c;
-  arm_efi = loader/efi/linux.c;
+  efi = loader/efi/linux.c;

This change breaks the build for i386_efi. Any suggestions on how to rephrase this?

I will do more test builds in the following days and get back to you with results. And probably some fixes...

Anyway, thank you for making this patch set.

Daniel

#8 lore raw

Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64

Quoted 24 lines · Daniel Kiper
Quoted 22 lines · Ard Biesheuvel
Quoted 21 lines · Ard Biesheuvel

Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot.

---
 grub-core/Makefile.core.def  |  6 +-----
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/loader/efi/linux.c | 12 ++++++++++++
 include/grub/efi/efi.h       |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)
grub-core/Makefile.core.def +0 -0
index c17d022195b3fdca..f9e89a0cc4389dd0 100644
@@ -1822,7 +1822,6 @@ module = {
 
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
grub-core/Makefile.core.def +0 -1
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;
@@ -1832,11 +1831,8 @@ module = {
Quoted 8 lines

grub-core/Makefile.core.def module = { · line 1834

Quoted 5 lines
grub-core/Makefile.core.def +1 -1
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm_coreboot = loader/arm/linux.c;
-  arm_efi = loader/efi/linux.c;
+  efi = loader/efi/linux.c;

This change breaks the build for i386_efi. Any suggestions on how to rephrase this?

Also, I think the command line piece is missing - I'll fix that up for v2.

Quoted 7 lines

I will do more test builds in the following days and get back to you with results. And probably some fixes...

Anyway, thank you for making this patch set.

Daniel

#9 lore raw

Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64

Quoted 42 lines · Ard Biesheuvel
Quoted 24 lines · Daniel Kiper
Quoted 22 lines · Ard Biesheuvel
Quoted 21 lines · Ard Biesheuvel

Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot.

---
 grub-core/Makefile.core.def  |  6 +-----
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/loader/efi/linux.c | 12 ++++++++++++
 include/grub/efi/efi.h       |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)
grub-core/Makefile.core.def +0 -0
index c17d022195b3fdca..f9e89a0cc4389dd0 100644
@@ -1822,7 +1822,6 @@ module = {
 
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
grub-core/Makefile.core.def +0 -1
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;
@@ -1832,11 +1831,8 @@ module = {
Quoted 8 lines

grub-core/Makefile.core.def module = { · line 1834

Quoted 5 lines
grub-core/Makefile.core.def +1 -1
   sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
   ia64_efi = loader/ia64/efi/linux.c;
   arm_coreboot = loader/arm/linux.c;
-  arm_efi = loader/efi/linux.c;
+  efi = loader/efi/linux.c;

This change breaks the build for i386_efi. Any suggestions on how to rephrase this?

Quoted 2 lines

Also, I think the command line piece is missing - I'll fix that up for v2.

Never mind - I was looking at distro GRUB, which looks quite different :-)

I'll replace this hunk with

grub-core/Makefile.core.def +2 -1
@@ -1809,7 +1809,7 @@ module = {
 
 module = {
   name = linux;
-  x86 = loader/i386/linux.c;
+  i386 = loader/i386/linux.c;
   i386_xen_pvh = loader/i386/linux.c;
   xen = loader/i386/xen.c;
   i386_pc = lib/i386/pc/vesa_modes_table.c;
@@ -1823,6 +1823,7 @@ module = {
   arm64 = loader/efi/linux.c;
   riscv32 = loader/efi/linux.c;
   riscv64 = loader/efi/linux.c;
+  x86_64_efi = loader/efi/linux.c;
   emu = loader/emu/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;

and we can always consolidate it later if we figure out how