> On Feb 26, 2016, at 11:53 AM, Stephen Polkowski <[email protected]> wrote: > > Hi guys, > > I have an embedded OS that wants to live at the top of system memory. > Normally, a shell is app is loaded in the middle of system memory. > > Is there a Protocol function to load a shell app to a new address?
No. > Or, is there a way in the PE/COFF file format to signal the loader that the > appliation wants to load to the top of memory? > No. A PE/COFF image is linked at an address and contains relocations. If the PE/COFF image does not contain relocations the PE/COFF loader will try to load it at the linked address. All the relocation to run in virtual mode are done by EFI independent of PE/COFF, and require the cooperation of the code being relocated. > > My current idea is to use the EFI_LOADED_IMAGE_PROTOCOL to get the > ImageBase of the running shell application. Then, I will allocate an upper > memory area and copy the PE/COFF image to it. Lastly, I will use something > like PeCoffLoaderRelocateImageForRuntime() to update the relocations. > However, I'm worried that PeCoffLoaderRelocateImageForRuntime() won't work > with an image that has already been relocated. > You can't move a running application if that is what you are asking? The function in question exists to support the transition of runtime drivers from physical to virtual mode. That transition requires cooperation from the driver. Not to mention this function assumes the driver does NOT move in physical memory, and only the virtual address is changing. So the data initialized into a global variable is still there. The RelocationData passed into PeCoffLoaderRelocateImageForRuntime() was collected and stored by the DXE Core so you don't have access to it if you did not load the image using the library functions. > Is there a better way to do this? > Pre allocate the ranges you want so it will not get allocated by some one else? You could try making the code you care about an EFI Runtime Driver, as it will likely get loaded at the top of memory with the rest of the firmware. The only difference between a Driver and an Application (other than the type in the PE/COFF image) is that an application always unloads on exit, while a driver only unloads on exit if it returns an error. Thanks, Andrew Fish > > Thanks, > > Stephen > > > _______________________________________________ > edk2-devel mailing list > [email protected] > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

