Skip to content

Commit

Permalink
Adjust the source code and build enviornment so that Mangos Zero will…
Browse files Browse the repository at this point in the history
… build on ARM32. (mangoszero#79)

This was primarily done to test the feasibility of running on a RPi4 running
Debian Buster (it works quite well).

Summary of changes:

  - Reworked patches I found on the Mangos forum, original pastebins here:
      https://pastebin.com/BxqCmCML
  - Adjusted cmake's arch detection to include ARM32/ARM64
  - Adjusted compiler flags for Linux builds and supressed some extraneous notes

I have played for about an hour and noticed no issues or differences from i386/x86_64 VMs.

One note, currently the map extraction tools for ARM are broken.  They compile but do
work properly.  I'll work on that next.
  • Loading branch information
sterlingalexander authored and billy1arm committed Jan 9, 2020
1 parent b103caa commit fe79b0d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cmake/SetDefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ else()
endif()

if(XCODE)
if(PLATFORM MATCHES 32)
# Here we add a check for ARM32, as they can't leverage SSE/SSE2
if(PLATFORM MATCHES 32 AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set(CMAKE_OSX_ARCHITECTURES ARM32)
# Default for 32-bit left as i386
elseif(PLATFORM MATCHES 32)
set(CMAKE_OSX_ARCHITECTURES i386)
# Check for ARM64
elseif(PLATFORM MATCHES 64 AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set(CMAKE_OSX_ARCHITECTURES ARM64)
# Default for 64-bit left as x86_64
else()
set(CMAKE_OSX_ARCHITECTURES x86_64)
endif()
endif()


#
# Compile definitions
#
Expand Down Expand Up @@ -112,10 +119,17 @@ endif ()
# GCC compiler options
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(DEFAULT_COMPILE_OPTS ${DEFAULT_COMPILE_OPTS}
$<$<EQUAL:${PLATFORM},32>:
# Enhanced 32-bit check, now we can use the arch to specify flags
$<$<STREQUAL:${CMAKE_OSX_ARCHITECTURES},"i386">:
-msse2
-mfpmath=sse
>
$<$<STREQUAL:${CMAKE_OSX_ARCHITECTURES},"ARM32">:
# explicit space for compiler flags
>
$<$<STREQUAL:${CMAKE_OSX_ARCHITECTURES},"ARM64">:
# explicit space for compiler flags
>
$<$<CONFIG:Debug>:
-W
-Wall
Expand All @@ -128,6 +142,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")

$<$<CONFIG:Release>:
--no-warnings
# Suppress compiler note on parameter passing. See the following
# GCC BZ for more info: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728
-Wno-psabi
>
)
endif ()
Expand Down
24 changes: 24 additions & 0 deletions src/shared/Database/SQLStorageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ template<class S, class D>
*/
void SQLStorageLoaderBase<DerivedLoader, StorageClass>::convert(uint32 /*field_pos*/, S src, D& dst)
{
#if defined(__arm__)
if (((unsigned) &dst) % sizeof(D)) {
//The address is not aligned. Use memcpy to avoid ARM unaligned trap
D converted(src);
memcpy((void*) &dst, (void*) &converted, sizeof(D));
}
else
#endif
dst = D(src);
}

Expand Down Expand Up @@ -92,6 +100,14 @@ template<class D>
*/
void SQLStorageLoaderBase<DerivedLoader, StorageClass>::convert_from_str(uint32 /*field_pos*/, char const* /*src*/, D& dst)
{
#if defined(__arm__)
if (((unsigned) &dst) % sizeof(D)) {
//The address is not aligned. Use memcpy to avoid ARM unaligned trap
D converted(0);
memcpy((void*) &dst, (void*) &converted, sizeof(D));
}
else
#endif
dst = 0;
}

Expand All @@ -106,6 +122,14 @@ template<class S, class D>
*/
void SQLStorageLoaderBase<DerivedLoader, StorageClass>::default_fill(uint32 /*field_pos*/, S src, D& dst)
{
#if defined(__arm__)
if (((unsigned) &dst) % sizeof(D)) {
//The address is not aligned. Use memcpy to avoid ARM unaligned trap
D converted(src);
memcpy((void*) &dst, (void*) &converted, sizeof(D));
}
else
#endif
dst = D(src);
}

Expand Down
6 changes: 6 additions & 0 deletions src/shared/Utilities/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,13 @@ class ByteBuffer
{
if (pos + sizeof(T) > size())
{ throw ByteBufferException(false, pos, sizeof(T), size()); }
#if defined(__arm__)
// ARM has alignment issues, we need to use memcpy to avoid them
T val;
memcpy((void*)&val, (void*)&_storage[pos], sizeof(T));
#else
T val = *((T const*)&_storage[pos]);
#endif
EndianConvert(val);
return val;
}
Expand Down

0 comments on commit fe79b0d

Please sign in to comment.