소스 검색

From: Pete Batard <pete@akeo.ie>
Date: Wed, 10 Dec 2014 21:08:34 +0000
Subject: [PATCH] fixes for MSVC compilation

These fixes are needed to address the following error and warnings when compiling the library part
using Visual Studio 2013 Community Edition (as in https://github.com/pbatard/uefi-simple):
* "lib\x86_64\math.c(49): error C4235: nonstandard extension used : '_asm' keyword not supported
on this architecture"
* "lib\print.c(98): error C2059: syntax error : '('" due to placement of EFIAPI macro
* "lib\cmdline.c(94): warning C4090: 'function' : different 'const' qualifiers"
* "lib\smbios.c(25): warning C4068: unknown pragma"
* Also update macro definitions in "inc\<arch>\efibind.h" for MSVC

Signed-off-by: Pete Batard <pete@akeo.ie>
Signed-off-by: Nigel Croxon <nigel.croxon@hp.com>

Nigel Croxon 10 년 전
부모
커밋
09027207f7
7개의 변경된 파일60개의 추가작업 그리고 37개의 파일을 삭제
  1. 7 2
      inc/ia32/efibind.h
  2. 25 19
      inc/ia64/efibind.h
  3. 14 4
      inc/x86_64/efibind.h
  4. 2 2
      lib/cmdline.c
  5. 6 6
      lib/print.c
  6. 2 0
      lib/smbios.c
  7. 4 4
      lib/x86_64/math.c

+ 7 - 2
inc/ia32/efibind.h

@@ -233,9 +233,13 @@ typedef uint32_t   UINTN;
 
 //
 // When build similiar to FW, then link everything together as
-// one big module.
+// one big module. For the MSVC toolchain, we simply tell the
+// linker what our driver init function is using /ENTRY.
 //
-
+#if defined(_MSC_EXTENSIONS)
+    #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
+        __pragma(comment(linker, "/ENTRY:" # InitFunction))
+#else
     #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
         UINTN                                       \
         InitializeDriver (                          \
@@ -252,6 +256,7 @@ typedef uint32_t   UINTN;
             EFI_SYSTEM_TABLE *systab                \
             ) __attribute__((weak,                  \
                     alias ("InitializeDriver")));
+#endif
 
     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
             (_if)->LoadInternal(type, name, entry)

+ 25 - 19
inc/ia64/efibind.h

@@ -179,27 +179,33 @@ void __mf (void);
 #pragma intrinsic (__mf)  
 #define MEMORY_FENCE()    __mf()
 #endif
+
 //
 // When build similiar to FW, then link everything together as
-// one big module.
-//
-
-#define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
-    UINTN                                       \
-    InitializeDriver (                          \
-        VOID    *ImageHandle,                   \
-        VOID    *SystemTable                    \
-        )                                       \
-    {                                           \
-        return InitFunction(ImageHandle,        \
-                SystemTable);                   \
-    }                                           \
-                                                \
-    EFI_STATUS efi_main(                        \
-        EFI_HANDLE image,                       \
-        EFI_SYSTEM_TABLE *systab                \
-        ) __attribute__((weak,                  \
-                alias ("InitializeDriver")));
+// one big module. For the MSVC toolchain, we simply tell the
+// linker what our driver init function is using /ENTRY.
+//
+#if defined(_MSC_EXTENSIONS)
+    #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
+        __pragma(comment(linker, "/ENTRY:" # InitFunction))
+#else
+    #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
+        UINTN                                       \
+        InitializeDriver (                          \
+            VOID    *ImageHandle,                   \
+            VOID    *SystemTable                    \
+            )                                       \
+        {                                           \
+            return InitFunction(ImageHandle,        \
+                    SystemTable);                   \
+        }                                           \
+                                                    \
+        EFI_STATUS efi_main(                        \
+            EFI_HANDLE image,                       \
+            EFI_SYSTEM_TABLE *systab                \
+            ) __attribute__((weak,                  \
+                    alias ("InitializeDriver")));
+#endif
 
 #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
         (_if)->LoadInternal(type, name, entry)

+ 14 - 4
inc/x86_64/efibind.h

@@ -245,9 +245,13 @@ typedef uint64_t   UINTN;
 
 //
 // When build similiar to FW, then link everything together as
-// one big module.
+// one big module. For the MSVC toolchain, we simply tell the
+// linker what our driver init function is using /ENTRY.
 //
-
+#if defined(_MSC_EXTENSIONS)
+    #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
+        __pragma(comment(linker, "/ENTRY:" # InitFunction))
+#else
     #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
         UINTN                                       \
         InitializeDriver (                          \
@@ -264,11 +268,12 @@ typedef uint64_t   UINTN;
             EFI_SYSTEM_TABLE *systab                \
             ) __attribute__((weak,                  \
                     alias ("InitializeDriver")));
+#endif
 
     #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
             (_if)->LoadInternal(type, name, entry)
 
-#endif // EFI_FW_NT 
+#endif // EFI_NT_EMULATOR
 
 //
 // Some compilers don't support the forward reference construct:
@@ -371,7 +376,12 @@ UINT64 efi_call10(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
   __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__)
 
 #endif
-#define EFI_FUNCTION __attribute__((ms_abi))
+
+#if defined(HAVE_USE_MS_ABI) && !defined(_MSC_EXTENSIONS)
+    #define EFI_FUNCTION __attribute__((ms_abi))
+#else
+    #define EFI_FUNCTION
+#endif
 
 #ifdef _MSC_EXTENSIONS
 #pragma warning ( disable : 4731 )  // Suppress warnings about modification of EBP

+ 2 - 2
lib/cmdline.c

@@ -86,7 +86,7 @@ INTN GetShellArgcArgv(EFI_HANDLE ImageHandle, CHAR16 **Argv[])
 
   Status = uefi_call_wrapper(BS->OpenProtocol, 6,
                              ImageHandle,
-                             &EfiShellParametersProtocolGuid,
+                             (EFI_GUID*)&EfiShellParametersProtocolGuid,
                              (VOID **)&EfiShellParametersProtocol,
                              ImageHandle,
                              NULL,
@@ -103,7 +103,7 @@ INTN GetShellArgcArgv(EFI_HANDLE ImageHandle, CHAR16 **Argv[])
   // try to get shell 1.0 interface instead.
   Status = uefi_call_wrapper(BS->OpenProtocol, 6,
                              ImageHandle,
-                             &ShellInterfaceProtocolGuid,
+                             (EFI_GUID*)&ShellInterfaceProtocolGuid,
                              (VOID **)&EfiShellInterfaceProtocol,
                              ImageHandle,
                              NULL,

+ 6 - 6
lib/print.c

@@ -95,8 +95,8 @@ typedef struct _pstate {
     UINTN       AttrHighlight;
     UINTN       AttrError;
 
-    INTN EFIAPI       (*Output)(VOID *context, CHAR16 *str);
-    INTN EFIAPI       (*SetAttr)(VOID *context, UINTN attr);
+    INTN        (EFIAPI *Output)(VOID *context, CHAR16 *str);
+    INTN        (EFIAPI *SetAttr)(VOID *context, UINTN attr);
     VOID        *Context;    
 
     // Current item being formatted
@@ -235,7 +235,7 @@ Returns:
     if (DbgOut) {
         ps.Attr = DbgOut->Mode->Attribute;
         ps.Context = DbgOut;
-        ps.SetAttr = (INTN EFIAPI (*)(VOID *, UINTN))  DbgOut->SetAttribute;
+        ps.SetAttr = (INTN (EFIAPI *)(VOID *, UINTN))  DbgOut->SetAttribute;
     }
 
     SavedAttribute = ps.Attr;
@@ -403,7 +403,7 @@ _PoolCatPrint (
     IN CHAR16           *fmt,
     IN va_list          args,
     IN OUT POOL_PRINT   *spc,
-    IN INTN EFIAPI      (*Output)(VOID *context, CHAR16 *str)
+    IN INTN             (EFIAPI *Output)(VOID *context, CHAR16 *str)
     )
 // Dispath function for SPrint, PoolPrint, and CatPrint
 {
@@ -781,8 +781,8 @@ _IPrint (
 
     ZeroMem (&ps, sizeof(ps));
     ps.Context = Out;
-    ps.Output  = (INTN EFIAPI (*)(VOID *, CHAR16 *)) Out->OutputString;
-    ps.SetAttr = (INTN EFIAPI (*)(VOID *, UINTN))  Out->SetAttribute;
+    ps.Output  = (INTN (EFIAPI *)(VOID *, CHAR16 *)) Out->OutputString;
+    ps.SetAttr = (INTN (EFIAPI *)(VOID *, UINTN))  Out->SetAttribute;
     ps.Attr = Out->Mode->Attribute;
    
     back = (ps.Attr >> 4) & 0xF;

+ 2 - 0
lib/smbios.c

@@ -22,7 +22,9 @@ Revision History
  * "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]"
  * we can safely ignore them here.
  */
+#ifdef __GNUC__
 #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
+#endif
 
 EFI_STATUS
 LibGetSmbiosSystemGuidAndSerialNumber (

+ 4 - 4
lib/x86_64/math.c

@@ -42,7 +42,7 @@ LShiftU64 (
     )
 // Left shift 64bit by 32bit and get a 64bit result
 {
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
     return Operand << Count;
 #else
     UINT64      Result;
@@ -77,7 +77,7 @@ RShiftU64 (
     )
 // Right shift 64bit by 32bit and get a 64bit result
 {
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
     return Operand >> Count;
 #else
     UINT64      Result;
@@ -113,7 +113,7 @@ MultU64x32 (
     )
 // Multiple 64bit by 32bit and get a 64bit result
 {
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
     return Multiplicand * Multiplier;
 #else
     UINT64      Result;
@@ -140,7 +140,7 @@ DivU64x32 (
 // divide 64bit by 32bit and get a 64bit result
 // N.B. only works for 31bit divisors!!
 {
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(_MSC_EXTENSIONS)
     if (Remainder)
 	*Remainder = Dividend % Divisor;
     return Dividend / Divisor;