From be223b9de7a194cc114ca70c6fd323d0e38ac298 Mon Sep 17 00:00:00 2001 From: Justin Miller Date: Fri, 22 Oct 2021 08:52:32 -0700 Subject: [PATCH] [SDK] Allow ARM64 MSVC to complete configuration (#4045) - Add some of the missing CMake adjustments to continue the configure and compile process with ARM64 MSVC - Created quick stubs for the functions in SDK needed to finish the configuration process - Put in an ARM64 option for spec2def CORE-17518 CORE-17615 --- CMakeLists.txt | 3 +++ sdk/cmake/msvc.cmake | 7 ++++++- sdk/include/psdk/windows.h | 4 +++- sdk/include/reactos/msvctarget.h | 7 +++++++ sdk/include/xdk/ntbasedef.h | 2 +- sdk/lib/crt/except/arm64/chkstk_asm.s | 19 +++++++++++++++++++ sdk/lib/crt/except/except.cmake | 2 ++ sdk/lib/crt/math/arm64/atan2.s | 16 ++++++++++++++++ sdk/lib/crt/math/math.cmake | 2 ++ sdk/tools/spec2def/spec2def.c | 8 +++++--- 10 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 sdk/lib/crt/except/arm64/chkstk_asm.s create mode 100644 sdk/lib/crt/math/arm64/atan2.s diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccebb71c66..f02a6023eae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,6 +267,9 @@ Enable this if the module uses typeid or dynamic_cast. You will probably need to if(SARCH STREQUAL "omap3-zoom2") add_definitions(-D_ZOOM2_) endif() + elseif(ARCH STREQUAL "arm64") + # GNU tools refer to arm64 as aarch64 + add_definitions(-D_ARM64_ -D__arm64__ -D__aarch64__ -D_WIN64) endif() # Other diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake index d284cae91a5..8377e717739 100644 --- a/sdk/cmake/msvc.cmake +++ b/sdk/cmake/msvc.cmake @@ -256,6 +256,8 @@ function(set_subsystem MODULE SUBSYSTEM) target_link_options(${MODULE} PRIVATE "/SUBSYSTEM:${_subsystem},5.02") elseif(ARCH STREQUAL "arm") target_link_options(${MODULE} PRIVATE "/SUBSYSTEM:${_subsystem},6.02") + elseif(ARCH STREQUAL "arm64") + target_link_options(${MODULE} PRIVATE "/SUBSYSTEM:${_subsystem},6.04") else() target_link_options(${MODULE} PRIVATE "/SUBSYSTEM:${_subsystem},5.01") endif() @@ -363,6 +365,9 @@ if(ARCH STREQUAL "amd64") elseif(ARCH STREQUAL "arm") add_definitions(/D__arm__) set(SPEC2DEF_ARCH arm) +elseif(ARCH STREQUAL "arm64") + add_definitions(/D__arm64__) + set(SPEC2DEF_ARCH arm64) else() set(SPEC2DEF_ARCH i386) endif() @@ -440,7 +445,7 @@ function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_addres COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_includes} ${_defines} /D__ASM__ /D_USE_ML /EP /c ${_asm_file} > ${_temp_file} DEPENDS ${_asm_file}) - if(ARCH STREQUAL "arm") + if(ARCH STREQUAL "arm" OR ARCH STREQUAL "arm64") set(_asm16_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_temp_file}) else() set(_asm16_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_temp_file}) diff --git a/sdk/include/psdk/windows.h b/sdk/include/psdk/windows.h index 67b25150b2e..347b164c33d 100644 --- a/sdk/include/psdk/windows.h +++ b/sdk/include/psdk/windows.h @@ -18,7 +18,7 @@ #endif #if !defined(_X86_) && !defined(_AMD64_) && !defined(_IA64_) && !defined(_ALPHA_) && \ - !defined(_ARM_) && !defined(_PPC_) && !defined(_MIPS_) && !defined(_68K_) && !defined(_SH_) + !defined(_ARM_) && !defined(_ARM64_) && !defined(_PPC_) && !defined(_MIPS_) && !defined(_68K_) && !defined(_SH_) #if defined(_M_AMD64) || defined(__x86_64__) #define _AMD64_ @@ -30,6 +30,8 @@ #define _ALPHA_ #elif defined(_M_ARM) || defined(__arm__) #define _ARM_ +#elif defined(_M_ARM64) || defined(__arm64__) || defined(__aarch64__) +#define _ARM64_ #elif defined(_M_PPC) || defined(__powerpc__) #define _PPC_ #elif defined(_M_MRX000) || defined(__mips__) diff --git a/sdk/include/reactos/msvctarget.h b/sdk/include/reactos/msvctarget.h index 6b2241f3016..3b54ee66eaf 100644 --- a/sdk/include/reactos/msvctarget.h +++ b/sdk/include/reactos/msvctarget.h @@ -26,6 +26,13 @@ #if !defined(_M_ARM) #define _M_ARM 1 #endif +#elif defined(__arm64__) + #if !defined(_ARM64_) + #define _ARM64_ 1 + #endif + #if !defined(_M_ARM64) + #define _M_ARM64 1 + #endif #elif defined(__ia64__) #if !defined(_IA64_) #define _IA64_ 1 diff --git a/sdk/include/xdk/ntbasedef.h b/sdk/include/xdk/ntbasedef.h index 0071d7352e9..753bfd0f1b5 100644 --- a/sdk/include/xdk/ntbasedef.h +++ b/sdk/include/xdk/ntbasedef.h @@ -119,7 +119,7 @@ #if defined(_AMD64_) || defined(_X86_) #define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT($ULONG) -#elif defined(_IA64_) || defined(_ARM_) +#elif defined(_IA64_) || defined(_ARM_) || defined(_ARM64_) #define PROBE_ALIGNMENT(_s) max((TYPE_ALIGNMENT(_s), TYPE_ALIGNMENT($ULONG)) #elif !defined(RC_INVOKED) #error "Unknown architecture" diff --git a/sdk/lib/crt/except/arm64/chkstk_asm.s b/sdk/lib/crt/except/arm64/chkstk_asm.s new file mode 100644 index 00000000000..ada72aeb331 --- /dev/null +++ b/sdk/lib/crt/except/arm64/chkstk_asm.s @@ -0,0 +1,19 @@ + +/* INCLUDES ******************************************************************/ + +/* We need one of these first! */ +/* #include */ + +/* CODE **********************************************************************/ + TEXTAREA + + LEAF_ENTRY __chkstk + /* TODO: add an assert fail call, as this is unimplemented */ + LEAF_END __chkstk + + LEAF_ENTRY __alloca_probe + /* TODO: add an assert fail call, as this is unimplemented */ + LEAF_END __alloca_probe + + END +/* EOF */ diff --git a/sdk/lib/crt/except/except.cmake b/sdk/lib/crt/except/except.cmake index c135c2309e7..418bbcdeb9b 100644 --- a/sdk/lib/crt/except/except.cmake +++ b/sdk/lib/crt/except/except.cmake @@ -64,6 +64,8 @@ elseif(ARCH STREQUAL "amd64") list(APPEND CHKSTK_ASM_SOURCE except/amd64/chkstk_ms.s) elseif(ARCH STREQUAL "arm") list(APPEND CHKSTK_ASM_SOURCE except/arm/chkstk_asm.s) +elseif(ARCH STREQUAL "arm64") + list(APPEND CHKSTK_ASM_SOURCE except/arm64/chkstk_asm.s) endif() add_asm_files(chkstk_lib_asm ${CHKSTK_ASM_SOURCE}) diff --git a/sdk/lib/crt/math/arm64/atan2.s b/sdk/lib/crt/math/arm64/atan2.s new file mode 100644 index 00000000000..f5848fab3f9 --- /dev/null +++ b/sdk/lib/crt/math/arm64/atan2.s @@ -0,0 +1,16 @@ + +/* INCLUDES ******************************************************************/ + +/* We need one of these first! */ +/* #include */ + +/* CODE **********************************************************************/ + + TEXTAREA + + LEAF_ENTRY atan2 + /* TODO: add an assert fail call, as this is unimplemented */ + LEAF_END atan2 + + END +/* EOF */ diff --git a/sdk/lib/crt/math/math.cmake b/sdk/lib/crt/math/math.cmake index a534fc8832e..fcf9e5eecdf 100644 --- a/sdk/lib/crt/math/math.cmake +++ b/sdk/lib/crt/math/math.cmake @@ -185,6 +185,8 @@ elseif(ARCH STREQUAL "amd64") list(APPEND ATAN2_ASM_SOURCE math/amd64/atan2.S) elseif(ARCH STREQUAL "arm") list(APPEND ATAN2_ASM_SOURCE math/arm/atan2.s) +elseif(ARCH STREQUAL "arm64") + list(APPEND ATAN2_ASM_SOURCE math/arm64/atan2.s) endif() add_asm_files(atan2_asm ${ATAN2_ASM_SOURCE}) diff --git a/sdk/tools/spec2def/spec2def.c b/sdk/tools/spec2def/spec2def.c index e5c452d0512..ee50fe01f35 100644 --- a/sdk/tools/spec2def/spec2def.c +++ b/sdk/tools/spec2def/spec2def.c @@ -57,6 +57,7 @@ enum _ARCH ARCH_AMD64, ARCH_IA64, ARCH_ARM, + ARCH_ARM64, ARCH_PPC }; @@ -449,7 +450,7 @@ OutputHeader_asmstub(FILE *file, char *libname) { fprintf(file, ".code\n"); } - else if (giArch == ARCH_ARM) + else if (giArch == ARCH_ARM || giArch == ARCH_ARM64) { fprintf(file, " AREA |.text|,ALIGN=2,CODE,READONLY\n\n"); } @@ -458,7 +459,7 @@ OutputHeader_asmstub(FILE *file, char *libname) void Output_stublabel(FILE *fileDest, char* pszSymbolName) { - if (giArch == ARCH_ARM) + if (giArch == ARCH_ARM || giArch == ARCH_ARM64) { fprintf(fileDest, "\tEXPORT |%s| [FUNC]\n|%s|\n", @@ -1405,7 +1406,7 @@ void usage(void) " -n= name of the dll\n" " --implib generate a def file for an import library\n" " --no-private-warnings suppress warnings about symbols that should be -private\n" - " -a= set architecture to (i386, x86_64, arm)\n" + " -a= set architecture to (i386, x86_64, arm, arm64)\n" " --with-tracing generate wine-like \"+relay\" trace trampolines (needs -s)\n"); } @@ -1494,6 +1495,7 @@ int main(int argc, char *argv[]) else if (strcasecmp(pszArchString, "x86_64") == 0) giArch = ARCH_AMD64; else if (strcasecmp(pszArchString, "ia64") == 0) giArch = ARCH_IA64; else if (strcasecmp(pszArchString, "arm") == 0) giArch = ARCH_ARM; + else if (strcasecmp(pszArchString, "arm64") == 0) giArch = ARCH_ARM64; else if (strcasecmp(pszArchString, "ppc") == 0) giArch = ARCH_PPC; if ((giArch == ARCH_AMD64) || (giArch == ARCH_IA64))