diff --git a/asm/dolphin/os/OSExec/GetApploaderPosition.s b/asm/dolphin/os/OSExec/GetApploaderPosition.s deleted file mode 100644 index 02ad7c3f350..00000000000 --- a/asm/dolphin/os/OSExec/GetApploaderPosition.s +++ /dev/null @@ -1,58 +0,0 @@ -lbl_8033CCFC: -/* 8033CCFC 7C 08 02 A6 */ mflr r0 -/* 8033CD00 90 01 00 04 */ stw r0, 4(r1) -/* 8033CD04 94 21 FF B8 */ stwu r1, -0x48(r1) -/* 8033CD08 93 E1 00 44 */ stw r31, 0x44(r1) -/* 8033CD0C 80 6D 90 DC */ lwz r3, apploaderPosition(r13) -/* 8033CD10 2C 03 00 00 */ cmpwi r3, 0 -/* 8033CD14 41 82 00 08 */ beq lbl_8033CD1C -/* 8033CD18 48 00 00 94 */ b lbl_8033CDAC -lbl_8033CD1C: -/* 8033CD1C 3F E0 80 00 */ lis r31, 0x8000 /* 0x800030F4@ha */ -/* 8033CD20 80 1F 30 F4 */ lwz r0, 0x30F4(r31) /* 0x800030F4@l */ -/* 8033CD24 2C 00 00 00 */ cmpwi r0, 0 -/* 8033CD28 41 82 00 78 */ beq lbl_8033CDA0 -/* 8033CD2C 38 60 00 40 */ li r3, 0x40 -/* 8033CD30 38 80 00 20 */ li r4, 0x20 -/* 8033CD34 4B FF E5 79 */ bl OSAllocFromArenaLo -/* 8033CD38 80 DF 30 F4 */ lwz r6, 0x30f4(r31) -/* 8033CD3C 7C 7F 1B 78 */ mr r31, r3 -/* 8033CD40 7F E4 FB 78 */ mr r4, r31 -/* 8033CD44 38 61 00 08 */ addi r3, r1, 8 -/* 8033CD48 38 A0 00 40 */ li r5, 0x40 -/* 8033CD4C 38 E0 00 00 */ li r7, 0 -/* 8033CD50 39 00 00 00 */ li r8, 0 -/* 8033CD54 48 00 DF D9 */ bl DVDReadAbsAsyncPrio -/* 8033CD58 48 00 00 04 */ b lbl_8033CD5C -lbl_8033CD5C: -/* 8033CD5C 48 00 00 04 */ b lbl_8033CD60 -lbl_8033CD60: -/* 8033CD60 48 00 00 18 */ b lbl_8033CD78 -lbl_8033CD64: -/* 8033CD64 48 00 E8 C5 */ bl DVDCheckDisk -/* 8033CD68 2C 03 00 00 */ cmpwi r3, 0 -/* 8033CD6C 40 82 00 0C */ bne lbl_8033CD78 -/* 8033CD70 38 60 00 00 */ li r3, 0 -/* 8033CD74 48 00 2A F1 */ bl __OSDoHotReset -lbl_8033CD78: -/* 8033CD78 38 61 00 08 */ addi r3, r1, 8 -/* 8033CD7C 48 00 E4 01 */ bl DVDGetCommandBlockStatus -/* 8033CD80 2C 03 00 00 */ cmpwi r3, 0 -/* 8033CD84 40 82 FF E0 */ bne lbl_8033CD64 -/* 8033CD88 3C 60 80 00 */ lis r3, 0x8000 /* 0x800030F4@ha */ -/* 8033CD8C 80 1F 00 38 */ lwz r0, 0x38(r31) -/* 8033CD90 80 63 30 F4 */ lwz r3, 0x30F4(r3) /* 0x800030F4@l */ -/* 8033CD94 7C 03 02 14 */ add r0, r3, r0 -/* 8033CD98 90 0D 90 DC */ stw r0, apploaderPosition(r13) -/* 8033CD9C 48 00 00 0C */ b lbl_8033CDA8 -lbl_8033CDA0: -/* 8033CDA0 38 00 24 40 */ li r0, 0x2440 -/* 8033CDA4 90 0D 90 DC */ stw r0, apploaderPosition(r13) -lbl_8033CDA8: -/* 8033CDA8 80 6D 90 DC */ lwz r3, apploaderPosition(r13) -lbl_8033CDAC: -/* 8033CDAC 80 01 00 4C */ lwz r0, 0x4c(r1) -/* 8033CDB0 83 E1 00 44 */ lwz r31, 0x44(r1) -/* 8033CDB4 38 21 00 48 */ addi r1, r1, 0x48 -/* 8033CDB8 7C 08 03 A6 */ mtlr r0 -/* 8033CDBC 4E 80 00 20 */ blr diff --git a/asm/dolphin/os/OSExec/ReadDisc.s b/asm/dolphin/os/OSExec/ReadDisc.s deleted file mode 100644 index 8711599d81b..00000000000 --- a/asm/dolphin/os/OSExec/ReadDisc.s +++ /dev/null @@ -1,32 +0,0 @@ -lbl_8033CC44: -/* 8033CC44 7C 08 02 A6 */ mflr r0 -/* 8033CC48 90 01 00 04 */ stw r0, 4(r1) -/* 8033CC4C 94 21 FF B8 */ stwu r1, -0x48(r1) -/* 8033CC50 7C 80 23 78 */ mr r0, r4 -/* 8033CC54 7C A6 2B 78 */ mr r6, r5 -/* 8033CC58 7C 64 1B 78 */ mr r4, r3 -/* 8033CC5C 7C 05 03 78 */ mr r5, r0 -/* 8033CC60 38 61 00 14 */ addi r3, r1, 0x14 -/* 8033CC64 38 E0 00 00 */ li r7, 0 -/* 8033CC68 39 00 00 00 */ li r8, 0 -/* 8033CC6C 48 00 E0 C1 */ bl DVDReadAbsAsyncPrio -/* 8033CC70 48 00 00 04 */ b lbl_8033CC74 -lbl_8033CC74: -/* 8033CC74 48 00 00 04 */ b lbl_8033CC78 -lbl_8033CC78: -/* 8033CC78 48 00 00 18 */ b lbl_8033CC90 -lbl_8033CC7C: -/* 8033CC7C 48 00 E9 AD */ bl DVDCheckDisk -/* 8033CC80 2C 03 00 00 */ cmpwi r3, 0 -/* 8033CC84 40 82 00 0C */ bne lbl_8033CC90 -/* 8033CC88 38 60 00 00 */ li r3, 0 -/* 8033CC8C 48 00 2B D9 */ bl __OSDoHotReset -lbl_8033CC90: -/* 8033CC90 38 61 00 14 */ addi r3, r1, 0x14 -/* 8033CC94 48 00 E4 E9 */ bl DVDGetCommandBlockStatus -/* 8033CC98 2C 03 00 00 */ cmpwi r3, 0 -/* 8033CC9C 40 82 FF E0 */ bne lbl_8033CC7C -/* 8033CCA0 80 01 00 4C */ lwz r0, 0x4c(r1) -/* 8033CCA4 38 21 00 48 */ addi r1, r1, 0x48 -/* 8033CCA8 7C 08 03 A6 */ mtlr r0 -/* 8033CCAC 4E 80 00 20 */ blr diff --git a/asm/dolphin/os/OSExec/__OSGetExecParams.s b/asm/dolphin/os/OSExec/__OSGetExecParams.s deleted file mode 100644 index 78e2ae0ad24..00000000000 --- a/asm/dolphin/os/OSExec/__OSGetExecParams.s +++ /dev/null @@ -1,19 +0,0 @@ -lbl_8033CCBC: -/* 8033CCBC 7C 08 02 A6 */ mflr r0 -/* 8033CCC0 90 01 00 04 */ stw r0, 4(r1) -/* 8033CCC4 94 21 FF F8 */ stwu r1, -8(r1) -/* 8033CCC8 3C A0 80 00 */ lis r5, 0x8000 /* 0x800030F0@ha */ -/* 8033CCCC 80 85 30 F0 */ lwz r4, 0x30F0(r5) /* 0x800030F0@l */ -/* 8033CCD0 7C 05 20 40 */ cmplw r5, r4 -/* 8033CCD4 41 81 00 10 */ bgt lbl_8033CCE4 -/* 8033CCD8 38 A0 00 1C */ li r5, 0x1c -/* 8033CCDC 4B CC 68 65 */ bl memcpy -/* 8033CCE0 48 00 00 0C */ b lbl_8033CCEC -lbl_8033CCE4: -/* 8033CCE4 38 00 00 00 */ li r0, 0 -/* 8033CCE8 90 03 00 00 */ stw r0, 0(r3) -lbl_8033CCEC: -/* 8033CCEC 80 01 00 0C */ lwz r0, 0xc(r1) -/* 8033CCF0 38 21 00 08 */ addi r1, r1, 8 -/* 8033CCF4 7C 08 03 A6 */ mtlr r0 -/* 8033CCF8 4E 80 00 20 */ blr diff --git a/asm/dolphin/os/OSReboot/__OSReboot.s b/asm/dolphin/os/OSReboot/__OSReboot.s deleted file mode 100644 index bc30c1b928a..00000000000 --- a/asm/dolphin/os/OSReboot/__OSReboot.s +++ /dev/null @@ -1,29 +0,0 @@ -lbl_8033F5D0: -/* 8033F5D0 7C 08 02 A6 */ mflr r0 -/* 8033F5D4 90 01 00 04 */ stw r0, 4(r1) -/* 8033F5D8 94 21 FD 18 */ stwu r1, -0x2e8(r1) -/* 8033F5DC 93 E1 02 E4 */ stw r31, 0x2e4(r1) -/* 8033F5E0 3B E4 00 00 */ addi r31, r4, 0 -/* 8033F5E4 93 C1 02 E0 */ stw r30, 0x2e0(r1) -/* 8033F5E8 3B C3 00 00 */ addi r30, r3, 0 -/* 8033F5EC 4B FF E1 09 */ bl OSDisableInterrupts -/* 8033F5F0 3C 60 81 28 */ lis r3, 0x8128 -/* 8033F5F4 4B FF BC B1 */ bl OSSetArenaLo -/* 8033F5F8 3C 60 81 2F */ lis r3, 0x812f -/* 8033F5FC 4B FF BC A1 */ bl OSSetArenaHi -/* 8033F600 38 61 00 18 */ addi r3, r1, 0x18 -/* 8033F604 4B FF C9 FD */ bl OSClearContext -/* 8033F608 38 61 00 18 */ addi r3, r1, 0x18 -/* 8033F60C 4B FF C8 2D */ bl OSSetCurrentContext -/* 8033F610 38 00 00 00 */ li r0, 0 -/* 8033F614 90 01 00 10 */ stw r0, 0x10(r1) -/* 8033F618 38 7F 00 00 */ addi r3, r31, 0 -/* 8033F61C 67 C4 80 00 */ oris r4, r30, 0x8000 -/* 8033F620 38 A1 00 10 */ addi r5, r1, 0x10 -/* 8033F624 4B FF DC 21 */ bl __OSBootDol -/* 8033F628 80 01 02 EC */ lwz r0, 0x2ec(r1) -/* 8033F62C 83 E1 02 E4 */ lwz r31, 0x2e4(r1) -/* 8033F630 83 C1 02 E0 */ lwz r30, 0x2e0(r1) -/* 8033F634 38 21 02 E8 */ addi r1, r1, 0x2e8 -/* 8033F638 7C 08 03 A6 */ mtlr r0 -/* 8033F63C 4E 80 00 20 */ blr diff --git a/include/dolphin/dvd/dvd.h b/include/dolphin/dvd/dvd.h index 3c55da4c853..122cc2a4454 100644 --- a/include/dolphin/dvd/dvd.h +++ b/include/dolphin/dvd/dvd.h @@ -136,7 +136,7 @@ BOOL DVDSetAutoInvalidation(BOOL autoInval); void DVDResume(void); static BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback); s32 DVDCancel(DVDCommandBlock* block); - +void __DVDPrepareResetAsync(DVDCBCallback callbac); BOOL DVDCompareDiskID(DVDDiskID* id1, DVDDiskID* id2); #ifdef __cplusplus diff --git a/include/dolphin/os/OS.h b/include/dolphin/os/OS.h index 21bbc497974..32383d1480e 100644 --- a/include/dolphin/os/OS.h +++ b/include/dolphin/os/OS.h @@ -99,6 +99,11 @@ extern u8 __OSReport_Warning_disable; extern u8 __OSReport_System_disable; extern u8 __OSReport_enable; +extern BOOL __OSIsGcam; + +extern u32 BOOT_REGION_START : 0x812FDFF0; +extern u32 BOOT_REGION_END : 0x812FDFEC; + void OSReportInit__Fv(void); // needed for inline asm u8* OSGetStackPointer(void); @@ -189,16 +194,6 @@ typedef struct OSBootInfo { /* 0x3C */ u32 fst_max_length; } OSBootInfo; -typedef struct { - BOOL valid; - u32 restartCode; - u32 bootDol; - void* regionStart; - void* regionEnd; - BOOL argsUseDefault; - void* argsAddr; // valid only when argsUseDefault = FALSE -} OSExecParams; - typedef struct BI2Debug { /* 0x00 */ s32 debugMonSize; /* 0x04 */ s32 simMemSize; @@ -245,7 +240,7 @@ struct GLOBAL_MEMORY { u8 padding_0x30e0[4]; u32 field_0x30e4; /* __OSPADButton */ u8 padding_0x30ec[8]; - u32 field_0x30f0; /* DOL Execute Parameters */ + OSExecParams* field_0x30f0; /* DOL Execute Parameters */ u8 padding_0x30f4[12]; u32 field_0x3100; /* Physical MEM1 size */ u32 field_0x3104; /* Simulated MEM1 size */ diff --git a/include/dolphin/os/OSExec.h b/include/dolphin/os/OSExec.h index cb6a2a9d6a9..d2878e800cb 100644 --- a/include/dolphin/os/OSExec.h +++ b/include/dolphin/os/OSExec.h @@ -7,14 +7,23 @@ extern "C" { #endif +typedef struct { + /* 0x00 */ BOOL valid; + /* 0x04 */ u32 restartCode; + /* 0x08 */ u32 bootDol; + /* 0x0C */ void* regionStart; + /* 0x10 */ void* regionEnd; + /* 0x18 */ BOOL argsUseDefault; + /* 0x14 */ void* argsAddr; // valid only when argsUseDefault = FALSE +} OSExecParams; + static s32 PackArgs(void* param_0, u32 param_1, void* param_2); -static void Run(void); +static void Run(int param_0); static void ReadDisc(void* param_0, s32 param_1, s32 param_2); static void Callback(void); -void __OSGetExecParams(void* param_0); -static void GetApploaderPosition(void); +void __OSGetExecParams(OSExecParams* param_0); void __OSBootDolSimple(u32 param_0, u32 param_1, void* param_2, void* param_3, s32 param_4, u32 param_5, void* param_6); -void __OSBootDol(s32 param_0, u32 param_1, s32 param_2); +void __OSBootDol(s32 param_0, u32 param_1, char** param_2); #ifdef __cplusplus }; diff --git a/libs/dolphin/os/OS.c b/libs/dolphin/os/OS.c index 3a6702d8137..d1a4dd10eb1 100644 --- a/libs/dolphin/os/OS.c +++ b/libs/dolphin/os/OS.c @@ -87,7 +87,6 @@ extern f64 ZeroF; f64 ZeroF; /* 8045160C-80451610 000B0C 0004+00 1/1 1/1 0/0 .sbss __OSIsGcam */ -extern BOOL __OSIsGcam; BOOL __OSIsGcam; /* 80339DD4-80339EFC 334714 0128+00 0/0 1/1 0/0 .text __OSFPRInit */ @@ -193,9 +192,6 @@ static DVDDriveInfo DriveInfo; void* __OSSavedRegionStart; void* __OSSavedRegionEnd; -extern u32 BOOT_REGION_START : 0x812FDFF0; //(*(u32 *)0x812fdff0) -extern u32 BOOT_REGION_END : 0x812FDFEC; //(*(u32 *)0x812fdfec) - inline void ClearArena(void) { u32 resetCode = OSGetResetCode(); BOOL val = resetCode != 0U ? TRUE : FALSE; diff --git a/libs/dolphin/os/OSExec.c b/libs/dolphin/os/OSExec.c index ff49636e0e5..5e7a88ae6fc 100644 --- a/libs/dolphin/os/OSExec.c +++ b/libs/dolphin/os/OSExec.c @@ -4,46 +4,13 @@ // #include "dolphin/os/OSExec.h" +#include "dolphin/os/OS.h" +#include "dolphin/os/OSReset.h" +#include "dolphin/dvd/dvd.h" +#include "dolphin/ai/ai.h" #include "dol2asm.h" - -// -// External References: -// - -SECTION_INIT void memset(); -SECTION_INIT void memcpy(); -void OSReport(); -void OSSetArenaLo(); -void OSAllocFromArenaLo(); -void ICInvalidateRange(); -void ICFlashInvalidate(); -void OSDisableInterrupts(); -void OSEnableInterrupts(); -void __OSMaskInterrupts(); -void __OSUnmaskInterrupts(); -void OSGetSaveRegion(); -void __OSDoHotReset(); -void DVDInit(); -void DVDReadAbsAsyncPrio(); -void DVDCancelStreamAsync(); -void DVDGetCommandBlockStatus(); -void DVDSetAutoInvalidation(); -void DVDResume(); -void DVDGetCurrentDiskID(); -void DVDCheckDisk(); -void __DVDPrepareResetAsync(); -void AISetStreamPlayState(); -void AISetStreamVolLeft(); -void AISetStreamVolRight(); -void sprintf(); -void strncmp(); -void strcpy(); -void strlen(); -extern u8 __OSIsGcam[4]; - -// -// Declarations: -// +#include "MSL_C/MSL_Common/Src/string.h" +#include "MSL_C/MSL_Common/Src/printf.h" /* 8033CA80-8033CC08 3373C0 0188+00 1/1 0/0 0/0 .text PackArgs */ #pragma push @@ -56,7 +23,7 @@ static asm s32 PackArgs(void* param_0, u32 param_1, void* param_2) { #pragma pop /* 8033CC08-8033CC44 337548 003C+00 1/1 0/0 0/0 .text Run */ -static asm void Run(void) { +static asm void Run(int param_0) { // clang-format off nofralloc @@ -80,14 +47,15 @@ static asm void Run(void) { } /* 8033CC44-8033CCB0 337584 006C+00 1/1 0/0 0/0 .text ReadDisc */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -static asm void ReadDisc(void* param_0, s32 param_1, s32 param_2) { - nofralloc -#include "asm/dolphin/os/OSExec/ReadDisc.s" +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); + } + } } -#pragma pop /* ############################################################################################## */ /* 80451658-8045165C 000B58 0004+00 2/2 0/0 0/0 .sbss Prepared */ @@ -98,35 +66,200 @@ static void Callback(void) { Prepared = TRUE; } +OSExecParams* osExecParams : 0x800030f0; + /* 8033CCBC-8033CCFC 3375FC 0040+00 0/0 1/1 0/0 .text __OSGetExecParams */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void __OSGetExecParams(void* param_0) { - nofralloc -#include "asm/dolphin/os/OSExec/__OSGetExecParams.s" +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; } -#pragma pop /* ############################################################################################## */ /* 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 */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -static asm void GetApploaderPosition(void) { - nofralloc -#include "asm/dolphin/os/OSExec/GetApploaderPosition.s" +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; } -#pragma pop /* ############################################################################################## */ /* 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 @@ -135,17 +268,50 @@ asm void __OSBootDolSimple(u32 param_0, u32 param_1, void* param_2, void* param_ #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, s32 param_2) { +asm void __OSBootDol(s32 param_0, u32 param_1, char** param_2) { nofralloc #include "asm/dolphin/os/OSExec/__OSBootDol.s" } #pragma pop +#endif diff --git a/libs/dolphin/os/OSReboot.c b/libs/dolphin/os/OSReboot.c index 11ec464df09..274736930a7 100644 --- a/libs/dolphin/os/OSReboot.c +++ b/libs/dolphin/os/OSReboot.c @@ -4,32 +4,23 @@ // #include "dolphin/os/OSReboot.h" +#include "dolphin/os/OSArena.h" +#include "dolphin/os/OSContext.h" +#include "dolphin/os/OSExec.h" #include "dolphin/types.h" -// -// External References: -// - -void OSSetArenaHi(); -void OSSetArenaLo(); -void OSSetCurrentContext(); -void OSClearContext(); -void __OSBootDol(); -void OSDisableInterrupts(); - -// -// Declarations: -// - /* 8033F5D0-8033F640 339F10 0070+00 0/0 1/1 0/0 .text __OSReboot */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void __OSReboot(u32 param_0, u32 param_1) { - nofralloc -#include "asm/dolphin/os/OSReboot/__OSReboot.s" +void __OSReboot(u32 resetCode, u32 bootDol) { + struct OSContext context; + char* iVar1; + OSDisableInterrupts(); + OSSetArenaLo((void*)0x81280000); + OSSetArenaHi((void*)0x812f0000); + OSClearContext(&context); + OSSetCurrentContext(&context); + iVar1 = NULL; + __OSBootDol(bootDol, resetCode | 0x80000000, &iVar1); } -#pragma pop /* ############################################################################################## */ /* 80451688-8045168C 000B88 0004+00 2/2 0/0 0/0 .sbss SaveStart */