diff --git a/CMakeLists.txt b/CMakeLists.txt index bf5cea670..2c943b9d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.1) project(rehlds CXX) +option(ARM32 "Build for ARM 32bit cpus" OFF) + if (WIN32) message(FATAL_ERROR "CMakeLists.txt Windows platform isn't supported yet. Use msvc/ReHLDS.sln instead it!") endif() diff --git a/build_arm.sh b/build_arm.sh new file mode 100644 index 000000000..9c1cf5b24 --- /dev/null +++ b/build_arm.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +main() +{ + CC=arm-linux-gnueabi-gcc + CXX=arm-linux-gnueabi-g++ + + if [[ "$*" =~ "--help" ]]; then + help + exit 0; + fi + + n=0 + args=() + for i in "$@" + do + case $i in + -j=*|--jobs=*) + jobs="-j${i#*=}" + shift + ;; + -c=*|--compiler=*) + C="${i#*=}" + shift + ;; + *) + args[$n]="$i" + ((++n)) + ;; + esac + done + + case "$C" in + ("intel"|"icc") CC=icc CXX=icpc ;; + ("gcc"|"g++") CC=gcc CXX=g++ ;; + ("clang|llvm") CC=clang CXX=clang++ ;; + *) + ;; + esac + + #rm -rf build + #mkdir build + pushd build &> /dev/null + CC=$CC CXX=$CXX cmake -DARM32=1 ${args[@]} .. + make ${jobs} + popd > /dev/null +} + +help() +{ + printf "Usage: ./build.sh \n\n" + printf " -c= | --compiler= - Select preferred C/C++ compiler to build\n" + printf " -j= | --jobs= - Specifies the number of jobs (commands) to run simultaneously (For faster building)\n\n" +} + +# Initialize +main $* + +# Exit normally +exit 0 diff --git a/dep/bzip2/CMakeLists.txt b/dep/bzip2/CMakeLists.txt index 50e77a602..e857419a8 100644 --- a/dep/bzip2/CMakeLists.txt +++ b/dep/bzip2/CMakeLists.txt @@ -20,6 +20,9 @@ include_directories( ) add_library(bzip2 STATIC ${BZIP2_SRCS}) -set_target_properties(bzip2 PROPERTIES - COMPILE_FLAGS "-m32" -) + +if (NOT ARM32) + set_target_properties(bzip2 PROPERTIES + COMPILE_FLAGS "-m32" + ) +endif() diff --git a/rehlds/CMakeLists.txt b/rehlds/CMakeLists.txt index 0583b6538..c897469aa 100644 --- a/rehlds/CMakeLists.txt +++ b/rehlds/CMakeLists.txt @@ -31,8 +31,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") -set(LINK_FLAGS "-m32") +if (ARM32) + set(COMPILE_FLAGS "-U_FORTIFY_SOURCE ") +else() + set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE ") + set(LINK_FLAGS "-m32") +endif() if (ASAN) set(COMPILE_FLAGS "${COMPILE_FLAGS} -fsanitize=address -fno-omit-frame-pointer") @@ -70,13 +74,16 @@ else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. set(COMPILE_FLAGS "${COMPILE_FLAGS} \ - -mtune=generic -msse3\ -fpermissive -fno-sized-deallocation\ -Wno-unknown-pragmas -Wno-invalid-offsetof\ -Wno-unused-variable -Wno-unused-result -Wno-unused-function -Wno-delete-non-virtual-dtor\ -Wno-write-strings -Wno-format\ -Wno-sign-compare -Wno-strict-aliasing -Wno-ignored-attributes") + if (NOT ARM32) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mtune=generic -msse3") + endif() + # Check if not Clang compiler if (NOT "$ENV{CXX}" MATCHES "clang") set(COMPILE_FLAGS "${COMPILE_FLAGS} -fno-plt -Wno-unused-but-set-variable") diff --git a/rehlds/engine/common.cpp b/rehlds/engine/common.cpp index e70d03ca1..7272c475b 100644 --- a/rehlds/engine/common.cpp +++ b/rehlds/engine/common.cpp @@ -393,6 +393,25 @@ void MSG_WBits_MaybeFlush() { bfwrite.nCurOutputBit -= 32; } +#ifdef __arm__ +void MSG_WriteBits(uint32_t data, int numbits) +{ + uint32_t maxval = (1 << numbits) - 1; + if (data > maxval) + data = maxval; + + MSG_WBits_MaybeFlush(); + + uint64_t* pendingPtr = &bfwrite.pendingData.u64; + uint64_t pending = *pendingPtr; + + uint64_t mmdata = (uint64_t)data << bfwrite.nCurOutputBit; + pending |= mmdata; + + *pendingPtr = pending; + bfwrite.nCurOutputBit += numbits; +} +#else void MSG_WriteBits(uint32 data, int numbits) { uint32 maxval = _mm_cvtsi128_si32(_mm_slli_epi64(_mm_cvtsi32_si128(1), numbits)) - 1; //maxval = (1 << numbits) - 1 @@ -409,6 +428,7 @@ void MSG_WriteBits(uint32 data, int numbits) _mm_store_si128((__m128i*) &bfwrite.pendingData.u64, pending); bfwrite.nCurOutputBit += numbits; } +#endif void MSG_WriteOneBit(int nValue) { MSG_WriteBits(nValue, 1); diff --git a/rehlds/engine/sse_mathfun.cpp b/rehlds/engine/sse_mathfun.cpp index 724cb2658..ae5412c73 100644 --- a/rehlds/engine/sse_mathfun.cpp +++ b/rehlds/engine/sse_mathfun.cpp @@ -29,6 +29,8 @@ misrepresented as being the original software. (this is the zlib license) */ +#ifndef __arm__ + #include "precompiled.h" /* natural logarithm computed for 4 simultaneous float @@ -445,3 +447,5 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) { *s = _mm_xor_ps(xmm1, sign_bit_sin); *c = _mm_xor_ps(xmm2, sign_bit_cos); } + +#endif \ No newline at end of file diff --git a/rehlds/engine/sse_mathfun.h b/rehlds/engine/sse_mathfun.h index 240732784..2925f8f0f 100644 --- a/rehlds/engine/sse_mathfun.h +++ b/rehlds/engine/sse_mathfun.h @@ -30,6 +30,7 @@ misrepresented as being the original software. */ #pragma once +#ifndef __arm__ #include /* yes I know, the top of this file is quite ugly */ @@ -118,3 +119,5 @@ extern v4sf exp_ps(v4sf x); extern v4sf sin_ps(v4sf x); extern v4sf cos_ps(v4sf x); extern void sincos_ps(v4sf x, v4sf *s, v4sf *c); + +#endif \ No newline at end of file diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 1975c567c..d7369ce66 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1860,7 +1860,7 @@ challenge_buf_t g_raw_challenge_buf; void SV_ChallengesInit() { -#ifdef REHLDS_FIXES +#if defined(REHLDS_FIXES) && !defined(__arm__) static_assert(sizeof(g_raw_challenge_buf) == 64u, "Invalid g_raw_challenge_buf size"); for (uint32_t& s : g_raw_challenge_buf.salt) s = __rdtsc() * rand(); diff --git a/rehlds/public/rehlds/crc32c.cpp b/rehlds/public/rehlds/crc32c.cpp index 4fcde71dd..0052cc015 100644 --- a/rehlds/public/rehlds/crc32c.cpp +++ b/rehlds/public/rehlds/crc32c.cpp @@ -14,7 +14,10 @@ along with this program; if not, see . #include "crc32c.h" #include "sys_shared.h" + +#ifndef __arm__ #include "immintrin.h" +#endif /*****************************************************************/ /* */ diff --git a/rehlds/public/rehlds/maintypes.h b/rehlds/public/rehlds/maintypes.h index b211e2d8c..ec94ea115 100644 --- a/rehlds/public/rehlds/maintypes.h +++ b/rehlds/public/rehlds/maintypes.h @@ -46,7 +46,10 @@ #define __HACK_LINE_AS_STRING__(x) CONST_INTEGER_AS_STRING(x) //__LINE__ can only be converted to an actual number by going through this, otherwise the output is literally "__LINE__" #define __LINE__AS_STRING __HACK_LINE_AS_STRING__(__LINE__) //Gives you the line number in constant string form -#if defined _MSC_VER || defined __INTEL_COMPILER + +#ifdef __arm__ +#define NOXREFCHECK +#elif defined _MSC_VER || defined __INTEL_COMPILER #define NOXREFCHECK int __retAddr; __asm { __asm mov eax, [ebp + 4] __asm mov __retAddr, eax }; Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr) #else // For EBP based stack (older gcc) (uncomment version apropriate for your compiler) diff --git a/rehlds/public/rehlds/osconfig.h b/rehlds/public/rehlds/osconfig.h index 8d889af1a..3b1d47fd2 100644 --- a/rehlds/public/rehlds/osconfig.h +++ b/rehlds/public/rehlds/osconfig.h @@ -88,8 +88,10 @@ #include #include +#ifndef __arm__ #include #include +#endif #ifdef _WIN32 // WINDOWS @@ -136,7 +138,11 @@ VirtualFree(ptr, 0, MEM_RELEASE); } #else // _WIN32 - #include + #ifdef __arm__ + #define _mm_prefetch(arg1, arg2) + #else + #include + #endif #ifndef PAGESIZE #define PAGESIZE 4096 @@ -161,7 +167,12 @@ #define NOINLINE __attribute__((noinline)) #define ALIGN16 __attribute__((aligned(16))) #define NORETURN __attribute__((noreturn)) - #define FORCE_STACK_ALIGN __attribute__((force_align_arg_pointer)) + + #ifdef __arm__ + #define FORCE_STACK_ALIGN + #else + #define FORCE_STACK_ALIGN __attribute__((force_align_arg_pointer)) + #endif #if defined __INTEL_COMPILER #define FUNC_TARGET(x) diff --git a/rehlds/public/rehlds/sys_shared.cpp b/rehlds/public/rehlds/sys_shared.cpp index c9d089393..a3dc95ca5 100644 --- a/rehlds/public/rehlds/sys_shared.cpp +++ b/rehlds/public/rehlds/sys_shared.cpp @@ -27,7 +27,9 @@ */ #include "sys_shared.h" -#if defined(__GNUC__) +#ifdef __arm__ + +#elif defined(__GNUC__) #include #elif _MSC_VER >= 1400 && !defined(ASMLIB_H) #include // __cpuidex @@ -47,7 +49,9 @@ void Sys_CheckCpuInstructionsSupport(void) { unsigned int cpuid_data[4]; -#if defined ASMLIB_H +#if defined __arm__ + memset(cpuid_data, 0, 4*sizeof(unsigned int)); +#elif defined ASMLIB_H cpuid_ex((int *)cpuid_data, 1, 0); #elif defined(__GNUC__) __get_cpuid(0x1, &cpuid_data[0], &cpuid_data[1], &cpuid_data[2], &cpuid_data[3]);