SSBM Decomp
Loading...
Searching...
No Matches
os.h
Go to the documentation of this file.
1#ifndef _DOLPHIN_OS_H_
2#define _DOLPHIN_OS_H_
3
4#include <dolphin/types.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef s64 OSTime;
11typedef u32 OSTick;
12
15
17
18typedef void (*__OSInterruptHandler)(__OSInterrupt interrupt,
19 OSContext* context);
20
21// IWYU pragma: begin_exports
22#include <dolphin/os/OSAlarm.h>
23#include <dolphin/os/OSAlloc.h>
24#include <dolphin/os/OSCache.h>
25#include <dolphin/os/OSDC.h>
26#include <dolphin/os/OSError.h>
29#include <dolphin/os/OSFont.h>
30#include <dolphin/os/OSIC.h>
32#include <dolphin/os/OSL2.h>
33#include <dolphin/os/OSLC.h>
35#include <dolphin/os/OSModule.h>
36#include <dolphin/os/OSMutex.h>
37#include <dolphin/os/OSReboot.h>
38#include <dolphin/os/OSReset.h>
40#include <dolphin/os/OSRtc.h>
41#include <dolphin/os/OSSerial.h>
43#include <dolphin/os/OSThread.h>
44#include <dolphin/os/OSTime.h>
45// IWYU pragma: end_exports
46
47// private macro, maybe shouldn't be defined here?
48#define OFFSET(addr, align) (((u32) (addr) & ((align) - 1)))
49#define ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1))
50#define TRUNC(n, a) (((u32) (n)) & ~((a) - 1))
51
54
55// Upper words of the masks, since UIMM is only 16 bits
56#define OS_CACHED_REGION_PREFIX 0x8000
57#define OS_UNCACHED_REGION_PREFIX 0xC000
58#define OS_PHYSICAL_MASK 0x3FFF
59
60#define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16)
61#define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16)
62
63#if defined(__MWERKS__) && !defined(M2CTX)
64u32 __OSPhysicalMemSize : (OS_BASE_CACHED | 0x0028);
65volatile int __OSTVMode : (OS_BASE_CACHED | 0x00CC);
66OSThread* __gUnkThread1 : (OS_BASE_CACHED | 0x00D8);
68OSThread* __gCurrentThread : (OS_BASE_CACHED | 0x00E4);
69u32 __OSSimulatedMemSize : (OS_BASE_CACHED | 0x00F0);
72int __EXIProbeStartTime[2] : (OS_BASE_CACHED | 0x30C0);
73#else
74#define __OSBusClock (*(u32*) (OS_BASE_CACHED | 0x00F8))
75#define __OSCoreClock (*(u32*) (OS_BASE_CACHED | 0x00FC))
76#endif
77#define OS_BUS_CLOCK __OSBusClock
78#define OS_CORE_CLOCK __OSCoreClock
79#define OS_TIMER_CLOCK (OS_BUS_CLOCK / 4)
80
81#define OSTicksToSeconds(ticks) ((ticks) / (OS_TIMER_CLOCK))
82#define OSTicksToMilliseconds(ticks) ((ticks) / (OS_TIMER_CLOCK / 1000))
83#define OSTicksToMicroseconds(ticks) ((ticks) * 8 / (OS_TIMER_CLOCK / 125000))
84#define OSSecondsToTicks(sec) ((sec) * (OS_TIMER_CLOCK))
85#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000))
86#define OSNanosecondsToTicks(nsec) \
87 (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000)
88#define OSMicrosecondsToTicks(usec) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8)
89
90unsigned long OSGetConsoleType(void);
91void OSInit(void);
92
93void* OSGetArenaHi(void);
94void* OSGetArenaLo(void);
95void OSSetArenaHi(void*);
96void OSSetArenaLo(void*);
97void* OSAllocFromArenaLo(u32 size, u32 align);
98void* OSAllocFromArenaHi(u32 size, u32 align);
99
101
104
105typedef struct OSCalendarTime {
106 /*0x00*/ int sec;
107 /*0x04*/ int min;
108 /*0x08*/ int hour;
109 /*0x0C*/ int mday;
110 /*0x10*/ int mon;
111 /*0x14*/ int year;
112 /*0x18*/ int wday;
113 /*0x1C*/ int yday;
114 /*0x20*/ int msec;
115 /*0x24*/ int usec;
117
118#include <dolphin/dvd.h>
119
120typedef struct OSBootInfo_s {
121 // total size: 0x40
122 DVDDiskID DVDDiskID; // offset 0x0, size 0x20
123 unsigned long magic; // offset 0x20, size 0x4
124 unsigned long version; // offset 0x24, size 0x4
125 unsigned long memorySize; // offset 0x28, size 0x4
126 unsigned long consoleType; // offset 0x2C, size 0x4
127 void* arenaLo; // offset 0x30, size 0x4
128 void* arenaHi; // offset 0x34, size 0x4
129 void* FSTLocation; // offset 0x38, size 0x4
130 unsigned long FSTMaxLength; // offset 0x3C, size 0x4
131} OSBootInfo;
132
140
141#define OS_CONSOLE_MASK 0xf0000000
142#define OS_CONSOLE_RETAIL 0x00000000
143#define OS_CONSOLE_DEVELOPMENT 0x10000000
144#define OS_CONSOLE_TDEV 0x20000000
145
146#define OS_CONSOLE_RETAIL4 0x00000004
147#define OS_CONSOLE_RETAIL3 0x00000003
148#define OS_CONSOLE_RETAIL2 0x00000002
149#define OS_CONSOLE_RETAIL1 0x00000001
150#define OS_CONSOLE_TDEVHW4 0x20000007
151#define OS_CONSOLE_TDEVHW3 0x20000006
152#define OS_CONSOLE_TDEVHW2 0x20000005
153#define OS_CONSOLE_TDEVHW1 0x20000004
154#define OS_CONSOLE_DEVHW4 0x10000007
155#define OS_CONSOLE_DEVHW3 0x10000006
156#define OS_CONSOLE_DEVHW2 0x10000005
157#define OS_CONSOLE_DEVHW1 0x10000004
158#define OS_CONSOLE_MINNOW 0x10000003
159#define OS_CONSOLE_ARTHUR 0x10000002
160#define OS_CONSOLE_PC_EMULATOR 0x10000001
161#define OS_CONSOLE_EMULATOR 0x10000000
162
163#define OS_SOUND_MODE_MONO 0
164#define OS_SOUND_MODE_STEREO 1
165
168
169#ifndef DOLPHIN_ATTRIBUTE_NORETURN
170#if defined(__clang__) || defined(__GNUC__)
171#define DOLPHIN_ATTRIBUTE_NORETURN __attribute__((noreturn))
172#else
173#define DOLPHIN_ATTRIBUTE_NORETURN
174#endif
175#endif
176
177void OSReport(char*, ...);
178DOLPHIN_ATTRIBUTE_NORETURN void OSPanic(char* file, int line, char* msg, ...);
179
180#define OSRoundUp32B(x) (((u32) (x) + 32 - 1) & ~(32 - 1))
181#define OSRoundDown32B(x) (((u32) (x)) & ~(32 - 1))
182
187void* OSCachedToUncached(void* caddr);
188void* OSUncachedToCached(void* ucaddr);
189#if !DEBUG
190#define OSPhysicalToCached(paddr) \
191 ((void*) ((u32) (OS_BASE_CACHED + (u32) (paddr))))
192#define OSPhysicalToUncached(paddr) \
193 ((void*) ((u32) (OS_BASE_UNCACHED + (u32) (paddr))))
194#define OSCachedToPhysical(caddr) ((u32) ((u32) (caddr) - OS_BASE_CACHED))
195#define OSUncachedToPhysical(ucaddr) \
196 ((u32) ((u32) (ucaddr) - OS_BASE_UNCACHED))
197#define OSCachedToUncached(caddr) \
198 ((void*) ((u8*) (caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED)))
199#define OSUncachedToCached(ucaddr) \
200 ((void*) ((u8*) (ucaddr) - (OS_BASE_UNCACHED - OS_BASE_CACHED)))
201#endif
202
203#ifdef __cplusplus
204}
205#endif
206
207#endif
int BOOL
Definition types.h:20
unsigned long u32
Definition types.h:9
signed short int s16
Definition types.h:6
signed long long int s64
Definition types.h:10
BOOL OSDisableInterrupts(void)
#define OS_BASE_CACHED
Definition os.h:60
OSTime OSGetTime(void)
#define OSUncachedToCached(ucaddr)
Definition os.h:199
BOOL OSRestoreInterrupts(BOOL level)
#define OSCachedToPhysical(caddr)
Definition os.h:194
#define __OSBusClock
Definition os.h:74
void(* __OSInterruptHandler)(__OSInterrupt interrupt, OSContext *context)
Definition os.h:18
#define OSPhysicalToUncached(paddr)
Definition os.h:192
unsigned long OSGetConsoleType(void)
void OSSetArenaLo(void *)
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime *td)
u32 OSGetConsoleSimulatedMemSize(void)
void OSReport(char *,...)
u32 OSGetPhysicalMemSize(void)
s64 OSTime
Definition os.h:10
void OSSetSoundMode(u32 mode)
BOOL OSEnableInterrupts(void)
void * OSAllocFromArenaHi(u32 size, u32 align)
s16 __OSInterrupt
Definition os.h:13
void __OSPSInit()
#define OSCachedToUncached(caddr)
Definition os.h:197
#define DOLPHIN_ATTRIBUTE_NORETURN
Definition os.h:173
u32 OSGetSoundMode(void)
u32 OSTick
Definition os.h:11
#define __OSCoreClock
Definition os.h:75
void * OSGetArenaLo(void)
DOLPHIN_ATTRIBUTE_NORETURN void OSPanic(char *file, int line, char *msg,...)
void OSSetArenaHi(void *)
OSTick OSGetTick(void)
#define OSPhysicalToCached(paddr)
Definition os.h:190
void * OSAllocFromArenaLo(u32 size, u32 align)
void * OSGetArenaHi(void)
OSTime OSCalendarTimeToTicks(OSCalendarTime *td)
#define OSUncachedToPhysical(ucaddr)
Definition os.h:195
u32 __OSGetDIConfig(void)
u32 OSInterruptMask
Definition os.h:14
void OSInit(void)
int td
Definition os.h:120
unsigned long magic
Definition os.h:123
void * arenaHi
Definition os.h:128
DVDDiskID DVDDiskID
Definition os.h:122
unsigned long consoleType
Definition os.h:126
void * FSTLocation
Definition os.h:129
unsigned long FSTMaxLength
Definition os.h:130
void * arenaLo
Definition os.h:127
unsigned long version
Definition os.h:124
unsigned long memorySize
Definition os.h:125
Definition os.h:105
int msec
Definition os.h:114
int mday
Definition os.h:109
int sec
Definition os.h:106
int yday
Definition os.h:113
int mon
Definition os.h:110
int wday
Definition os.h:112
int year
Definition os.h:111
int usec
Definition os.h:115
int min
Definition os.h:107
int hour
Definition os.h:108
Definition OSContext.h:138
Definition OSThread.h:15
Definition OSThread.h:39
OSThreadQueue __OSActiveThreadQueue
Definition targimpl.c:26