On Mar 15, 2014, at 2:55 PM, Scott Duplichan <sc...@notabs.org> wrote:

> Andrew Fish [mailto:af...@apple.com]  wrote:
> 
> ]On Mar 11, 2014, at 6:17 PM, Ben Schroeder <ben...@mellanox.com> wrote:
> ]
> ]
> ]  Hi,
> ] 
> ]  Regarding EFIAPI calling convention, the UEFI 2.3.1 specification
> ]  writes:
> ]    “All public interfaces of a UEFI module must follow the UEFI calling
> ]    convention. Public interfaces include the image entry point, UEFI
> ]    event handlers, and protocol member functions. The type EFIAPI is
> ]    used to indicate conformance to the calling conventions defined in
> ]    this section. Non public interfaces, such as private functions and
> ]    static library calls, are not required to follow the UEFI calling
> ]    conventions and may be optimized by the compiler”
> ] 
> ]  Specifically I am interested in UEFI event handlers.
> ]  I have a function that registered with CreateEvent as a timer,
> ]  and then registered with SetTimer to be polled periodically.
> ]  So I understand this function (call it foo()) must have EFIAPI
> ]  calling convention (because it will be called periodically by the 
> ]  uefi system)
> ]
> ]That is correct. 
> ]
> ]
> ]  Do functions that are called by foo() also need to be in EFIAPI convention?
> ]
> ]No
> 
> I believe there is one exception to this rule. For x86 code (I tested x64 
> only),
> the VA_START and VA_ARG macros defined by EDK2 work only for the Microsoft
> x64 calling convention and not for System V calling convention. For example,
> the sample app Hello.c can be modified to include and call these two 
> functions:
> 

Good point! VA_LIST (AKA marker) is non portable. So you can not pass it 
between the ABI worlds. If my memory is correct the X64 marker for EFIAPI (Win 
ABI) is just a pointer, but for GCC it is a structure. 

This is why we don’t have any public APIs (other that libs) that use marker 
(VA_LIST), we also try to avoid having a protocol publish a var arg function as 
it goes badly very quickly as you found out. 

We actually hit an issue with report status code where the binaries where 
produced by both VC++ and GNU. We ended up having to add BASE_LIST. This fixed 
the issue that the report status code structure was constructing a fake frame 
to pass through the interface, but was using VA_LIST, and that is not portable 
C code. 

You can see the BASE_LIST implementation in: 
https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Library/BasePrintLib/PrintLib.c

Thanks,

Andrew Fish

> static void test1 (char *format, ...)
>    {
>    static char buffer [200];
>    VA_LIST marker;
>    VA_START (marker, format);
>    AsciiVSPrint (buffer, sizeof buffer, format, marker);
>    VA_END (marker);
>    AsciiPrint (buffer);
>    }
> 
> static void EFIAPI test2 (char *format, ...)
>    {
>    static char buffer [200];
>    VA_LIST marker;
>    VA_START (marker, format);
>    AsciiVSPrint (buffer, sizeof buffer, format, marker);
>    VA_END (marker);
>    AsciiPrint (buffer);
>    }
> 



> When built with Windows tools, both functions work. But when built from
> Linux using gnu tools, only the second function works properly.
> 
> In the current edk2 code, the PrintString() function in files DuetPkg/DxeIpl
> and DuetPkg/EfiLdr fail when built from Linux because of this. Adding
> EFIAPI to those function declarations fixes the Linux build problem.
> The EDKII Module Development Environment Library Specification hints
> at this requirement in the text for VA_START and VA_ARG:
> "The method for computing the pointer to the next argument in
> the argument list is CPU specific following the EFIAPI ABI."
> Thanks,
> Scott
> 
> [...]
> 
> ]Thanks,
> ]
> ]Andrew Fish
> ]
> ]
> ]Thanks,
> ]Ben.
> 
> 
> 
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to