Imported most of dolphin/os

This commit is contained in:
dbalatoni13 2024-11-12 19:16:59 +01:00
parent 023cd90675
commit 970da00ce2
35 changed files with 6591 additions and 131 deletions

View file

@ -4,30 +4,33 @@
#include <types.h>
typedef struct OSSram {
u16 checkSum;
u16 checkSumInv;
u32 ead0;
u32 ead1;
u32 counterBias;
s8 displayOffsetH;
u8 ntd;
u8 language;
u8 flags;
u16 checkSum;
u16 checkSumInv;
u32 ead0;
u32 ead1;
u32 counterBias;
s8 displayOffsetH;
u8 ntd;
u8 language;
u8 flags;
} OSSram;
typedef struct OSSramEx {
u8 flashID[2][12];
u32 wirelessKeyboardID;
u16 wirelessPadID[4];
u8 dvdErrorCode;
u8 _padding0;
u8 flashIDCheckSum[2];
u16 gbs;
u8 _padding1[2];
u8 flashID[2][12];
u32 wirelessKeyboardID;
u16 wirelessPadID[4];
u8 dvdErrorCode;
u8 _padding0;
u8 flashIDCheckSum[2];
u16 gbs;
u8 _padding1[2];
} OSSramEx;
OSSram* __OSLockSram();
OSSramEx* __OSLockSramEx();
void __OSInitSram();
OSSram *__OSLockSram();
BOOL __OSSyncSram();
BOOL __OSUnlockSram(BOOL commit);
OSSramEx *__OSLockSramEx();
void OSSetWirelessID(s32 chan, u16 id);
u16 OSGetWirelessID(s32 chan);

View file

