For the C builds the tools_def.txt file uses $(IMAGE_ENTRY_POINT). The build maps that over to the _ModelEntryPoint label I mentioned. It would probably be good to sue the same symbol.
The C we have is free standing so there is nothing that is setup for the C language, other that libs the user asked for.
The edk2 way to do this seems to me is to create an edk2 RustEntryPoint lib that models the edk2 *EntryPointLib [1]. The entry point would be _ModelEntryPoint.
I’m not 100% clear on all the dependencies but the big picture is for C edk2 injects code between the entry point and the main function. I think you will want that in your Rust world.
The other thing you need to manage is the entry point hands-off the only way to bind to all the EFI Services so that needs to make it into your Rust world.
We have different flavors of these entry point libs as the handoff, and sometimes entry exit behavior are different:
$ git grep 'EntryPoint|' -- \*.inf | grep LIBRARY_CLASS
MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf:18: LIBRARY_CLASS = DxeCoreEntryPoint|DXE_CORE
MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf:18: LIBRARY_CLASS = PeiCoreEntryPoint|PEI_CORE
MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf:18: LIBRARY_CLASS = PeimEntryPoint|PEIM
MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf:21: LIBRARY_CLASS = StandaloneMmDriverEntryPoint|MM_STANDALONE
MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf:18: LIBRARY_CLASS = UefiApplicationEntryPoint|UEFI_APPLICATION
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf:18: LIBRARY_CLASS = UefiDriverEntryPoint|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER SMM_CORE DXE_SMM_DRIVER
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf:18: LIBRARY_CLASS = StandaloneMmCoreEntryPoint|MM_CORE_STANDALONE
I think what this means from a practical point after reading your Rust thread is:
1) Have some custom code, per driver type, to maybe convert the EFI/PEI/edk2 define entry point arguments maybe into standard Rust args.
argc = 2
argv[0] = ImageHandle
argv[1] = *SystemTable
2) Then you can call the common Rust init flow from your link.
3) rt_entry() is custom for edk2. It would basically do the same things as the edk2 C *EntryPoint libs _ModuleEntryPoint() functions. Call the auto generated lib constructor functions, call the auto generated entry point function that calls the function in the users Rust code. Call the lib destructor. Also provide support for the Exit function.
You can kind of hard code bits to get started, but If you think about it this way I think it will be easier to layer in edk2 like build features as we grow the Rust support.
You could get really fancy and pass the mode BASE/PEIM/DXE in argv[0], and the args in args[1], …. By doing that you might need small stubs that are mode specific to capture the different entry point APIs, but all the other lib infrastructure could be common. The little tiny entry stub libs could depend on the common lib so the INF files would only need to specify the entry point stub lib.
Thanks,
Andrew Fish