mirror of
https://github.com/zeldaret/tp
synced 2026-08-08 10:34:08 -04:00
Work on OSExec, OSReboot OK (#1992)
This commit is contained in:
@@ -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;
|
||||
|
||||
+228
-62
@@ -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
|
||||
|
||||
+13
-22
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user