@ -23,26 +23,26 @@ extern "C" {
#endif
typedef s64 OSTime;
typedef u32 OSTick;
u32 __OSBusClock AT_ADDRESS(OS_BASE_CACHED | 0x00F8); // sync with OSLoMem.h
u32 __OSBusClock AT_ADDRESS(OS_BASE_CACHED | 0x00F8); // sync with OSLoMem.h
u32 __OSCoreClock AT_ADDRESS(OS_BASE_CACHED | 0x00FC); // sync with OSLoMem.h
#define OS_BUS_CLOCK (u32)__OSBusClock
#define OS_BUS_CLOCK (u32) __OSBusClock
#define OS_CORE_CLOCK __OSCoreClock
#define OS_TIMER_CLOCK (OS_BUS_CLOCK / 4)
#ifndef _DEBUG
#define OSPhysicalToCached(paddr) ((void*)((u32)(paddr) + OS_BASE_CACHED))
#define OSPhysicalToUncached(paddr) ((void*)((u32)(paddr) + OS_BASE_UNCACHED))
#define OSCachedToPhysical(caddr) ((u32)((u8*)(caddr)-OS_BASE_CACHED))
#define OSUncachedToPhysical(ucaddr) ((u32)((u8*)(ucaddr)-OS_BASE_UNCACHED))
#define OSCachedToUncached(caddr) ((void*)((u8*)(caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED)))
#define OSUncachedToCached(ucaddr) ((void*)((u8*)(ucaddr) - (OS_BASE_UNCACHED - OS_BASE_CACHED)))
#define OSPhysicalToCached(paddr) ((void *)((u32)(paddr) + OS_BASE_CACHED))
#define OSPhysicalToUncached(paddr) ((void *)((u32)(paddr) + OS_BASE_UNCACHED))
#define OSCachedToPhysical(caddr) ((u32)((u8 *)(caddr)-OS_BASE_CACHED))
#define OSUncachedToPhysical(ucaddr) ((u32)((u8 *)(ucaddr)-OS_BASE_UNCACHED))
#define OSCachedToUncached(caddr) ((void *)((u8 *)(caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED)))
#define OSUncachedToCached(ucaddr) ((void *)((u8 *)(ucaddr) - (OS_BASE_UNCACHED - OS_BASE_CACHED)))
#else
u32 OSPhysicalToCached(void* paddr);
u32 OSPhysicalToUncached(void* paddr);
u32 OSCachedToPhysical(void* caddr);
u32 OSUncachedToPhysical(void* ucaddr);
u32 OSCachedToUncached(void* caddr);
u32 OSUncachedToCached(void* ucaddr);
u32 OSPhysicalToCached(void *paddr);
u32 OSPhysicalToUncached(void *paddr);
u32 OSCachedToPhysical(void *caddr);
u32 OSUncachedToPhysical(void *ucaddr);
u32 OSCachedToUncached(void *caddr);
u32 OSUncachedToCached(void *ucaddr);
#endif
#define OSTicksToCycles(ticks) (((ticks) * ((OS_CORE_CLOCK * 2) / OS_TIMER_CLOCK)) / 2)
@ -50,7 +50,7 @@ u32 OSUncachedToCached(void* ucaddr);
#define OSTicksToMilliseconds(ticks) ((ticks) / (OS_TIMER_CLOCK / 1000))
#define OSTicksToMicroseconds(ticks) (((ticks)*8) / (OS_TIMER_CLOCK / 125000))
#define OSTicksToNanoseconds(ticks) (((ticks)*8000) / (OS_TIMER_CLOCK / 125000))
#define OSSecondsToTicks(sec) ((sec)*OS_TIMER_CLOCK)
#define OSSecondsToTicks(sec) ((sec)*OS_TIMER_CLOCK)
#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000))
#define OSMicrosecondsToTicks(usec) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8)
#define OSNanosecondsToTicks(nsec) (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000)
@ -60,52 +60,44 @@ u32 OSUncachedToCached(void* ucaddr);
#define OSRoundUp32B(v) (((u32)(v + 31) & ~31))
#define OSRoundDown32B(x) (((u32)(x)) & ~31)
void* OSGetArenaHi(void);
void* OSGetArenaLo(void);
void OSSetArenaHi(void* newHi);
void OSSetArenaLo(void* newLo);
void* OSAllocFromArenaLo(u32 size, u32 align);
void* OSAllocFromArenaHi(u32 size, u32 align);
void OSInit();
OSTime OSGetTime();
OSTick OSGetTick();
typedef struct OSCalendarTime {
int sec; // seconds after the minute [0, 61]
int min; // minutes after the hour [0, 59]
int hour; // hours since midnight [0, 23]
int mday; // day of the month [1, 31]
int mon; // month since January [0, 11]
int year; // years in AD [1, ...]
int wday; // days since Sunday [0, 6]
int yday; // days since January 1 [0, 365]
int sec; // seconds after the minute [0, 61]
int min; // minutes after the hour [0, 59]
int hour; // hours since midnight [0, 23]
int mday; // day of the month [1, 31]
int mon; // month since January [0, 11]
int year; // years in AD [1, ...]
int wday; // days since Sunday [0, 6]
int yday; // days since January 1 [0, 365]
int msec; // milliseconds after the second [0,999]
int usec; // microseconds after the millisecond [0,999]
int msec; // milliseconds after the second [0,999]
int usec; // microseconds after the millisecond [0,999]
} OSCalendarTime;
OSTime OSCalendarTimeToTicks(OSCalendarTime* td);
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* td);
OSTime OSCalendarTimeToTicks(OSCalendarTime *td);
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime *td);
typedef struct OSStopwatch {
char* name;
OSTime total;
u32 hits;
OSTime min;
OSTime max;
OSTime last;
BOOL running;
char *name;
OSTime total;
u32 hits;
OSTime min;
OSTime max;
OSTime last;
BOOL running;
} OSStopwatch;
void OSInitStopwatch(OSStopwatch* sw, char* name);
void OSStartStopwatch(OSStopwatch* sw);
void OSStopStopwatch(OSStopwatch* sw);
OSTime OSCheckStopwatch(OSStopwatch* sw);
void OSResetStopwatch(OSStopwatch* sw);
void OSDumpStopwatch(OSStopwatch* sw);
void OSInitStopwatch(OSStopwatch *sw, char *name);
void OSStartStopwatch(OSStopwatch *sw);
void OSStopStopwatch(OSStopwatch *sw);
OSTime OSCheckStopwatch(OSStopwatch *sw);
void OSResetStopwatch(OSStopwatch *sw);
void OSDumpStopwatch(OSStopwatch *sw);
#define OS_CONSOLE_MASK 0xf0000000
#define OS_CONSOLE_RETAIL 0x00000000
@ -159,7 +151,7 @@ void OSSetLanguage(u8 language);
u32 OSGetEuRgb60Mode(void);
void OSSetEuRgb60Mode(u32 on);
void OSRegisterVersion(const char* id);
void OSRegisterVersion(const char *id);
BOOL OSDisableInterrupts(void);
BOOL OSEnableInterrupts(void);
@ -174,8 +166,7 @@ BOOL OSRestoreInterrupts(BOOL level);
#endif
#ifndef ASSERTMSG
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || \
defined(__SN__)
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || defined(__SN__)
#define ASSERTMSG(exp, ...) (void)((exp) || (OSPanic(__FILE__, __LINE__, __VA_ARGS__), 0))
#else
#define ASSERTMSG(exp, msg) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg)), 0))
@ -183,23 +174,20 @@ BOOL OSRestoreInterrupts(BOOL level);
#endif
#ifndef ASSERTMSG1
#define ASSERTMSG1(exp, msg, param1) \
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1)), 0))
#define ASSERTMSG1(exp, msg, param1) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1)), 0))
#endif
#ifndef ASSERTMSG2
#define ASSERTMSG2(exp, msg, param1, param2) \
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2)), 0))
#define ASSERTMSG2(exp, msg, param1, param2) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2)), 0))
#endif
#ifndef ASSERTMSG3
#define ASSERTMSG3(exp, msg, param1, param2, param3) \
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3)), 0))
#define ASSERTMSG3(exp, msg, param1, param2, param3) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3)), 0))
#endif
#ifndef ASSERTMSG4
#define ASSERTMSG4(exp, msg, param1, param2, param3, param4) \
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3), (param4)), 0))
#define ASSERTMSG4(exp, msg, param1, param2, param3, param4) \
(void)((exp) || (OSPanic(__FILE__, __LINE__, (msg), (param1), (param2), (param3), (param4)), 0))
#endif
#else // _DEBUG
@ -209,8 +197,7 @@ BOOL OSRestoreInterrupts(BOOL level);
#endif
#ifndef ASSERTMSG
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || \
defined(__SN__)
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__MWERKS__) || defined(__SN__)
#define ASSERTMSG(exp, ...) ((void)0)
#else
#define ASSERTMSG(exp, msg) ((void)0)
@ -232,9 +219,9 @@ BOOL OSRestoreInterrupts(BOOL level);
#endif // _DEBUG
void OSReport(const char* msg, ...);
void OSPanic(const char* file, int line, const char* msg, ...);
void OSFatal(GXColor fg, GXColor bg, const char* msg);
void OSReport(const char *msg, ...);
void OSPanic(const char *file, int line, const char *msg, ...);
void OSFatal(GXColor fg, GXColor bg, const char *msg);
u32 OSGetPhysicalMemSize(void);
u32 OSGetConsoleSimulatedMemSize(void);
@ -253,6 +240,7 @@ u32 OSGetConsoleSimulatedMemSize(void);
#include <dolphin/os/OSExpansion.h>
#include <dolphin/os/OSFastCast.h>
#include <dolphin/os/OSFont.h>
#include <dolphin/os/OSIC.h>
#include <dolphin/os/OSInterrupt.h>
#include <dolphin/os/OSMemory.h>
#include <dolphin/os/OSMessage.h>

