From 15a4c813d6e2f4f7fdfef7da84ac1ba7eae26830 Mon Sep 17 00:00:00 2001 From: leper Date: Thu, 30 Jul 2015 19:52:55 +0000 Subject: [PATCH] Add support for AArch64 (ARM64). Patch by tbm. Fixes #3345. This was SVN commit r16899. --- build/premake/premake4.lua | 4 ++ source/lib/byte_order.h | 4 +- source/lib/sysdep/arch.h | 10 ++++- source/lib/sysdep/arch/aarch64/aarch64.cpp | 49 ++++++++++++++++++++++ source/ps/GameSetup/HWDetect.cpp | 3 +- 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 source/lib/sysdep/arch/aarch64/aarch64.cpp diff --git a/build/premake/premake4.lua b/build/premake/premake4.lua index 1cfc2ee94b..734ed9ed85 100644 --- a/build/premake/premake4.lua +++ b/build/premake/premake4.lua @@ -86,6 +86,8 @@ else arch = "x86" elseif string.find(machine, "arm") == 1 then arch = "arm" + elseif string.find(machine, "aarch64") == 1 then + arch = "aarch64" else print("WARNING: Cannot determine architecture from GCC, assuming x86") end @@ -828,6 +830,8 @@ function setup_all_libs () table.insert(source_dirs, "lib/sysdep/arch/x86_x64"); elseif arch == "arm" then table.insert(source_dirs, "lib/sysdep/arch/arm"); + elseif arch == "aarch64" then + table.insert(source_dirs, "lib/sysdep/arch/aarch64"); end -- OS-specific diff --git a/source/lib/byte_order.h b/source/lib/byte_order.h index 3ed04157c1..72763f04e3 100644 --- a/source/lib/byte_order.h +++ b/source/lib/byte_order.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Wildfire Games +/* Copyright (c) 2015 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -33,7 +33,7 @@ #ifndef BYTE_ORDER # define LITTLE_ENDIAN 0x4321 # define BIG_ENDIAN 0x1234 -# if ARCH_IA32 || ARCH_IA64 || ARCH_AMD64 || ARCH_ALPHA || ARCH_ARM || ARCH_MIPS || defined(__LITTLE_ENDIAN__) +# if ARCH_IA32 || ARCH_IA64 || ARCH_AMD64 || ARCH_ALPHA || ARCH_ARM || ARCH_AARCH64 || ARCH_MIPS || defined(__LITTLE_ENDIAN__) # define BYTE_ORDER LITTLE_ENDIAN # else # define BYTE_ORDER BIG_ENDIAN diff --git a/source/lib/sysdep/arch.h b/source/lib/sysdep/arch.h index 5f97ebe945..270da517e1 100644 --- a/source/lib/sysdep/arch.h +++ b/source/lib/sysdep/arch.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Wildfire Games +/* Copyright (c) 2015 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -58,6 +58,12 @@ #else # define ARCH_ARM 0 #endif +// .. AArch64 (ARM64) +#if defined(__aarch64__) +# define ARCH_AARCH64 1 +#else +# define ARCH_AARCH64 0 +#endif // .. MIPS #if defined(__MIPS__) || defined(__mips__) || defined(__mips) # define ARCH_MIPS 1 @@ -66,7 +72,7 @@ #endif // ensure exactly one architecture has been detected -#if (ARCH_IA32+ARCH_IA64+ARCH_AMD64+ARCH_ALPHA+ARCH_ARM+ARCH_MIPS) != 1 +#if (ARCH_IA32+ARCH_IA64+ARCH_AMD64+ARCH_ALPHA+ARCH_ARM+ARCH_AARCH64+ARCH_MIPS) != 1 # error "architecture not correctly detected (either none or multiple ARCH_* defined)" #endif diff --git a/source/lib/sysdep/arch/aarch64/aarch64.cpp b/source/lib/sysdep/arch/aarch64/aarch64.cpp new file mode 100644 index 0000000000..46638396b7 --- /dev/null +++ b/source/lib/sysdep/arch/aarch64/aarch64.cpp @@ -0,0 +1,49 @@ +/* Copyright (c) 2015 Wildfire Games + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * routines specific to AArch64 + */ + +#include "precompiled.h" + +#include "lib/sysdep/cpu.h" + +intptr_t cpu_AtomicAdd(volatile intptr_t* location, intptr_t increment) +{ + return __sync_fetch_and_add(location, increment); +} + +bool cpu_CAS(volatile intptr_t* location, intptr_t expected, intptr_t newValue) +{ + return __sync_bool_compare_and_swap(location, expected, newValue); +} + +bool cpu_CAS64(volatile i64* location, i64 expected, i64 newValue) +{ + return __sync_bool_compare_and_swap(location, expected, newValue); +} + +const char* cpu_IdentifierString() +{ + return "unknown"; // TODO +} diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index 1f6c8505b2..205e398583 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -223,6 +223,7 @@ void RunHardwareDetection() scriptInterface.SetProperty(settings, "arch_ia32", ARCH_IA32); scriptInterface.SetProperty(settings, "arch_amd64", ARCH_AMD64); scriptInterface.SetProperty(settings, "arch_arm", ARCH_ARM); + scriptInterface.SetProperty(settings, "arch_aarch64", ARCH_AARCH64); #ifdef NDEBUG scriptInterface.SetProperty(settings, "build_debug", 0);