mirror of https://github.com/zeldaret/tp.git
316 lines
9.1 KiB
C
316 lines
9.1 KiB
C
//
|
|
// Generated By: dol2asm
|
|
// Translation Unit: OSExec
|
|
//
|
|
|
|
#include "dolphin/os/OSExec.h"
|
|
#include "dolphin/os.h"
|
|
#include "dolphin/ai.h"
|
|
#include "dol2asm.h"
|
|
#include "string.h"
|
|
#include "printf.h"
|
|
|
|
/* 8033CA80-8033CC08 3373C0 0188+00 1/1 0/0 0/0 .text PackArgs */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
static asm s32 PackArgs(void* param_0, u32 param_1, void* param_2) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSExec/PackArgs.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033CC08-8033CC44 337548 003C+00 1/1 0/0 0/0 .text Run */
|
|
static asm void Run(int param_0) {
|
|
// clang-format off
|
|
nofralloc
|
|
|
|
mflr r0
|
|
stw r0, 4(r1)
|
|
stwu r1, -0x18(r1)
|
|
stw r31, 0x14(r1)
|
|
mr r31, r3
|
|
bl ICFlashInvalidate
|
|
sync
|
|
isync
|
|
mtlr r31
|
|
blr
|
|
|
|
lwz r0, 0x1c(r1)
|
|
lwz r31, 0x14(r1)
|
|
addi r1, r1, 0x18
|
|
mtlr r0
|
|
blr
|
|
// clang-format on
|
|
}
|
|
|
|
/* 8033CC44-8033CCB0 337584 006C+00 1/1 0/0 0/0 .text ReadDisc */
|
|
static void ReadDisc(void* param_0, s32 param_1, s32 param_2) {
|
|
DVDCommandBlock cmd;
|
|
DVDReadAbsAsyncPrio(&cmd, param_0, param_1, param_2, NULL, 0);
|
|
while (DVDGetCommandBlockStatus(&cmd)) {
|
|
if (!DVDCheckDisk()) {
|
|
__OSDoHotReset(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* ############################################################################################## */
|
|
/* 80451658-8045165C 000B58 0004+00 2/2 0/0 0/0 .sbss Prepared */
|
|
static BOOL Prepared;
|
|
|
|
/* 8033CCB0-8033CCBC 3375F0 000C+00 1/1 0/0 0/0 .text Callback */
|
|
static void Callback(void) {
|
|
Prepared = TRUE;
|
|
}
|
|
|
|
OSExecParams* osExecParams : 0x800030f0;
|
|
|
|
/* 8033CCBC-8033CCFC 3375FC 0040+00 0/0 1/1 0/0 .text __OSGetExecParams */
|
|
void __OSGetExecParams(OSExecParams* param_0) {
|
|
if (OSPhysicalToCached(0) <= osExecParams) {
|
|
memcpy(param_0, osExecParams, sizeof(OSExecParams));
|
|
} else {
|
|
param_0->valid = FALSE;
|
|
}
|
|
}
|
|
|
|
static __OSSetExecParams(const OSExecParams* src, OSExecParams* dst) {
|
|
memcpy(dst, src, sizeof(OSExecParams));
|
|
osExecParams = dst;
|
|
}
|
|
|
|
/* ############################################################################################## */
|
|
/* 8045165C-80451660 000B5C 0004+00 2/2 0/0 0/0 .sbss apploaderPosition$69 */
|
|
static s32 apploaderPosition;
|
|
|
|
/* 8033CCFC-8033CDC0 33763C 00C4+00 1/1 0/0 0/0 .text GetApploaderPosition */
|
|
s32 appLoaderOffset : 0x800030f4;
|
|
|
|
static int GetApploaderPosition(void) {
|
|
u8 padding[8];
|
|
|
|
if (apploaderPosition != 0) {
|
|
return apploaderPosition;
|
|
}
|
|
|
|
if (appLoaderOffset) {
|
|
void* buffer = OSAllocFromArenaLo(0x40, 0x20);
|
|
ReadDisc(buffer, 0x40, appLoaderOffset);
|
|
apploaderPosition = appLoaderOffset + ((s32*)buffer)[0xe];
|
|
} else {
|
|
apploaderPosition = 0x2440;
|
|
}
|
|
return apploaderPosition;
|
|
}
|
|
|
|
/* ############################################################################################## */
|
|
/* 803CFC38-803CFC48 02CD58 000B+05 1/1 0/0 0/0 .data @115 */
|
|
SECTION_DATA static char lit_115[] = "2004/02/01";
|
|
|
|
/* 8033CDC0-8033D244 337700 0484+00 1/1 0/0 0/0 .text __OSBootDolSimple */
|
|
// GetApploaderPosition inline issue + end of function
|
|
#ifdef NONMATCHING
|
|
|
|
typedef int (*AppLoaderInnerCallback)(void*, s32*, s32*);
|
|
typedef void (*LogCallback)(void*);
|
|
typedef void (*AppLoaderCallback)(LogCallback*, AppLoaderInnerCallback*, int (**callback)(void));
|
|
|
|
typedef struct {
|
|
char version[10];
|
|
s16 field_0xa;
|
|
s32 field_0xc;
|
|
AppLoaderCallback field_0x10;
|
|
s32 field_0x14;
|
|
s32 field_0x18;
|
|
s32 field_0x1c;
|
|
} AppLoaderStruct;
|
|
|
|
static AppLoaderStruct* LoadApploader() {
|
|
AppLoaderStruct* iVar1;
|
|
s32 pos;
|
|
s32 nextPos;
|
|
|
|
iVar1 = (AppLoaderStruct*)OSAllocFromArenaLo(sizeof(AppLoaderStruct), sizeof(AppLoaderStruct));
|
|
pos = GetApploaderPosition();
|
|
ReadDisc(iVar1, sizeof(AppLoaderStruct), pos);
|
|
nextPos = GetApploaderPosition();
|
|
ReadDisc((void*)0x81200000, iVar1->field_0x14 + 0x1fU & 0xffffffe0, nextPos + 0x20);
|
|
ICInvalidateRange((void*)0x81200000, iVar1->field_0x14 + 0x1fU & 0xffffffe0);
|
|
return iVar1;
|
|
}
|
|
|
|
static BOOL IsNewApploader(const char* version) {
|
|
BOOL rv;
|
|
if (strncmp(version, "2004/02/01", 10) > 0) {
|
|
rv = TRUE;
|
|
} else {
|
|
rv = FALSE;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
static int LoadDol(OSExecParams* def, AppLoaderCallback cb) {
|
|
LogCallback local_c;
|
|
AppLoaderInnerCallback innercb;
|
|
int (*local_14)(void);
|
|
OSExecParams* execParams;
|
|
void* local_18;
|
|
s32 local_1c;
|
|
s32 local_20;
|
|
cb(&local_c, &innercb, &local_14);
|
|
execParams = OSAllocFromArenaLo(sizeof(OSExecParams), 1);
|
|
__OSSetExecParams(def, execParams);
|
|
local_c(OSReport);
|
|
OSSetArenaLo(execParams);
|
|
while (innercb(&local_18, &local_1c, &local_20)) {
|
|
ReadDisc(local_18, local_1c, local_20);
|
|
}
|
|
return (*local_14)();
|
|
}
|
|
|
|
static void StartDol(OSExecParams* execParams, int param_1) {
|
|
OSExecParams* uVar1 = (OSExecParams*)OSAllocFromArenaLo(sizeof(OSExecParams), 1);
|
|
__OSSetExecParams(execParams, uVar1);
|
|
__PIRegs[9] = 7;
|
|
OSDisableInterrupts();
|
|
Run(param_1);
|
|
}
|
|
|
|
u8 DAT_800030e2 : 0x800030E2;
|
|
|
|
void __OSBootDolSimple(u32 param_0, u32 param_1, void* param_2, void* param_3, s32 param_4, u32 param_5, void* param_6) {
|
|
OSExecParams* puVar1;
|
|
AppLoaderStruct* iVar3;
|
|
DVDDiskID* id;
|
|
int uVar2;
|
|
s32 iVar4;
|
|
s32 is_streaming;
|
|
DVDCommandBlock cmd;
|
|
|
|
OSDisableInterrupts();
|
|
puVar1 = (OSExecParams*)OSAllocFromArenaLo(sizeof(OSExecParams), 1);
|
|
puVar1->valid = 1;
|
|
puVar1->restartCode = param_1;
|
|
puVar1->regionStart = param_2;
|
|
puVar1->regionEnd = param_3;
|
|
puVar1->argsUseDefault = param_4;
|
|
if (param_4 == 0) {
|
|
puVar1->argsAddr = OSAllocFromArenaLo(0x2000, 1);
|
|
PackArgs(puVar1->argsAddr, param_5, param_6);
|
|
}
|
|
DVDInit();
|
|
DVDSetAutoInvalidation(TRUE);
|
|
DVDResume();
|
|
Prepared = FALSE;
|
|
__DVDPrepareResetAsync((DVDCBCallback)Callback);
|
|
__OSMaskInterrupts(0xffffffe0);
|
|
__OSUnmaskInterrupts(0x400);
|
|
OSEnableInterrupts();
|
|
while (Prepared != TRUE) {
|
|
if (!DVDCheckDisk()) {
|
|
__OSDoHotReset(0);
|
|
}
|
|
}
|
|
|
|
if (!__OSIsGcam) {
|
|
id = DVDGetCurrentDiskID();
|
|
if (id->is_streaming) {
|
|
is_streaming = TRUE;
|
|
} else {
|
|
is_streaming = FALSE;
|
|
}
|
|
if (is_streaming) {
|
|
AISetStreamVolLeft(0);
|
|
AISetStreamVolRight(0);
|
|
DVDCancelStreamAsync(&cmd, NULL);
|
|
while (DVDGetCommandBlockStatus(&cmd)) {
|
|
if (!DVDCheckDisk()) {
|
|
__OSDoHotReset(0);
|
|
}
|
|
}
|
|
AISetStreamPlayState(0);
|
|
}
|
|
}
|
|
|
|
iVar3 = LoadApploader();
|
|
if (IsNewApploader(iVar3->version)) {
|
|
if (param_0 == -1) {
|
|
param_0 = GetApploaderPosition();
|
|
param_0 += iVar3->field_0x14;
|
|
param_0 += 0x20;
|
|
}
|
|
puVar1->bootDol = param_0;
|
|
uVar2 = LoadDol(puVar1, iVar3->field_0x10);
|
|
StartDol(puVar1, uVar2);
|
|
} else {
|
|
BOOT_REGION_START = (u32)param_2;
|
|
BOOT_REGION_END = (u32)param_3;
|
|
DAT_800030e2 = 1;
|
|
// GetApploaderPosition is inlined for some reason
|
|
iVar4 = GetApploaderPosition() + iVar3->field_0x14;
|
|
ReadDisc((void*)0x81300000, iVar3->field_0x18 + 0x1fU & 0xffffffe0,
|
|
iVar4 + 0x20);
|
|
ICInvalidateRange((void*)0x81300000, iVar3->field_0x18 + 0x1fU & 0xffffffe0);
|
|
OSDisableInterrupts();
|
|
ICFlashInvalidate();
|
|
Run(0x81300000);
|
|
}
|
|
}
|
|
#else
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void __OSBootDolSimple(u32 param_0, u32 param_1, void* param_2, void* param_3, s32 param_4, u32 param_5, void* param_6) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSExec/__OSBootDolSimple.s"
|
|
}
|
|
#pragma pop
|
|
#endif
|
|
|
|
/* ############################################################################################## */
|
|
/* 804509A8-804509B0 000428 0003+05 1/1 0/0 0/0 .sdata @213 */
|
|
SECTION_SDATA static char lit_213[] = "%d";
|
|
|
|
/* 8033D244-8033D3E0 337B84 019C+00 0/0 1/1 0/0 .text __OSBootDol */
|
|
#ifdef NONMATCHING
|
|
void __OSBootDol(s32 param_0, u32 param_1, char** param_2) {
|
|
char acStack_28[20];
|
|
void* local_2c;
|
|
void* local_30;
|
|
s32 iVar3;
|
|
char** ppcVar1;
|
|
char** ppcVar2;
|
|
char** ppcVarDst;
|
|
char** ppcVarSrc;
|
|
int iVar2;
|
|
OSGetSaveRegion(&local_2c, &local_30);
|
|
sprintf(acStack_28, "%d", param_0);
|
|
iVar3 = 0;
|
|
if (param_2 != NULL) {
|
|
ppcVar2 = param_2;
|
|
while (*ppcVar2 != NULL) {
|
|
ppcVar2++;
|
|
iVar3++;
|
|
}
|
|
}
|
|
ppcVar1 = (char**)OSAllocFromArenaLo((iVar3 + 2) * 4, 1);
|
|
*ppcVar1 = acStack_28;
|
|
ppcVarSrc = param_2;
|
|
ppcVarDst = ppcVar1 + 1;
|
|
for (iVar2 = 1; iVar2 < iVar3 + 1; iVar2++) {
|
|
*ppcVarDst++ = *ppcVarSrc++;
|
|
}
|
|
__OSBootDolSimple(0xffffffff, param_1, local_2c, local_30, 0, iVar3 + 1, ppcVar1);
|
|
}
|
|
#else
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void __OSBootDol(s32 param_0, u32 param_1, char** param_2) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSExec/__OSBootDol.s"
|
|
}
|
|
#pragma pop
|
|
#endif
|