View file

@ -7,19 +7,18 @@
extern "C" {
#endif
typedef int OSHeapHandle;
typedef void (*OSAllocVisitor)(void* obj, u32 size);
void* OSInitAlloc(void* arenaStart, void* arenaEnd, int maxHeaps);
OSHeapHandle OSCreateHeap(void* start, void* end);
typedef void (*OSAllocVisitor)(void *obj, u32 size);
void *OSInitAlloc(void *arenaStart, void *arenaEnd, int maxHeaps);
OSHeapHandle OSCreateHeap(void *start, void *end);
void OSDestroyHeap(OSHeapHandle heap);
void OSAddToHeap(OSHeapHandle heap, void* start, void* end);
void OSAddToHeap(OSHeapHandle heap, void *start, void *end);
OSHeapHandle OSSetCurrentHeap(OSHeapHandle heap);
void* OSAllocFromHeap(OSHeapHandle heap, u32 size);
void* OSAllocFixed(void** rstart, void** rend);
void OSFreeToHeap(OSHeapHandle heap, void* ptr);
void *OSAllocFromHeap(OSHeapHandle heap, u32 size);
void *OSAllocFixed(void **rstart, void **rend);
void OSFreeToHeap(OSHeapHandle heap, void *ptr);
long OSCheckHeap(OSHeapHandle heap);
void OSDumpHeap(OSHeapHandle heap);
void *OSAllocFixed(void **rstart, void **rend);
u32 OSReferentSize(void* ptr);
u32 OSReferentSize(void *ptr);
void OSVisitAllocated(OSAllocVisitor visitor);
extern volatile OSHeapHandle __OSCurrHeap;
#define OSAlloc(size) OSAllocFromHeap(__OSCurrHeap, (size))

View file

@ -158,10 +158,16 @@ typedef struct OSContext {
} OSContext;
u32 OSGetStackPointer(void);
void OSDumpContext(OSContext *context);
u32 OSSaveContext(OSContext* context);
void OSLoadContext(OSContext* context);
void OSClearContext(OSContext* context);
OSContext* OSGetCurrentContext();
void OSSetCurrentContext(OSContext* context);
void OSSaveFPUContext(OSContext *fpuContext);
void OSInitContext(OSContext *context, u32 pc, u32 newsp);
#ifdef __cplusplus
}

