2

I am working on a tiny x86 64 bit kernel that is multiboot2 compliant, the kernel is loaded and launched by Grub. The requirement is that, once the kernel finishes its activity it needs to relaunch Grub. In non UEFI based systems, we used to achieve this by bringing the processor back to real mode jumping to address 0x7c00.

With UEFI systems, I am trying to understand if something similar is feasible, one possible approach in my mind is to reload Grub from the kernel using the EFI_IMAGE_LOAD and EFI_IMAGE_START routines in the EFI boot services table. My understanding of UEFI internals are very limited, it would be greatly helpful if someone can confirm if this approach will work or not.

GKT
  • 23
  • 5

1 Answers1

1

Yes, that will work, assuming you can locate the Grub image. (It will be more difficult if Grub was loaded over the network, for example.)

You don’t need to understand UEFI internals to do this. An understanding of the UEFI interface specification is sufficient.

You must not call ExitBootServices from your kernel, so you are somewhat restricted in what your OS can do. You have to use UEFI for memory allocation, for example. You have to maintain 1 to 1 mapping of virtual to physical address space. Your ability to use multiprocessing may be somewhat constrained. See section 2.3.4 of the UEFI spec.

prl
  • 11,716
  • 2
  • 13
  • 31
  • Thanks for the response, really helped in getting a better picture of what needs to be done. Will ensure to have the processor mode, registers and other settings done as per what is detailed under 2.3.4 of the UEFI Spec. – GKT Jun 23 '20 at 08:12
  • A follow up question, with regards to the invocation of EFI_BOOT_SERVICES.LoadImage() for loading Grub, one of the input arguments expected by this routine is 'EFI_HANDLE ParentImageHandle' and the spec states that, this should be the caller's image handle. Now as the caller is my kernel, it does not have any 'image handle', I was wondering if I can pass the image handle of Grub itself here that was passed to the kernel as part of the multiboot tag, MULTIBOOT_TAG_EFI64_IH? – GKT Jun 23 '20 at 08:22
  • Yes, that’s right, if I understand correctly what you’re suggesting. UEFI starts Grub, which then starts your code and passes the image handle to it. You want to continue to use that image handle. You will need it for various other calls, too. – prl Jun 23 '20 at 12:04
  • You can make your code a UEFI program instead of a multi boot program. – prl Jun 23 '20 at 12:09
  • Yes, as of now the boot sequence is exactly what you have stated in your earlier comment. For now, will try to use the Grub's image handle. Thanks once again for clarifying. – GKT Jun 24 '20 at 04:40