OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 5:00 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Is there a better way for uefi on windows than edk2?
PostPosted: Mon Jan 12, 2015 10:50 pm 
Offline

Joined: Thu Nov 27, 2014 8:23 pm
Posts: 11
Since the interface of EDK2 is so strange and troublesome...
Is there a way to link .obj files directly to .efi,
or is there a way to convert a particularly designed .dll or .exe into .efi ?

I know FASM can generate EFI images in a sample way, but can't find a "-S" option for cl

I guess a EFI image has little difference with a DLL image, for they're all PE format and x64 native code,
so maybe a manually modification can be a solution ?

BTW, Is there sth. really in EFI Byte Code ?

:)


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 12:15 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 306
Location: Germany
As always in programming, there's not the single one best answer. What I prefer is creating my own library and compiling it as an ELF. You can use objcopy to get the proper UEFI format. I tested this once and it worked flawlessly.

I have no idea about Windows tools, but as always, having a Linux box will help you dramatically.

_________________
managarm


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 1:34 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
no92 wrote:
What I prefer is creating my own library and compiling it as an ELF. You can use objcopy to get the proper UEFI format.

I like this method. Which configure parameters (target triplet?) did you use when compiling objcopy / binutils, and with which parameters do you use it for the conversion to uefi?

_________________
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 3:20 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Yes, EDK2 is a horrible example of how not to do things, using a proper PE-oriented toolchain is certainly the better alternative. In particular:
Quote:
What I prefer is creating my own library and compiling it as an ELF. You can use objcopy to get the proper UEFI format
EDK2 on linux does exactly that, and it results in defective binaries.

Since you seem to be using Visual Studio, you're probably interested in it's /SUBSYSTEM linker option. To be honest, I wouldn't be surprised if that actually worked easier than a GNU toolchain for this matter.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 6:52 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
XenOS wrote:
no92 wrote:
What I prefer is creating my own library and compiling it as an ELF. You can use objcopy to get the proper UEFI format.

I like this method. Which configure parameters (target triplet?) did you use when compiling objcopy / binutils, and with which parameters do you use it for the conversion to uefi?
I would be slightly cautious here. Whilst you may well get a PE file with the appropriate headers, note that the ABI used to compile the original code will still be the gcc default (probably sysV i386/AMD x64) rather than the Microsoft equivalent (which you need for UEFI). What this means is that the arguments to functions will be in the wrong place, and the stack alignment may be different, some registers may not be preserved across functions etc. This is only a problem when calling from your code to UEFI (and having UEFI functions call back to your own code e.g. with timers). There is a hack called gnu-efi which uses a stub function to rearrange function arguments for you, then uses objcopy, but it is not particularly robust.

There is an article on using gcc for UEFI here.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 7:15 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
Thanks for providing this information. I didn't know that UEFI uses a different ABI - in fact, I haven't used UEFI before, I'm just curious to support it in my OS. Well, actually using a toolchain targeted for "x86_64-w64-mingw32" and fancy file system tools looks a bit horrible to me (not in the sense that it would be difficult, but it somehow looks like using a sledgehammer to crack a nut), but as far as I understood, there is only limited / broken support for UEFI targets in GCC / binutils.

_________________
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 8:47 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
Its been a while since I last looked at it. I've removed the dependency on mkfat to use mtools instead.

As not using the mingw32 toolchain, I suppose its possible to use the standard x86_64-elf cross-compiler with the -mabi=ms option and then objcopy it to a PE file, but I haven't had a chance to look into this.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 10:16 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 306
Location: Germany
XenOS wrote:
I like this method. Which configure parameters (target triplet?) did you use when compiling objcopy / binutils, and with which parameters do you use it for the conversion to uefi?
It's been a while since I did that - but as far as I can remember that was really tricky. I don't remember any more details.

What I do right now is using a mingw32-w64 gcc/binutils, which outputs a perfectly valid binary. This works perfectly for me.

_________________
managarm


Top
 Profile  
 
 Post subject: Re: Is there a better way for uefi on windows than edk2?
PostPosted: Tue Jan 13, 2015 7:29 pm 
Offline

Joined: Thu Nov 27, 2014 8:23 pm
Posts: 11
Combuster wrote:
Yes, EDK2 is a horrible example of how not to do things, using a proper PE-oriented toolchain is certainly the better alternative. In particular:
Quote:
What I prefer is creating my own library and compiling it as an ELF. You can use objcopy to get the proper UEFI format
EDK2 on linux does exactly that, and it results in defective binaries.

Since you seem to be using Visual Studio, you're probably interested in it's /SUBSYSTEM linker option. To be honest, I wouldn't be surprised if that actually worked easier than a GNU toolchain for this matter.


I've just tried to compile with Visual Studio subsystem EFI application,
only to be told the missing of some #defines found in auto generated files when compile with EDK2...

including,
_PCD_GET_MODE_*
_PCD_VALUE_*
_PCD_TOKEN_*

such as

#define _PCD_TOKEN_PcdVerifyNodeInList 23U
#define _PCD_GET_MODE_BOOL_PcdVerifyNodeInList _gPcd_FixedAtBuild_PcdVerifyNodeInList

EDK2 generate them with python...and _gPcd_*s seems to...as its name...fixed at build...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot], Majestic-12 [Bot] and 111 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group