2013-12-19 17:10:14 +00:00
|
|
|
#pragma once
|
2020-03-28 16:58:01 +00:00
|
|
|
#include "types.h"
|
2021-10-14 09:51:39 +00:00
|
|
|
#if defined(__SWITCH__)
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2020-03-28 16:58:01 +00:00
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
void os_SetWindowText(const char* text);
|
|
|
|
double os_GetSeconds();
|
|
|
|
|
|
|
|
void os_DoEvents();
|
|
|
|
void os_CreateWindow();
|
2018-08-20 11:36:34 +00:00
|
|
|
void os_SetupInput();
|
2021-07-20 11:06:08 +00:00
|
|
|
void os_InstallFaultHandler();
|
|
|
|
void os_UninstallFaultHandler();
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2019-08-25 16:39:44 +00:00
|
|
|
#ifdef _MSC_VER
|
2013-12-19 17:10:14 +00:00
|
|
|
#include <intrin.h>
|
|
|
|
#endif
|
|
|
|
|
2015-05-16 08:04:30 +00:00
|
|
|
u32 static INLINE bitscanrev(u32 v)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2019-08-25 16:41:42 +00:00
|
|
|
#ifdef __GNUC__
|
2013-12-19 17:10:14 +00:00
|
|
|
return 31-__builtin_clz(v);
|
|
|
|
#else
|
|
|
|
unsigned long rv;
|
|
|
|
_BitScanReverse(&rv,v);
|
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
}
|
2021-07-05 17:44:08 +00:00
|
|
|
|
|
|
|
namespace hostfs
|
|
|
|
{
|
|
|
|
std::string getVmuPath(const std::string& port);
|
2021-07-20 08:06:44 +00:00
|
|
|
|
|
|
|
std::string getArcadeFlashPath();
|
2021-07-05 17:44:08 +00:00
|
|
|
|
|
|
|
std::string findFlash(const std::string& prefix, const std::string& names);
|
|
|
|
std::string getFlashSavePath(const std::string& prefix, const std::string& name);
|
|
|
|
std::string findNaomiBios(const std::string& name);
|
|
|
|
|
|
|
|
std::string getSavestatePath(int index, bool writable);
|
|
|
|
|
|
|
|
std::string getTextureLoadPath(const std::string& gameId);
|
|
|
|
std::string getTextureDumpPath();
|
|
|
|
|
2021-12-14 15:48:23 +00:00
|
|
|
std::string getShaderCachePath(const std::string& filename);
|
2021-07-05 17:44:08 +00:00
|
|
|
|
|
|
|
std::string getBiosFontPath();
|
|
|
|
}
|
2021-07-24 20:24:37 +00:00
|
|
|
|
|
|
|
#ifdef _WIN64
|
2021-07-25 09:47:14 +00:00
|
|
|
#ifdef __MINGW64__
|
2021-07-24 20:24:37 +00:00
|
|
|
struct _RUNTIME_FUNCTION;
|
2021-07-25 09:47:14 +00:00
|
|
|
typedef struct _RUNTIME_FUNCTION RUNTIME_FUNCTION;
|
|
|
|
#else
|
|
|
|
struct _IMAGE_RUNTIME_FUNCTION_ENTRY;
|
|
|
|
typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY RUNTIME_FUNCTION;
|
|
|
|
#endif
|
2021-07-24 20:24:37 +00:00
|
|
|
#endif
|
2021-07-25 09:47:14 +00:00
|
|
|
|
2021-07-24 20:24:37 +00:00
|
|
|
class UnwindInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void start(void *address);
|
|
|
|
void pushReg(u32 offset, int reg);
|
2021-07-29 15:46:46 +00:00
|
|
|
void saveReg(u32 offset, int reg, int stackOffset);
|
|
|
|
void saveExtReg(u32 offset, int reg, int stackOffset);
|
2021-07-24 20:24:37 +00:00
|
|
|
void allocStack(u32 offset, int size);
|
|
|
|
void endProlog(u32 offset);
|
2021-07-29 15:46:46 +00:00
|
|
|
size_t end(u32 offset, ptrdiff_t rwRxOffset = 0);
|
2021-07-24 20:24:37 +00:00
|
|
|
|
|
|
|
void clear();
|
2021-08-01 15:07:17 +00:00
|
|
|
void allocStackPtr(const void *address, int size) {
|
|
|
|
allocStack((u32)((const u8 *)address - startAddr), size);
|
|
|
|
}
|
2021-07-24 20:24:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
u8 *startAddr;
|
|
|
|
#ifdef _WIN64
|
2021-07-25 09:47:14 +00:00
|
|
|
std::vector<RUNTIME_FUNCTION *> tables;
|
2021-07-24 20:24:37 +00:00
|
|
|
std::vector<u16> codes;
|
|
|
|
#endif
|
2021-07-29 15:46:46 +00:00
|
|
|
#if defined(__unix__) || defined(__APPLE__) || defined(__SWITCH__)
|
2021-07-24 20:24:37 +00:00
|
|
|
int stackOffset = 0;
|
2021-07-30 17:13:52 +00:00
|
|
|
uintptr_t lastOffset = 0;
|
2021-07-24 20:24:37 +00:00
|
|
|
std::vector<u8> cieInstructions;
|
|
|
|
std::vector<u8> fdeInstructions;
|
|
|
|
std::vector<u8 *> registeredFrames;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2021-08-10 09:32:22 +00:00
|
|
|
#if HOST_CPU != CPU_X64 && HOST_CPU != CPU_ARM64 && (HOST_CPU != CPU_X86 || defined(_WIN32))
|
2021-07-24 20:24:37 +00:00
|
|
|
inline void UnwindInfo::start(void *address) {
|
|
|
|
}
|
|
|
|
inline void UnwindInfo::pushReg(u32 offset, int reg) {
|
|
|
|
}
|
2021-07-29 15:46:46 +00:00
|
|
|
inline void UnwindInfo::saveReg(u32 offset, int reg, int stackOffset) {
|
|
|
|
}
|
|
|
|
inline void UnwindInfo::saveExtReg(u32 offset, int reg, int stackOffset) {
|
2021-07-24 20:24:37 +00:00
|
|
|
}
|
|
|
|
inline void UnwindInfo::allocStack(u32 offset, int size) {
|
|
|
|
}
|
|
|
|
inline void UnwindInfo::endProlog(u32 offset) {
|
|
|
|
}
|
2021-07-29 15:46:46 +00:00
|
|
|
inline size_t UnwindInfo::end(u32 offset, ptrdiff_t rwRxOffset) {
|
2021-07-24 20:24:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
inline void UnwindInfo::clear() {
|
|
|
|
}
|
|
|
|
#endif
|
2021-10-14 09:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
static inline void *allocAligned(size_t alignment, size_t size)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return _aligned_malloc(size, alignment);
|
|
|
|
#elif defined(__SWITCH__)
|
|
|
|
return memalign(alignment, size);
|
|
|
|
#else
|
|
|
|
void *data;
|
|
|
|
if (posix_memalign(&data, alignment, size) != 0)
|
|
|
|
return nullptr;
|
|
|
|
else
|
|
|
|
return data;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void freeAligned(void *p)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
_aligned_free(p);
|
|
|
|
#else
|
|
|
|
free(p);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|