mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-07 23:41:18 +12:00
Initial macOS port bringup (#52)
This commit is contained in:
parent
a2abffd37b
commit
974edaa649
84 changed files with 157 additions and 122 deletions
8234
src/Common/unix/date.h
Normal file
8234
src/Common/unix/date.h
Normal file
File diff suppressed because it is too large
Load diff
2980
src/Common/unix/fast_float.h
Normal file
2980
src/Common/unix/fast_float.h
Normal file
File diff suppressed because it is too large
Load diff
23
src/Common/unix/platform.cpp
Normal file
23
src/Common/unix/platform.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
uint32_t GetTickCount()
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (1000 * ts.tv_sec + ts.tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
#include <cpuid.h>
|
||||
|
||||
void (__cpuid)(int __cpuVal[4], unsigned int __leaf)
|
||||
{
|
||||
__cpuid(__cpuVal[0], __cpuVal[1], __cpuVal[2], __cpuVal[3], __leaf);
|
||||
}
|
||||
#undef __cpuid
|
||||
|
||||
void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf)
|
||||
{
|
||||
__cpuid_count (__leaf, __subleaf, __cpuid_info[0], __cpuid_info[1],
|
||||
__cpuid_info[2], __cpuid_info[3]);
|
||||
}
|
93
src/Common/unix/platform.h
Normal file
93
src/Common/unix/platform.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include <shared_mutex>
|
||||
|
||||
class SlimRWLock
|
||||
{
|
||||
public:
|
||||
void LockRead()
|
||||
{
|
||||
m_sm.lock_shared();
|
||||
}
|
||||
|
||||
void UnlockRead()
|
||||
{
|
||||
m_sm.unlock_shared();
|
||||
}
|
||||
|
||||
void LockWrite()
|
||||
{
|
||||
m_sm.lock();
|
||||
}
|
||||
|
||||
void UnlockWrite()
|
||||
{
|
||||
m_sm.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_mutex m_sm;
|
||||
};
|
||||
|
||||
inline uint32_t GetExceptionError()
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
#undef False
|
||||
#undef True
|
||||
#undef None
|
||||
#undef Bool
|
||||
#undef Status
|
||||
#undef Success
|
||||
#undef ClientMessage
|
||||
|
||||
// cpu id (somewhat hacky, reorganize later)
|
||||
void (__cpuid)(int __cpuVal[4], unsigned int __leaf);
|
||||
void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
|
||||
|
||||
// placeholder
|
||||
uint32_t GetTickCount();
|
||||
|
||||
// strcpy_s and strcat_s implementations
|
||||
template<size_t N>
|
||||
void strcpy_s(char (&dst)[N], const char* src)
|
||||
{
|
||||
if(N == 0)
|
||||
return;
|
||||
char* dstP = dst;
|
||||
const char* end = src + N - 1;
|
||||
while(src < end)
|
||||
{
|
||||
char c = *src;
|
||||
*dstP = c;
|
||||
if(c == '\0')
|
||||
return;
|
||||
dstP++;
|
||||
src++;
|
||||
c++;
|
||||
}
|
||||
*dstP = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
void strcat_s(char (&dst)[N], const char* src)
|
||||
{
|
||||
if(N == 0)
|
||||
return;
|
||||
char* dstP = dst;
|
||||
const char* end = dstP + N - 1;
|
||||
while(dstP < end && *dstP != '\0')
|
||||
dstP++;
|
||||
while(dstP < end)
|
||||
{
|
||||
char c = *src;
|
||||
*dstP = c;
|
||||
if(c == '\0')
|
||||
return;
|
||||
dstP++;
|
||||
src++;
|
||||
c++;
|
||||
}
|
||||
*dstP = '\0';
|
||||
return;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue