Skip to content

Commit

Permalink
Make it easier to compiler on IRIX (#997)
Browse files Browse the repository at this point in the history
Thanks ]joshyfishy22 for testing on an actual machine running IRIX
  • Loading branch information
UnknownShadow200 committed Mar 23, 2023
1 parent c666ee3 commit 3783380
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Core.h
Expand Up @@ -185,6 +185,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_POSIX
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#if defined CC_BUILD_RPI
Expand Down Expand Up @@ -218,6 +219,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_POSIX
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __FreeBSD__ || defined __DragonFly__
Expand All @@ -226,6 +228,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_BSD
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __OpenBSD__
Expand All @@ -234,6 +237,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_BSD
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __NetBSD__
Expand All @@ -242,6 +246,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_BSD
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_XINPUT2
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __HAIKU__
Expand All @@ -250,6 +255,14 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
#define CC_BUILD_GL
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#elif defined __sgi
#define CC_BUILD_IRIX
#define CC_BUILD_POSIX
#define CC_BUILD_GL
#define CC_BUILD_X11
#define CC_BUILD_CURL
#define CC_BUILD_OPENAL
#define CC_BIG_ENDIAN
#elif defined __EMSCRIPTEN__
#define CC_BUILD_WEB
#define CC_BUILD_GL
Expand Down
23 changes: 23 additions & 0 deletions src/Logger.c
Expand Up @@ -236,6 +236,12 @@ static void DumpFrame(cc_string* trace, void* addr) {
}
#elif defined CC_BUILD_PSP
/* No backtrace support implemented for PSP */
#elif defined CC_BUILD_IRIX
/* IRIX doesn't expose a nice interface for dladdr */
static void DumpFrame(cc_string* trace, void* addr) {
cc_uintptr addr_ = (cc_uintptr)addr;
String_Format1(trace, "%x", &addr_);
}
#elif defined CC_BUILD_POSIX
/* need to define __USE_GNU for dladdr */
#ifndef __USE_GNU
Expand Down Expand Up @@ -360,6 +366,11 @@ void Logger_Backtrace(cc_string* trace, void* ctx) {
String_AppendConst(trace, "-- backtrace unimplemented --");
/* Backtrace not implemented for PSP */
}
#elif defined CC_BUILD_IRIX
void Logger_Backtrace(cc_string* trace, void* ctx) {
String_AppendConst(trace, "-- backtrace unimplemented --");
/* TODO implement backtrace using exc_unwind https://nixdoc.net/man-pages/IRIX/man3/exception.3.html */
}
#elif defined CC_BUILD_POSIX
#include <execinfo.h>
void Logger_Backtrace(cc_string* trace, void* ctx) {
Expand Down Expand Up @@ -790,6 +801,18 @@ static void PrintRegisters(cc_string* str, void* ctx) {
#error "Unknown CPU architecture"
#endif
}
#elif defined CC_BUILD_IRIX
/* See /usr/include/sys/ucontext.h */
/* https://nixdoc.net/man-pages/IRIX/man5/UCONTEXT.5.html */
static void PrintRegisters(cc_string* str, void* ctx) {
mcontext_t* r = &((ucontext_t*)ctx)->uc_mcontext;

#define REG_GNUM(num) &r->__gregs[CTX_EPC]
#define REG_GET_PC() &r->__gregs[CTX_MDLO]
#define REG_GET_LO() &r->__gregs[CTX_MDLO]
#define REG_GET_HI() &r->__gregs[CTX_MDHI]
Dump_MIPS()
}
#elif defined CC_BUILD_PSP
static void PrintRegisters(cc_string* str, void* ctx) {
/* Register dumping not implemented */
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile
Expand Up @@ -94,6 +94,11 @@ ifeq ($(PLAT),serenityos)
LIBS=-lgl -lSDL2
endif

ifeq ($(PLAT),irix)
CC=gcc
LIBS=-lGL -lX11 -lXi -lm -lpthread -ldl
endif

ifeq ($(PLAT),psp)
CC=psp-gcc
LIBS=-lm -lpspgum -lpspgu -lpspge -lpspdisplay
Expand Down Expand Up @@ -129,6 +134,8 @@ haiku:
$(MAKE) $(ENAME) PLAT=haiku
serenityos:
$(MAKE) $(ENAME) PLAT=serenityos
irix:
$(MAKE) $(ENAME) PLAT=irix
psp:
$(MAKE) ClassiCube.elf PLAT=psp

Expand Down
26 changes: 25 additions & 1 deletion src/Platform_Posix.c
Expand Up @@ -140,8 +140,12 @@ cc_uint64 Stopwatch_Measure(void) { return gethrtime(); }
#else
cc_uint64 Stopwatch_Measure(void) {
struct timespec t;
#ifdef CC_BUILD_IRIX
clock_gettime(CLOCK_REALTIME, &t);
#else
/* TODO: CLOCK_MONOTONIC_RAW ?? */
clock_gettime(CLOCK_MONOTONIC, &t);
#endif
return (cc_uint64)t.tv_sec * NS_PER_SEC + t.tv_nsec;
}
#endif
Expand Down Expand Up @@ -202,7 +206,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
len = String_Length(src);
String_AppendUtf8(&path, src, len);

#if defined CC_BUILD_HAIKU || defined CC_BUILD_SOLARIS
#if defined CC_BUILD_HAIKU || defined CC_BUILD_SOLARIS || defined CC_BUILD_IRIX
{
char full_path[NATIVE_STR_LEN];
struct stat sb;
Expand Down Expand Up @@ -801,6 +805,16 @@ static cc_result Process_RawGetExePath(char* path, int* len) {
Mem_Copy(path, info.name, *len);
return 0;
}
#elif defined CC_BUILD_IRIX
static cc_result Process_RawGetExePath(char* path, int* len) {
static cc_string file = String_FromConst("ClassiCube");

/* TODO properly get exe path */
/* Maybe use PIOCOPENM from https://nixdoc.net/man-pages/IRIX/man4/proc.4.html */
Mem_Copy(path, file.buffer, file.length);
*len = file.length;
return 0;
}
#endif


Expand Down Expand Up @@ -1008,6 +1022,15 @@ static void Platform_InitPosix(void) {
}
void Platform_Free(void) { }

#ifdef CC_BUILD_IRIX
cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
const char* err = strerror(res);
if (!err || res >= 1000) return false;

String_AppendUtf8(dst, err, String_Length(err));
return true;
}
#else
cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
char chars[NATIVE_STR_LEN];
int len;
Expand All @@ -1024,6 +1047,7 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
String_AppendUtf8(dst, chars, len);
return true;
}
#endif

#if defined CC_BUILD_DARWIN
static void Platform_InitStopwatch(void) {
Expand Down
7 changes: 7 additions & 0 deletions src/Window_X11.c
Expand Up @@ -10,7 +10,9 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#ifdef CC_BUILD_XINPUT2
#include <X11/extensions/XInput2.h>
#endif
#include <stdio.h>

#ifdef X_HAVE_UTF8_STRING
Expand Down Expand Up @@ -1129,6 +1131,7 @@ void Window_CloseKeyboard(void) { }
static cc_bool rawMouseInited, rawMouseSupported;
static int xiOpcode;

#ifdef CC_BUILD_XINPUT2
static void CheckMovementDelta(double dx, double dy) {
/* Despite the assumption that XI_RawMotion is relative, */
/* unfortunately there's a few buggy corner cases out there */
Expand Down Expand Up @@ -1210,6 +1213,10 @@ static void InitRawMouse(void) {
XISelectEvents(win_display, win_rootWin, &evmask, 1);
rawMouseSupported = true;
}
#else
static void HandleGenericEvent(XEvent* e) { }
static void InitRawMouse(void) { }
#endif

void Window_EnableRawMouse(void) {
DefaultEnableRawMouse();
Expand Down

0 comments on commit 3783380

Please sign in to comment.