Match and link OSReset

This commit is contained in:
Phillip Stephens 2022-10-11 00:01:27 -07:00
parent 111a04b74f
commit fecef57a18
6 changed files with 91 additions and 14 deletions

View File

@ -11,7 +11,11 @@
"files.associations": {
"source_location": "cpp",
"console_io.h": "c",
"file_struc.h": "c"
"file_struc.h": "c",
"osreset.h": "c",
"vi.h": "c",
"gxstruct.h": "c",
"vifuncs.h": "c"
},
"files.autoSave": "onFocusChange",
"files.insertFinalNewline": true,

View File

@ -91,7 +91,7 @@ lbl_80383120:
/* 80383130 00380090 38 21 00 20 */ addi r1, r1, 0x20
/* 80383134 00380094 7C 08 03 A6 */ mtlr r0
/* 80383138 00380098 4E 80 00 20 */ blr
.global Reset
Reset:
/* 8038313C 0038009C 48 00 00 20 */ b lbl_8038315C
lbl_80383140:

View File

@ -812,7 +812,7 @@ LIBS = [
"Dolphin/os/OSMemory",
"Dolphin/os/OSMutex",
"Dolphin/os/OSReboot",
"Dolphin/os/OSReset",
["Dolphin/os/OSReset", True],
"Dolphin/os/OSResetSW",
"Dolphin/os/OSRtc",
["Dolphin/os/OSSync", True],

View File

@ -7,6 +7,16 @@
extern "C" {
#endif
#define OS_RESETCODE_RESTART 0x80000000
#define OS_RESETCODE_SYSTEM 0x40000000
#define OS_RESETCODE_EXEC 0xC0000000
#define OS_RESETCODE_NETCONFIG 0xC0010000
#define OS_RESET_RESTART 0
#define OS_RESET_HOTRESET 1
#define OS_RESET_SHUTDOWN 2
typedef BOOL (*OSResetFunction)(BOOL final);
typedef struct OSResetFunctionInfo OSResetFunctionInfo;

View File

@ -700,9 +700,9 @@ OS_FILES :=\
$(BUILD_DIR)/asm/Dolphin/os/OSMemory.o\
$(BUILD_DIR)/asm/Dolphin/os/OSMutex.o\
$(BUILD_DIR)/asm/Dolphin/os/OSReboot.o\
$(BUILD_DIR)/asm/Dolphin/os/OSReset.o\
$(BUILD_DIR)/src/Dolphin/os/OSReset.ep.o\
$(BUILD_DIR)/asm/Dolphin/os/OSResetSW.o\
$(BUILD_DIR)/src/Dolphin/os/OSRtc.ep.o\
$(BUILD_DIR)/asm/Dolphin/os/OSRtc.o\
$(BUILD_DIR)/src/Dolphin/os/OSSync.o\
$(BUILD_DIR)/asm/Dolphin/os/OSThread.o\
$(BUILD_DIR)/asm/Dolphin/os/OSTime.o\

View File

@ -1,4 +1,6 @@
#include "dolphin/os/OSReset.h"
#include "dolphin/OSRtcPriv.h"
#include "dolphin/os.h"
#include "dolphin/vi.h"
volatile u8 DAT_800030e2 : 0x800030e2;
typedef struct Unk {
@ -52,10 +54,9 @@ void OSRegisterResetFunction(OSResetFunctionInfo* func) {
tmp->next = func;
}
s32 __OSCallResetFunctions(s32 arg0) {
BOOL __OSCallResetFunctions(u32 arg0) {
OSResetFunctionInfo* iter;
s32 retCode = 0;
u32 ret;
for (iter = ResetFunctionQueue.first; iter != NULL; iter = iter->next) {
retCode |= !iter->func(arg0);
@ -72,9 +73,9 @@ asm void Reset(register s32 resetCode) {
nofralloc
b lbl_8038315C
lbl_80383140:
mfspr r8, 0x3f0
mfspr r8, HID0
ori r8, r8, 8
mtspr 0x3f0, r8
mtspr HID0, r8
isync
sync
nop
@ -82,9 +83,9 @@ lbl_80383140:
lbl_8038315C:
b lbl_8038317C
lbl_80383160:
mftb r5, 0x10c
mftb r5, 268
lbl_80383164:
mftb r6, 0x10c
mftb r6, 268
subf r7, r5, r6
cmplwi r7, 0x1124
blt lbl_80383164
@ -110,14 +111,76 @@ lbl_803831A8:
// clang-format on
}
OSThreadQueue __OSActiveThreadQueue : (OS_BASE_CACHED | 0x00DC);
static void KillThreads(void) {
OSThread* thread;
OSThread* next;
for (thread = __OSActiveThreadQueue.head; thread; thread = next) {
next = thread->linkActive.next;
switch (thread->state) {
case 1:
case 4:
OSCancelThread(thread);
break;
default:
break;
}
}
}
void __OSDoHotReset(s32 arg0) {
OSDisableInterrupts();
DAT_cc002000._2 = 0;
__VIRegs[1] = 0;
ICFlashInvalidate();
Reset(arg0 * 8);
}
void OSResetSystem(int reset, u32 resetCode, BOOL forceMenu) {}
void OSResetSystem(int reset, u32 resetCode, BOOL forceMenu) {
BOOL rc;
BOOL disableRecalibration;
u32 unk[3];
OSDisableScheduler();
__OSStopAudioSystem();
if (reset == OS_RESET_SHUTDOWN) {
disableRecalibration = __PADDisableRecalibration(TRUE);
}
while (!__OSCallResetFunctions(FALSE))
;
if (reset == OS_RESET_HOTRESET && forceMenu) {
OSSram* sram;
sram = __OSLockSram();
sram->flags |= 0x40;
__OSUnlockSram(TRUE);
while (!__OSSyncSram())
;
}
OSDisableInterrupts();
__OSCallResetFunctions(TRUE);
LCDisable();
if (reset == OS_RESET_HOTRESET) {
__OSDoHotReset(resetCode);
} else if (reset == OS_RESET_RESTART) {
KillThreads();
OSEnableScheduler();
__OSReboot(resetCode, forceMenu);
}
KillThreads();
memset(OSPhysicalToCached(0x40), 0, 0xcc - 0x40);
memset(OSPhysicalToCached(0xd4), 0, 0xe8 - 0xd4);
memset(OSPhysicalToCached(0xf4), 0, 0xf8 - 0xf4);
memset(OSPhysicalToCached(0x3000), 0, 0xc0);
memset(OSPhysicalToCached(0x30c8), 0, 0xd4 - 0xc8);
memset(OSPhysicalToCached(0x30e2), 0, 1);
__PADDisableRecalibration(disableRecalibration);
}
u32 OSGetResetCode(void) {
if (DAT_800030e2 != 0) {