]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/Library/CompilerIntrinsicsLib: Enable VS2017/ARM builds
authorPete Batard <pete@akeo.ie>
Fri, 12 Jan 2018 13:33:29 +0000 (21:33 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 7 Feb 2018 01:49:22 +0000 (09:49 +0800)
Introduce CRT assembly replacements for __rt_sdiv, __rt_udiv,
__rt_udiv64, __rt_sdiv64, __rt_srsh (by reusing the RVCT code)
as well as memcpy and memset.
For MSFT compatibility, some of the code needs to be explicitly
forced to ARM, and the /oldit assembly flag needs to be added.
Also, while RVCT_ASM_EXPORT macro invocations have been removed,
the replacement code is designed to be as close as possible to
the one that would have been generated if using the macros.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPkg/Library/CompilerIntrinsicsLib/Arm/div.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/ldivmod.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/llsr.asm
ArmPkg/Library/CompilerIntrinsicsLib/Arm/uldiv.asm
ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c [new file with mode: 0644]
ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c [new file with mode: 0644]

index b539e516892d1ce21f058cae5a50591b8ca028e6..f9e0107395f20f0957c86c3be6bce173bf8ddbdf 100644 (file)
@@ -1,6 +1,7 @@
 //------------------------------------------------------------------------------\r
 //\r
 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+// Copyright (c) 2018, Pete Batard. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
     EXPORT  __aeabi_uidivmod\r
     EXPORT  __aeabi_idiv\r
     EXPORT  __aeabi_idivmod\r
+    EXPORT  __rt_udiv\r
+    EXPORT  __rt_sdiv\r
 \r
     AREA  Math, CODE, READONLY\r
 \r
 ;\r
 ;UINT32\r
 ;EFIAPI\r
-;__aeabi_uidivmode (\r
-;  IN UINT32  Dividen\r
+;__aeabi_uidivmod (\r
+;  IN UINT32  Dividend\r
 ;  IN UINT32  Divisor\r
 ;  );\r
 ;\r
-\r
 __aeabi_uidiv\r
 __aeabi_uidivmod\r
     RSBS    r12, r1, r0, LSR #4\r
@@ -39,11 +41,41 @@ __aeabi_uidivmod
     MOV     r3, #0\r
     B       __arm_div_large\r
 \r
+;\r
+;UINT64\r
+;EFIAPI\r
+;__rt_udiv (\r
+;  IN UINT32  Divisor,\r
+;  IN UINT32  Dividend\r
+;  );\r
+;\r
+__rt_udiv\r
+    ; Swap R0 and R1\r
+    MOV     r12, r0\r
+    MOV     r0, r1\r
+    MOV     r1, r12\r
+    B       __aeabi_uidivmod\r
+\r
+;\r
+;UINT64\r
+;EFIAPI\r
+;__rt_sdiv (\r
+;  IN INT32  Divisor,\r
+;  IN INT32  Dividend\r
+;  );\r
+;\r
+__rt_sdiv\r
+    ; Swap R0 and R1\r
+    MOV     r12, r0\r
+    MOV     r0, r1\r
+    MOV     r1, r12\r
+    B       __aeabi_idivmod\r
+\r
 ;\r
 ;INT32\r
 ;EFIAPI\r
-;__aeabi_idivmode (\r
-;  IN INT32  Dividen\r
+;__aeabi_idivmod (\r
+;  IN INT32  Dividend\r
 ;  IN INT32  Divisor\r
 ;  );\r
 ;\r
@@ -152,4 +184,3 @@ __aeabi_idiv0
     BX      r14\r
 \r
     END\r
-\r
index c71bd59e4520768290a43ed63a68f8090c78b355..115a2b9c0e3c80c88feb4d004de2d192293d69c9 100644 (file)
@@ -1,6 +1,7 @@
 //------------------------------------------------------------------------------\r
 //\r
 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+// Copyright (c) 2018, Pete Batard. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 //------------------------------------------------------------------------------\r
 \r
 \r
-    EXTERN  __aeabi_uldivmod\r
+    IMPORT  __aeabi_uldivmod\r
+    EXPORT  __aeabi_ldivmod\r
+    EXPORT  __rt_sdiv64\r
 \r
-    INCLUDE AsmMacroExport.inc\r
+    AREA  s___aeabi_ldivmod, CODE, READONLY, ARM\r
+\r
+    ARM\r
 \r
 ;\r
-;UINT32\r
+;INT64\r
 ;EFIAPI\r
-;__aeabi_uidivmode (\r
-;  IN UINT32  Dividen\r
-;  IN UINT32  Divisor\r
+;__rt_sdiv64 (\r
+;  IN  INT64  Divisor\r
+;  IN  INT64  Dividend\r
 ;  );\r
 ;\r
+__rt_sdiv64\r
+    ; Swap r0-r1 and r2-r3\r
+    MOV     r12, r0\r
+    MOV     r0, r2\r
+    MOV     r2, r12\r
+    MOV     r12, r1\r
+    MOV     r1, r3\r
+    MOV     r3, r12\r
+    B       __aeabi_ldivmod\r
 \r
- RVCT_ASM_EXPORT __aeabi_ldivmod\r
+;\r
+;INT64\r
+;EFIAPI\r
+;__aeabi_ldivmod (\r
+;  IN  INT64  Dividend\r
+;  IN  INT64  Divisor\r
+;  );\r
+;\r
+__aeabi_ldivmod\r
     PUSH     {r4,lr}\r
     ASRS     r4,r1,#1\r
     EOR      r4,r4,r3,LSR #1\r
@@ -39,7 +61,7 @@ L_Test1
     RSBS     r2,r2,#0\r
     RSC      r3,r3,#0\r
 L_Test2\r
-    BL       __aeabi_uldivmod  ;\r
+    BL       __aeabi_uldivmod\r
     TST      r4,#0x40000000\r
     BEQ      L_Test3\r
     RSBS     r0,r0,#0\r
@@ -53,5 +75,3 @@ L_Exit
     POP      {r4,pc}\r
 \r
     END\r
-\r
-\r
index 881db106d9d7e62185a667e3e992019ff1f4e88b..abfd7ab64a7951d5dbdc759b8615ceeeee2b53c7 100644 (file)
@@ -1,6 +1,7 @@
 //------------------------------------------------------------------------------\r
 //\r
 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+// Copyright (c) 2018, Pete Batard. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 //\r
 //------------------------------------------------------------------------------\r
 \r
+  EXPORT  __aeabi_llsr\r
+  EXPORT  __rt_srsh\r
 \r
+  AREA  s___aeabi_llsr, CODE, READONLY, ARM\r
 \r
-    INCLUDE AsmMacroExport.inc\r
+  ARM\r
 \r
 ;\r
 ;VOID\r
 ;EFIAPI\r
 ;__aeabi_llsr (\r
-; IN  VOID    *Destination,\r
-; IN  VOID    *Source,\r
-; IN  UINT32  Size\r
-; );\r
+;  IN  UINT64  Value,\r
+;  IN  UINT32  Shift\r
+;)\r
 ;\r
- RVCT_ASM_EXPORT __aeabi_llsr\r
+__aeabi_llsr\r
+__rt_srsh\r
     SUBS     r3,r2,#0x20\r
-    BPL      {pc} + 0x18  ; 0x1c\r
+    BPL      __aeabi_llsr_label1\r
     RSB      r3,r2,#0x20\r
     LSR      r0,r0,r2\r
     ORR      r0,r0,r1,LSL r3\r
     LSR      r1,r1,r2\r
     BX       lr\r
+__aeabi_llsr_label1\r
     LSR      r0,r1,r3\r
     MOV      r1,#0\r
     BX       lr\r
 \r
     END\r
-\r
-\r
-\r
index 6b6184ebd3fc60411b04845ebfbf61874ef23233..aedaac8c6c7f293b2ceb05cd70ec18216b81f9bb 100644 (file)
@@ -1,6 +1,7 @@
 //------------------------------------------------------------------------------\r
 //\r
 // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+// Copyright (c) 2018, Pete Batard. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
 //------------------------------------------------------------------------------\r
 \r
 \r
+    EXPORT  __aeabi_uldivmod\r
+    EXPORT  __rt_udiv64\r
 \r
+    AREA  s___aeabi_uldivmod, CODE, READONLY, ARM\r
 \r
-    INCLUDE AsmMacroExport.inc\r
+    ARM\r
+\r
+;\r
+;UINT64\r
+;EFIAPI\r
+;__rt_udiv64 (\r
+;  IN  UINT64   Divisor\r
+;  IN  UINT64   Dividend\r
+;  )\r
+;\r
+__rt_udiv64\r
+  ; Swap r0-r1 and r2-r3\r
+  mov     r12, r0\r
+  mov     r0, r2\r
+  mov     r2, r12\r
+  mov     r12, r1\r
+  mov     r1, r3\r
+  mov     r3, r12\r
+  b       __aeabi_uldivmod\r
 \r
 ;\r
 ;UINT64\r
@@ -25,7 +47,7 @@
 ;  IN  UINT64   Divisor\r
 ;  )\r
 ;\r
- RVCT_ASM_EXPORT __aeabi_uldivmod\r
+__aeabi_uldivmod\r
   stmdb   sp!, {r4, r5, r6, lr}\r
   mov     r4, r1\r
   mov     r5, r0\r
@@ -261,7 +283,6 @@ _ll_div0
   b       __aeabi_ldiv0\r
 \r
 __aeabi_ldiv0\r
-  BX        r14\r
+  bx        r14\r
 \r
   END\r
-\r
index 44333141a70ab6c2113a233e80d0bb44a93461fd..14e88da7ce06d2962828f3ccc248307c08fcfb47 100644 (file)
   LIBRARY_CLASS                  = CompilerIntrinsicsLib\r
 \r
 [Sources]\r
-  memcpy.c\r
-  memset.c\r
+  memcpy.c             | RVCT\r
+  memcpy.c             | GCC\r
+  memcpy_ms.c          | MSFT\r
+  memset.c             | RVCT\r
+  memset.c             | GCC\r
+  memset_ms.c          | MSFT\r
 \r
 [Sources.ARM]\r
   Arm/mullu.asm        | RVCT\r
   Arm/llsr.S       | GCC\r
   Arm/llsl.S       | GCC\r
 \r
+  Arm/div.asm      | MSFT\r
+  Arm/uldiv.asm    | MSFT\r
+  Arm/ldivmod.asm  | MSFT\r
+  Arm/llsr.asm     | MSFT\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
 \r
 [LibraryClasses]\r
 \r
+[BuildOptions]\r
+  MSFT:*_*_ARM_CC_FLAGS = /GL-\r
+  MSFT:*_*_ARM_ASM_FLAGS = /oldit\r
+  MSFT:*_*_AARCH64_CC_FLAGS = /GL-\r
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c
new file mode 100644 (file)
index 0000000..90bbbb9
--- /dev/null
@@ -0,0 +1,34 @@
+//------------------------------------------------------------------------------\r
+//\r
+// Copyright (c) 2017, Pete Batard. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials are licensed and made\r
+// available under the terms and conditions of the BSD License which\r
+// accompanies this distribution.  The full text of the license may be\r
+// found at http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR\r
+// IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+#if defined(_M_ARM64)\r
+typedef unsigned __int64  size_t;\r
+#else\r
+typedef unsigned __int32  size_t;\r
+#endif\r
+\r
+void* memcpy(void *, const void *, size_t);\r
+#pragma intrinsic(memcpy)\r
+#pragma function(memcpy)\r
+void* memcpy(void *dest, const void *src, size_t n)\r
+{\r
+  unsigned char *d = dest;\r
+  unsigned char const *s = src;\r
+\r
+  while (n--)\r
+    *d++ = *s++;\r
+\r
+  return dest;\r
+}\r
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c
new file mode 100644 (file)
index 0000000..64205e5
--- /dev/null
@@ -0,0 +1,33 @@
+//------------------------------------------------------------------------------\r
+//\r
+// Copyright (c) 2017, Pete Batard. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials are licensed and made\r
+// available under the terms and conditions of the BSD License which\r
+// accompanies this distribution.  The full text of the license may be\r
+// found at http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR\r
+// IMPLIED.\r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+#if defined(_M_ARM64)\r
+typedef unsigned __int64  size_t;\r
+#else\r
+typedef unsigned __int32  size_t;\r
+#endif\r
+\r
+void* memset(void *, int, size_t);\r
+#pragma intrinsic(memset)\r
+#pragma function(memset)\r
+void *memset(void *s, int c, size_t n)\r
+{\r
+  unsigned char *d = s;\r
+\r
+  while (n--)\r
+    *d++ = (unsigned char)c;\r
+\r
+  return s;\r
+}\r