BSD: Add support (#140)

* BSD: Add support

* BSD: other fixes

There is still a bug when vgui haven't got text, maybe because of resources.

Also there is bug where when trying to start new game caption names shows wrong.

* BSD: Debugging

* BSD: modify preprocessor and fix windows

* BSD: Remove debugging and fix labels in gameui

* BSD: Remove disabling some DX9 commands

* BSD: Remove -g flag
This commit is contained in:
Er2
2022-11-24 22:04:29 +03:00
committed by GitHub
parent 807eaae850
commit 53bd92f7a8
49 changed files with 221 additions and 178 deletions

View File

@@ -11,7 +11,7 @@
#include <windows.h>
#elif defined(_LINUX)
#include <stdlib.h>
#elif defined(OSX)
#elif defined(OSX) || defined(BSD)
#include <sys/sysctl.h>
#endif
@@ -273,7 +273,7 @@ bool CheckSSE4aTechnology( void )
static bool Check3DNowTechnology(void)
{
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__)
#if defined( _X360 ) || defined( _PS3 ) || defined (__arm__) || defined(__SANITIZE_ADDRESS__) || (defined(BSD) && defined(COMPILER_CLANG))
return false;
#else
uint32 eax, unused;
@@ -448,7 +448,9 @@ uint64 CalculateCPUFreq(); // from cpu_linux.cpp
static int64 CalculateClockSpeed()
{
#if defined( _WIN32 )
#if !defined( _X360 )
#if defined( _X360 )
return 3200000000LL;
#else
LARGE_INTEGER waitTime, startCount, curCount;
CCycleCount start, end;
@@ -476,15 +478,14 @@ static int64 CalculateClockSpeed()
freq = 2000000000;
}
return freq;
#else
return 3200000000LL;
#endif
#elif defined(BSD)
return CalculateCPUFreq() * 1000000.0f;
#elif defined(POSIX)
int64 freq =(int64)CalculateCPUFreq();
if ( freq == 0 ) // couldn't calculate clock speed
{
Error( "Unable to determine CPU Frequency\n" );
Warning( "Unable to determine CPU Frequency\n" );
}
return freq;
#endif
@@ -583,7 +584,7 @@ const CPUInformation* GetCPUInformation()
pi.m_nLogicalProcessors = 1;
Assert( !"couldn't read cpu information from /proc/cpuinfo" );
}
#elif defined(OSX)
#elif defined(OSX) || defined(BSD)
int mib[2], num_cpu = 1;
size_t len;
mib[0] = CTL_HW;

View File

@@ -11,6 +11,11 @@
#include <linux/sysctl.h>
#else
#include <sys/sysctl.h>
# ifdef __APPLE__
# define CPUFREQ_SYSCTL "hw.cpufrequency_max"
# else
# define CPUFREQ_SYSCTL "dev.cpu.0.freq"
# endif
#endif
#include <sys/time.h>
#include <unistd.h>
@@ -46,18 +51,15 @@ static inline uint64 diff(uint64 v1, uint64 v2)
return -d;
}
#ifdef OSX
#if defined(OSX) || defined(BSD)
// Mac
// Mac or BSD
uint64 GetCPUFreqFromPROC()
{
int mib[2] = {CTL_HW, HW_CPU_FREQ};
uint64 frequency = 0;
size_t len = sizeof(frequency);
if (sysctl(mib, 2, &frequency, &len, NULL, 0) == -1)
return 0;
return frequency;
uint64 freq_hz = 0;
size_t freq_size = sizeof(freq_hz);
int retval = sysctlbyname(CPUFREQ_SYSCTL, &freq_hz, &freq_size, NULL, 0);
return freq_hz;
}
#else
@@ -99,14 +101,8 @@ uint64 GetCPUFreqFromPROC()
uint64 CalculateCPUFreq()
{
#ifdef __APPLE__
uint64 freq_hz = 0;
size_t freq_size = sizeof(freq_hz);
int retval = sysctlbyname("hw.cpufrequency_max", &freq_hz, &freq_size, NULL, 0);
// MoeMod : TODO dont know how to get freq on Apple Silicon
if(!freq_hz)
freq_hz = 3200000000;
return freq_hz;
#if defined(__APPLE__) || defined(BSD)
return GetCPUFreqFromPROC();
#else
// Try to open cpuinfo_max_freq. If the kernel was built with cpu scaling support disabled, this will fail.
FILE *fp = fopen( "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r" );
@@ -127,9 +123,9 @@ uint64 CalculateCPUFreq()
return retVal * 1000;
}
}
#endif
#if !defined(__arm__) && !defined(__aarch64__)
// fallback mechanism to calculate when failed
// Compute the period. Loop until we get 3 consecutive periods that
// are the same to within a small error. The error is chosen
// to be +/- 0.02% on a P-200.
@@ -179,7 +175,10 @@ uint64 CalculateCPUFreq()
}
return period;
#endif
#else
// ARM hard-coded frequency
return (uint64)2000000000;
#endif // if !ARM
#endif // if APPLE
}

