1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00

Irqmgr and Sched Retail OK (#1678)

* irqmgr OK

* sched OK

* PR review renames
This commit is contained in:
Derek Hensley 2024-01-31 16:26:31 -08:00 committed by GitHub
parent 06379c3109
commit 2bc159e518
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 71 deletions

View File

@ -253,31 +253,36 @@ void IrqMgr_ThreadEntry(void* arg) {
case IRQ_RETRACE_MSG: case IRQ_RETRACE_MSG:
IrqMgr_HandleRetrace(irqMgr); IrqMgr_HandleRetrace(irqMgr);
break; break;
case IRQ_PRENMI_MSG: case IRQ_PRENMI_MSG:
PRINTF("PRE_NMI_MSG\n"); PRINTF("PRE_NMI_MSG\n");
// "Scheduler: Receives PRE_NMI message" // "Scheduler: Receives PRE_NMI message"
PRINTF("スケジューラPRE_NMIメッセージを受信\n"); PRINTF("スケジューラPRE_NMIメッセージを受信\n");
IrqMgr_HandlePreNMI(irqMgr); IrqMgr_HandlePreNMI(irqMgr);
break; break;
case IRQ_PRENMI450_MSG: case IRQ_PRENMI450_MSG:
PRINTF("PRENMI450_MSG\n"); PRINTF("PRENMI450_MSG\n");
// "Scheduler: Receives PRENMI450 message" // "Scheduler: Receives PRENMI450 message"
PRINTF("スケジューラPRENMI450メッセージを受信\n"); PRINTF("スケジューラPRENMI450メッセージを受信\n");
IrqMgr_HandlePreNMI450(irqMgr); IrqMgr_HandlePreNMI450(irqMgr);
break; break;
case IRQ_PRENMI480_MSG: case IRQ_PRENMI480_MSG:
PRINTF("PRENMI480_MSG\n"); PRINTF("PRENMI480_MSG\n");
// "Scheduler: Receives PRENMI480 message" // "Scheduler: Receives PRENMI480 message"
PRINTF("スケジューラPRENMI480メッセージを受信\n"); PRINTF("スケジューラPRENMI480メッセージを受信\n");
IrqMgr_HandlePreNMI480(irqMgr); IrqMgr_HandlePreNMI480(irqMgr);
break; break;
case IRQ_PRENMI500_MSG: case IRQ_PRENMI500_MSG:
PRINTF("PRENMI500_MSG\n"); PRINTF("PRENMI500_MSG\n");
// "Scheduler: Receives PRENMI500 message" // "Scheduler: Receives PRENMI500 message"
PRINTF("スケジューラPRENMI500メッセージを受信\n"); PRINTF("スケジューラPRENMI500メッセージを受信\n");
exit = true;
IrqMgr_HandlePreNMI500(irqMgr); IrqMgr_HandlePreNMI500(irqMgr);
exit = true;
break; break;
default: default:
// "Unexpected message received" // "Unexpected message received"
PRINTF("irqmgr.c:予期しないメッセージを受け取りました(%08x)\n", msg); PRINTF("irqmgr.c:予期しないメッセージを受け取りました(%08x)\n", msg);

View File

@ -45,34 +45,44 @@
#define RDP_DONE_MSG 668 #define RDP_DONE_MSG 668
#define NOTIFY_MSG 670 // original name: ENTRY_MSG #define NOTIFY_MSG 670 // original name: ENTRY_MSG
vs32 sLogScheduler = false; vs32 sSchedDebugPrintfEnabled = false;
OSTime sRSPGfxTimeStart; OSTime sRSPGfxTimeStart;
OSTime sRSPAudioTimeStart; OSTime sRSPAudioTimeStart;
OSTime sRSPOtherTimeStart; OSTime sRSPOtherTimeStart;
OSTime sRDPTimeStart; OSTime sRDPTimeStart;
#if OOT_DEBUG
#define SCHED_DEBUG_PRINTF \
if (sSchedDebugPrintfEnabled) \
PRINTF
#elif defined(__sgi)
// See comment about PRINTF in macros.h
#define SCHED_DEBUG_PRINTF(args) (void)0
#else
#define SCHED_DEBUG_PRINTF(format, ...) (void)0
#endif
/** /**
* Set the current framebuffer to the swapbuffer pointed to by the provided cfb * Set the current framebuffer to the swapbuffer pointed to by the provided cfb
*/ */
void Sched_SwapFrameBufferImpl(CfbInfo* cfbInfo) { void Sched_SwapFrameBufferImpl(CfbInfo* cfbInfo) {
u16 width;
LOG_UTILS_CHECK_VALID_POINTER("cfbinfo->swapbuffer", cfbInfo->swapBuffer, "../sched.c", 340); LOG_UTILS_CHECK_VALID_POINTER("cfbinfo->swapbuffer", cfbInfo->swapBuffer, "../sched.c", 340);
if (cfbInfo->swapBuffer != NULL) { if (cfbInfo->swapBuffer != NULL) {
// Register the swapbuffer to display on next VI // Register the swapbuffer to display on next VI
osViSwapBuffer(cfbInfo->swapBuffer); osViSwapBuffer(cfbInfo->swapBuffer);
cfbInfo->updateTimer = cfbInfo->updateRate; cfbInfo->updateTimer = cfbInfo->updateRate;
SCHED_DEBUG_PRINTF("osViSwapBuffer %08x %08x %08x\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(),
(cfbInfo != NULL) ? cfbInfo->swapBuffer : NULL);
if (sLogScheduler) { {
PRINTF("osViSwapBuffer %08x %08x %08x\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(), u16 width = (cfbInfo->viMode != NULL) ? cfbInfo->viMode->comRegs.width : (u32)gScreenWidth;
(cfbInfo != NULL) ? cfbInfo->swapBuffer : NULL);
Fault_SetFrameBuffer(cfbInfo->swapBuffer, width, 16);
} }
width = (cfbInfo->viMode != NULL) ? cfbInfo->viMode->comRegs.width : (u32)gScreenWidth; #if OOT_DEBUG
Fault_SetFrameBuffer(cfbInfo->swapBuffer, width, 16);
if (R_HREG_MODE == HREG_MODE_SCHED && R_SCHED_INIT != HREG_MODE_SCHED) { if (R_HREG_MODE == HREG_MODE_SCHED && R_SCHED_INIT != HREG_MODE_SCHED) {
R_SCHED_TOGGLE_SPECIAL_FEATURES = 0; R_SCHED_TOGGLE_SPECIAL_FEATURES = 0;
R_SCHED_GAMMA_ON = 0; R_SCHED_GAMMA_ON = 0;
@ -100,6 +110,7 @@ void Sched_SwapFrameBufferImpl(CfbInfo* cfbInfo) {
osViSetSpecialFeatures(R_SCHED_GAMMA_DITHER_ON ? OS_VI_GAMMA_DITHER_ON : OS_VI_GAMMA_DITHER_OFF); osViSetSpecialFeatures(R_SCHED_GAMMA_DITHER_ON ? OS_VI_GAMMA_DITHER_ON : OS_VI_GAMMA_DITHER_OFF);
osViSetSpecialFeatures(R_SCHED_DIVOT_ON ? OS_VI_DIVOT_ON : OS_VI_DIVOT_OFF); osViSetSpecialFeatures(R_SCHED_DIVOT_ON ? OS_VI_DIVOT_ON : OS_VI_DIVOT_OFF);
} }
#endif
} }
cfbInfo->unk_10 = 0; cfbInfo->unk_10 = 0;
@ -117,6 +128,7 @@ void Sched_SwapFrameBuffer(Scheduler* sc, CfbInfo* cfbInfo) {
} }
void Sched_HandlePreNMI(Scheduler* sc) { void Sched_HandlePreNMI(Scheduler* sc) {
#if OOT_DEBUG
OSTime now; OSTime now;
if (sc->curRSPTask != NULL) { if (sc->curRSPTask != NULL) {
@ -143,6 +155,7 @@ void Sched_HandlePreNMI(Scheduler* sc) {
} }
} }
} }
#endif
} }
void Sched_HandleNMI(Scheduler* sc) { void Sched_HandleNMI(Scheduler* sc) {
@ -161,10 +174,9 @@ void Sched_QueueTask(Scheduler* sc, OSScTask* task) {
463); 463);
if (type == M_AUDTASK) { if (type == M_AUDTASK) {
if (sLogScheduler) { // "You have entered an audio task"
// "You have entered an audio task" SCHED_DEBUG_PRINTF("オーディオタスクをエントリしました\n");
PRINTF("オーディオタスクをエントリしました\n");
}
// Add to audio queue // Add to audio queue
if (sc->audioListTail != NULL) { if (sc->audioListTail != NULL) {
sc->audioListTail->next = task; sc->audioListTail->next = task;
@ -176,10 +188,10 @@ void Sched_QueueTask(Scheduler* sc, OSScTask* task) {
// Set audio flag // Set audio flag
sc->doAudio = true; sc->doAudio = true;
} else { } else {
if (sLogScheduler) {
// "Entered graph task" // "Entered graph task"
PRINTF("グラフタスクをエントリしました\n"); SCHED_DEBUG_PRINTF("グラフタスクをエントリしました\n");
}
// Add to graphics queue // Add to graphics queue
if (sc->gfxListTail != NULL) { if (sc->gfxListTail != NULL) {
sc->gfxListTail->next = task; sc->gfxListTail->next = task;
@ -202,9 +214,7 @@ void Sched_Yield(Scheduler* sc) {
// Send yield request // Send yield request
osSpTaskYield(); osSpTaskYield();
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08d:osSpTaskYield\n", (u32)(OS_CYCLES_TO_USEC(osGetTime())));
PRINTF("%08d:osSpTaskYield\n", (u32)(OS_CYCLES_TO_USEC(osGetTime())));
}
} }
} }
@ -405,11 +415,9 @@ void Sched_RunTask(Scheduler* sc, OSScTask* spTask, OSScTask* dpTask) {
// Run RSP // Run RSP
osSpTaskStartGo(&spTask->list); osSpTaskStartGo(&spTask->list);
if (sLogScheduler) { SCHED_DEBUG_PRINTF(
PRINTF( "%08d:osSpTaskStartGo(%08x) %s\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), &spTask->list,
"%08d:osSpTaskStartGo(%08x) %s\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), &spTask->list, (spTask->list.t.type == M_AUDTASK ? "AUDIO" : (spTask->list.t.type == M_GFXTASK ? "GRAPH" : "OTHER")));
(spTask->list.t.type == M_AUDTASK ? "AUDIO" : (spTask->list.t.type == M_GFXTASK ? "GRAPH" : "OTHER")));
}
// Set currently running RSP task // Set currently running RSP task
sc->curRSPTask = spTask; sc->curRSPTask = spTask;
@ -442,9 +450,8 @@ void Sched_HandleNotification(Scheduler* sc) {
// signal to the currently running task to yield the RSP so that the audio task may // signal to the currently running task to yield the RSP so that the audio task may
// be ran as soon as possible. // be ran as soon as possible.
if (sc->doAudio && sc->curRSPTask != NULL) { if (sc->doAudio && sc->curRSPTask != NULL) {
if (sLogScheduler) { SCHED_DEBUG_PRINTF("[YIELD B]");
PRINTF("[YIELD B]");
}
Sched_Yield(sc); Sched_Yield(sc);
return; return;
} }
@ -454,15 +461,12 @@ void Sched_HandleNotification(Scheduler* sc) {
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) { if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
Sched_RunTask(sc, nextRSP, nextRDP); Sched_RunTask(sc, nextRSP, nextRDP);
} }
if (sLogScheduler) { SCHED_DEBUG_PRINTF("EN sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
PRINTF("EN sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
}
} }
void Sched_HandleRetrace(Scheduler* sc) { void Sched_HandleRetrace(Scheduler* sc) {
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08d:scHandleRetrace %08x\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), osViGetCurrentFramebuffer());
PRINTF("%08d:scHandleRetrace %08x\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), osViGetCurrentFramebuffer());
}
ViConfig_UpdateBlack(); ViConfig_UpdateBlack();
sc->retraceCount++; sc->retraceCount++;
@ -490,11 +494,9 @@ void Sched_HandleRetrace(Scheduler* sc) {
} }
} }
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08x %08x %08x %d\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(),
PRINTF("%08x %08x %08x %d\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(), (sc->pendingSwapBuf1 != NULL) ? sc->pendingSwapBuf1->swapBuffer : NULL,
(sc->pendingSwapBuf1 != NULL) ? sc->pendingSwapBuf1->swapBuffer : NULL, (sc->curBuf != NULL) ? sc->curBuf->updateTimer : 0);
(sc->curBuf != NULL) ? sc->curBuf->updateTimer : 0);
}
// Run the notification handler to enqueue any waiting tasks and possibly run one // Run the notification handler to enqueue any waiting tasks and possibly run one
Sched_HandleNotification(sc); Sched_HandleNotification(sc);
@ -524,14 +526,11 @@ void Sched_HandleRSPDone(Scheduler* sc) {
curRSPTask = sc->curRSPTask; curRSPTask = sc->curRSPTask;
sc->curRSPTask = NULL; sc->curRSPTask = NULL;
if (sLogScheduler) { SCHED_DEBUG_PRINTF("RSP DONE %d %d", curRSPTask->state & OS_SC_YIELD, osSpTaskYielded(&curRSPTask->list));
PRINTF("RSP DONE %d %d", curRSPTask->state & OS_SC_YIELD, osSpTaskYielded(&curRSPTask->list));
}
if ((curRSPTask->state & OS_SC_YIELD) && osSpTaskYielded(&curRSPTask->list)) { if ((curRSPTask->state & OS_SC_YIELD) && osSpTaskYielded(&curRSPTask->list)) {
if (sLogScheduler) { SCHED_DEBUG_PRINTF("[YIELDED]\n");
PRINTF("[YIELDED]\n");
}
// Task yielded, set yielded state // Task yielded, set yielded state
curRSPTask->state |= OS_SC_YIELDED; curRSPTask->state |= OS_SC_YIELDED;
// Add it to the front of the queue // Add it to the front of the queue
@ -541,9 +540,7 @@ void Sched_HandleRSPDone(Scheduler* sc) {
sc->gfxListTail = curRSPTask; sc->gfxListTail = curRSPTask;
} }
} else { } else {
if (sLogScheduler) { SCHED_DEBUG_PRINTF("[NOT YIELDED]\n");
PRINTF("[NOT YIELDED]\n");
}
// Task has completed on the RSP, unset RSP flag and check if the task is fully complete // Task has completed on the RSP, unset RSP flag and check if the task is fully complete
curRSPTask->state &= ~OS_SC_SP; curRSPTask->state &= ~OS_SC_SP;
Sched_TaskComplete(sc, curRSPTask); Sched_TaskComplete(sc, curRSPTask);
@ -554,9 +551,7 @@ void Sched_HandleRSPDone(Scheduler* sc) {
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) { if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
Sched_RunTask(sc, nextRSP, nextRDP); Sched_RunTask(sc, nextRSP, nextRDP);
} }
if (sLogScheduler) { SCHED_DEBUG_PRINTF("SP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
PRINTF("SP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
}
} }
/** /**
@ -588,9 +583,7 @@ void Sched_HandleRDPDone(Scheduler* sc) {
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) { if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
Sched_RunTask(sc, nextRSP, nextRDP); Sched_RunTask(sc, nextRSP, nextRDP);
} }
if (sLogScheduler) { SCHED_DEBUG_PRINTF("DP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
PRINTF("DP sc:%08x sp:%08x dp:%08x state:%x\n", sc, nextRSP, nextRDP, state);
}
} }
/** /**
@ -601,9 +594,7 @@ void Sched_HandleRDPDone(Scheduler* sc) {
* Original name: osScKickEntryMsg * Original name: osScKickEntryMsg
*/ */
void Sched_Notify(Scheduler* sc) { void Sched_Notify(Scheduler* sc) {
if (sLogScheduler) { SCHED_DEBUG_PRINTF("osScKickEntryMsg\n");
PRINTF("osScKickEntryMsg\n");
}
osSendMesg(&sc->interruptQueue, (OSMesg)NOTIFY_MSG, OS_MESG_BLOCK); osSendMesg(&sc->interruptQueue, (OSMesg)NOTIFY_MSG, OS_MESG_BLOCK);
} }
@ -613,41 +604,38 @@ void Sched_ThreadEntry(void* arg) {
Scheduler* sc = (Scheduler*)arg; Scheduler* sc = (Scheduler*)arg;
while (true) { while (true) {
if (sLogScheduler) { // "%08d: standby"
// "%08d: standby" SCHED_DEBUG_PRINTF("%08d:待機中\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
PRINTF("%08d:待機中\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
}
// Await interrupt messages, either from the OS, IrqMgr, or another thread // Await interrupt messages, either from the OS, IrqMgr, or another thread
osRecvMesg(&sc->interruptQueue, &msg, OS_MESG_BLOCK); osRecvMesg(&sc->interruptQueue, &msg, OS_MESG_BLOCK);
switch ((s32)msg) { switch ((s32)msg) {
case NOTIFY_MSG: case NOTIFY_MSG:
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08d:ENTRY_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
PRINTF("%08d:ENTRY_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
}
Sched_HandleNotification(sc); Sched_HandleNotification(sc);
continue; continue;
case RSP_DONE_MSG: case RSP_DONE_MSG:
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08d:RSP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
PRINTF("%08d:RSP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
}
Sched_HandleRSPDone(sc); Sched_HandleRSPDone(sc);
continue; continue;
case RDP_DONE_MSG: case RDP_DONE_MSG:
if (sLogScheduler) { SCHED_DEBUG_PRINTF("%08d:RDP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
PRINTF("%08d:RDP_DONE_MSG\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
}
Sched_HandleRDPDone(sc); Sched_HandleRDPDone(sc);
continue; continue;
} }
switch (((OSScMsg*)msg)->type) { switch (((OSScMsg*)msg)->type) {
case OS_SC_RETRACE_MSG: case OS_SC_RETRACE_MSG:
Sched_HandleRetrace(sc); Sched_HandleRetrace(sc);
continue; continue;
case OS_SC_PRE_NMI_MSG: case OS_SC_PRE_NMI_MSG:
Sched_HandlePreNMI(sc); Sched_HandlePreNMI(sc);
continue; continue;
case OS_SC_NMI_MSG: case OS_SC_NMI_MSG:
Sched_HandleNMI(sc); Sched_HandleNMI(sc);
continue; continue;