mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
Initial work on BSD port
This commit is contained in:
parent
953bb2ca19
commit
524c652bda
3 changed files with 80 additions and 39 deletions
|
@ -99,6 +99,11 @@ typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
|||
#define CC_BUILD_X11
|
||||
#define CC_BUILD_POSIX
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
#define CC_BUILD_BSD
|
||||
#define CC_BUILD_X11
|
||||
#define CC_BUILD_POSIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CC_BUILD_D3D9
|
||||
|
|
71
src/Logger.c
71
src/Logger.c
|
@ -345,7 +345,7 @@ void Logger_Abort2(ReturnCode result, const char* raw_msg) {
|
|||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Info dumping------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_SOLARIS
|
||||
#if defined CC_BUILD_OSX || defined CC_BUILD_LINUX || defined CC_BUILD_BSD || defined CC_BUILD_SOLARIS
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 8];
|
||||
mcontext_t r;
|
||||
|
@ -355,6 +355,7 @@ static void Logger_DumpRegisters(void* ctx) {
|
|||
String_InitArray(str, strBuffer);
|
||||
String_AppendConst(&str, "-- registers --\n");
|
||||
|
||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_SOLARIS
|
||||
/* TODO: There must be a better way of getting these.. */
|
||||
#ifdef __i386__
|
||||
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r.gregs[11], &r.gregs[8], &r.gregs[10]);
|
||||
|
@ -370,9 +371,48 @@ static void Logger_DumpRegisters(void* ctx) {
|
|||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined CC_BUILD_OSX
|
||||
/* You can find these definitions at /usr/include/mach/i386/_structs.h */
|
||||
#if defined __i386__
|
||||
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r->__ss.__eax, &r->__ss.__ebx, &r->__ss.__ecx);
|
||||
String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r->__ss.__edx, &r->__ss.__esi, &r->__ss.__edi);
|
||||
String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r->__ss.__eip, &r->__ss.__ebp, &r->__ss.__esp);
|
||||
#elif defined __x86_64__
|
||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r->__ss.__rax, &r->__ss.__rbx, &r->__ss.__rcx);
|
||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r->__ss.__rdx, &r->__ss.__rsi, &r->__ss.__rdi);
|
||||
String_Format3(&str, "rip=%x rbp=%x rsp=%x\n", &r->__ss.__rip, &r->__ss.__rbp, &r->__ss.__rsp);
|
||||
String_Format3(&str, "r8 =%x r9 =%x r10=%x\n", &r->__ss.__r8, &r->__ss.__r9, &r->__ss.__r10);
|
||||
String_Format3(&str, "r11=%x r12=%x r13=%x\n", &r->__ss.__r11, &r->__ss.__r12, &r->__ss.__r13);
|
||||
String_Format2(&str, "r14=%x r15=%x\n", &r->__ss.__r14, &r->__ss.__r15);
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined CC_BUILD_BSD
|
||||
#if defined __i386__
|
||||
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r.mc__eax, &r.mc__ebx, &r.mc__ecx);
|
||||
String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r.mc__edx, &r.mc__esi, &r.mc__edi);
|
||||
String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r.mc__eip, &r.mc__ebp, &r.mc__esp);
|
||||
#elif defined __x86_64__
|
||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r.mc__rax, &r.mc__rbx, &r.mc__rcx);
|
||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r.mc__rdx, &r.mc__rsi, &r.mc__rdi);
|
||||
String_Format3(&str, "rip=%x rbp=%x rsp=%x\n", &r.mc__rip, &r.mc__rbp, &r.mc__rsp);
|
||||
String_Format3(&str, "r8 =%x r9 =%x r10=%x\n", &r.mc__r8, &r.mc__r9, &r.mc__r10);
|
||||
String_Format3(&str, "r11=%x r12=%x r13=%x\n", &r.mc__r11, &r.mc__r12, &r.mc__r13);
|
||||
String_Format2(&str, "r14=%x r15=%x\n", &r.mc__r14, &r.mc__r15);
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Logger_Log(&str);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_SOLARIS
|
||||
static void Logger_DumpMemoryMap(void) {
|
||||
String str; char strBuffer[STRING_SIZE * 5];
|
||||
int n, fd;
|
||||
|
@ -398,34 +438,7 @@ static void Logger_DumpCommon(String* str, void* ctx) {
|
|||
Logger_Log(&memMap);
|
||||
Logger_DumpMemoryMap();
|
||||
}
|
||||
#elif defined CC_BUILD_OSX
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[STRING_SIZE * 8];
|
||||
mcontext_t r;
|
||||
if (!ctx) return;
|
||||
|
||||
r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
String_InitArray(str, strBuffer);
|
||||
String_AppendConst(&str, "-- registers --\n");
|
||||
|
||||
/* You can find these definitions at /usr/include/mach/i386/_structs.h */
|
||||
#if defined __i386__
|
||||
String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r->__ss.__eax, &r->__ss.__ebx, &r->__ss.__ecx);
|
||||
String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r->__ss.__edx, &r->__ss.__esi, &r->__ss.__edi);
|
||||
String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r->__ss.__eip, &r->__ss.__ebp, &r->__ss.__esp);
|
||||
#elif defined __x86_64__
|
||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r->__ss.__rax, &r->__ss.__rbx, &r->__ss.__rcx);
|
||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r->__ss.__rdx, &r->__ss.__rsi, &r->__ss.__rdi);
|
||||
String_Format3(&str, "rip=%x rbp=%x rsp=%x\n", &r->__ss.__rip, &r->__ss.__rbp, &r->__ss.__rsp);
|
||||
String_Format3(&str, "r8 =%x r9 =%x r10=%x\n", &r->__ss.__r8, &r->__ss.__r9, &r->__ss.__r10);
|
||||
String_Format3(&str, "r11=%x r12=%x r13=%x\n", &r->__ss.__r11, &r->__ss.__r12, &r->__ss.__r13);
|
||||
String_Format2(&str, "r14=%x r15=%x\n", &r->__ss.__r14, &r->__ss.__r15);
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#endif
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
#elif defined CC_BUILD_OSX || defined CC_BUILD_BSD
|
||||
static void Logger_DumpCommon(String* str, void* ctx) {
|
||||
const static String backtrace = String_FromConst("-- backtrace --\n");
|
||||
Logger_Log(&backtrace);
|
||||
|
|
|
@ -85,11 +85,18 @@ const ReturnCode ReturnCode_InvalidArg = EINVAL;
|
|||
const ReturnCode ReturnCode_SocketInProgess = EINPROGRESS;
|
||||
const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
|
||||
#endif
|
||||
/* Platform specific include files */
|
||||
#ifdef CC_BUILD_LINUX
|
||||
#include <X11/Xlib.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
#ifdef CC_BUILD_BSD
|
||||
#include <X11/Xlib.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#ifdef CC_BUILD_SOLARIS
|
||||
#include <X11/Xlib.h>
|
||||
#include <AL/al.h>
|
||||
|
@ -347,7 +354,7 @@ void DateTime_CurrentLocal(struct DateTime* time_) {
|
|||
|
||||
#define NS_PER_SEC 1000000000ULL
|
||||
#endif
|
||||
#ifdef CC_BUILD_LINUX
|
||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_BSD
|
||||
uint64_t Stopwatch_Measure(void) {
|
||||
struct timespec t;
|
||||
/* TODO: CLOCK_MONOTONIC_RAW ?? */
|
||||
|
@ -1240,6 +1247,9 @@ static void Font_Init(void) {
|
|||
#ifdef CC_BUILD_LINUX
|
||||
const static String dir = String_FromConst("/usr/share/fonts");
|
||||
#endif
|
||||
#ifdef CC_BUILD_BSD
|
||||
const static String dir = String_FromConst("/usr/local/share/fonts");
|
||||
#endif
|
||||
#ifdef CC_BUILD_SOLARIS
|
||||
const static String dir = String_FromConst("/usr/share/fonts");
|
||||
#endif
|
||||
|
@ -2059,13 +2069,15 @@ static void Platform_InitDisplay(void) {
|
|||
DisplayDevice_Default.BitsPerPixel = DefaultDepth(display, screen);
|
||||
}
|
||||
#endif
|
||||
#ifdef CC_BUILD_LINUX
|
||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_BSD || defined CC_BUILD_SOLARIS
|
||||
ReturnCode Platform_StartOpen(const String* args) {
|
||||
/* TODO: Can this also be used on solaris, or is it just an OpenIndiana thing */
|
||||
const static String path = String_FromConst("xdg-open");
|
||||
return Platform_StartProcess(&path, args);
|
||||
}
|
||||
static void Platform_InitStopwatch(void) { sw_freqDiv = 1000; }
|
||||
|
||||
#endif
|
||||
#ifdef CC_BUILD_LINUX
|
||||
ReturnCode Platform_GetExePath(String* path) {
|
||||
char str[600];
|
||||
int len = readlink("/proc/self/exe", str, 600);
|
||||
|
@ -2075,14 +2087,25 @@ ReturnCode Platform_GetExePath(String* path) {
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef CC_BUILD_SOLARIS
|
||||
ReturnCode Platform_StartOpen(const String* args) {
|
||||
/* TODO: Is this on solaris, or just an OpenIndiana thing */
|
||||
const static String path = String_FromConst("xdg-open");
|
||||
return Platform_StartProcess(&path, args);
|
||||
}
|
||||
static void Platform_InitStopwatch(void) { sw_freqDiv = 1000; }
|
||||
#ifdef CC_BUILD_BSD
|
||||
ReturnCode Platform_GetExePath(String* path) {
|
||||
char str[600];
|
||||
int mib[4];
|
||||
size_t size = 600;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PATHNAME;
|
||||
mib[3] = -1; /* self process id */
|
||||
|
||||
if (sysctl(mib, 4, str, &size, NULL, 0) == -1) return errno;
|
||||
|
||||
size = String_CalcLen(str, 600);
|
||||
Convert_DecodeUtf8(path, str, size);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef CC_BUILD_SOLARIS
|
||||
ReturnCode Platform_GetExePath(String* path) {
|
||||
char str[600];
|
||||
int len = readlink("/proc/self/path/a.out", str, 600);
|
||||
|
|
Loading…
Add table
Reference in a new issue