mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-06 14:20:11 +00:00
First proper commit.
This commit is contained in:
parent
be78236d36
commit
087f561f77
14086 changed files with 1200489 additions and 1 deletions
19
src/libultra_boot_O1/__osDequeueThread.c
Normal file
19
src/libultra_boot_O1/__osDequeueThread.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <global.h>
|
||||
|
||||
void __osDequeueThread(OSThread **queue, OSThread *thread)
|
||||
{
|
||||
register OSThread **a2;
|
||||
register OSThread *a3;
|
||||
a2 = queue;
|
||||
a3 = *a2;
|
||||
while (a3 != NULL)
|
||||
{
|
||||
if (a3 == thread)
|
||||
{
|
||||
*a2 = thread->next;
|
||||
return;
|
||||
}
|
||||
a2 = &a3->next;
|
||||
a3 = *a2;
|
||||
}
|
||||
}
|
7
src/libultra_boot_O1/__osGetHWIntrRoutine.c
Normal file
7
src/libultra_boot_O1/__osGetHWIntrRoutine.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <global.h>
|
||||
|
||||
void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg)
|
||||
{
|
||||
*outQueue = __osHwIntTable[idx].queue;
|
||||
*outMsg = __osHwIntTable[idx].msg;
|
||||
}
|
10
src/libultra_boot_O1/__osResetGlobalIntMask.c
Normal file
10
src/libultra_boot_O1/__osResetGlobalIntMask.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <global.h>
|
||||
|
||||
void __osResetGlobalIntMask(u32 mask)
|
||||
{
|
||||
register s32 prevInt;
|
||||
|
||||
prevInt = __osDisableInt();
|
||||
__OSGlobalIntMask &= ~(mask & ~0x401);
|
||||
__osRestoreInt(prevInt);
|
||||
}
|
10
src/libultra_boot_O1/__osSetGlobalIntMask.c
Normal file
10
src/libultra_boot_O1/__osSetGlobalIntMask.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <global.h>
|
||||
|
||||
void __osSetGlobalIntMask(u32 mask)
|
||||
{
|
||||
register s32 prevInt;
|
||||
|
||||
prevInt = __osDisableInt();
|
||||
__OSGlobalIntMask |= mask;
|
||||
__osRestoreInt(prevInt);
|
||||
}
|
13
src/libultra_boot_O1/__osSetHWIntrRoutine.c
Normal file
13
src/libultra_boot_O1/__osSetHWIntrRoutine.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <global.h>
|
||||
|
||||
void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg)
|
||||
{
|
||||
register int prevInt;
|
||||
|
||||
prevInt = __osDisableInt();
|
||||
|
||||
__osHwIntTable[idx].queue = queue;
|
||||
__osHwIntTable[idx].msg = msg;
|
||||
|
||||
__osRestoreInt(prevInt);
|
||||
}
|
83
src/libultra_boot_O1/initialize.c
Normal file
83
src/libultra_boot_O1/initialize.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
#include <global.h>
|
||||
#include <ultra64/hardware.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 ins_00; //lui k0, 0x8000
|
||||
u32 ins_04; //addiu k0, k0, 0x39e0
|
||||
u32 ins_08; //jr k0 ; __osException
|
||||
u32 ins_0C; //nop
|
||||
} struct_exceptionPreamble;
|
||||
|
||||
u64 osClockRate = 62500000;
|
||||
u32 osViClock = VI_NTSC_CLOCK;
|
||||
u32 __osShutdown = 0;
|
||||
u32 __OSGlobalIntMask = 0x003FFF01;
|
||||
|
||||
u32 D_800145C0;
|
||||
|
||||
void __createSpeedParam(void)
|
||||
{
|
||||
__Dom1SpeedParam.type = DEVICE_TYPE_INIT;
|
||||
__Dom1SpeedParam.latency = HW_REG(PI_BSD_DOM1_LAT_REG, u32);
|
||||
__Dom1SpeedParam.pulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32);
|
||||
__Dom1SpeedParam.pageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32);
|
||||
__Dom1SpeedParam.relDuration = HW_REG(PI_BSD_DOM1_RLS_REG, u32);
|
||||
|
||||
__Dom2SpeedParam.type = DEVICE_TYPE_INIT;
|
||||
__Dom2SpeedParam.latency = HW_REG(PI_BSD_DOM2_LAT_REG, u32);
|
||||
__Dom2SpeedParam.pulse = HW_REG(PI_BSD_DOM2_PWD_REG, u32);
|
||||
__Dom2SpeedParam.pageSize = HW_REG(PI_BSD_DOM2_PGS_REG, u32);
|
||||
__Dom2SpeedParam.relDuration = HW_REG(PI_BSD_DOM2_RLS_REG, u32);
|
||||
}
|
||||
|
||||
void __osInitialize_common(void)
|
||||
{
|
||||
u32 sp2C;
|
||||
|
||||
D_800145C0 = 1;
|
||||
__osSetSR(__osGetSR() | 0x20000000);
|
||||
__osSetFpcCsr(0x1000800);
|
||||
__osSetWatchLo(0x4900000);
|
||||
|
||||
while (__osSiRawReadIo((void*)0x1fc007fc, &sp2C))
|
||||
;
|
||||
|
||||
while (__osSiRawWriteIo((void*)0x1fc007fc, sp2C | 8))
|
||||
;
|
||||
|
||||
*(struct_exceptionPreamble*)0x80000000 = *(struct_exceptionPreamble*)__osExceptionPreamble; //TLB miss
|
||||
*(struct_exceptionPreamble*)0x80000080 = *(struct_exceptionPreamble*)__osExceptionPreamble; //XTLB miss
|
||||
*(struct_exceptionPreamble*)0x80000100 = *(struct_exceptionPreamble*)__osExceptionPreamble; //cache errors
|
||||
*(struct_exceptionPreamble*)0x80000180 = *(struct_exceptionPreamble*)__osExceptionPreamble; //general exceptions
|
||||
|
||||
osWritebackDCache(0x80000000, 0x190);
|
||||
osInvalICache(0x80000000, 0x190);
|
||||
__createSpeedParam();
|
||||
osUnmapTLBAll();
|
||||
osMapTLBRdb();
|
||||
|
||||
osClockRate = (u64)((osClockRate * 3ll) / 4ull);
|
||||
|
||||
if (!osResetType)
|
||||
bzero(osAppNmiBuffer, 0x40);
|
||||
|
||||
if (osTvType == 0)
|
||||
osViClock = VI_PAL_CLOCK;
|
||||
else if (osTvType == 2)
|
||||
osViClock = VI_MPAL_CLOCK;
|
||||
else
|
||||
osViClock = VI_NTSC_CLOCK;
|
||||
|
||||
if (__osGetCause() & 0x1000)
|
||||
while (true)
|
||||
;
|
||||
|
||||
HW_REG(AI_CONTROL_REG, u32) = 1;
|
||||
HW_REG(AI_DACRATE_REG, u32) = 0x3fff;
|
||||
HW_REG(AI_BITRATE_REG, u32) = 0xf;
|
||||
}
|
||||
|
||||
void __osInitialize_autodetect()
|
||||
{
|
||||
}
|
11
src/libultra_boot_O1/osCreateMesgQueue.c
Normal file
11
src/libultra_boot_O1/osCreateMesgQueue.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <global.h>
|
||||
|
||||
void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count)
|
||||
{
|
||||
mq->mtqueue = __osThreadTail;
|
||||
mq->fullqueue = __osThreadTail;
|
||||
mq->validCount = 0;
|
||||
mq->first = 0;
|
||||
mq->msgCount = count;
|
||||
mq->msg = msg;
|
||||
}
|
34
src/libultra_boot_O1/osCreateThread.c
Normal file
34
src/libultra_boot_O1/osCreateThread.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <global.h>
|
||||
|
||||
OSThread* __osThreadTail[2] = { NULL, (OSThread*)-1 };
|
||||
OSThread *__osRunQueue = __osThreadTail;
|
||||
OSThread *__osActiveQueue = __osThreadTail;
|
||||
OSThread *__osRunningThread = NULL;
|
||||
OSThread* __osFaultedThread = NULL;
|
||||
|
||||
void osCreateThread(OSThread* thread, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri pri)
|
||||
{
|
||||
register u32 s0;
|
||||
u32 t8;
|
||||
|
||||
thread->id = id;
|
||||
thread->priority = pri;
|
||||
thread->next = (struct OSThread_s*)NULL;
|
||||
thread->queue = (struct OSThread_s**)NULL;
|
||||
thread->context.pc = (u32)entry;
|
||||
thread->context.a0 = (u64)arg;
|
||||
thread->context.sp = (u64)sp - 16;
|
||||
thread->context.ra = (u64)__osCleanupThread;
|
||||
t8 = 0x3FFF01;
|
||||
thread->context.sr = (t8 & 0xFF01) | 2;
|
||||
thread->context.rcp = (t8 & 0x3F0000) >> 16;
|
||||
thread->context.fpcsr = 0x01000800;
|
||||
thread->fp = 0;
|
||||
thread->state = 1;
|
||||
thread->flags = 0;
|
||||
|
||||
s0 = __osDisableInt();
|
||||
thread->tlnext = __osActiveQueue;
|
||||
__osActiveQueue = thread;
|
||||
__osRestoreInt(s0);
|
||||
}
|
39
src/libultra_boot_O1/osDestroyThread.c
Normal file
39
src/libultra_boot_O1/osDestroyThread.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <global.h>
|
||||
|
||||
void osDestroyThread(OSThread *thread)
|
||||
{
|
||||
register s32 int_disabled;
|
||||
|
||||
register OSThread *s1;
|
||||
register OSThread *s2;
|
||||
|
||||
int_disabled = __osDisableInt();
|
||||
|
||||
if (thread == NULL)
|
||||
thread = __osRunningThread;
|
||||
|
||||
else if (thread->state != OS_STATE_STOPPED)
|
||||
__osDequeueThread(thread->queue, thread);
|
||||
|
||||
if (__osActiveQueue == thread)
|
||||
__osActiveQueue = __osActiveQueue->tlnext;
|
||||
else
|
||||
{
|
||||
s1 = __osActiveQueue;
|
||||
while (s1->priority != -1)
|
||||
{
|
||||
s2 = s1->tlnext;
|
||||
if (s2 == thread)
|
||||
{
|
||||
s1->tlnext = thread->tlnext;
|
||||
break;
|
||||
}
|
||||
s1 = s2;
|
||||
}
|
||||
}
|
||||
|
||||
if (thread == __osRunningThread)
|
||||
__osDispatchThread();
|
||||
|
||||
__osRestoreInt(int_disabled);
|
||||
}
|
34
src/libultra_boot_O1/osGetMemSize.c
Normal file
34
src/libultra_boot_O1/osGetMemSize.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <global.h>
|
||||
|
||||
#define STEP 0x100000
|
||||
|
||||
u32 osGetMemSize(void)
|
||||
{
|
||||
u32* ptr;
|
||||
u32 size;
|
||||
u32 data0;
|
||||
u32 data1;
|
||||
|
||||
size = 0x400000;
|
||||
|
||||
while(size < 0x800000)
|
||||
{
|
||||
ptr = (u32*)(0xA0000000 + size);
|
||||
|
||||
data0 = *ptr;
|
||||
data1 = ptr[STEP/4-1];
|
||||
|
||||
*ptr ^= ~0;
|
||||
ptr[STEP/4-1] ^= ~0;
|
||||
|
||||
if ((*ptr != (data0 ^ ~0)) || (ptr[STEP/4-1] != (data1 ^ ~0)))
|
||||
return size;
|
||||
|
||||
*ptr = data0;
|
||||
ptr[STEP/4-1] = data1;
|
||||
|
||||
size += STEP;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
9
src/libultra_boot_O1/osGetThreadId.c
Normal file
9
src/libultra_boot_O1/osGetThreadId.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <global.h>
|
||||
|
||||
OSId osGetThreadId(OSThread* thread)
|
||||
{
|
||||
if (thread == NULL)
|
||||
thread = __osRunningThread;
|
||||
|
||||
return thread->id;
|
||||
}
|
9
src/libultra_boot_O1/osGetThreadPri.c
Normal file
9
src/libultra_boot_O1/osGetThreadPri.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <global.h>
|
||||
|
||||
OSPri osGetThreadPri(OSThread* thread)
|
||||
{
|
||||
if (thread == NULL)
|
||||
thread = __osRunningThread;
|
||||
|
||||
return thread->priority;
|
||||
}
|
17
src/libultra_boot_O1/osGetTime.c
Normal file
17
src/libultra_boot_O1/osGetTime.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <global.h>
|
||||
|
||||
OSTime osGetTime(void)
|
||||
{
|
||||
u32 sp34;
|
||||
u32 sp30;
|
||||
u64 t1;
|
||||
register u32 s0;
|
||||
|
||||
s0 = __osDisableInt();
|
||||
sp34 = osGetCount();
|
||||
sp30 = sp34 - __osBaseCounter;
|
||||
t1 = __osCurrentTime;
|
||||
__osRestoreInt(s0);
|
||||
|
||||
return sp30 + t1;
|
||||
}
|
24
src/libultra_boot_O1/osJamMesg.c
Normal file
24
src/libultra_boot_O1/osJamMesg.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <global.h>
|
||||
|
||||
s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) {
|
||||
register s32 int_disabled;
|
||||
int_disabled = __osDisableInt();
|
||||
while (mq->validCount >= mq->msgCount) {
|
||||
if (flag == OS_MESG_BLOCK) {
|
||||
__osRunningThread->state = OS_STATE_WAITING;
|
||||
__osEnqueueAndYield(&mq->fullqueue);
|
||||
} else {
|
||||
__osRestoreInt(int_disabled);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount;
|
||||
mq->msg[mq->first] = msg;
|
||||
mq->validCount++;
|
||||
if (mq->mtqueue->next != NULL) {
|
||||
osStartThread(__osPopThread(&mq->mtqueue));
|
||||
}
|
||||
__osRestoreInt(int_disabled);
|
||||
return 0;
|
||||
}
|
30
src/libultra_boot_O1/osRecvMesg.c
Normal file
30
src/libultra_boot_O1/osRecvMesg.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <global.h>
|
||||
|
||||
s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag)
|
||||
{
|
||||
register s32 s0 = __osDisableInt();
|
||||
|
||||
while (mq->validCount == 0)
|
||||
{
|
||||
if (flag == OS_MESG_NOBLOCK)
|
||||
{
|
||||
__osRestoreInt(s0);
|
||||
return -1;
|
||||
}
|
||||
__osRunningThread->state = 8;
|
||||
__osEnqueueAndYield(mq);
|
||||
}
|
||||
|
||||
if (msg != NULL)
|
||||
*msg = mq->msg[mq->first];
|
||||
|
||||
mq->first = (mq->first + 1) % mq->msgCount;
|
||||
mq->validCount--;
|
||||
|
||||
if (mq->fullqueue->next != NULL)
|
||||
osStartThread(__osPopThread(&mq->fullqueue));
|
||||
|
||||
__osRestoreInt(s0);
|
||||
|
||||
return 0;
|
||||
}
|
32
src/libultra_boot_O1/osSendMesg.c
Normal file
32
src/libultra_boot_O1/osSendMesg.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <global.h>
|
||||
|
||||
s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag)
|
||||
{
|
||||
register u32 s0 = __osDisableInt();
|
||||
register u32 index;
|
||||
|
||||
while (mq->validCount >= mq->msgCount)
|
||||
{
|
||||
if (flag == OS_MESG_BLOCK)
|
||||
{
|
||||
__osRunningThread->state = 8;
|
||||
__osEnqueueAndYield(&mq->fullqueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
__osRestoreInt(s0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
index = (mq->first + mq->validCount) % mq->msgCount;
|
||||
mq->msg[index] = mesg;
|
||||
mq->validCount++;
|
||||
|
||||
if (mq->mtqueue->next != NULL)
|
||||
osStartThread(__osPopThread(&mq->mtqueue));
|
||||
|
||||
__osRestoreInt(s0);
|
||||
|
||||
return 0;
|
||||
}
|
26
src/libultra_boot_O1/osSetEventMesg.c
Normal file
26
src/libultra_boot_O1/osSetEventMesg.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <global.h>
|
||||
|
||||
__OSEventState __osEventStateTab[16];
|
||||
|
||||
u32 __osPreNMI = 0;
|
||||
|
||||
void osSetEventMesg(OSEvent e, OSMesgQueue *mq, OSMesg msg)
|
||||
{
|
||||
register u32 int_disabled;
|
||||
__OSEventState *msgs;
|
||||
|
||||
int_disabled = __osDisableInt();
|
||||
msgs = __osEventStateTab + e;
|
||||
msgs->queue = mq;
|
||||
msgs->msg = msg;
|
||||
|
||||
if (e == OS_EVENT_PRENMI)
|
||||
{
|
||||
if (__osShutdown && !__osPreNMI)
|
||||
osSendMesg(mq, msg, 0);
|
||||
|
||||
__osPreNMI = true;
|
||||
}
|
||||
__osRestoreInt(int_disabled);
|
||||
|
||||
}
|
26
src/libultra_boot_O1/osSetThreadPri.c
Normal file
26
src/libultra_boot_O1/osSetThreadPri.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <global.h>
|
||||
|
||||
void osSetThreadPri(OSThread* thread, OSPri pri)
|
||||
{
|
||||
register u32 s0 = __osDisableInt();
|
||||
|
||||
if (thread == NULL)
|
||||
thread = __osRunningThread;
|
||||
|
||||
if (thread->priority != pri)
|
||||
{
|
||||
thread->priority = pri;
|
||||
if (thread != __osRunningThread && thread->state != 1)
|
||||
{
|
||||
__osDequeueThread(thread->queue, thread);
|
||||
__osEnqueueThread(thread->queue, thread);
|
||||
}
|
||||
if (__osRunningThread->priority < __osRunQueue->priority)
|
||||
{
|
||||
__osRunningThread->state = 2;
|
||||
__osEnqueueAndYield(&__osRunQueue);
|
||||
}
|
||||
}
|
||||
|
||||
__osRestoreInt(s0);
|
||||
}
|
42
src/libultra_boot_O1/osStartThread.c
Normal file
42
src/libultra_boot_O1/osStartThread.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <global.h>
|
||||
|
||||
void osStartThread(OSThread* thread)
|
||||
{
|
||||
register u32 s0 = __osDisableInt();
|
||||
|
||||
switch (thread->state)
|
||||
{
|
||||
case 8:
|
||||
thread->state = 2;
|
||||
__osEnqueueThread(&__osRunQueue, thread);
|
||||
break;
|
||||
case 1:
|
||||
if (thread->queue == NULL || thread->queue == &__osRunQueue)
|
||||
{
|
||||
thread->state = 2;
|
||||
__osEnqueueThread(&__osRunQueue, thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
thread->state = 8;
|
||||
__osEnqueueThread(thread->queue, thread);
|
||||
__osEnqueueThread(&__osRunQueue, __osPopThread(thread->queue));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (__osRunningThread == NULL)
|
||||
{
|
||||
__osDispatchThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__osRunningThread->priority < __osRunQueue->priority)
|
||||
{
|
||||
__osRunningThread->state = 2;
|
||||
__osEnqueueAndYield(&__osRunQueue);
|
||||
}
|
||||
}
|
||||
|
||||
__osRestoreInt(s0);
|
||||
}
|
27
src/libultra_boot_O1/osStopThread.c
Normal file
27
src/libultra_boot_O1/osStopThread.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <global.h>
|
||||
|
||||
void osStopThread(OSThread* thread)
|
||||
{
|
||||
register u32 s0 = __osDisableInt();
|
||||
register u32 state;
|
||||
|
||||
if (thread == NULL)
|
||||
state = 4;
|
||||
else
|
||||
state = thread->state;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case 4:
|
||||
__osRunningThread->state = 1;
|
||||
__osEnqueueAndYield(NULL);
|
||||
break;
|
||||
case 2:
|
||||
case 8:
|
||||
thread->state = 1;
|
||||
__osDequeueThread(thread->queue, thread);
|
||||
break;
|
||||
}
|
||||
|
||||
__osRestoreInt(s0);
|
||||
}
|
6
src/libultra_boot_O1/osViExtendVStart.c
Normal file
6
src/libultra_boot_O1/osViExtendVStart.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <global.h>
|
||||
|
||||
void osViExtendVStart(u32 arg0)
|
||||
{
|
||||
__additional_scanline = arg0;
|
||||
}
|
33
src/libultra_boot_O1/osViModePalLan1.c
Normal file
33
src/libultra_boot_O1/osViModePalLan1.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <global.h>
|
||||
|
||||
OSViMode osViModePalLan1 =
|
||||
{
|
||||
0x10, //type
|
||||
{ //comRegs
|
||||
0x311E, //ctrl
|
||||
0x140, //width
|
||||
0x4541E3A, //burst
|
||||
0x271, //vSync
|
||||
0x170C69, //hSync
|
||||
0xC6F0C6D, //leap
|
||||
0x800300, //hStart
|
||||
0x200, //xScale
|
||||
0 //vCurrent
|
||||
},
|
||||
{ //fldRegs
|
||||
{
|
||||
0x280, //origin
|
||||
0x400, //yScale
|
||||
0x5F0239, //vStart
|
||||
0x9026B, //vBurst
|
||||
2, //vIntr
|
||||
},
|
||||
{
|
||||
0x280, //origin
|
||||
0x400, //yScale
|
||||
0x5F0239, //vStart
|
||||
0x9026B, //vBurst
|
||||
2 //vIntr
|
||||
}
|
||||
}
|
||||
};
|
12
src/libultra_boot_O1/osVirtualToPhysical.c
Normal file
12
src/libultra_boot_O1/osVirtualToPhysical.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <global.h>
|
||||
|
||||
u32 osVirtualToPhysical(void* vaddr)
|
||||
{
|
||||
if ((u32)vaddr >= 0x80000000 && (u32)vaddr < 0xA0000000)
|
||||
return (u32)vaddr & 0x1FFFFFFF;
|
||||
|
||||
if ((u32)vaddr >= 0xA0000000 && (u32)vaddr < 0xC0000000)
|
||||
return (u32)vaddr & 0x1FFFFFFF;
|
||||
|
||||
return __osProbeTLB(vaddr);
|
||||
}
|
11
src/libultra_boot_O1/osYieldThread.c
Normal file
11
src/libultra_boot_O1/osYieldThread.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <global.h>
|
||||
|
||||
void osYieldThread()
|
||||
{
|
||||
register u32 prevInt;
|
||||
|
||||
prevInt = __osDisableInt();
|
||||
__osRunningThread->state = OS_STATE_RUNNABLE;
|
||||
__osEnqueueAndYield(&__osRunQueue);
|
||||
__osRestoreInt(prevInt);
|
||||
}
|
28
src/libultra_boot_O1/piacs.c
Normal file
28
src/libultra_boot_O1/piacs.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <global.h>
|
||||
|
||||
u32 __osPiAccessQueueEnabled = 0;
|
||||
|
||||
OSMesg piAccessBuf;
|
||||
OSMesgQueue __osPiAccessQueue;
|
||||
|
||||
void __osPiCreateAccessQueue(void)
|
||||
{
|
||||
__osPiAccessQueueEnabled = 1;
|
||||
osCreateMesgQueue(&__osPiAccessQueue, &piAccessBuf, 1);
|
||||
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
||||
|
||||
void __osPiGetAccess(void)
|
||||
{
|
||||
OSMesg mesg;
|
||||
|
||||
if (!__osPiAccessQueueEnabled)
|
||||
__osPiCreateAccessQueue();
|
||||
|
||||
osRecvMesg(&__osPiAccessQueue, &mesg, OS_MESG_BLOCK);
|
||||
}
|
||||
|
||||
void __osPiRelAccess(void)
|
||||
{
|
||||
osSendMesg(&__osPiAccessQueue, 0, OS_MESG_NOBLOCK);
|
||||
}
|
97
src/libultra_boot_O1/timerintr.c
Normal file
97
src/libultra_boot_O1/timerintr.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <global.h>
|
||||
|
||||
OSTimer __osBaseTimer;
|
||||
OSTime __osCurrentTime;
|
||||
u32 __osBaseCounter;
|
||||
u32 __osViIntrCount;
|
||||
u32 __osTimerCounter;
|
||||
OSTimer* __osTimerList = &__osBaseTimer;
|
||||
|
||||
void __osTimerServicesInit()
|
||||
{
|
||||
__osCurrentTime = 0;
|
||||
__osBaseCounter = 0;
|
||||
__osViIntrCount = 0;
|
||||
__osTimerList->prev = __osTimerList;
|
||||
__osTimerList->next = __osTimerList->prev;
|
||||
__osTimerList->value = 0;
|
||||
__osTimerList->interval = __osTimerList->value;
|
||||
__osTimerList->mq = NULL;
|
||||
__osTimerList->msg = NULL;
|
||||
}
|
||||
|
||||
void __osTimerInterrupt()
|
||||
{
|
||||
OSTimer *sp24;
|
||||
u32 sp20;
|
||||
u32 sp1c;
|
||||
if (__osTimerList->next == __osTimerList) {
|
||||
return;
|
||||
}
|
||||
while (1) {
|
||||
sp24 = __osTimerList->next;
|
||||
if (sp24 == __osTimerList) {
|
||||
__osSetCompare(0);
|
||||
__osTimerCounter = 0;
|
||||
break;
|
||||
}
|
||||
sp20 = osGetCount();
|
||||
sp1c = sp20 - __osTimerCounter;
|
||||
__osTimerCounter = sp20;
|
||||
if (sp1c < sp24->value) {
|
||||
sp24->value -= sp1c;
|
||||
__osSetTimerIntr(sp24->value);
|
||||
return;
|
||||
} else {
|
||||
sp24->prev->next = sp24->next;
|
||||
sp24->next->prev = sp24->prev;
|
||||
sp24->next = NULL;
|
||||
sp24->prev = NULL;
|
||||
if (sp24->mq != NULL) {
|
||||
osSendMesg(sp24->mq, sp24->msg, OS_MESG_NOBLOCK);
|
||||
}
|
||||
if (sp24->interval != 0) {
|
||||
sp24->value = sp24->interval;
|
||||
__osInsertTimer(sp24);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __osSetTimerIntr(OSTime tim)
|
||||
{
|
||||
OSTime NewTime;
|
||||
u32 savedMask;
|
||||
|
||||
if (tim < 468)
|
||||
tim = 468;
|
||||
|
||||
savedMask = __osDisableInt();
|
||||
|
||||
__osTimerCounter = osGetCount();
|
||||
NewTime = tim + __osTimerCounter;
|
||||
__osSetCompare((u32)NewTime);
|
||||
__osRestoreInt(savedMask);
|
||||
}
|
||||
|
||||
OSTime __osInsertTimer(OSTimer *a0)
|
||||
{
|
||||
OSTimer *sp34;
|
||||
u64 sp28;
|
||||
s32 intDisabled;
|
||||
intDisabled = __osDisableInt();
|
||||
for (sp34 = __osTimerList->next, sp28 = a0->value; sp34 != __osTimerList && sp28 > sp34->value;
|
||||
sp28 -= sp34->value, sp34 = sp34->next) {
|
||||
;
|
||||
}
|
||||
a0->value = sp28;
|
||||
if (sp34 != __osTimerList) {
|
||||
sp34->value -= sp28;
|
||||
}
|
||||
a0->next = sp34;
|
||||
a0->prev = sp34->prev;
|
||||
sp34->prev->next = a0;
|
||||
sp34->prev = a0;
|
||||
__osRestoreInt(intDisabled);
|
||||
return sp28;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue