public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* edk2 and gnu-efi calling schemes
@ 2018-12-06 22:34 Peter Wiehe
  2018-12-06 22:46 ` Bill Paul
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Wiehe @ 2018-12-06 22:34 UTC (permalink / raw)
  To: edk2-devel

OK, another question:

when writing an UEFI application, edk2 and gnu-efi have different 64bit 
calling schemes. Does that only apply to calling the 
runtime-library/object file (and inside of the UEFI-application, of 
course)? Or does the call from application to UEFI differ in both 
toolkits, too? (If it is the latter, it would mean that the UEFI 
standard is unprecise!)

Kind regards

Peter Wiehe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: edk2 and gnu-efi calling schemes
  2018-12-06 22:34 edk2 and gnu-efi calling schemes Peter Wiehe
@ 2018-12-06 22:46 ` Bill Paul
  2018-12-07 13:06   ` Laszlo Ersek
  0 siblings, 1 reply; 5+ messages in thread
From: Bill Paul @ 2018-12-06 22:46 UTC (permalink / raw)
  To: edk2-devel

Of all the gin joints in all the towns in all the world, Peter Wiehe had to 
walk into mine at 14:34 on Thursday 06 December 2018 and say:

> OK, another question:
> 
> when writing an UEFI application, edk2 and gnu-efi have different 64bit
> calling schemes. Does that only apply to calling the
> runtime-library/object file (and inside of the UEFI-application, of
> course)? Or does the call from application to UEFI differ in both
> toolkits, too? (If it is the latter, it would mean that the UEFI
> standard is unprecise!)

Both the EDK and GNU EFI obey the same standards when calling UEFI APIs. Their 
exact implementations may differ depending on the circumstances. For example, 
GNU EFI may use the __attribute__((ms_abi)) tag to tell the compiler what ABI 
to use, or if the compiler doesn't support this it can fall back to using some 
compatibility wrapper macros (see lib/x86_64/efi_stub.S). Either way, you end 
up with the same behavior.

Within a given FOO.EFI application, the application code itself can get away 
with using whatever calling convention it wants, right up until it needs to 
call a UEFI firmware routine. At that point, it has to follow the conventions 
spelled out in the UEFI spec.

-Bill

> Kind regards
> 
> Peter Wiehe
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
-- 
=============================================================================
-Bill Paul            (510) 749-2329 | Senior Member of Technical Staff,
                 wpaul@windriver.com | Master of Unix-Fu - Wind River Systems
=============================================================================
   "I put a dollar in a change machine. Nothing changed." - George Carlin
=============================================================================


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: edk2 and gnu-efi calling schemes
  2018-12-06 22:46 ` Bill Paul
@ 2018-12-07 13:06   ` Laszlo Ersek
  2018-12-07 13:26     ` Knop, Ryszard
  0 siblings, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2018-12-07 13:06 UTC (permalink / raw)
  To: Peter Wiehe; +Cc: Bill Paul, edk2-devel

On 12/06/18 23:46, Bill Paul wrote:
> Of all the gin joints in all the towns in all the world, Peter Wiehe had to 
> walk into mine at 14:34 on Thursday 06 December 2018 and say:
> 
>> OK, another question:
>>
>> when writing an UEFI application, edk2 and gnu-efi have different 64bit
>> calling schemes. Does that only apply to calling the
>> runtime-library/object file (and inside of the UEFI-application, of
>> course)? Or does the call from application to UEFI differ in both
>> toolkits, too? (If it is the latter, it would mean that the UEFI
>> standard is unprecise!)
> 
> Both the EDK and GNU EFI obey the same standards when calling UEFI APIs. Their 
> exact implementations may differ depending on the circumstances. For example, 
> GNU EFI may use the __attribute__((ms_abi)) tag to tell the compiler what ABI 
> to use, or if the compiler doesn't support this it can fall back to using some 
> compatibility wrapper macros (see lib/x86_64/efi_stub.S). Either way, you end 
> up with the same behavior.
> 
> Within a given FOO.EFI application, the application code itself can get away 
> with using whatever calling convention it wants, right up until it needs to 
> call a UEFI firmware routine. At that point, it has to follow the conventions 
> spelled out in the UEFI spec.

I'd like to add:

- in edk2, functions declared in lib class headers have to be EFIAPI;

