Skip to content

Commit 29446db

Browse files
runlevel5illwieckz
authored andcommitted
Add ppc64le/ppc64 architecture support
Add build support for ppc64le (little-endian, POWER8+) and ppc64 (big-endian, POWER5+) architectures: - CMake architecture detection, compiler flags (-mcpu), and NaCl build defines for ppc64el/ppc64 - NACL_RUNTIME_ARCH allowlist and DAEMON_NACL_RUNTIME_ENABLED define to track whether a NaCl loader exists for the target architecture - vm.nacl.available ROM cvar so the UI can detect NaCl availability - Sys::Error when attempting to launch a NaCl VM on a platform without a NaCl loader, advising to use native DLL mode with devmap
1 parent bd2e006 commit 29446db

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

cmake/DaemonArchitecture.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ endif()
9191

9292
daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${NACL_ARCH}\"")
9393

94+
# NaCl runtime is only available on architectures that have a NaCl loader.
95+
set(NACL_RUNTIME_ARCH amd64 i686 armhf)
96+
if (NACL_ARCH IN_LIST NACL_RUNTIME_ARCH)
97+
add_definitions(-DDAEMON_NACL_RUNTIME_ENABLED)
98+
endif()
99+
94100
option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
95101
mark_as_advanced(USE_ARCH_INTRINSICS)
96102

@@ -111,6 +117,7 @@ set_arch_intrinsics(${ARCH})
111117

112118
set(amd64_PARENT "i686")
113119
set(arm64_PARENT "armhf")
120+
set(ppc64el_PARENT "ppc64")
114121

115122
if (${ARCH}_PARENT)
116123
set_arch_intrinsics(${${ARCH}_PARENT})

cmake/DaemonFlags.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,18 @@ elseif (NOT NACL)
659659
set(GCC_GENERIC_ARCH "armv6")
660660
# There is no generic tuning option for armv6.
661661
unset(GCC_GENERIC_TUNE)
662+
elseif (ARCH STREQUAL "ppc64el")
663+
# POWER8 minimum (first little-endian POWER).
664+
# GCC uses -mcpu instead of -march/-mtune for POWER.
665+
unset(GCC_GENERIC_ARCH)
666+
unset(GCC_GENERIC_TUNE)
667+
set(GCC_GENERIC_CPU "power8")
668+
elseif (ARCH STREQUAL "ppc64")
669+
# POWER5 minimum (first 64-bit POWER in wide use).
670+
# GCC uses -mcpu instead of -march/-mtune for POWER.
671+
unset(GCC_GENERIC_ARCH)
672+
unset(GCC_GENERIC_TUNE)
673+
set(GCC_GENERIC_CPU "power5")
662674
else()
663675
message(WARNING "Unknown architecture ${ARCH}")
664676
endif()
@@ -676,6 +688,11 @@ elseif (NOT NACL)
676688
if (GCC_GENERIC_TUNE)
677689
try_c_cxx_flag_werror(MTUNE "-mtune=${GCC_GENERIC_TUNE}")
678690
endif()
691+
692+
# POWER architectures use -mcpu instead of -march/-mtune.
693+
if (GCC_GENERIC_CPU)
694+
try_c_cxx_flag_werror(MCPU "-mcpu=${GCC_GENERIC_CPU}")
695+
endif()
679696
endif()
680697

681698
if (USE_CPU_RECOMMENDED_FEATURES)

cmake/DaemonNacl.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ else()
7171
add_definitions( -DNACL_BUILD_SUBARCH=32 )
7272
elseif( NACL_ARCH STREQUAL "armhf" )
7373
add_definitions( -DNACL_BUILD_ARCH=arm )
74+
elseif( NACL_ARCH STREQUAL "ppc64el" OR NACL_ARCH STREQUAL "ppc64" )
75+
# NaCl does not support PPC, but these defines must be set for native
76+
# builds. Use dummy x86 values as PNaCl does for arch-independent builds.
77+
add_definitions( -DNACL_BUILD_ARCH=x86 )
78+
add_definitions( -DNACL_BUILD_SUBARCH=64 )
7479
else()
7580
message(WARNING "Unknown architecture ${NACL_ARCH}")
7681
endif()

src/engine/framework/VirtualMachine.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ static Cvar::Cvar<int> vm_timeout(
8888
"Receive timeout in seconds",
8989
Cvar::NONE, 2);
9090

91+
#if defined(DAEMON_NACL_RUNTIME_ENABLED)
92+
static Cvar::Cvar<bool> vm_nacl_available(
93+
"vm.nacl.available",
94+
"Whether NaCl runtime is available on this platform",
95+
Cvar::ROM, true);
96+
#else
97+
static Cvar::Cvar<bool> vm_nacl_available(
98+
"vm.nacl.available",
99+
"Whether NaCl runtime is available on this platform",
100+
Cvar::ROM, false);
101+
#endif
102+
91103
namespace VM {
92104

93105
// https://github.com/Unvanquished/Unvanquished/issues/944#issuecomment-744454772
@@ -497,6 +509,13 @@ void VMBase::Create()
497509
std::pair<IPC::Socket, IPC::Socket> pair = IPC::Socket::CreatePair();
498510

499511
IPC::Socket rootSocket;
512+
#if !defined(DAEMON_NACL_RUNTIME_ENABLED)
513+
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
514+
Sys::Error("NaCl VM is not supported on this platform. "
515+
"Set vm.cgame.type and vm.sgame.type to 3 (native DLL) "
516+
"and use devmap instead of map.");
517+
}
518+
#endif
500519
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
501520
std::tie(processHandle, rootSocket) = CreateNaClVM(std::move(pair), name, params.debug.Get(), type == TYPE_NACL, params.debugLoader.Get());
502521
} else if (type == TYPE_NATIVE_EXE) {

0 commit comments

Comments
 (0)