Skip to content

Commit

Permalink
arm32 build WIP
Browse files Browse the repository at this point in the history
won't work because the steam library for linux is closed source and not built for ARM linux, so linking fails. It was recently compiled for Mac M1 CPUs, but since the format is .dylib it won't work on linux, and there's no way to convert to an .so file.

ValveSoftware/steam-for-linux#4061
  • Loading branch information
wootguy committed Jun 24, 2024
1 parent b102e35 commit 4e1d0e8
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
60 changes: 60 additions & 0 deletions build_arm.sh
Original file line number Diff line number Diff line change
@@ -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 <options>\n\n"
printf " -c= | --compiler=<icc|gcc|clang> - Select preferred C/C++ compiler to build\n"
printf " -j= | --jobs=<N> - Specifies the number of jobs (commands) to run simultaneously (For faster building)\n\n"
}

# Initialize
main $*

# Exit normally
exit 0
9 changes: 6 additions & 3 deletions dep/bzip2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 10 additions & 3 deletions rehlds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions rehlds/engine/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions rehlds/engine/sse_mathfun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions rehlds/engine/sse_mathfun.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ misrepresented as being the original software.
*/
#pragma once

#ifndef __arm__
#include <xmmintrin.h>

/* yes I know, the top of this file is quite ugly */
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions rehlds/public/rehlds/crc32c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.

#include "crc32c.h"
#include "sys_shared.h"

#ifndef __arm__
#include "immintrin.h"
#endif

/*****************************************************************/
/* */
Expand Down
5 changes: 4 additions & 1 deletion rehlds/public/rehlds/maintypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions rehlds/public/rehlds/osconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@
#include <fstream>
#include <iomanip>

#ifndef __arm__
#include <smmintrin.h>
#include <xmmintrin.h>
#endif


#ifdef _WIN32 // WINDOWS
Expand Down Expand Up @@ -136,7 +138,11 @@
VirtualFree(ptr, 0, MEM_RELEASE);
}
#else // _WIN32
#include <x86intrin.h>
#ifdef __arm__
#define _mm_prefetch(arg1, arg2)
#else
#include <x86intrin.h>
#endif

#ifndef PAGESIZE
#define PAGESIZE 4096
Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions rehlds/public/rehlds/sys_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*/
#include "sys_shared.h"

#if defined(__GNUC__)
#ifdef __arm__

#elif defined(__GNUC__)
#include <cpuid.h>
#elif _MSC_VER >= 1400 && !defined(ASMLIB_H)
#include <intrin.h> // __cpuidex
Expand All @@ -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]);
Expand Down

0 comments on commit 4e1d0e8

Please sign in to comment.