View File

@@ -16,12 +16,17 @@
#include <sys/resource.h>
#include <unistd.h>
#ifdef OSX
#include <mach/mach.h>
#include <mach/mach_time.h>
#if defined(OSX) || defined(BSD)
# ifdef BSD
# include <sys/proc.h>
# include <sys/user.h>
# else
# include <mach/mach.h>
# include <mach/mach_time.h>
# endif
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#ifdef LINUX
@@ -436,41 +441,29 @@ PLATFORM_INTERFACE void Plat_SetAllocErrorFn( Plat_AllocErrorFn fn )
#endif // !NO_HOOK_MALLOC
#if defined( OSX )
#if defined( OSX ) || defined(BSD)
// From the Apple tech note: http://developer.apple.com/library/mac/#qa/qa1361/_index.html
bool Plat_IsInDebugSession()
{
static int s_IsInDebugSession;
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
static int s_IsInDebugSession = -1;
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
#ifndef BSD
info.kp_proc.p_flag = 0;
#endif
if ( s_IsInDebugSession == -1 )
{
// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.
size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
info.kp_proc.p_flag = 0;
// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
// Call sysctl.
size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
// We're being debugged if the P_TRACED flag is set.
s_IsInDebugSession = ( (info.kp_proc.p_flag & P_TRACED) != 0 );
}
// We're being debugged if the P_TRACED flag is set.
#ifdef BSD
s_IsInDebugSession = info.ki_flag & P_TRACED;
#else
s_IsInDebugSession = info.kp_proc.p_flag & P_TRACED;
#endif
return !!s_IsInDebugSession;
}
@@ -509,7 +502,6 @@ bool Plat_IsInDebugSession()
return ( tracerpid > 0 );
}
#endif // defined( LINUX )
void Plat_DebugString( const char * psz )
@@ -567,7 +559,7 @@ PLATFORM_INTERFACE const char *Plat_GetCommandLineA()
PLATFORM_INTERFACE bool GetMemoryInformation( MemoryInformation *pOutMemoryInfo )
{
#if defined( LINUX ) || defined( OSX )
#if defined( LINUX ) || defined( OSX ) || defined(BSD)
return false;
#else
#error "Need to fill out GetMemoryInformation or at least return false for this platform"
@@ -579,7 +571,7 @@ PLATFORM_INTERFACE bool Is64BitOS()
{
#if defined OSX
return true;
#elif defined LINUX
#elif defined(LINUX) || defined(BSD)
FILE *pp = popen( "uname -m", "r" );
if ( pp != NULL )
{
@@ -789,7 +781,7 @@ static void InstallHooks( void )
__realloc_hook = ReallocHook;
}
#elif OSX
#elif OSX || BSD
static void RemoveHooks( void )

View File

@@ -43,6 +43,11 @@
#define OS_TO_PTHREAD(x) pthread_from_mach_thread_np( x )
#endif // !OSX
#ifdef BSD
# undef OS_TO_PTRHEAD
# define OS_TO_PTHREAD(x) (pthread_t)(x)
#endif
#endif
#ifndef _PS3
@@ -1680,7 +1685,7 @@ bool CThreadFullMutex::Release()
//
//-----------------------------------------------------------------------------
#if defined( WIN32 ) || defined( _PS3 ) || defined( _OSX ) || defined (_LINUX)
#if defined( WIN32 ) || defined( _PS3 ) || defined( _OSX ) || defined (_LINUX) || defined(BSD)
#if !defined(_PS3)
namespace GenericThreadLocals
{