Skip to content

Commit

Permalink
m_Do_printf match, JUTException errorHandler match
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Oct 11, 2023
1 parent f63b762 commit 1000421
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def DolphinLib(lib_name, objects):
"objects": [
# machine
Object(Matching, "m_Do/m_Do_main.cpp"),
Object(NonMatching, "m_Do/m_Do_printf.cpp"),
Object(Matching, "m_Do/m_Do_printf.cpp"),
Object(NonMatching, "m_Do/m_Do_audio.cpp"),
Object(NonMatching, "m_Do/m_Do_controller_pad.cpp"),
Object(NonMatching, "m_Do/m_Do_graphic.cpp"),
Expand Down
26 changes: 12 additions & 14 deletions src/JSystem/JUtility/JUTException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ u32 JUTException::fpscr;

/* 802C4CEC-802C5084 .text errorHandler__12JUTExceptionFUsP9OSContextUlUl */
void JUTException::errorHandler(OSError error, OSContext* context, u32 param_3, u32 param_4) {
/* Nonmatching */
if (error == 0x10) {
OSReport("\x1b[41;37m");
OSReport(" FPE: 浮動小数点例外が発生しました。アドレスは %08x fpscr=%08x\n", context->srr0, context->fpscr);
Expand All @@ -134,9 +133,10 @@ void JUTException::errorHandler(OSError error, OSContext* context, u32 param_3,
search_name_part((u8*)stack_3c, stack_38, 0x20);
OSReport("%s:%x section:%d\n", stack_38, stack_48, stack_44);
}
u32 r31 = context->fpscr;
r31 &= ((context->fpscr & 0xf8) << 22) | 0x01f80700;
if (r31 & 0x20000000) {
u32 ctx_fpcsr = context->fpscr;
ctx_fpcsr &= ((ctx_fpcsr & 0xf8) << 22) | 0x01f80700;

if (ctx_fpcsr & 0x20000000) {
context->fpscr &= ~0x80;
OSReport(" FPE: Invalid operation(無効な演算)\n");
if (fpscr & 0x01000000) {
Expand Down Expand Up @@ -167,19 +167,19 @@ void JUTException::errorHandler(OSError error, OSContext* context, u32 param_3,
OSReport(" Invalid integer convert\n");
}
}
if (r31 & 0x10000000) {
if (ctx_fpcsr & 0x10000000) {
context->fpscr &= ~0x40;
OSReport(" FPE: Overflow(オーバーフロー)\n");
}
if (r31 & 0x08000000) {
if (ctx_fpcsr & 0x08000000) {
context->fpscr &= ~0x20;
OSReport(" FPE: Underflow(アンダーフロー)\n");
}
if (r31 & 0x04000000) {
if (ctx_fpcsr & 0x04000000) {
context->fpscr &= ~0x10;
OSReport(" FPE: Zero division(0による割り算)\n");
}
if (r31 & 0x02000000) {
if (ctx_fpcsr & 0x02000000) {
context->fpscr &= ~0x08;
OSReport(" FPE: Inexact result(不正確な結果)\n");
}
Expand Down Expand Up @@ -264,11 +264,11 @@ bool JUTException::searchPartialModule(u32 address, u32* module_id, u32* section
}

OSModuleInfo* module = *(OSModuleInfo**)0x800030C8;
while (module) {
for (; module != NULL; module = (OSModuleInfo*)module->mNext) {
OSSectionInfo* section = (OSSectionInfo*)module->info.sectionInfoOffset;
for (u32 i = 0; i < module->mNumSections; section = section + 1, i++) {
if (section->mSize) {
u32 addr = ALIGN_PREV(section->mOffset, 2);
for (u32 i = 0; i < module->mNumSections; section++, i++) {
if (section->mSize != 0) {
u32 addr = section->mOffset & ~0x01;
if ((addr <= address) && (address < addr + section->mSize)) {
if (module_id)
*module_id = module->mId;
Expand All @@ -282,8 +282,6 @@ bool JUTException::searchPartialModule(u32 address, u32* module_id, u32* section
}
}
}

module = (OSModuleInfo*)module->mNext;
}

return false;
Expand Down
41 changes: 37 additions & 4 deletions src/m_Do/m_Do_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,46 @@ extern "C" int OSGetActiveThreadID(OSThread* thread) {
}

/* 800066B0-80006770 .text search_partial_address */
extern "C" int search_partial_address(void* param_0, int* param_1, int* param_2, int* param_3, int* param_4) {
/* Nonmatching */
extern "C" int search_partial_address(void* address, int* module_id, int* section_id, int* section_offset, int* name_offset) {
if (address == NULL)
return 0xFFFFFFFF;

OSModuleInfo* module = *(OSModuleInfo**)0x800030C8;
for (; module != NULL; module = (OSModuleInfo*)module->mNext) {
u32 i, addr;
OSSectionInfo* section = (OSSectionInfo*)module->info.sectionInfoOffset;

for (i = 0; i < module->mNumSections; section++, i++) {
if (section->mSize != 0) {
addr = section->mOffset & ~0x01;
if ((addr <= (u32)address) && (u32)address < (addr + section->mSize)) {
if (module_id != NULL)
*module_id = module->mId;
if (section_id != NULL)
*section_id = i;
if (section_offset)
*section_offset = (u32)address - addr;
if (name_offset)
*name_offset = module->mModuleNameOffset;
return 0;
}
}
}
}

return 0xFFFFFFFF;
}

/* 80006770-800067D0 .text convert_partial_address */
extern "C" int convert_partial_address(void* param_0) {
/* Nonmatching */
extern "C" u32 convert_partial_address(void* param_0) {
int param_1;
int param_2;
int param_3;
if (search_partial_address(param_0, &param_1, &param_2, &param_3, NULL) == 0) {
return (param_2 << 28) + (param_3 & 0x01FFFFFF);
} else {
return (u32)param_0;
}
}

/* 800067D0-800067DC .text OSReportDisable */
Expand Down

0 comments on commit 1000421

Please sign in to comment.