Match OSReboot.c and some of TRK + port mstory3Dll (#541)

* Match OSReboot.c and match some of TRK

* Port mstory3Dll
This commit is contained in:
dbalatoni13 2025-01-19 21:54:38 +01:00 committed by GitHub
parent edacd76015
commit 6575f573f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1438 additions and 1287 deletions

View file

@ -3,6 +3,7 @@
#include <dolphin/os/OSBootInfo.h>
#include <dolphin/os/OSContext.h>
#include <dolphin/os/OSInterrupt.h>
#include <dolphin/os/OSPriv.h>
typedef struct ApploaderHeader {
// total size: 0x20
@ -13,18 +14,7 @@ typedef struct ApploaderHeader {
u32 reserved2; // offset 0x1C, size 0x4
} ApploaderHeader;
struct {
// total size: 0x1C
int valid; // offset 0x0, size 0x4
unsigned long restartCode; // offset 0x4, size 0x4
unsigned long bootDol; // offset 0x8, size 0x4
void *regionStart; // offset 0xC, size 0x4
void *regionEnd; // offset 0x10, size 0x4
int argsUseDefault; // offset 0x14, size 0x4
void *argsAddr; // offset 0x18, size 0x4
} __OSRebootParams; // size: 0x1C, address: 0x0
static ApploaderHeader Header;
static ApploaderHeader Header ATTRIBUTE_ALIGN(32);
extern void *__OSSavedRegionStart;
extern void *__OSSavedRegionEnd;
@ -34,22 +24,25 @@ static void *SaveEnd = NULL;
volatile u8 DAT_800030e2 : 0x800030e2;
extern u32 BOOT_REGION_START AT_ADDRESS(0x812FDFF0); //(*(u32 *)0x812fdff0)
extern u32 BOOT_REGION_END AT_ADDRESS(0x812FDFEC); //(*(u32 *)0x812fdfec)
extern void *BOOT_REGION_START AT_ADDRESS(0x812FDFF0); //(*(u32 *)0x812fdff0)
extern void *BOOT_REGION_END AT_ADDRESS(0x812FDFEC); //(*(u32 *)0x812fdfec)
extern u32 UNK_HOT_RESET1 AT_ADDRESS(0x817ffff8);
extern u32 UNK_HOT_RESET2 AT_ADDRESS(0x817ffffc);
// extern u32 OS_RESET_CODE AT_ADDRESS(0x800030F0);
// extern u8 OS_REBOOT_BOOL AT_ADDRESS(0x800030E2); // unknown function, set to true by __OSReboot
extern u32 OS_RESET_CODE AT_ADDRESS(0x800030F0);
extern u8 OS_REBOOT_BOOL AT_ADDRESS(0x800030E2); // unknown function, set to true by __OSReboot
extern u32 UNK_817FFFF8 AT_ADDRESS(0x817FFFF8);
extern u32 UNK_817FFFFC AT_ADDRESS(0x817FFFFC);
extern u32 __OSIsGcam;
static BOOL Prepared = FALSE;
static volatile BOOL Prepared = FALSE;
extern void __DVDPrepareResetAsync(DVDCBCallback callback);
extern BOOL DVDCheckDisk(void);
extern BOOL DVDReadAbsAsyncForBS(DVDCommandBlock *block, void *addr, s32 length, s32 offset, DVDCBCallback callback);
void Run(register u32 addr)
#pragma dont_inline on
// peephole bug with mwcc
static asm void myFunc() { }
static void Run(register void (*addr)())
{
OSDisableInterrupts();
ICFlashInvalidate();
@ -62,33 +55,83 @@ void Run(register u32 addr)
}
// clang-format on
}
#pragma dont_inline reset
static void Callback()
{
Prepared = TRUE;
}
void ReadApploader(OSTime time1) { }
inline void ReadApploader(DVDCommandBlock *dvdCmd, void *addr, u32 offset, u32 numBytes)
{
/* Not sure if this inline is correct - might need to call other inlines */
while (Prepared == FALSE) { }
DVDReadAbsAsyncForBS(dvdCmd, addr, numBytes, offset + 0x2440, NULL);
while (TRUE) {
switch (dvdCmd->state) {
case 0:
break;
case 1:
default:
continue;
case -1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
__OSDoHotReset(UNK_817FFFFC);
continue;
}
break;
}
}
void __OSReboot(u32 resetCode, u32 bootDol)
{
// TODO
}
OSContext exceptionContext;
DVDCommandBlock dvdCmd;
DVDCommandBlock dvdCmd2;
u32 numBytes;
u32 offset;
void OSSetSaveRegion(void *start, void *end)
{
SaveStart = start;
SaveEnd = end;
}
OSDisableInterrupts();
void OSGetSaveRegion(void **start, void **end)
{
*start = SaveStart;
*end = SaveEnd;
}
UNK_817FFFFC = 0;
UNK_817FFFF8 = 0;
OS_REBOOT_BOOL = TRUE;
BOOT_REGION_START = SaveStart;
BOOT_REGION_END = SaveEnd;
OSClearContext(&exceptionContext);
OSSetCurrentContext(&exceptionContext);
DVDInit();
DVDSetAutoInvalidation(TRUE);
void OSGetSavedRegion(void **start, void **end)
{
*start = __OSSavedRegionStart;
*end = __OSSavedRegionEnd;
__DVDPrepareResetAsync(Callback);
if (!DVDCheckDisk()) {
__OSDoHotReset(UNK_817FFFFC);
}
__OSMaskInterrupts(0xffffffe0);
__OSUnmaskInterrupts(0x400);
OSEnableInterrupts();
offset = 0;
numBytes = 32;
ReadApploader(&dvdCmd, (void *)&Header, offset, numBytes);
offset = Header.size + 0x20;
numBytes = OSRoundUp32B(Header.rebootSize);
ReadApploader(&dvdCmd2, OS_BOOTROM_ADDR, offset, numBytes);
ICInvalidateRange(OS_BOOTROM_ADDR, numBytes);
Run(OS_BOOTROM_ADDR);
}