]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Include/EfiStdArg.h
Fixed issues compiling for Apple gcc on IA-32
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Include / EfiStdArg.h
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 EfiStdArg.h\r
15\r
16Abstract:\r
17\r
18 Support for variable length argument lists using the ANSI standard.\r
19 \r
20 Since we are using the ANSI standard we used the standard nameing and\r
21 did not folow the coding convention\r
22\r
23 VA_LIST - typedef for argument list.\r
24 VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.\r
25 VA_END (VA_LIST Marker) - Clear Marker\r
26 VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argumnet from\r
27 the ... list. You must know the size and pass it in this macro.\r
28\r
29 example:\r
30\r
31 UINTN\r
32 ExampleVarArg (\r
33 IN UINTN NumberOfArgs,\r
34 ...\r
35 )\r
36 {\r
37 VA_LIST Marker;\r
38 UINTN Index;\r
39 UINTN Result;\r
40\r
41 //\r
42 // Initialize the Marker\r
43 //\r
44 VA_START (Marker, NumberOfArgs);\r
45 for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {\r
46 //\r
47 // The ... list is a series of UINTN values, so average them up.\r
48 //\r
49 Result += VA_ARG (Marker, UINTN);\r
50 }\r
51\r
52 VA_END (Marker);\r
53 return Result\r
54 }\r
55\r
56--*/\r
57\r
58#ifndef _EFISTDARG_H_\r
59#define _EFISTDARG_H_\r
60\r
61#define _EFI_INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))\r
62\r
e8de4680
A
63#if defined(__GNUC__)\r
64//\r
65// Use GCC built-in macros for variable argument lists.\r
66//\r
67\r
68///\r
69/// Variable used to traverse the list of arguments. This type can vary by \r
70/// implementation and could be an array or structure. \r
71///\r
72typedef __builtin_va_list VA_LIST;\r
73\r
74#define VA_START(Marker, Parameter) __builtin_va_start (Marker, Parameter)\r
75\r
76#define VA_ARG(Marker, TYPE) ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))\r
77\r
78#define VA_END(Marker) __builtin_va_end (Marker)\r
79\r
80#else\r
81\r
3eb9473e 82//\r
83// Also support coding convention rules for var arg macros\r
84//\r
85#ifndef VA_START\r
86\r
87typedef CHAR8 *VA_LIST;\r
88#define VA_START(ap, v) (ap = (VA_LIST) & (v) + _EFI_INT_SIZE_OF (v))\r
89#define VA_ARG(ap, t) (*(t *) ((ap += _EFI_INT_SIZE_OF (t)) - _EFI_INT_SIZE_OF (t)))\r
90#define VA_END(ap) (ap = (VA_LIST) 0)\r
91\r
e8de4680
A
92#endif\r
93\r
94\r
3eb9473e 95#endif\r
96\r
97#endif\r