Add register dumping for Darwin ARM64, simplify opengl function loading code slightly

This commit is contained in:
UnknownShadow200 2021-11-19 23:02:33 +11:00
parent 2c59a9ebf7
commit bbf185fdcc
6 changed files with 14 additions and 11 deletions

View File

@ -457,6 +457,12 @@ static void PrintRegisters(cc_string* str, void* ctx) {
#elif defined __x86_64__ #elif defined __x86_64__
#define REG_GET(reg, ign) &r->__ss.__r##reg #define REG_GET(reg, ign) &r->__ss.__r##reg
Dump_X64() Dump_X64()
#elif defined __aarch64__
#define REG_GNUM(num) &r->__ss.__x[num]
#define REG_GET_SP() &r->__ss.__sp
#define REG_GET_IP() &r->__ss.__pc
/* TODO this reads invalid memory */
Dump_ARM64()
#elif defined __arm__ #elif defined __arm__
#define REG_GNUM(num) &r->__ss.__r[num] #define REG_GNUM(num) &r->__ss.__r[num]
#define REG_GET(reg, ign) &r->__ss.__ ## reg #define REG_GET(reg, ign) &r->__ss.__ ## reg

View File

@ -798,11 +798,9 @@ void GLContext_Free(void) {
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
static const cc_string glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"); static const cc_string glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
static void* lib; static void* lib;
void* addr;
if (!lib) lib = DynamicLib_Load2(&glPath); if (!lib) lib = DynamicLib_Load2(&glPath);
addr = DynamicLib_Get2(lib, function); return DynamicLib_Get2(lib, function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }
cc_bool GLContext_SwapBuffers(void) { cc_bool GLContext_SwapBuffers(void) {

View File

@ -651,16 +651,19 @@ void GLContext_Free(void) {
ctx_handle = NULL; ctx_handle = NULL;
} }
/* https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions#Windows */
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
static const cc_string glPath = String_FromConst("OPENGL32.dll"); static const cc_string glPath = String_FromConst("OPENGL32.dll");
static void* lib; static void* lib;
void* addr = (void*)wglGetProcAddress(function); void* addr = (void*)wglGetProcAddress(function);
if (!GLContext_IsInvalidAddress(addr)) return addr; if (!GLContext_IsInvalidAddress(addr)) return addr;
/* Some drivers return NULL from wglGetProcAddress for core OpenGL functions */ /* Some drivers return NULL from wglGetProcAddress for core OpenGL functions */
if (!lib) lib = DynamicLib_Load2(&glPath); if (!lib) lib = DynamicLib_Load2(&glPath);
addr = DynamicLib_Get2(lib, function); return DynamicLib_Get2(lib, function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }
cc_bool GLContext_SwapBuffers(void) { cc_bool GLContext_SwapBuffers(void) {

View File

@ -1159,8 +1159,7 @@ void GLContext_Free(void) {
} }
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
void* addr = (void*)glXGetProcAddress((const GLubyte*)function); return (void*)glXGetProcAddress((const GLubyte*)function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }
cc_bool GLContext_SwapBuffers(void) { cc_bool GLContext_SwapBuffers(void) {

View File

@ -99,7 +99,6 @@ static void InitGraphicsMode(struct GraphicsMode* m) {
#ifdef CC_BUILD_GL #ifdef CC_BUILD_GL
/* OpenGL contexts are heavily tied to the window, so for simplicitly are also included here */ /* OpenGL contexts are heavily tied to the window, so for simplicitly are also included here */
/* EGL is window system agnostic, other OpenGL context backends are tied to one windowing system. */ /* EGL is window system agnostic, other OpenGL context backends are tied to one windowing system. */
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
void GLContext_GetAll(const struct DynamicLibSym* syms, int count) { void GLContext_GetAll(const struct DynamicLibSym* syms, int count) {
int i; int i;

View File

@ -606,11 +606,9 @@ void GLContext_Free(void) {
void* GLContext_GetAddress(const char* function) { void* GLContext_GetAddress(const char* function) {
static const cc_string glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"); static const cc_string glPath = String_FromConst("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL");
static void* lib; static void* lib;
void* addr;
if (!lib) lib = DynamicLib_Load2(&glPath); if (!lib) lib = DynamicLib_Load2(&glPath);
addr = DynamicLib_Get2(lib, function); return DynamicLib_Get2(lib, function);
return GLContext_IsInvalidAddress(addr) ? NULL : addr;
} }
cc_bool GLContext_SwapBuffers(void) { cc_bool GLContext_SwapBuffers(void) {