29 u64 at, v0, v1, a0, a1, a2, a3;
30 u64 t0, t1, t2, t3, t4, t5, t6, t7;
31 u64 s0, s1, s2, s3, s4, s5, s6, s7;
32 u64 t8, t9, gp, sp,
s8, ra;
34 u32 sr, pc, cause, badvaddr, rcp;
36 __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14;
37 __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30;
54#define OS_STATE_STOPPED 1
55#define OS_STATE_RUNNABLE 2
56#define OS_STATE_RUNNING 4
57#define OS_STATE_WAITING 8
60#define OS_PRIORITY_MAX 255
61#define OS_PRIORITY_VIMGR 254
62#define OS_PRIORITY_RMON 250
63#define OS_PRIORITY_RMONSPIN 200
64#define OS_PRIORITY_PIMGR 150
65#define OS_PRIORITY_SIMGR 140
66#define OS_PRIORITY_APPMAX 127
67#define OS_PRIORITY_IDLE 0
86#define OS_MESG_NOBLOCK 0
87#define OS_MESG_BLOCK 1
92#define OS_EVENT_CART 2
93#define OS_EVENT_COUNTER 3
100#define OS_EVENT_CPU_BREAK 10
101#define OS_EVENT_SP_BREAK 11
102#define OS_EVENT_FAULT 12
103#define OS_EVENT_THREADSTATUS 13
104#define OS_EVENT_PRENMI 14
107#define MQ_GET_COUNT(mq) ((mq)->validCount)
109#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0)
111#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount)
114#define OS_IM_NONE 0x00000001
115#define OS_IM_SW1 0x00000501
116#define OS_IM_SW2 0x00000601
117#define OS_IM_RCP 0x00000401
118#define OS_IM_CART 0x00000C01
119#define OS_IM_PRENMI 0x00001401
120#define OS_IM_RDBWRITE 0x00002401
121#define OS_IM_RDBREAD 0x00004401
122#define OS_IM_COUNTER 0x00008401
123#define OS_IM_CPU 0x0000FF01
124#define OS_IM_SP 0x00010401
125#define OS_IM_SI 0x00020401
126#define OS_IM_AI 0x00040401
127#define OS_IM_VI 0x00080401
128#define OS_IM_PI 0x00100401
129#define OS_IM_DP 0x00200401
130#define OS_IM_ALL 0x003FFF01
146#define OS_CLOCK_RATE 62500000LL
148#define OS_CPU_COUNTER (OS_CLOCK_RATE * 3 / 4)
150#define OS_NSEC_TO_CYCLES(n) \
151 (((u64)(n) * (OS_CPU_COUNTER / 15625000LL)) / (1000000000LL / 15625000LL))
153#define OS_USEC_TO_CYCLES(n) (((u64)(n) * (OS_CPU_COUNTER / 15625LL)) / (1000000LL / 15625LL))
155#define OS_CYCLES_TO_NSEC(c) \
156 (((u64)(c) * (1000000000LL / 15625000LL)) / (OS_CPU_COUNTER / 15625000LL))
158#define OS_CYCLES_TO_USEC(c) (((u64)(c) * (1000000LL / 15625LL)) / (OS_CPU_COUNTER / 15625LL))
178 __OSBlockInfo block[2];
235#define OS_MESG_PRI_NORMAL 0
236#define OS_MESG_PRI_HIGH 1
239#define OS_MESG_TYPE_BASE 10
240#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE + 0)
241#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE + 1)
242#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE + 2)
243#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE + 3)
244#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE + 4)
245#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE + 5)
246#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE + 6)
249#define DEVICE_TYPE_CART 0
250#define DEVICE_TYPE_BULK 1
251#define DEVICE_TYPE_64DD 2
252#define DEVICE_TYPE_SRAM 3
253#define DEVICE_TYPE_INIT 7
282#define VI_NTSC_CLOCK 48681812
283#define VI_PAL_CLOCK 49656530
284#define VI_MPAL_CLOCK 48628316
317#define OS_VI_GAMMA_ON 0x0001
318#define OS_VI_GAMMA_OFF 0x0002
319#define OS_VI_GAMMA_DITHER_ON 0x0004
320#define OS_VI_GAMMA_DITHER_OFF 0x0008
321#define OS_VI_DIVOT_ON 0x0010
322#define OS_VI_DIVOT_OFF 0x0020
323#define OS_VI_DITHER_FILTER_ON 0x0040
324#define OS_VI_DITHER_FILTER_OFF 0x0080
336#if TGR_REGION == TGR_REGION_EU
944s32 __osAiDeviceBusy(
void);
1002#if TGR_PLATFORM == TGR_PLATFORM_N64
1009unsigned long long __ull_rshift(
unsigned long long a0,
unsigned long long a1);
1017unsigned long long __ull_rem(
unsigned long long a0,
unsigned long long a1);
1025unsigned long long __ull_div(
unsigned long long a0,
unsigned long long a1);
1033long long __ll_lshift(
long long a0,
long long a1);
1041long long __ll_rem(
unsigned long long a0,
long long a1);
1049long long __ll_div(
long long a0,
long long a1);
1057long long __ll_mul(
long long a0,
long long a1);
1065void __ull_divremi(
unsigned long long *quotient,
1066 unsigned long long *remainder,
1067 unsigned long long dividend,
1068 unsigned short divisor);
1076long long __ll_mod(
long long a0,
long long a1);
1084long long __ll_rshift(
long long a0,
long long a1);
1093long long __d_to_ll(
double d);
1101long long __f_to_ll(
float f);
1109unsigned long long __d_to_ull(
double d);
1117unsigned long long __f_to_ull(
float f);
1125double __ll_to_d(
long long s);
1133float __ll_to_f(
long long s);
1141double __ull_to_d(
unsigned long long u);
1149float __ull_to_f(
unsigned long long u);
void osSyncPrintf(const char *fmt,...)
Print to the debugger.
u32 OSPageMask
Definition os.h:72
u32 osResetType
The reset type reported by IPL3.
void osCreateViManager(OSPri pri)
Start the VI manager thread at priority pri.
int osSetTimer(OSTimer *t, OSTime countdown, OSTime interval, OSMesgQueue *mq, OSMesg msg)
Start a timer that sends msg to mq after countdown cycles, or after interval cycles when countdown is...
u64 osClockRate
The rate of the CPU counter, OS_CPU_COUNTER until osInitialize() sets it.
void osYieldThread(void)
Put the running thread at the end of the threads of its priority and dispatch.
void osViSetSpecialFeatures(u32 func)
Turn the gamma, gamma dither, divot, and dither filter features on and off, from the OS_VI_* flags.
OSIntMask osSetIntMask(OSIntMask im)
Set the CPU and RCP interrupts that may occur, within the global mask.
s32 osEPiRawStartDma(OSPiHandle *pihandle, s32 direction, u32 devAddr, void *dramAddr, u32 size)
Start a DMA with the device a handle describes, selecting its domain timing when another handle selec...
u32 osCicId
The cartridge CIC identifier reported by IPL3.
s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, u32 devAddr, void *vAddr, u32 nbytes, OSMesgQueue *mq)
Queue a DMA request with the PI manager.
OSIntMask osGetIntMask(void)
Return the CPU and RCP interrupts that may occur.
void osSetThreadPri(OSThread *t, OSPri pri)
Change the priority of a thread, a NULL thread being the running one, and yield when a runnable threa...
s32 OSId
Definition os.h:18
void osCreateThread(OSThread *t, OSId id, void(*entry)(void *), void *arg, void *sp, OSPri pri)
Create a stopped thread on the active queue.
void osViSwapBuffer(void *frameBufPtr)
Show a frame buffer from the next field on.
void osWritebackDCache(void *vaddr, s32 nbytes)
Write back the data cache over a range.
s32 osViClock
The frequency of the video clock.
u32 OSIntMask
Definition os.h:71
s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flag)
Append a message to a queue and make its first receiver runnable.
void osInvalDCache(void *vaddr, s32 nbytes)
Invalidate the data cache over a range.
u32 osTvType
The television standard reported by IPL3.
OSViMode osViModePalLan1
The low-resolution PAL video mode with anti-aliasing.
struct OSPiHandle_s OSPiHandle
A device on the peripheral interface, with the timing of its PI domain.
void osSetEventMesg(OSEvent e, OSMesgQueue *mq, OSMesg m)
Register the queue and message that event e sends.
struct OSTimer_s OSTimer
A timer that sends a message when it expires, once or periodically.
void osViBlack(u8 active)
Blank the screen from the next field on, or show it again.
u64 OSTime
Definition os.h:133
u32 osVersion
The operating-system version reported by IPL3.
u8 aiHdwrBugFlag
Whether the last buffer osAiSetNextBuffer() queued ended 0x2000 bytes into a 16 KiB page,...
void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt)
Start the PI manager thread at priority pri, serving the requests of cmdQ.
OSMesgQueue * osPiGetCmdQueue(void)
Return the command queue of the PI manager, or NULL when it does not run.
void osInvalICache(void *vaddr, s32 nbytes)
Invalidate the instruction cache over a range.
u32 osVirtualToPhysical(void *vaddr)
Translate a virtual address to a physical one.
struct OSThread_s OSThread
A thread: its place in the queues, its state, and the registers saved when it last stopped.
struct OSMesgQueue_s OSMesgQueue
A message queue: a ring of messages and the threads blocked sending or receiving.
void rmonPrintf(const char *fmt,...)
Print to the remote monitor.
void osStartThread(OSThread *t)
Make a stopped or waiting thread runnable, and yield to it when its priority is higher.
void * OSMesg
Definition os.h:73
OSViMode osViModeNtscLan1
The low-resolution NTSC video mode with anti-aliasing.
OSTime osGetTime(void)
Return the time since the VI manager started, in CPU counter cycles.
void osViSetEvent(OSMesgQueue *mq, OSMesg m, u32 retraceCount)
Send m to mq every retraceCount vertical retraces.
s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flag)
Take the first message of a queue, store it unless msg is NULL, and make its first sender runnable.
s32 osEPiRawWriteIo(OSPiHandle *pihandle, u32 devAddr, u32 data)
Write a word of the device a handle describes.
u32 osRomBase
The cartridge ROM base address reported by IPL3.
OSPri osGetThreadPri(OSThread *t)
Return the priority of a thread, a NULL thread being the running one.
u32 osRomType
The cartridge ROM type reported by IPL3.
void osViSetMode(OSViMode *modep)
Select the video mode from the next field on.
u32 osAiGetStatus(void)
Return the audio status register.
u32 osMemSize
The installed memory size reported by IPL3.
void osWritebackDCacheAll(void)
Write back the whole data cache.
OSPiHandle * osCartRomInit(void)
Return the handle of the cartridge ROM, creating it from the timing its first word records.
void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 count)
Initialise an empty message queue over a buffer of count messages.
OSViMode osViModeMpalLan1
The low-resolution MPAL video mode with anti-aliasing.
s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag)
Insert a message at the front of a queue and make its first receiver runnable.
s32 osEPiRawReadIo(OSPiHandle *pihandle, u32 devAddr, u32 *data)
Read a word of the device a handle describes.
void osInitialize(void)
Initialise the system: the FPU, the PIF, the exception vectors and the clock rates.
void * osViGetCurrentFramebuffer(void)
Return the frame buffer the screen shows.
u32 OSEvent
Definition os.h:70
s32 osAiSetFrequency(u32 frequency)
Set the sample rate of the audio DAC to the nearest the video clock allows.
u8 osAppNMIBuffer[64]
The application buffer retained across an NMI reset.
s32 osAiSetNextBuffer(void *bufPtr, u32 size)
Queue a buffer of samples for the audio DMA.
u32 osGetCount(void)
Read the CPU counter, or advance the emulated counter on Windows.
u32 osAiGetLength(void)
Return the remaining length of the buffer the audio DMA plays.
void osDestroyThread(OSThread *t)
Remove a thread from its queue and from the active queue.
s32 osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size)
Start a DMA between RDRAM and the cartridge domain at an offset from the ROM base.
s32 OSPri
Definition os.h:17
s32 osPiRawReadIo(u32 devAddr, u32 *data)
Read a word of the cartridge domain at an offset from the ROM base.
OSPiHandle * osLeoDiskInit(void)
Create the handle of the 64DD and select its domain 2 timing.
void osMapTLBRdb(void)
Map the RDB port of the development hardware.
OSViMode osViModePalHaf1
The high-resolution PAL video mode with anti-aliasing.
A device manager: the thread and queues that serve the I/O requests of one interface.
Definition os.h:219
s32(* edma)(OSPiHandle *, s32, u32, void *, u32)
Definition os.h:226
s32 active
Definition os.h:220
OSMesgQueue * evtQueue
Definition os.h:223
OSThread * thread
Definition os.h:221
OSMesgQueue * acsQueue
Definition os.h:224
s32(* dma)(s32, u32, void *, u32)
Definition os.h:225
OSMesgQueue * cmdQueue
Definition os.h:222
The header of an I/O request to a device manager.
Definition os.h:202
u8 pri
Definition os.h:204
OSMesgQueue * retQueue
Definition os.h:206
u16 type
Definition os.h:203
u8 status
Definition os.h:205
An I/O request to a device manager: a DMA between RDRAM and a device.
Definition os.h:210
u32 devAddr
Definition os.h:213
OSIoMesgHdr hdr
Definition os.h:211
u32 size
Definition os.h:214
OSPiHandle * piHandle
Definition os.h:215
void * dramAddr
Definition os.h:212
A message queue: a ring of messages and the threads blocked sending or receiving.
Definition os.h:76
s32 validCount
Definition os.h:79
OSMesg * msg
Definition os.h:82
OSThread * mtqueue
Definition os.h:77
OSThread * fullqueue
Definition os.h:78
s32 first
Definition os.h:80
s32 msgCount
Definition os.h:81
A device on the peripheral interface, with the timing of its PI domain.
Definition os.h:182
u8 domain
Definition os.h:189
u8 relDuration
Definition os.h:187
u32 speed
Definition os.h:191
u32 baseAddress
Definition os.h:190
__OSTranxInfo transferInfo
Definition os.h:192
u8 pulse
Definition os.h:188
struct OSPiHandle_s * next
Definition os.h:183
u8 type
Definition os.h:184
u8 latency
Definition os.h:185
u8 pageSize
Definition os.h:186
The type and base address of a device on the peripheral interface.
Definition os.h:196
u32 address
Definition os.h:198
u8 type
Definition os.h:197
A thread: its place in the queues, its state, and the registers saved when it last stopped.
Definition os.h:41
u16 flags
Definition os.h:47
OSPri priority
Definition os.h:43
__OSThreadContext context
Definition os.h:50
struct OSThread_s ** queue
Definition os.h:44
struct OSThread_s * next
Definition os.h:42
struct OSThread_s * tlnext
Definition os.h:45
OSId id
Definition os.h:48
u16 state
Definition os.h:46
A timer that sends a message when it expires, once or periodically.
Definition os.h:136
struct OSTimer_s * prev
Definition os.h:138
OSTime value
Definition os.h:140
OSMesg msg
Definition os.h:142
OSMesgQueue * mq
Definition os.h:141
OSTime interval
Definition os.h:139
struct OSTimer_s * next
Definition os.h:137
The video interface registers a video mode sets for both fields.
Definition os.h:288
u32 hStart
Definition os.h:295
u32 xScale
Definition os.h:296
u32 ctrl
Definition os.h:289
u32 width
Definition os.h:290
u32 vSync
Definition os.h:292
u32 hSync
Definition os.h:293
u32 burst
Definition os.h:291
u32 leap
Definition os.h:294
u32 vCurrent
Definition os.h:297
The video interface registers a video mode sets for one field.
Definition os.h:301
u32 vBurst
Definition os.h:305
u32 yScale
Definition os.h:303
u32 vIntr
Definition os.h:306
u32 vStart
Definition os.h:304
u32 origin
Definition os.h:302
A video mode: the registers of the video interface for a resolution and television standard.
Definition os.h:310
u8 type
Definition os.h:311
OSViCommonRegs comRegs
Definition os.h:312
OSViFieldRegs fldRegs[2]
Definition os.h:313
Integer and floating-point types of libultra.
unsigned int u32
Definition ultratypes.h:20
signed char s8
Definition ultratypes.h:23
float f32
Definition ultratypes.h:38
double f64
Definition ultratypes.h:39
unsigned short u16
Definition ultratypes.h:19
int s32
Definition ultratypes.h:25
unsigned long long u64
Definition ultratypes.h:21
unsigned char u8
Definition ultratypes.h:18