View file

@ -9,17 +9,44 @@ extern "C" {
#define OS_FONT_ENCODE_ANSI 0u
#define OS_FONT_ENCODE_SJIS 1u
#define OS_FONT_ENCODE_UTF8 3u // UTF-8 [RFC 3629]
#define OS_FONT_ENCODE_UTF16 4u // UTF-16BE [RFC 2781]
#define OS_FONT_ENCODE_UTF32 5u // UTF-32
#define OS_FONT_ENCODE_MAX 5u
#define OS_FONT_ENCODE_VOID 0xffffu
#define OS_FONT_SIZE_ANSI (288 + 131072) // 9 sheets
#define OS_FONT_SIZE_SJIS (3840 + 1179648) // 1 sheet
#define OS_FONT_ROM_SIZE_ANSI 0x03000
#define OS_FONT_ROM_SIZE_SJIS 0x4D000
#define OS_FONT_PROPORTIONAL FALSE
#define OS_FONT_FIXED TRUE
typedef struct OSFontHeader
{
/*0x00*/ u16 fontType;
u16 firstChar;
u16 lastChar;
u16 invalChar;
/*0x08*/ u16 ascent;
u16 descent;
u16 width;
u16 leading;
/*0x10*/ u16 cellWidth;
u16 cellHeight;
/*0x14*/ u32 sheetSize;
/*0x18*/ u16 sheetFormat;
u16 sheetColumn;
u16 sheetRow;
u16 sheetWidth;
/*0x20*/ u16 sheetHeight;
u16 widthTable;
u32 sheetImage;
u32 sheetFullSize;
u8 c0;
u8 c1;
u8 c2;
u8 c3;
} OSFontHeader;
u16 OSGetFontEncode(void);
u16 OSSetFontEncode(u16 encode);
BOOL OSInitFont(OSFontHeader *fontData);
u32 OSLoadFont(OSFontHeader *fontData, void *temp);
char *OSGetFontTexture(char *string, void **image, s32 *x, s32 *y, s32 *width);
char *OSGetFontWidth(char *string, s32 *width);
char *OSGetFontTexel(char *string, void *image, s32 pos, s32 stride, s32 *width);
#ifdef __cplusplus
}

20
include/dolphin/os/OSIC.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef _DOLPHIN_OSIC
#define _DOLPHIN_OSIC
#ifdef __cplusplus
extern "C" {
#endif
void ICFlashInvalidate(void);
void ICEnable(void);
void ICDisable(void);
void ICFreeze(void);
void ICUnfreeze(void);
void ICBlockInvalidate(void *addr);
void ICSync(void);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -105,8 +105,8 @@ BOOL OSUnlink(OSModuleInfo* oldModule);
OSModuleInfo* OSSearchModule(void* ptr, u32* section, u32* offset);
// debugger notification
void OSNotifyLink(OSModuleInfo* module);
void OSNotifyUnlink(OSModuleInfo* module);
void OSNotifyLink(void);
void OSNotifyUnlink(void);
#ifdef __cplusplus
}

View file

@ -7,10 +7,42 @@
extern "C" {
#endif
#define OFFSET(addr, align) (((u32)(addr) & ((align)-1)))
// OSAudioSystem.c
void __OSInitAudioSystem(void);
void __OSStopAudioSystem(void);
// OSCache.c
void __OSCacheInit(void);
// OSContext.c
void __OSContextInit(void);
// OSMutex.c
void __OSUnlockAllMutex(struct OSThread *thread);
// OSInterrupt.c
extern void __RAS_OSDisableInterrupts_begin(void);
extern void __RAS_OSDisableInterrupts_end(void);
void __OSInterruptInit(void);
void __OSModuleInit(void);
void __OSInitSystemCall(void);
// OSThread.c
void __OSThreadInit(void);
void __OSReschedule(void);
typedef void (*OSExceptionHandler)(__OSException, OSContext*);
OSExceptionHandler __OSSetExceptionHandler(__OSException exception, OSExceptionHandler handler);
__OSExceptionHandler __OSGetExceptionHandler(__OSException exception);
OSTime __OSGetSystemTime();
OSTime __OSTimeToSystemTime(OSTime);
// OSReboot
void __OSReboot(u32 resetCode, u32 bootDol);
#ifdef __cplusplus
}
#endif