1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 05:45:03 +00:00
oot/src/libultra_boot_O2/__osDevMgrMain.c

100 lines
4.1 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <global.h>
#include <ultra64/hardware.h>
2020-03-22 21:19:43 +00:00
void __osDevMgrMain(void* arg) {
2020-03-17 04:31:30 +00:00
OSIoMesg* ioMesg;
OSMesg sp70;
OSMesg sp6C;
OSMgrArgs* arg0;
__OSTranxInfo* transfer;
__OSBlockInfo* block;
s32 phi_s2;
s32 phi_s0;
u32 sp54;
arg0 = (OSMgrArgs*)arg;
ioMesg = NULL;
2020-03-22 21:19:43 +00:00
while (true) {
2020-03-17 04:31:30 +00:00
osRecvMesg(arg0->cmdQueue, (OSMesg)&ioMesg, OS_MESG_BLOCK);
2020-03-22 21:19:43 +00:00
if ((ioMesg->piHandle != NULL) && (ioMesg->piHandle->type == DEVICE_TYPE_64DD) &&
((ioMesg->piHandle->transferInfo.cmdType == 0) || (ioMesg->piHandle->transferInfo.cmdType == 1))) {
2020-03-17 04:31:30 +00:00
transfer = &ioMesg->piHandle->transferInfo;
block = &transfer->block[transfer->blockNum];
transfer->sectorNum = -1;
2020-03-22 21:19:43 +00:00
if (transfer->transferMode != 3) {
2020-03-17 04:31:30 +00:00
block->dramAddr = (void*)((u32)block->dramAddr - block->sectorSize);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
phi_s2 = ((transfer->transferMode == 2) && (ioMesg->piHandle->transferInfo.cmdType == 0)) ? 1 : 0;
osRecvMesg(arg0->acccessQueue, &sp6C, OS_MESG_BLOCK);
__osResetGlobalIntMask(0x00100401);
__osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x80000000);
2020-03-22 21:19:43 +00:00
while (true) {
2020-03-17 04:31:30 +00:00
osRecvMesg(arg0->eventQueue, &sp70, OS_MESG_BLOCK);
transfer = &ioMesg->piHandle->transferInfo;
block = &transfer->block[transfer->blockNum];
2020-03-22 21:19:43 +00:00
if (block->errStatus == 0x1D) {
2020-03-17 04:31:30 +00:00
__osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x10000000);
__osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow);
__osEPiRawReadIo(ioMesg->piHandle, 0x05000508, &sp54);
2020-03-22 21:19:43 +00:00
if (sp54 & 0x02000000) {
2020-03-17 04:31:30 +00:00
__osEPiRawWriteIo(ioMesg->piHandle, 0x05000510, transfer->bmCtlShadow | 0x1000000);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
block->errStatus = 4;
HW_REG(PI_STATUS_REG, u32) = PI_STATUS_CLEAR_INTR;
__osSetGlobalIntMask(0x00100C01);
}
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
2020-03-22 21:19:43 +00:00
if ((phi_s2 != 1) || (ioMesg->piHandle->transferInfo.block[0].errStatus != 0)) {
2020-03-17 04:31:30 +00:00
break;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
phi_s2 = 0;
}
osSendMesg(arg0->acccessQueue, 0, OS_MESG_NOBLOCK);
2020-03-22 21:19:43 +00:00
if (ioMesg->piHandle->transferInfo.blockNum == 1) {
2020-03-17 04:31:30 +00:00
osYieldThread();
2020-03-22 21:19:43 +00:00
}
} else {
switch (ioMesg->hdr.type) {
2020-03-17 04:31:30 +00:00
case 11:
osRecvMesg(arg0->acccessQueue, &sp6C, OS_MESG_BLOCK);
phi_s0 = arg0->piDmaCallback(OS_READ, ioMesg->devAddr, ioMesg->dramAddr, ioMesg->size);
break;
case 12:
osRecvMesg(arg0->acccessQueue, &sp6C, OS_MESG_BLOCK);
phi_s0 = arg0->piDmaCallback(OS_WRITE, ioMesg->devAddr, ioMesg->dramAddr, ioMesg->size);
break;
case 15:
osRecvMesg(arg0->acccessQueue, &sp6C, OS_MESG_BLOCK);
2020-03-22 21:19:43 +00:00
phi_s0 = arg0->epiDmaCallback(ioMesg->piHandle, OS_READ, ioMesg->devAddr, ioMesg->dramAddr,
ioMesg->size);
2020-03-17 04:31:30 +00:00
break;
case 16:
osRecvMesg(arg0->acccessQueue, &sp6C, OS_MESG_BLOCK);
2020-03-22 21:19:43 +00:00
phi_s0 = arg0->epiDmaCallback(ioMesg->piHandle, OS_WRITE, ioMesg->devAddr, ioMesg->dramAddr,
ioMesg->size);
2020-03-17 04:31:30 +00:00
break;
case 10:
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
phi_s0 = -1;
break;
default:
phi_s0 = -1;
break;
}
2020-03-22 21:19:43 +00:00
if (phi_s0 == 0) {
2020-03-17 04:31:30 +00:00
osRecvMesg(arg0->eventQueue, &sp70, OS_MESG_BLOCK);
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
osSendMesg(arg0->acccessQueue, NULL, OS_MESG_NOBLOCK);
}
}
}
}