- functions that take variable arguments must be EFIAPI, even if they
  are STATIC (long story).

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: edk2 and gnu-efi calling schemes
  2018-12-07 13:06   ` Laszlo Ersek
@ 2018-12-07 13:26     ` Knop, Ryszard
  2018-12-07 14:09       ` Laszlo Ersek
  0 siblings, 1 reply; 5+ messages in thread
From: Knop, Ryszard @ 2018-12-07 13:26 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: edk2-devel@lists.01.org, Bill Paul, Peter Wiehe

Hi Laszlo,
Regarding "functions that take variable arguments must be EFIAPI, even if they are STATIC (long story)" - what's the story? :)
Thanks, Richard.

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
Sent: Friday, December 7, 2018 14:07
To: Peter Wiehe <peter.wiehe2@gmail.com>
Cc: edk2-devel@lists.01.org; Bill Paul <wpaul@windriver.com>
Subject: Re: [edk2] edk2 and gnu-efi calling schemes

On 12/06/18 23:46, Bill Paul wrote:
> Of all the gin joints in all the towns in all the world, Peter Wiehe 
> had to walk into mine at 14:34 on Thursday 06 December 2018 and say:
> 
>> OK, another question:
>>
>> when writing an UEFI application, edk2 and gnu-efi have different 
>> 64bit calling schemes. Does that only apply to calling the 
>> runtime-library/object file (and inside of the UEFI-application, of 
>> course)? Or does the call from application to UEFI differ in both 
>> toolkits, too? (If it is the latter, it would mean that the UEFI 
>> standard is unprecise!)
> 
> Both the EDK and GNU EFI obey the same standards when calling UEFI 
> APIs. Their exact implementations may differ depending on the 
> circumstances. For example, GNU EFI may use the 
> __attribute__((ms_abi)) tag to tell the compiler what ABI to use, or 
> if the compiler doesn't support this it can fall back to using some 
> compatibility wrapper macros (see lib/x86_64/efi_stub.S). Either way, you end up with the same behavior.
> 
> Within a given FOO.EFI application, the application code itself can 
> get away with using whatever calling convention it wants, right up 
> until it needs to call a UEFI firmware routine. At that point, it has 
> to follow the conventions spelled out in the UEFI spec.

I'd like to add:

- in edk2, functions declared in lib class headers have to be EFIAPI;

- functions that take variable arguments must be EFIAPI, even if they
  are STATIC (long story).

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: edk2 and gnu-efi calling schemes
  2018-12-07 13:26     ` Knop, Ryszard
@ 2018-12-07 14:09       ` Laszlo Ersek
  0 siblings, 0 replies; 5+ messages in thread
From: Laszlo Ersek @ 2018-12-07 14:09 UTC (permalink / raw)
  To: Knop, Ryszard; +Cc: edk2-devel@lists.01.org, Bill Paul, Peter Wiehe

On 12/07/18 14:26, Knop, Ryszard wrote:
> Hi Laszlo,
> Regarding "functions that take variable arguments must be EFIAPI, even if they are STATIC (long story)" - what's the story? :)

If I remember correctly, the issue was that the VA_*() macros could not
be implemented on gcc -- or, on *all* supported gcc toolchains at the
same time, anyway -- such that they'd work in both non-EFIAPI and EFIAPI
functions. This held for both manual stack manipulation *and* gcc
builtins, in the macros -- the gcc builtins would not auto-adapt (at
compile time) to the actual calling convention of the containing function.

Therefore, the VA_*() macros had to make a one-time choice (between
being usable in EFIAPI vs. non-EFIAPI functions). Given that variable
arguments are taken by both some edk2 lib class APIs, and (more
importantly) some UEFI services (ex.
gBS->InstallMultipleProtocolInterfaces()), VA_*() were made to assume
EFIAPI in the containing function.

So, I guess, to be more precise, I should say "functions that take
variable arguments must be EFIAPI, as long as you want to use VA_*()
macros in them".

This is my recollection anyway.

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-07 14:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-06 22:34 edk2 and gnu-efi calling schemes Peter Wiehe
2018-12-06 22:46 ` Bill Paul
2018-12-07 13:06   ` Laszlo Ersek
2018-12-07 13:26     ` Knop, Ryszard
2018-12-07 14:09       ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox