summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-04-15 10:53:58 -0600
committerGitHub <noreply@github.com>2024-04-15 10:53:58 -0600
commitd9c1ebb6263cc3a2d494c9ece53edb3c8a2a4b39 (patch)
treecffb2a939f6df969461949340fbedc6260241831 /src/os
parent3dd4c071e1ecdf15a30aa37187283f0b974dc825 (diff)
Initial gcc Support (#568)
* Added GCC
Diffstat (limited to 'src/os')
-rw-r--r--src/os/__osDequeueThread.c7
-rw-r--r--src/os/__osLeoInterrupt.c2
-rw-r--r--src/os/libultra_internal.h33
-rw-r--r--src/os/math/llmuldiv.c10
-rw-r--r--src/os/osCreateThread.c1
-rw-r--r--src/os/osEepromLongWrite.c3
-rw-r--r--src/os/osEepromRead.c23
-rw-r--r--src/os/osEepromWrite.c19
-rw-r--r--src/os/osint.h5
9 files changed, 50 insertions, 53 deletions
diff --git a/src/os/__osDequeueThread.c b/src/os/__osDequeueThread.c
index a9b01fcfc..7f4287cdd 100644
--- a/src/os/__osDequeueThread.c
+++ b/src/os/__osDequeueThread.c
@@ -1,10 +1,15 @@
#include "libultra_internal.h"
-OSThreadTail __osThreadTail = {NULL, -1};
+#ifndef AVOID_UB
+OSThread *__osThreadTail = NULL;
+u32 __osTest = -1;
OSThread *__osRunQueue = (OSThread *) &__osThreadTail;
OSThread *__osActiveQueue = (OSThread *) &__osThreadTail;
OSThread *__osRunningThread = NULL;
OSThread *__osFaultedThread = NULL;
+#else
+OSThread_ListHead __osThreadTail_fix = {NULL, -1, (OSThread *) &__osThreadTail_fix, (OSThread *) &__osThreadTail_fix, NULL, 0};
+#endif
void __osDequeueThread(OSThread **queue, OSThread *thread) {
register OSThread **a2;
diff --git a/src/os/__osLeoInterrupt.c b/src/os/__osLeoInterrupt.c
index d08a40e5e..e77c5af6d 100644
--- a/src/os/__osLeoInterrupt.c
+++ b/src/os/__osLeoInterrupt.c
@@ -1,8 +1,8 @@
#include "ultra64.h"
#include "osint.h"
#include "piint.h"
+#include "libultra_internal.h"
-extern OSThread *__osRunQueue;
static void __osLeoResume(void);
static void __osLeoAbnormalResume(void);
extern u8 leoDiskStack[OS_PIM_STACKSIZE]; //technically should have a OS_LEO_STACKSIZE or something..
diff --git a/src/os/libultra_internal.h b/src/os/libultra_internal.h
index 3e7032370..5a6027f75 100644
--- a/src/os/libultra_internal.h
+++ b/src/os/libultra_internal.h
@@ -1,6 +1,7 @@
#ifndef _LIBULTRA_INTERNAL_H_
#define _LIBULTRA_INTERNAL_H_
#include <ultra64.h>
+#include <PR/os_thread.h>
#include "macros.h"
typedef struct __OSEventState
@@ -15,15 +16,41 @@ typedef struct __osThreadTail
OSPri priority;
} OSThreadTail;
+/*
+ * This define is needed because the original definitions in __osDequeueThread.c are declared
+ * seperately instead of part of a single struct, however some code alises over this memory
+ * assuming a unified structure. To fix this, we declare the full type here and then alias the
+ * symbol names to the correct members in AVOID_UB.
+ */
+typedef struct
+{
+ /*0x00*/ struct OSThread_s *next;
+ /*0x04*/ OSPri priority;
+ /*0x08*/ struct OSThread_s *queue;
+ /*0x0C*/ struct OSThread_s *tlnext;
+ /*0x10*/ struct OSThread_s *unk10;
+ /*0x14*/ u32 unk14;
+} OSThread_ListHead;
+#ifdef AVOID_UB
+
+// Now fix the symbols to the new one.
+extern OSThread_ListHead __osThreadTail_fix;
+
+#define __osThreadTail __osThreadTail_fix.next
+#define D_80334894 __osThreadTail_fix.priority
+#define __osRunQueue __osThreadTail_fix.queue
+#define __osActiveQueue __osThreadTail_fix.tlnext
+#define __osRunningThread __osThreadTail_fix.unk10
+#else
// Original OSThread_ListHead definitions
-extern OSThreadTail __osThreadTail;
+extern OSThread *__osThreadTail;
extern OSThread *__osActiveQueue;
extern OSThread *__osRunQueue;
extern OSThread *__osRunningThread;
-
+#endif
// Original EEPROM definitions
-extern ALIGNED8 u32 D_80365E00[15];
+extern u32 D_80365E00[15];
extern u32 D_80365E3C;
typedef struct {
diff --git a/src/os/math/llmuldiv.c b/src/os/math/llmuldiv.c
index e64b9d0c8..2af91aae5 100644
--- a/src/os/math/llmuldiv.c
+++ b/src/os/math/llmuldiv.c
@@ -7,7 +7,7 @@ unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1)
return a0 % a1;
}
unsigned long long __ull_div(unsigned long long a0, unsigned long long a1)
-{
+{
return a0 / a1;
}
@@ -34,19 +34,19 @@ unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1)
void __ull_divremi(unsigned long long *div, unsigned long long *rem, unsigned long long a2, unsigned short a3)
{
*div = a2 / a3;
- *rem = a2 % a3;
-}
+ *rem = a2 % a3;
+}
long long __ll_mod(long long a0, long long a1)
{
long long tmp = a0 % a1;
if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0))
{
- tmp += a1;
+ tmp += a1;
}
return tmp;
}
-
+
long long __ll_rshift(long long a0, long long a1)
{
return a0 >> a1;
diff --git a/src/os/osCreateThread.c b/src/os/osCreateThread.c
index d714a8eba..93a6f241f 100644
--- a/src/os/osCreateThread.c
+++ b/src/os/osCreateThread.c
@@ -1,7 +1,6 @@
#include "libultra_internal.h"
void __osCleanupThread(void);
-extern OSThread *__osActiveQueue;
// Don't warn about pointer->u64 cast
diff --git a/src/os/osEepromLongWrite.c b/src/os/osEepromLongWrite.c
index 8a7f72e60..d68104ccd 100644
--- a/src/os/osEepromLongWrite.c
+++ b/src/os/osEepromLongWrite.c
@@ -1,8 +1,7 @@
#include "libultra_internal.h"
+#include "controller.h"
-extern u64 osClockRate;
extern u8 D_80365D20;
-extern u8 _osContNumControllers;
extern OSTimer D_80196548;
extern OSMesgQueue _osContMesgQueue;
extern OSMesg _osContMesgBuff[4];
diff --git a/src/os/osEepromRead.c b/src/os/osEepromRead.c
index a3fc3a4b3..040594444 100644
--- a/src/os/osEepromRead.c
+++ b/src/os/osEepromRead.c
@@ -1,30 +1,11 @@
#include "libultra_internal.h"
-#include "controller.h"
#include "macros.h"
+#include "controller.h"
-extern u8 __osContLastCmd;
+extern u8 _osLastSentSiCmd;
extern OSPifRam __osEepPifRam;
-typedef struct {
- u8 unk00;
- u8 unk01;
- u8 unk02;
- u8 unk03;
- u8 unk04;
- u8 unk05;
- u8 unk06;
- u8 unk07;
-} unkStruct3;
-
-typedef struct {
- u8 unk00;
- u8 unk01;
- u8 unk02;
- u8 unk03;
- unkStruct3 unk04;
-} unkStruct2;
-
s32 __osEepStatus(OSMesgQueue *, OSContStatus *);
void __osPackEepReadData(u8);
diff --git a/src/os/osEepromWrite.c b/src/os/osEepromWrite.c
index 845432502..a48f6873b 100644
--- a/src/os/osEepromWrite.c
+++ b/src/os/osEepromWrite.c
@@ -7,25 +7,6 @@ OSPifRam __osEepPifRam;
extern u8 __osContLastCmd;
-typedef struct {
- u8 unk00;
- u8 unk01;
- u8 unk02;
- u8 unk03;
- u8 unk04;
- u8 unk05;
- u8 unk06;
- u8 unk07;
-} unkStruct3;
-
-typedef struct {
- u8 unk00;
- u8 unk01;
- u8 unk02;
- u8 unk03;
- unkStruct3 unk04;
-} unkStruct2;
-
s32 __osEepStatus(OSMesgQueue *, OSContStatus *);
void __osPackEepWriteData(u8, u8 *);
diff --git a/src/os/osint.h b/src/os/osint.h
index f607d6a6e..9e35c1edb 100644
--- a/src/os/osint.h
+++ b/src/os/osint.h
@@ -1,6 +1,7 @@
#ifndef _OSINT_H
#define _OSINT_H
#include "libultra_internal.h"
+#include <macros.h>
//maybe should be in exceptasm.h?
extern void __osEnqueueAndYield(OSThread **);
@@ -15,10 +16,14 @@ extern void __osTimerInterrupt(void);
extern u32 __osProbeTLB(void *);
extern int __osSpDeviceBusy(void);
+#ifdef AVOID_UB
+extern OSThread_ListHead __osThreadTail_fix;
+#else
extern OSThread *__osRunningThread;
extern OSThread *__osActiveQueue;
extern OSThread *__osFaultedThread;
extern OSThread *__osRunQueue;
+#endif
extern OSTimer *__osTimerList;
extern OSTimer __osBaseTimer;