From 3c4ccd41fa92d3332ee98b993db82d96584f3bd3 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sat, 30 Jul 2016 11:41:40 +0200 Subject: [PATCH] Add basic NetBSD support --- extern/poshlib/posh.h | 7 +++++-- src/nvcore/CMakeLists.txt | 7 +++++-- src/nvcore/Debug.cpp | 17 +++++++++++++++-- src/nvcore/nvcore.h | 5 ++++- src/nvmath/nvmath.h | 4 ++-- src/nvthread/nvthread.cpp | 4 ++-- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/extern/poshlib/posh.h b/extern/poshlib/posh.h index 3d9e7aa..0fc39ce 100644 --- a/extern/poshlib/posh.h +++ b/extern/poshlib/posh.h @@ -306,6 +306,11 @@ LLVM: # define POSH_OS_STRING "FreeBSD" #endif +#if defined __NetBSD__ +# define POSH_OS_NETBSD 1 +# define POSH_OS_STRING "NetBSD" +#endif + #if defined __OpenBSD__ # define POSH_OS_OPENBSD 1 # define POSH_OS_STRING "OpenBSD" @@ -1027,5 +1032,3 @@ extern posh_i64_t POSH_ReadI64FromBig( const void *src ); #ifdef __cplusplus } #endif - - diff --git a/src/nvcore/CMakeLists.txt b/src/nvcore/CMakeLists.txt index 9246768..be6cdcb 100644 --- a/src/nvcore/CMakeLists.txt +++ b/src/nvcore/CMakeLists.txt @@ -38,9 +38,12 @@ ENDIF(NVCORE_SHARED) TARGET_LINK_LIBRARIES(nvcore ${LIBS}) +# On NetBSD backtrace() is provided by libexecinfo, not libc. +if (CMAKE_SYSTEM_NAME MATCHES "NetBSD") + TARGET_LINK_LIBRARIES(nvcore execinfo) +endif() + INSTALL(TARGETS nvcore RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static) - - diff --git a/src/nvcore/Debug.cpp b/src/nvcore/Debug.cpp index e84522a..ae803ab 100644 --- a/src/nvcore/Debug.cpp +++ b/src/nvcore/Debug.cpp @@ -51,7 +51,7 @@ # endif #endif -#if NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD +#if NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD # include # include # include // sysctl @@ -635,6 +635,19 @@ namespace # else # error "Unknown CPU" # endif +#elif NV_OS_NETBSD +# if NV_CPU_X86_64 + ucontext_t * ucp = (ucontext_t *)secret; + return (void *)ucp->uc_mcontext.__gregs[_REG_RIP]; +# elif NV_CPU_X86 + ucontext_t * ucp = (ucontext_t *)secret; + return (void *)ucp->uc_mcontext.__gregs[_REG_EIP]; +# elif NV_CPU_PPC + ucontext_t * ucp = (ucontext_t *)secret; + return (void *) ucp->uc_mcontext.__gregs[_REG_PC]; +# else +# error "Unknown CPU" +# endif #elif NV_OS_OPENBSD # if NV_CPU_X86_64 ucontext_t * ucp = (ucontext_t *)secret; @@ -666,7 +679,7 @@ namespace // How to obtain the instruction pointers in different platforms, from mlton's source code. // http://mlton.org/ - // OpenBSD && NetBSD + // OpenBSD // ucp->sc_eip // FreeBSD: // ucp->uc_mcontext.mc_eip diff --git a/src/nvcore/nvcore.h b/src/nvcore/nvcore.h index 511d23e..b402bb2 100644 --- a/src/nvcore/nvcore.h +++ b/src/nvcore/nvcore.h @@ -44,6 +44,9 @@ #elif defined POSH_OS_FREEBSD # define NV_OS_FREEBSD 1 # define NV_OS_UNIX 1 +#elif defined POSH_OS_NETBSD +# define NV_OS_NETBSD 1 +# define NV_OS_UNIX 1 #elif defined POSH_OS_OPENBSD # define NV_OS_OPENBSD 1 # define NV_OS_UNIX 1 @@ -290,7 +293,7 @@ NV_COMPILER_CHECK(sizeof(uint32) == 4); #elif NV_CC_GNUC # if NV_OS_LINUX # include "DefsGnucLinux.h" -# elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD +# elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD # include "DefsGnucDarwin.h" # elif NV_OS_MINGW # include "DefsGnucWin32.h" diff --git a/src/nvmath/nvmath.h b/src/nvmath/nvmath.h index fa423a3..7810c9f 100644 --- a/src/nvmath/nvmath.h +++ b/src/nvmath/nvmath.h @@ -172,7 +172,7 @@ namespace nv { #if NV_OS_WIN32 || NV_OS_XBOX return _finite(f) != 0; -#elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD || NV_OS_ORBIS +#elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD || NV_OS_ORBIS return isfinite(f); #elif NV_OS_LINUX return finitef(f); @@ -187,7 +187,7 @@ namespace nv { #if NV_OS_WIN32 || NV_OS_XBOX return _isnan(f) != 0; -#elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD || NV_OS_ORBIS +#elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_NETBSD || NV_OS_OPENBSD || NV_OS_ORBIS return isnan(f); #elif NV_OS_LINUX return isnanf(f); diff --git a/src/nvthread/nvthread.cpp b/src/nvthread/nvthread.cpp index 2db7c87..498c938 100644 --- a/src/nvthread/nvthread.cpp +++ b/src/nvthread/nvthread.cpp @@ -88,7 +88,7 @@ uint nv::processorCount() { return 6; #elif NV_OS_XBOX return 3; // or 6? -#elif NV_OS_LINUX // Linux, Solaris, & AIX +#elif NV_OS_LINUX || NV_OS_NETBSD // Linux, Solaris, & AIX return sysconf(_SC_NPROCESSORS_ONLN); #elif NV_OS_DARWIN || NV_OS_FREEBSD || NV_OS_OPENBSD int numCPU; @@ -329,4 +329,4 @@ uint nv::physicalProcessorCount() { return processorCount(); } -#endif \ No newline at end of file +#endif