From 346215bd4900444c3f64d341576ea04905fbcb12 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Mon, 3 Jan 2022 21:05:34 -0700 Subject: [PATCH 01/11] Match most of DynamicLink --- include/JSystem/JKernel/JKRHeap.h | 4 + include/JSystem/JUtility/JUTConsole.h | 14 +- include/dolphin/os/OSLink.h | 58 +- include/m_Do/m_Do_dvd_thread.h | 2 + libs/JSystem/JFramework/JFWSystem.cpp | 2 - libs/JSystem/JUtility/JUTConsole.cpp | 14 +- libs/JSystem/JUtility/JUTException.cpp | 16 +- libs/dolphin/os/OSLink.cpp | 9 +- src/DynamicLink.cpp | 1009 ++++++++++++++---------- 9 files changed, 663 insertions(+), 465 deletions(-) diff --git a/include/JSystem/JKernel/JKRHeap.h b/include/JSystem/JKernel/JKRHeap.h index 59019844c3..82de079c08 100644 --- a/include/JSystem/JKernel/JKRHeap.h +++ b/include/JSystem/JKernel/JKRHeap.h @@ -221,4 +221,8 @@ inline JKRHeap* JKRGetCurrentHeap() { return JKRHeap::getCurrentHeap(); } +inline u32 JKRGetMemBlockSize(JKRHeap* heap,void* block) { + return JKRHeap::getSize(block,heap); +} + #endif /* JKRHEAP_H */ diff --git a/include/JSystem/JUtility/JUTConsole.h b/include/JSystem/JUtility/JUTConsole.h index 274e8de7e7..a7b91ff82d 100644 --- a/include/JSystem/JUtility/JUTConsole.h +++ b/include/JSystem/JUtility/JUTConsole.h @@ -115,12 +115,12 @@ private: /* 0x10 */ JUTConsole* mDirectConsole; }; // Size: 0x14 -void JUTConsole_print_f_va_(JUTConsole*, const char*, va_list); -void JUTSetReportConsole(JUTConsole*); -JUTConsole* JUTGetReportConsole(); -void JUTSetWarningConsole(JUTConsole*); -JUTConsole* JUTGetWarningConsole(); -void JUTReportConsole_f_va(const char*, va_list); -void JUTReportConsole_f(const char*, ...); +extern "C" void JUTConsole_print_f_va_(JUTConsole*, const char*, va_list); +extern "C" void JUTSetReportConsole(JUTConsole*); +extern "C" JUTConsole* JUTGetReportConsole(); +extern "C" void JUTSetWarningConsole(JUTConsole*); +extern "C" JUTConsole* JUTGetWarningConsole(); +extern "C" void JUTReportConsole_f_va(const char*, va_list); +extern "C" void JUTReportConsole_f(const char*, ...); #endif /* JUTCONSOLE_H */ diff --git a/include/dolphin/os/OSLink.h b/include/dolphin/os/OSLink.h index 013e2be352..44476eb485 100644 --- a/include/dolphin/os/OSLink.h +++ b/include/dolphin/os/OSLink.h @@ -3,34 +3,40 @@ #include "dolphin/types.h" -struct OSModuleInfo { - u32 id; - OSModuleInfo* next; - OSModuleInfo* prev; - u32 num_sections; - u32 section_info_offset; - u32 name_offset; - u32 name_size; - u32 version; - u32 bss_size; - u32 rel_offset; - u32 imp_offset; - u32 imp_size; - u8 prolog_section; - u8 epilog_section; - u8 unresolved_section; - u8 bss_section; - u32 prolog; - u32 epilog; - u32 unresolved; - u32 align; - u32 bss_align; - u32 fix_size; +struct OSSectionInfo { + u32 mOffset; + u32 mSize; }; -struct OSSectionInfo { - u32 offset; - u32 size; +struct OSModuleInfo { + u32 mId; + OSModuleInfo* mNext; + OSModuleInfo* mPrev; + u32 mNumSections; + struct { //Needed to get an assert corret; very likely bigger + u32 sectionInfoOffset; + } info; + u32 mModuleNameOffset; + u32 mModuleNameSize; + u32 mModuleVersion; + u32 mBssSize; + u32 mRelocationTableOffset; + u32 mImportTableOffset; + u32 mImportTableSize; + u8 mPrologSection; + u8 mEpilogSection; + u8 mUnresolvedSection; + u8 mBssSection; + u32 (*prolog)(); + void(*epilog)(); + u32 mUnresolvedFuncOffset; + u32 mModuleAlignment; + u32 mBssAlignment; + u32 fixSize; }; +extern "C" BOOL OSLink(OSModuleInfo*); +extern "C" BOOL OSLinkFixed(OSModuleInfo*,u32); +extern "C" BOOL OSUnlink(OSModuleInfo*); + #endif /* OSLINK_H */ diff --git a/include/m_Do/m_Do_dvd_thread.h b/include/m_Do/m_Do_dvd_thread.h index 193d480bb3..39dc87c492 100644 --- a/include/m_Do/m_Do_dvd_thread.h +++ b/include/m_Do/m_Do_dvd_thread.h @@ -16,6 +16,8 @@ public: public: /* 800158FC */ virtual ~mDoDvdThd_command_c(); /* 80015B74 */ mDoDvdThd_command_c(); + inline s32 sync() {return mIsDone;} + inline void destroy() {delete this;} virtual s32 execute() = 0; }; // Size = 0x14 diff --git a/libs/JSystem/JFramework/JFWSystem.cpp b/libs/JSystem/JFramework/JFWSystem.cpp index 3339bf57df..955a649616 100644 --- a/libs/JSystem/JFramework/JFWSystem.cpp +++ b/libs/JSystem/JFramework/JFWSystem.cpp @@ -111,8 +111,6 @@ extern "C" void create__12JUTAssertionFv(); extern "C" void createManager__8JUTVideoFPC16_GXRenderModeObj(); extern "C" void create__10JUTConsoleFUiUiP7JKRHeap(); extern "C" void createManager__17JUTConsoleManagerFP7JKRHeap(); -extern "C" void JUTSetReportConsole(); -extern "C" void JUTSetWarningConsole(); extern "C" void OSInit(); extern "C" void OSGetCurrentThread(); extern "C" void DVDInit(); diff --git a/libs/JSystem/JUtility/JUTConsole.cpp b/libs/JSystem/JUtility/JUTConsole.cpp index b881a4e508..0831c2786a 100644 --- a/libs/JSystem/JUtility/JUTConsole.cpp +++ b/libs/JSystem/JUtility/JUTConsole.cpp @@ -259,7 +259,7 @@ asm void JUTConsole::print(char const* param_0) { #pragma pop /* 802E7F30-802E7F7C 2E2870 004C+00 1/1 1/1 0/0 .text JUTConsole_print_f_va_ */ -void JUTConsole_print_f_va_(JUTConsole* console, const char* fmt, va_list args) { +extern "C" void JUTConsole_print_f_va_(JUTConsole* console, const char* fmt, va_list args) { char buf[1024]; vsnprintf(buf, sizeof(buf), fmt, args); console->print(buf); @@ -415,12 +415,12 @@ void JUTConsoleManager::setDirectConsole(JUTConsole* pConsole) { static JUTConsole* sReportConsole; /* 802E8520-802E8528 2E2E60 0008+00 1/1 1/1 0/0 .text JUTSetReportConsole */ -void JUTSetReportConsole(JUTConsole* pConsole) { +extern "C" void JUTSetReportConsole(JUTConsole* pConsole) { sReportConsole = pConsole; } /* 802E8528-802E8530 -00001 0008+00 0/0 0/0 0/0 .text JUTGetReportConsole */ -JUTConsole* JUTGetReportConsole() { +extern "C" JUTConsole* JUTGetReportConsole() { return sReportConsole; } @@ -429,17 +429,17 @@ JUTConsole* JUTGetReportConsole() { static JUTConsole* sWarningConsole; /* 802E8530-802E8538 2E2E70 0008+00 1/1 1/1 0/0 .text JUTSetWarningConsole */ -void JUTSetWarningConsole(JUTConsole* pConsole) { +extern "C" void JUTSetWarningConsole(JUTConsole* pConsole) { sWarningConsole = pConsole; } /* 802E8538-802E8540 -00001 0008+00 0/0 0/0 0/0 .text JUTGetWarningConsole */ -JUTConsole* JUTGetWarningConsole() { +extern "C" JUTConsole* JUTGetWarningConsole() { return sWarningConsole; } /* 802E8540-802E85C8 2E2E80 0088+00 2/2 0/0 0/0 .text JUTReportConsole_f_va */ -void JUTReportConsole_f_va(const char* fmt, va_list args) { +extern "C" void JUTReportConsole_f_va(const char* fmt, va_list args) { char buf[256]; if (JUTGetReportConsole() == NULL) { @@ -451,7 +451,7 @@ void JUTReportConsole_f_va(const char* fmt, va_list args) { } /* 802E85C8-802E8648 2E2F08 0080+00 2/2 8/8 0/0 .text JUTReportConsole_f */ -void JUTReportConsole_f(const char* fmt, ...) { +extern "C" void JUTReportConsole_f(const char* fmt, ...) { va_list args; va_start(args, fmt); JUTReportConsole_f_va(fmt, args); diff --git a/libs/JSystem/JUtility/JUTException.cpp b/libs/JSystem/JUtility/JUTException.cpp index ca000d5b10..08952f671f 100644 --- a/libs/JSystem/JUtility/JUTException.cpp +++ b/libs/JSystem/JUtility/JUTException.cpp @@ -338,25 +338,25 @@ bool JUTException::searchPartialModule(u32 address, u32* module_id, u32* section OSModuleInfo* module = *(OSModuleInfo**)0x800030C8; while (module) { - OSSectionInfo* section = (OSSectionInfo*)module->section_info_offset; - for (u32 i = 0; i < module->num_sections; section++, i++) { - if (section->size) { - u32 addr = ALIGN_PREV(section->offset, 2); - if ((addr <= address) && (address < addr + section->size)) { + 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); + if ((addr <= address) && (address < addr + section->mSize)) { if (module_id) - *module_id = module->id; + *module_id = module->mId; if (section_id) *section_id = i; if (section_offset) *section_offset = address - addr; if (name_offset) - *name_offset = module->name_offset; + *name_offset = module->mModuleNameOffset; return true; } } } - module = module->next; + module = module->mNext; } return false; diff --git a/libs/dolphin/os/OSLink.cpp b/libs/dolphin/os/OSLink.cpp index a723152dfb..1bdb0b2283 100644 --- a/libs/dolphin/os/OSLink.cpp +++ b/libs/dolphin/os/OSLink.cpp @@ -16,10 +16,7 @@ extern "C" static void OSNotifyUnlink(); extern "C" void OSSetStringTable(); extern "C" static void Relocate(); extern "C" static void Link(); -extern "C" void OSLink(); -extern "C" void OSLinkFixed(); extern "C" static void Undo(); -extern "C" void OSUnlink(); extern "C" void __OSModuleInit(); // @@ -125,7 +122,7 @@ static asm void Link() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void OSLink() { +extern "C" asm BOOL OSLink(OSModuleInfo* info) { nofralloc #include "asm/dolphin/os/OSLink/OSLink.s" } @@ -135,7 +132,7 @@ asm void OSLink() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void OSLinkFixed() { +extern "C" asm BOOL OSLinkFixed(OSModuleInfo* info, u32 unk) { nofralloc #include "asm/dolphin/os/OSLink/OSLinkFixed.s" } @@ -201,7 +198,7 @@ static asm void Undo() { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void OSUnlink() { +extern "C" asm BOOL OSUnlink(OSModuleInfo* info) { nofralloc #include "asm/dolphin/os/OSLink/OSUnlink.s" } diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index bee87c9b98..d81f12bb98 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -6,90 +6,76 @@ #include "DynamicLink.h" #include "dol2asm.h" #include "dolphin/types.h" - -// -// Types: -// - -struct mDoDvdThd_callback_c { - /* 80015C74 */ void create(void* (*)(void*), void*); -}; - -struct JKRHeap { - /* 802CE474 */ void alloc(u32, int, JKRHeap*); - /* 802CE500 */ void free(void*, JKRHeap*); - /* 802CE624 */ void resize(void*, u32, JKRHeap*); - /* 802CE6B0 */ void getSize(void*, JKRHeap*); -}; - -struct JKRFileLoader { - /* 802D43A0 */ void detachResource(void*, JKRFileLoader*); -}; - -struct JKRFileCache { - /* 802D49B4 */ void mount(char const*, JKRHeap*, char const*); -}; - -struct JKRExpandSwitch {}; - -struct JKRDvdRipper { - struct EAllocDirection {}; - - /* 802D9B98 */ void loadToMainRAM(char const*, u8*, JKRExpandSwitch, u32, JKRHeap*, - JKRDvdRipper::EAllocDirection, u32, int*, u32*); -}; - -struct JKRArchive { - struct EMountMode {}; - - struct EMountDirection {}; - - /* 802D57E4 */ void mount(char const*, JKRArchive::EMountMode, JKRHeap*, - JKRArchive::EMountDirection); - /* 802D5B38 */ void getGlbResource(u32, char const*, JKRArchive*); -}; +#include "dolphin/os/OS.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "m_Do/m_Do_dvd_thread.h" +#include "m_Do/m_Do_ext.h" +#include "JSystem/JKernel/JKRFileCache.h" +#include "dolphin/os/OSLink.h" +#include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.h" +#include "JSystem/JKernel/JKRDvdRipper.h" struct DynamicModuleControlBase { - /* 800188DC */ bool getModuleName() const; - /* 802621CC */ ~DynamicModuleControlBase(); - /* 80262284 */ DynamicModuleControlBase(); - /* 802622D0 */ void link(); - /* 80262364 */ void unlink(); - /* 802623EC */ void load_async(); - /* 8026242C */ void force_unlink(); - /* 80262470 */ void dump(); - /* 802631D4 */ bool do_link(); - /* 802631DC */ bool do_load(); - /* 802631E4 */ bool do_unload(); - /* 802631EC */ bool do_unlink(); - /* 802631F4 */ bool do_load_async(); - /* 802631FC */ void dump2(); - /* 80263200 */ void getModuleTypeString() const; - /* 80263210 */ bool getModuleSize() const; + u16 mLinkCount; //0x0 + u16 mDoLinkCount; //0x2 + DynamicModuleControlBase* mPrev; //0x4 + DynamicModuleControlBase* mNext; //0x8 - static u8 mFirst[4]; - static u8 mLast[4]; + /* 802621CC */ virtual ~DynamicModuleControlBase(); //0xC + /* 800188DC */ virtual const char* getModuleName() const; + /* 80263210 */ virtual int getModuleSize() const; + /* 80263200 */ virtual const char* getModuleTypeString() const; + /* 80262470 */ virtual void dump(); + /* 802631FC */ virtual void dump2(); + /* 802631DC */ virtual bool do_load(); + /* 802631F4 */ virtual bool do_load_async(); + /* 802631E4 */ virtual bool do_unload(); + /* 802631D4 */ virtual BOOL do_link(); + /* 802631EC */ virtual bool do_unlink(); + /* 80262284 */ DynamicModuleControlBase(); + /* 802622D0 */ bool link(); + /* 80262364 */ bool unlink(); + /* 802623EC */ bool load_async(); + /* 8026242C */ bool force_unlink(); + + static inline DynamicModuleControlBase* getFirstClass() {return mFirst;} + inline DynamicModuleControlBase* getNextClass() {return mNext;} + + + static DynamicModuleControlBase* mFirst; + static DynamicModuleControlBase* mLast; }; -struct DynamicModuleControl { - /* 800188E4 */ ~DynamicModuleControl(); +struct DynamicModuleControl : DynamicModuleControlBase { + /* 800188E4 */ virtual ~DynamicModuleControl(); + /* 80263218 */ virtual const char* getModuleName() const; + /* 80263000 */ virtual int getModuleSize() const; + /* 80263070 */ virtual const char* getModuleTypeString() const; + //virtual void dump(); + /* 80262C0C */ virtual void dump2(); + /* 802627E8 */ virtual bool do_load(); + /* 80262AFC */ virtual bool do_load_async(); + /* 80262BC4 */ virtual bool do_unload(); + /* 80262C5C */ virtual BOOL do_link(); + /* 80262F28 */ virtual bool do_unlink(); /* 80262660 */ DynamicModuleControl(char const*); - /* 802626D0 */ void mountCallback(void*); - /* 8026275C */ void initialize(); - /* 80262794 */ void callback(void*); - /* 802627E8 */ void do_load(); - /* 80262AFC */ void do_load_async(); - /* 80262BC4 */ void do_unload(); - /* 80262C0C */ void dump2(); - /* 80262C5C */ void do_link(); - /* 80262F28 */ void do_unlink(); - /* 80263000 */ void getModuleSize() const; - /* 80263070 */ void getModuleTypeString() const; - /* 80263218 */ void getModuleName() const; + /* 802626D0 */ static JKRArchive* mountCallback(void*); + /* 8026275C */ bool initialize(); + /* 80262794 */ static void* callback(void*); + + OSModuleInfo* mModule; //0x10 + void* mBss; //0x14 + u32 unk_24; //0x18 + const char* mName; //0x1c + u8 mResourceType; //0x20 + u8 unk_33; //0x21 + u16 mChecksum; //0x22 + s32 mSize; //0x24 + mDoDvdThd_callback_c* mAsyncLoadCallback; //0x28 - static u8 sAllocBytes[4]; - static u8 sArchive[4]; - static u8 sFileCache[4 + 4 /* padding */]; + static u32 sAllocBytes; + static JKRArchive* sArchive; + static JKRFileCache* sFileCache; }; // @@ -119,8 +105,8 @@ extern "C" void getModuleTypeString__20DynamicModuleControlCFv(); extern "C" void ModuleProlog(); extern "C" void ModuleEpilog(); extern "C" void ModuleUnresolved(); -extern "C" void ModuleConstructorsX(); -extern "C" void ModuleDestructorsX(); +extern "C" void ModuleConstructorsX(void(**ctors)()); +extern "C" void ModuleDestructorsX(void(**dtors)()); extern "C" bool do_link__24DynamicModuleControlBaseFv(); extern "C" bool do_load__24DynamicModuleControlBaseFv(); extern "C" bool do_unload__24DynamicModuleControlBaseFv(); @@ -141,9 +127,6 @@ extern "C" u8 sFileCache__20DynamicModuleControl[4 + 4 /* padding */]; // External References: // -extern "C" void OSReport(); -extern "C" void OSReport_Error(); -extern "C" void OSReport_Warning(); extern "C" void mDoExt_getArchiveHeap__Fv(); extern "C" void create__20mDoDvdThd_callback_cFPFPv_PvPv(); extern "C" bool getModuleName__24DynamicModuleControlBaseCFv(); @@ -160,31 +143,147 @@ mount__10JKRArchiveFPCcQ210JKRArchive10EMountModeP7JKRHeapQ210JKRArchive15EMount extern "C" void getGlbResource__10JKRArchiveFUlPCcP10JKRArchive(); extern "C" void loadToMainRAM__12JKRDvdRipperFPCcPUc15JKRExpandSwitchUlP7JKRHeapQ212JKRDvdRipper15EAllocDirectionUlPiPUl(); -extern "C" void JUTReportConsole_f(); -extern "C" void OSGetStackPointer(); -extern "C" void OSLink(); -extern "C" void OSLinkFixed(); -extern "C" void OSUnlink(); -extern "C" void OSGetTime(); extern "C" void _savegpr_26(); extern "C" void _savegpr_28(); extern "C" void _savegpr_29(); extern "C" void _restgpr_26(); extern "C" void _restgpr_28(); extern "C" void _restgpr_29(); -extern "C" void snprintf(); // // Declarations: // +extern "C" void* __vt__20DynamicModuleControl[13]; +extern "C" void* __vt__24DynamicModuleControlBase[13]; + +/* 80451138-8045113C 000638 0004+00 3/3 0/0 0/0 .sbss mFirst__24DynamicModuleControlBase + */ +DynamicModuleControlBase* DynamicModuleControlBase::mFirst; + +/* 8045113C-80451140 00063C 0004+00 2/2 0/0 0/0 .sbss mLast__24DynamicModuleControlBase + */ +DynamicModuleControlBase* DynamicModuleControlBase::mLast; + +/* 802621CC-80262284 25CB0C 00B8+00 1/0 2/2 0/0 .text __dt__24DynamicModuleControlBaseFv + */ +#pragma push +#pragma optimization_level 0 +#pragma optimizewithasm off +asm DynamicModuleControlBase::~DynamicModuleControlBase() { + nofralloc +#include "asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s" +} +#pragma pop + +/* 80262284-802622D0 25CBC4 004C+00 1/1 0/0 0/0 .text __ct__24DynamicModuleControlBaseFv + */ +DynamicModuleControlBase::DynamicModuleControlBase() { + mLinkCount = 0; + mDoLinkCount = 0; + mNext = NULL; + if (mFirst==NULL) { + mFirst = this; + } + mPrev = mLast; + if (mPrev!=NULL) { + mPrev->mNext = this; + } + mLast = this; +} + +/* 802622D0-80262364 25CC10 0094+00 0/0 2/2 0/0 .text link__24DynamicModuleControlBaseFv + */ +bool DynamicModuleControlBase::link() { + if (mLinkCount==0) { + do_load(); + if (do_link()==false) { + return false; + } + if (mDoLinkCount<0xFFFF) { + mDoLinkCount++; + } + } + if(mLinkCount<0xFFFF) { + mLinkCount++; + } + return true; +} + +/* 80262364-802623EC 25CCA4 0088+00 0/0 1/1 0/0 .text unlink__24DynamicModuleControlBaseFv */ +bool DynamicModuleControlBase::unlink() { + if(mLinkCount!=0) { + mLinkCount--; + if(mLinkCount==0) { + do_unlink(); + do_unload(); + } + }else{ + OSReport_Warning("%08x DynamicModuleControlBase::unlink() mLinkCount id already zero.\n",this); + } + return true; +} + +/* 802623EC-8026242C 25CD2C 0040+00 0/0 1/1 0/0 .text load_async__24DynamicModuleControlBaseFv */ +bool DynamicModuleControlBase::load_async() { + if (mLinkCount==0) { + return do_load_async(); + } + return true; +} + +/* 8026242C-80262470 25CD6C 0044+00 1/1 0/0 0/0 .text force_unlink__24DynamicModuleControlBaseFv + */ +bool DynamicModuleControlBase::force_unlink() { + if (mLinkCount!=0) { + mLinkCount = 0; + do_unlink(); + } + return true; +} + +#ifdef NONMATCHING +void DynamicModuleControlBase::dump() { + DynamicModuleControlBase* current = getFirstClass(); + int totalSize = 0; + JUTReportConsole_f("\nDynamicModuleControlBase::dump()\n"); + JUTReportConsole_f("Do Lnk Size Name\n"); + while (current!=NULL) { + if (current->mDoLinkCount!=0||current->mLinkCount!=0) { + int size = current->getModuleSize(); + const char* name = current->getModuleName(); + if (size>=0) { + if (name==NULL) { + name = "(Null)"; + } + const char* type = current->getModuleTypeString(); + JUTReportConsole_f("%3d%3d%5.1f %05x %-4s %-24s ",mDoLinkCount,mLinkCount,(float)size*((float)1/(float)1024),size,type,name); + totalSize = totalSize + size; + }else{ + if (name==NULL) { + name = "(Null)"; + } + const char* type = current->getModuleTypeString(); + JUTReportConsole_f("%3d%3d ???? ????? %-4s %-24s ",mDoLinkCount,mLinkCount,type,name); + } + } + current->dump2(); + JUTReportConsole_f("\n"); + current=current->getNextClass(); + } + JUTReportConsole_f("TotalSize %6.2f %06x\n\n",(float)totalSize*(float)(1/1024),totalSize); +} +#else /* ############################################################################################## */ -/* 8039A4A0-8039A4A0 026B00 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ +/* 80455008-80455010 003608 0004+04 1/1 0/0 0/0 .sdata2 @3772 */ +SECTION_SDATA2 static f32 lit_3772[1 + 1 /* padding */] = { + 0.0009765625f, // 1/1024 + /* padding */ + 0.0f, +}; + #pragma push #pragma force_active on -SECTION_DEAD static char const* const stringBase_8039A4A0 = - "%08x DynamicModuleControlBase::unlink() mLinkCou" - "nt id already zero.\n"; SECTION_DEAD static char const* const stringBase_8039A4E5 = "\nDynamicModuleControlBase::dump()\n"; SECTION_DEAD static char const* const stringBase_8039A508 = "Do Lnk Size Name\n"; SECTION_DEAD static char const* const stringBase_8039A520 = "(Null)"; @@ -192,11 +291,181 @@ SECTION_DEAD static char const* const stringBase_8039A527 = "%3d%3d%5.1f %05x %- SECTION_DEAD static char const* const stringBase_8039A544 = "%3d%3d ???? ????? %-4s %-24s "; SECTION_DEAD static char const* const stringBase_8039A562 = "\n"; SECTION_DEAD static char const* const stringBase_8039A564 = "TotalSize %6.2f %06x\n\n"; +#pragma pop + +/* 80455010-80455018 003610 0008+00 1/1 0/0 0/0 .sdata2 @3774 */ +SECTION_SDATA2 static f64 lit_3774 = 4503599627370496.0 /* cast u32 to float */; + +/* 80262470-80262660 25CDB0 01F0+00 2/0 2/2 0/0 .text dump__24DynamicModuleControlBaseFv + */ +#pragma push +#pragma optimization_level 0 +#pragma optimizewithasm off +asm void DynamicModuleControlBase::dump() { + nofralloc +#include "asm/DynamicLink/dump__24DynamicModuleControlBaseFv.s" +} +#pragma pop +#endif + +/* 80262660-802626D0 25CFA0 0070+00 0/0 2/2 0/0 .text __ct__20DynamicModuleControlFPCc */ +DynamicModuleControl::DynamicModuleControl(char const* name) { + mModule = NULL; + mBss = NULL; + unk_24 = 0; + mName = name; + mResourceType = 0; + unk_33 = 0; + mChecksum = 0; + mSize = 0; + mAsyncLoadCallback = NULL; +} + +/* ############################################################################################## */ +/* 80451140-80451144 000640 0004+00 3/3 0/0 0/0 .sbss sAllocBytes__20DynamicModuleControl + */ +u32 DynamicModuleControl::sAllocBytes; + +/* 80451144-80451148 000644 0004+00 3/3 0/0 0/0 .sbss sArchive__20DynamicModuleControl */ +JKRArchive* DynamicModuleControl::sArchive; + +/* 80451148-80451150 000648 0004+04 3/3 0/0 0/0 .sbss sFileCache__20DynamicModuleControl + */ +JKRFileCache* DynamicModuleControl::sFileCache; + +#pragma push +#pragma force_active on SECTION_DEAD static char const* const stringBase_8039A57B = "Base"; -SECTION_DEAD static char const* const stringBase_8039A580 = "/rel/Final/Release"; -SECTION_DEAD static char const* const stringBase_8039A593 = "RELS.arc"; -SECTION_DEAD static char const* const stringBase_8039A59C = - "マウント失敗ですが単にアーカイブを作ってないだけなら遅いだけです %s\n"; +#pragma pop + +/* 802626D0-8026275C 25D010 008C+00 1/1 0/0 0/0 .text mountCallback__20DynamicModuleControlFPv */ +JKRArchive* DynamicModuleControl::mountCallback(void* param_0) { + JKRExpHeap* heap = mDoExt_getArchiveHeap(); + sFileCache = JKRFileCache::mount("/rel/Final/Release",heap,NULL); + sArchive = JKRArchive::mount("RELS.arc",JKRArchive::MOUNT_COMP,heap,JKRArchive::MOUNT_DIRECTION_HEAD); + if (sArchive == NULL) { + OSReport_Warning("マウント失敗ですが単にアーカイブを作ってないだけなら遅いだけです %s\n","RELS.arc"); + } + return sArchive; +} + +/* 8026275C-80262794 25D09C 0038+00 0/0 1/1 0/0 .text initialize__20DynamicModuleControlFv */ +bool DynamicModuleControl::initialize() { + sFileCache = NULL; + sAllocBytes = 0; + sArchive = NULL; + mountCallback(NULL); + return true; +} + +/* 80262794-802627C0 25D0D4 002C+00 1/1 0/0 0/0 .text callback__20DynamicModuleControlFPv + */ +void* DynamicModuleControl::callback(void* moduleControlPtr) { + DynamicModuleControl* moduleControl = (DynamicModuleControl*)moduleControlPtr; + moduleControl->do_load(); +} + +/* 802627C0-802627E8 25D100 0028+00 1/1 0/0 0/0 .text calcSum2__FPCUsUl */ +static u32 calcSum2(u16 const* data, u32 size) { + u32 sum = 0; + while (size>0) { + sum = sum + *data; + size=size-2; + data++; + } + return sum; +} + +#ifdef NONMATCHING +bool DynamicModuleControl::do_load() { + + if (mModule!=NULL) { + return true; + } + JKRExpHeap* heap = mDoExt_getArchiveHeap(); + s32 i = 0; + while(true) { + if(mModule != NULL) { + JKRHeap::free(mModule,NULL); + mModule = NULL; + } + char buffer[64]; + snprintf(buffer,64,"%s.rel",mName); + if(mModule==NULL&&sArchive!=NULL) { + if(mModule==NULL) { + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x4D4D454D,buffer,sArchive); + if(mModule!=NULL) { + mResourceType = 1; + } + } + if(mModule==NULL) { + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x414D454D,buffer,sArchive); + if(mModule!=NULL) { + mResourceType = 2; + } + } + if(mModule==NULL) { + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x444D454D,buffer,sArchive); + if(mModule!=NULL) { + mResourceType = 3; + } + } + } + if(mModule!=NULL) { + mSize = sArchive->getExpandedResSize(mModule); + JKRFileLoader::detachResource(mModule,NULL); + }else if(mModule==NULL){ + snprintf(buffer,64,"/rel/Final/Release/%s.rel",mName); + mModule = (OSModuleInfo*)JKRDvdRipper::loadToMainRAM(buffer,NULL,EXPAND_SWITCH_UNKNOWN1,0,heap,JKRDvdRipper::ALLOC_DIRECTION_FORWARD,0,NULL,NULL); + if(mModule!=NULL) { + mSize = 0; + mResourceType = 7; + } + } + if(mModule==NULL&&sFileCache!=NULL) { + mModule = (OSModuleInfo*)sFileCache->getResource(0x72656C73,buffer); + if(mModule!=NULL) { + mSize = 0; + mResourceType = 11; + JKRFileLoader::detachResource(mModule,NULL); + } + } + if(mModule==NULL) { + OSReport_Error("\x44\x79\x6E\x61\x6D\x69\x63\x4D\x6F\x64\x75\x6C\x65\x43\x6F\x6E\x74\x72\x6F\x6C\x3A\x3A\x64\x6F\x5F\x6C\x6F\x61\x64\x28\x29\x20\x83\x8A\x83\x5C\x81\x5B\x83\x58\x93\xC7\x82\xDD\x8D\x9E\x82\xDD\x8E\xB8\x94\x73\x20\x5B\x25\x73\x5D\x0A",mName); + return false; + } + if(mSize>0) { + u32 sum = calcSum2((u16*)mModule,mSize); + if(unk_33==0) { + mChecksum=sum; + unk_33++; + }else{ + u32 newsum = sum&0xFFFF; + if(newsum!=mChecksum) { + OSReport_Error("DynamicModuleControl::do_load() チェックサムエラー %04x %04x[%s]\n",newsum,mChecksum,mName); + unk_33 = 0; + i++; + if(i>=3) { + return false; + } + } + } + if(unk_33<0xFF) { + unk_33++; + return true; + } + } + if(unk_33<0xFF) { + unk_33++; + return true; + } + } +} +#else +/* ############################################################################################## */ +/* 8039A4A0-8039A4A0 026B00 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ +#pragma push +#pragma force_active on SECTION_DEAD static char const* const stringBase_8039A5E1 = "%s.rel"; SECTION_DEAD static char const* const stringBase_8039A5E8 = "/rel/Final/Release/%s.rel"; // MWCC ignores mapping of some japanese characters using the @@ -209,29 +478,214 @@ SECTION_DEAD static char const* const stringBase_8039A602 = SECTION_DEAD static char const* const stringBase_8039A63D = "DynamicModuleControl::do_load() チェックサムエラー %04x %" "04x[%s]\n"; -SECTION_DEAD static char const* const stringBase_8039A67F = - "DynamicModuleControl::do_load_async() 非同期読み込みコール" - "バック登録失敗 [%s]\n"; -SECTION_DEAD static char const* const stringBase_8039A6CE = "%08x-%08x %08x %08x"; +#pragma pop + +/* 802627E8-80262AFC 25D128 0314+00 1/0 0/0 0/0 .text do_load__20DynamicModuleControlFv + */ +#pragma push +#pragma optimization_level 0 +#pragma optimizewithasm off +asm bool DynamicModuleControl::do_load() { + nofralloc +#include "asm/DynamicLink/do_load__20DynamicModuleControlFv.s" +} +#pragma pop +#endif + +/* 80262AFC-80262BC4 25D43C 00C8+00 1/0 0/0 0/0 .text do_load_async__20DynamicModuleControlFv */ +bool DynamicModuleControl::do_load_async() { + if (mAsyncLoadCallback==NULL) { + if(mModule!=NULL) { + return true; + } + mAsyncLoadCallback = mDoDvdThd_callback_c::create(DynamicModuleControl::callback,this); + if(mAsyncLoadCallback==NULL) { + OSReport_Error("DynamicModuleControl::do_load_async() 非同期読み込みコールバック登録失敗 [%s]\n",mName); + } + } + if (mAsyncLoadCallback!=NULL&&mAsyncLoadCallback->sync()) { + mAsyncLoadCallback->destroy(); + mAsyncLoadCallback = NULL; + return true; + }else{ + return false; + } +} + +/* 80262BC4-80262C0C 25D504 0048+00 1/0 0/0 0/0 .text do_unload__20DynamicModuleControlFv + */ +bool DynamicModuleControl::do_unload() { + if (mModule!=NULL){ + JKRFree(mModule); + mModule = NULL; + } + return true; +} + +/* 80262C0C-80262C5C 25D54C 0050+00 1/0 0/0 0/0 .text dump2__20DynamicModuleControlFv */ +void DynamicModuleControl::dump2() { + if (mModule!=NULL) { + OSSectionInfo* section = (OSSectionInfo*)mModule->info.sectionInfoOffset; + OSSectionInfo* section2 = section+1; + u32 offset = section2->mOffset & ~(1); + OSReport("%08x-%08x %08x %08x",mModule,offset,offset+section2->mSize); + } +} + +#ifdef NONMATCHING +BOOL DynamicModuleControl::do_link() { + OSGetTime(); + if(mModule==NULL) { + do_load(); + } + + if(mModule!=NULL) { + ASSERT(mModule->info.sectionInfoOffset < 0x80000000); + ASSERT((u32)mModule + mModule->fixSize < 0x82000000); + OSGetTime(); + OSGetTime(); + if(mModule->mModuleVersion>=3) { + u32 unk = mModule->fixSize + 0x1f; + u32 unk3 = unk & ~0x1f; + u32 unk2 = (u32)mModule+unk3; + s32 size = JKRHeap::getSize(mModule,NULL); + if(size<0) { + void* bss = JKRHeap::alloc(mModule->mBssSize,0x20,NULL); + if (bss==NULL) { + OSReport_Error("BSSメモリ確保失敗\n"); + goto end; + }else{ + mBss = bss; + BOOL linkResult = OSLink(mModule); + if(linkResult==FALSE) { + OSReport_Error("リンク失敗\n"); + goto end; + } + } + }else{ + if(mModule->mBssSize+unkmBssSize+unk,NULL); + if (result<0) { + OSReport_Error("モジュールリサイズ(縮小)失敗\n"); + } + } + }else{ //lbl_80262DB0 + s32 result = JKRHeap::resize(mModule,mModule->mBssSize+unk,NULL); + if (result>0) { + BOOL linkResult = OSLinkFixed(mModule,unk2); + if(linkResult==FALSE) { + OSReport_Error("リンク失敗\n"); + goto end; + } + }else{ //lbl_80262DF0 + void* bss = JKRHeap::alloc(mModule->mBssSize,0x20,NULL); + if (bss==NULL) { + OSReport_Error("BSSメモリ確保失敗 [%x]\n",mModule->mBssSize); + goto end; + }else{ //lbl_80262E2C + mBss = bss; + BOOL linkResult = OSLinkFixed(mModule,(u32)bss); + if (linkResult==FALSE) { + OSReport_Error("リンク失敗\n"); + goto end; + } + //lbl_80262E58 + s32 result = JKRHeap::resize(mModule,unk3,NULL); + if (result<0) { + OSReport_Error("モジュールリサイズ(縮小)失敗\n"); + } + } + } + } + } + } + //lbl_80262E84 + OSGetTime(); + sAllocBytes = sAllocBytes + getModuleSize(); + OSGetTime(); + unk_24 = mModule->prolog(); + OSGetTime(); + return TRUE; + } + +end: //lbl_80262ECC + unk_33 = 0; + if(mBss!=NULL) { + JKRHeap::free(mBss,NULL); + mBss = NULL; + } + if(mModule!=NULL) { + JKRHeap::free(mModule,NULL); + mModule = NULL; + } + return FALSE; +} +#else +#pragma push +#pragma force_active on SECTION_DEAD static char const* const stringBase_8039A6E2 = "BSSメモリ確保失敗\n"; SECTION_DEAD static char const* const stringBase_8039A6F5 = "リンク失敗\n"; SECTION_DEAD static char const* const stringBase_8039A701 = "モジュールリサイズ(縮小)失敗\n"; SECTION_DEAD static char const* const stringBase_8039A71F = "BSSメモリ確保失敗 [%x]\n"; -SECTION_DEAD static char const* const stringBase_8039A737 = - "アンリンク失敗 mModule=%08x mBss=%08x\n"; -SECTION_DEAD static char const* const stringBase_8039A75E = "????"; -SECTION_DEAD static char const* const stringBase_8039A763 = "MEM"; -SECTION_DEAD static char const* const stringBase_8039A767 = "ARAM"; -SECTION_DEAD static char const* const stringBase_8039A76C = "DVD"; #pragma pop -/* 803C34B0-803C34C0 -00001 0010+00 1/1 0/0 0/0 .data strings$4165 */ -SECTION_DATA static void* strings[4] = { - (void*)(((char*)&DynamicLink__stringBase0) + 0x2BE), - (void*)(((char*)&DynamicLink__stringBase0) + 0x2C3), - (void*)(((char*)&DynamicLink__stringBase0) + 0x2C7), - (void*)(((char*)&DynamicLink__stringBase0) + 0x2CC), -}; +/* 80262C5C-80262F28 25D59C 02CC+00 1/0 0/0 0/0 .text do_link__20DynamicModuleControlFv + */ +#pragma push +#pragma optimization_level 0 +#pragma optimizewithasm off +asm BOOL DynamicModuleControl::do_link() { + nofralloc +#include "asm/DynamicLink/do_link__20DynamicModuleControlFv.s" +} +#pragma pop +#endif + +/* 80262F28-80263000 25D868 00D8+00 1/0 0/0 0/0 .text do_unlink__20DynamicModuleControlFv + */ +bool DynamicModuleControl::do_unlink() { + OSTime time1 = OSGetTime(); + mModule->epilog(); + OSTime time2 = OSGetTime(); + BOOL unklink = OSUnlink(mModule); + OSTime time3 = OSGetTime(); + if (unklink==FALSE) { + OSReport_Error("アンリンク失敗 mModule=%08x mBss=%08x\n",mModule,mBss); + return false; + } + sAllocBytes = sAllocBytes - getModuleSize(); + if (mBss!=NULL) { + JKRFree(mBss); + mBss = NULL; + } + do_unload(); + return true; +} + +/* 80263000-80263070 25D940 0070+00 1/0 0/0 0/0 .text getModuleSize__20DynamicModuleControlCFv */ +int DynamicModuleControl::getModuleSize() const { + if (mModule!=NULL){ + u32 size = JKRGetMemBlockSize(NULL,mModule); + if (mBss!=NULL) { + JKRGetMemBlockSize(NULL,mBss); + } + return size+mModule->mBssSize; + }else{ + return 0; + } +} + +/* 80263070-80263088 25D9B0 0018+00 1/0 0/0 0/0 .text + * getModuleTypeString__20DynamicModuleControlCFv */ +const char* DynamicModuleControl::getModuleTypeString() const { + static const char* strings[4] = {"????","MEM","ARAM","DVD"}; + return strings[mResourceType&3]; +} /* 803C34C0-803C34F4 0205E0 0034+00 1/1 2/2 0/0 .data __vt__20DynamicModuleControl */ SECTION_DATA extern void* __vt__20DynamicModuleControl[13] = { @@ -250,6 +704,8 @@ SECTION_DATA extern void* __vt__20DynamicModuleControl[13] = { (void*)do_unlink__20DynamicModuleControlFv, }; + + /* 803C34F4-803C3528 020614 0034+00 2/2 0/0 0/0 .data __vt__24DynamicModuleControlBase */ SECTION_DATA extern void* __vt__24DynamicModuleControlBase[13] = { (void*)NULL /* RTTI */, @@ -267,303 +723,48 @@ SECTION_DATA extern void* __vt__24DynamicModuleControlBase[13] = { (void*)do_unlink__24DynamicModuleControlBaseFv, }; -/* 80451138-8045113C 000638 0004+00 3/3 0/0 0/0 .sbss mFirst__24DynamicModuleControlBase - */ -u8 DynamicModuleControlBase::mFirst[4]; - -/* 8045113C-80451140 00063C 0004+00 2/2 0/0 0/0 .sbss mLast__24DynamicModuleControlBase - */ -u8 DynamicModuleControlBase::mLast[4]; - -/* 802621CC-80262284 25CB0C 00B8+00 1/0 2/2 0/0 .text __dt__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm DynamicModuleControlBase::~DynamicModuleControlBase() { - nofralloc -#include "asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 80262284-802622D0 25CBC4 004C+00 1/1 0/0 0/0 .text __ct__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm DynamicModuleControlBase::DynamicModuleControlBase() { - nofralloc -#include "asm/DynamicLink/__ct__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 802622D0-80262364 25CC10 0094+00 0/0 2/2 0/0 .text link__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::link() { - nofralloc -#include "asm/DynamicLink/link__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 80262364-802623EC 25CCA4 0088+00 0/0 1/1 0/0 .text unlink__24DynamicModuleControlBaseFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::unlink() { - nofralloc -#include "asm/DynamicLink/unlink__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 802623EC-8026242C 25CD2C 0040+00 0/0 1/1 0/0 .text load_async__24DynamicModuleControlBaseFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::load_async() { - nofralloc -#include "asm/DynamicLink/load_async__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 8026242C-80262470 25CD6C 0044+00 1/1 0/0 0/0 .text force_unlink__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::force_unlink() { - nofralloc -#include "asm/DynamicLink/force_unlink__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* ############################################################################################## */ -/* 80455008-80455010 003608 0004+04 1/1 0/0 0/0 .sdata2 @3772 */ -SECTION_SDATA2 static f32 lit_3772[1 + 1 /* padding */] = { - 0.0009765625f, - /* padding */ - 0.0f, -}; - -/* 80455010-80455018 003610 0008+00 1/1 0/0 0/0 .sdata2 @3774 */ -SECTION_SDATA2 static f64 lit_3774 = 4503599627370496.0 /* cast u32 to float */; - -/* 80262470-80262660 25CDB0 01F0+00 2/0 2/2 0/0 .text dump__24DynamicModuleControlBaseFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::dump() { - nofralloc -#include "asm/DynamicLink/dump__24DynamicModuleControlBaseFv.s" -} -#pragma pop - -/* 80262660-802626D0 25CFA0 0070+00 0/0 2/2 0/0 .text __ct__20DynamicModuleControlFPCc */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm DynamicModuleControl::DynamicModuleControl(char const* param_0) { - nofralloc -#include "asm/DynamicLink/__ct__20DynamicModuleControlFPCc.s" -} -#pragma pop - -/* ############################################################################################## */ -/* 80451140-80451144 000640 0004+00 3/3 0/0 0/0 .sbss sAllocBytes__20DynamicModuleControl - */ -u8 DynamicModuleControl::sAllocBytes[4]; - -/* 80451144-80451148 000644 0004+00 3/3 0/0 0/0 .sbss sArchive__20DynamicModuleControl */ -u8 DynamicModuleControl::sArchive[4]; - -/* 80451148-80451150 000648 0004+04 3/3 0/0 0/0 .sbss sFileCache__20DynamicModuleControl - */ -u8 DynamicModuleControl::sFileCache[4 + 4 /* padding */]; - -/* 802626D0-8026275C 25D010 008C+00 1/1 0/0 0/0 .text mountCallback__20DynamicModuleControlFPv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::mountCallback(void* param_0) { - nofralloc -#include "asm/DynamicLink/mountCallback__20DynamicModuleControlFPv.s" -} -#pragma pop - -/* 8026275C-80262794 25D09C 0038+00 0/0 1/1 0/0 .text initialize__20DynamicModuleControlFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::initialize() { - nofralloc -#include "asm/DynamicLink/initialize__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262794-802627C0 25D0D4 002C+00 1/1 0/0 0/0 .text callback__20DynamicModuleControlFPv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::callback(void* param_0) { - nofralloc -#include "asm/DynamicLink/callback__20DynamicModuleControlFPv.s" -} -#pragma pop - -/* 802627C0-802627E8 25D100 0028+00 1/1 0/0 0/0 .text calcSum2__FPCUsUl */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -static asm void calcSum2(u16 const* param_0, u32 param_1) { - nofralloc -#include "asm/DynamicLink/calcSum2__FPCUsUl.s" -} -#pragma pop - -/* 802627E8-80262AFC 25D128 0314+00 1/0 0/0 0/0 .text do_load__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::do_load() { - nofralloc -#include "asm/DynamicLink/do_load__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262AFC-80262BC4 25D43C 00C8+00 1/0 0/0 0/0 .text do_load_async__20DynamicModuleControlFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::do_load_async() { - nofralloc -#include "asm/DynamicLink/do_load_async__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262BC4-80262C0C 25D504 0048+00 1/0 0/0 0/0 .text do_unload__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::do_unload() { - nofralloc -#include "asm/DynamicLink/do_unload__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262C0C-80262C5C 25D54C 0050+00 1/0 0/0 0/0 .text dump2__20DynamicModuleControlFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::dump2() { - nofralloc -#include "asm/DynamicLink/dump2__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262C5C-80262F28 25D59C 02CC+00 1/0 0/0 0/0 .text do_link__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::do_link() { - nofralloc -#include "asm/DynamicLink/do_link__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80262F28-80263000 25D868 00D8+00 1/0 0/0 0/0 .text do_unlink__20DynamicModuleControlFv - */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::do_unlink() { - nofralloc -#include "asm/DynamicLink/do_unlink__20DynamicModuleControlFv.s" -} -#pragma pop - -/* 80263000-80263070 25D940 0070+00 1/0 0/0 0/0 .text getModuleSize__20DynamicModuleControlCFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::getModuleSize() const { - nofralloc -#include "asm/DynamicLink/getModuleSize__20DynamicModuleControlCFv.s" -} -#pragma pop - -/* 80263070-80263088 25D9B0 0018+00 1/0 0/0 0/0 .text - * getModuleTypeString__20DynamicModuleControlCFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::getModuleTypeString() const { - nofralloc -#include "asm/DynamicLink/getModuleTypeString__20DynamicModuleControlCFv.s" -} -#pragma pop - /* 80263088-8026308C 25D9C8 0004+00 0/0 0/0 756/756 .text ModuleProlog */ -void ModuleProlog() { +extern "C" void ModuleProlog() { /* empty function */ } /* 8026308C-80263090 25D9CC 0004+00 0/0 0/0 756/756 .text ModuleEpilog */ -void ModuleEpilog() { +extern "C" void ModuleEpilog() { /* empty function */ } -/* ############################################################################################## */ -/* 8039A4A0-8039A4A0 026B00 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ -#pragma push -#pragma force_active on -SECTION_DEAD static char const* const stringBase_8039A770 = - "\nError: リンクされていない関数が呼び出されました.\n"; -SECTION_DEAD static char const* const stringBase_8039A7A3 = "Address: Back Chain LR Save\n"; -SECTION_DEAD static char const* const stringBase_8039A7C8 = "0x%08x: 0x%08x 0x%08x\n"; -/* @stringBase0 padding */ -SECTION_DEAD static char const* const pad_8039A7E4 = "\0\0\0"; -#pragma pop - /* 80263090-8026314C 25D9D0 00BC+00 0/0 0/0 757/757 .text ModuleUnresolved */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void ModuleUnresolved() { - nofralloc -#include "asm/DynamicLink/ModuleUnresolved.s" +extern "C" void ModuleUnresolved() { + OSReport_Error("\nError: リンクされていない関数が呼び出されました.\n"); + OSReport_Error("Address: Back Chain LR Save\n"); + u32 i = 0; + u32* stackPtr = (u32*)OSGetStackPointer(); + while(stackPtr!=NULL&&(u32)stackPtr!=0xFFFFFFFF&&i++<0x10) { + OSReport_Error("0x%08x: 0x%08x 0x%08x\n",stackPtr,*stackPtr,*(stackPtr+1)); + stackPtr = (u32*)*stackPtr; + } + OSReport_Error("\n"); } -#pragma pop /* 8026314C-80263190 25DA8C 0044+00 0/0 0/0 757/757 .text ModuleConstructorsX */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void ModuleConstructorsX() { - nofralloc -#include "asm/DynamicLink/ModuleConstructorsX.s" +extern "C" void ModuleConstructorsX(void(**ctors)()) { + while (*ctors!=0) { + (**ctors)(); + ctors++; + } } -#pragma pop /* 80263190-802631D4 25DAD0 0044+00 0/0 0/0 757/757 .text ModuleDestructorsX */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void ModuleDestructorsX() { - nofralloc -#include "asm/DynamicLink/ModuleDestructorsX.s" +extern "C" void ModuleDestructorsX(void(**dtors)()) { + while (*dtors!=0) { + (**dtors)(); + dtors++; + } } -#pragma pop /* 802631D4-802631DC 25DB14 0008+00 1/0 0/0 0/0 .text do_link__24DynamicModuleControlBaseFv */ -bool DynamicModuleControlBase::do_link() { - return true; +BOOL DynamicModuleControlBase::do_link() { + return TRUE; } /* 802631DC-802631E4 25DB1C 0008+00 1/0 0/0 0/0 .text do_load__24DynamicModuleControlBaseFv */ @@ -595,29 +796,19 @@ void DynamicModuleControlBase::dump2() { /* 80263200-80263210 25DB40 0010+00 1/0 0/0 0/0 .text * getModuleTypeString__24DynamicModuleControlBaseCFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControlBase::getModuleTypeString() const { - nofralloc -#include "asm/DynamicLink/getModuleTypeString__24DynamicModuleControlBaseCFv.s" +const char* DynamicModuleControlBase::getModuleTypeString() const { + return "Base"; } -#pragma pop /* 80263210-80263218 25DB50 0008+00 1/0 0/0 0/0 .text getModuleSize__24DynamicModuleControlBaseCFv */ -bool DynamicModuleControlBase::getModuleSize() const { - return false; +int DynamicModuleControlBase::getModuleSize() const { + return 0; } /* 80263218-80263220 25DB58 0008+00 1/0 0/0 0/0 .text getModuleName__20DynamicModuleControlCFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void DynamicModuleControl::getModuleName() const { - nofralloc -#include "asm/DynamicLink/getModuleName__20DynamicModuleControlCFv.s" +const char* DynamicModuleControl::getModuleName() const { + return mName; } -#pragma pop /* 8039A4A0-8039A4A0 026B00 0000+00 0/0 0/0 0/0 .rodata @stringBase0 */ From 7e97dfab7bf2ed99a1ba31d78703816f1b6d5e38 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Tue, 11 Jan 2022 19:36:28 -0700 Subject: [PATCH 02/11] Match destructor and msl_c header include fixes --- include/DynamicLink.h | 67 ++++++++++ include/d/save/d_save.h | 4 +- include/dolphin/os/OSLink.h | 2 +- libs/JSystem/JKernel/JKRThread.cpp | 2 +- libs/JSystem/JUtility/JUTDirectPrint.cpp | 2 +- src/DynamicLink.cpp | 156 +++++++---------------- 6 files changed, 115 insertions(+), 118 deletions(-) diff --git a/include/DynamicLink.h b/include/DynamicLink.h index 0ad0393ece..633ba0abf8 100644 --- a/include/DynamicLink.h +++ b/include/DynamicLink.h @@ -2,5 +2,72 @@ #define DYNAMICLINK_H #include "dolphin/types.h" +#include "dolphin/os/OSLink.h" +#include "m_Do/m_Do_dvd_thread.h" +#include "JSystem/JKernel/JKRFileCache.h" + +struct DynamicModuleControlBase { + u16 mLinkCount; //0x0 + u16 mDoLinkCount; //0x2 + DynamicModuleControlBase* mPrev; //0x4 + DynamicModuleControlBase* mNext; //0x8 + + /* 802621CC */ virtual ~DynamicModuleControlBase(); //0xC + /* 800188DC */ virtual const char* getModuleName() const; + /* 80263210 */ virtual int getModuleSize() const; + /* 80263200 */ virtual const char* getModuleTypeString() const; + /* 80262470 */ virtual void dump(); + /* 802631FC */ virtual void dump2(); + /* 802631DC */ virtual bool do_load(); + /* 802631F4 */ virtual bool do_load_async(); + /* 802631E4 */ virtual bool do_unload(); + /* 802631D4 */ virtual BOOL do_link(); + /* 802631EC */ virtual bool do_unlink(); + /* 80262284 */ DynamicModuleControlBase(); + /* 802622D0 */ bool link(); + /* 80262364 */ bool unlink(); + /* 802623EC */ bool load_async(); + /* 8026242C */ bool force_unlink(); + + static inline DynamicModuleControlBase* getFirstClass() {return mFirst;} + inline DynamicModuleControlBase* getNextClass() {return mNext;} + + + static DynamicModuleControlBase* mFirst; + static DynamicModuleControlBase* mLast; +}; + +struct DynamicModuleControl : DynamicModuleControlBase { + /* 800188E4 */ virtual ~DynamicModuleControl(); + /* 80263218 */ virtual const char* getModuleName() const; + /* 80263000 */ virtual int getModuleSize() const; + /* 80263070 */ virtual const char* getModuleTypeString() const; + virtual void dump() = 0; + /* 80262C0C */ virtual void dump2(); + /* 802627E8 */ virtual bool do_load(); + /* 80262AFC */ virtual bool do_load_async(); + /* 80262BC4 */ virtual bool do_unload(); + /* 80262C5C */ virtual BOOL do_link(); + /* 80262F28 */ virtual bool do_unlink(); + /* 80262660 */ DynamicModuleControl(char const*); + /* 802626D0 */ static JKRArchive* mountCallback(void*); + /* 8026275C */ bool initialize(); + /* 80262794 */ static void* callback(void*); + + OSModuleInfo* mModule; //0x10 + void* mBss; //0x14 + u32 unk_24; //0x18 + const char* mName; //0x1c + u8 mResourceType; //0x20 + u8 unk_33; //0x21 + u16 mChecksum; //0x22 + s32 mSize; //0x24 + mDoDvdThd_callback_c* mAsyncLoadCallback; //0x28 + + static u32 sAllocBytes; + static JKRArchive* sArchive; + static JKRFileCache* sFileCache; +}; + #endif /* DYNAMICLINK_H */ diff --git a/include/d/save/d_save.h b/include/d/save/d_save.h index 217ba4c419..f7c906c0e9 100644 --- a/include/d/save/d_save.h +++ b/include/d/save/d_save.h @@ -1,8 +1,8 @@ #ifndef D_SAVE_D_SAVE_H #define D_SAVE_D_SAVE_H -#include "MSL_C.PPCEABI.bare.H/MSL_Common/src/printf.h" -#include "MSL_C.PPCEABI.bare.H/MSL_Common/src/string.h" +#include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.h" +#include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/string.h" #include "SSystem/SComponent/c_xyz.h" #include "dolphin/types.h" diff --git a/include/dolphin/os/OSLink.h b/include/dolphin/os/OSLink.h index 44476eb485..12a1ba6001 100644 --- a/include/dolphin/os/OSLink.h +++ b/include/dolphin/os/OSLink.h @@ -13,7 +13,7 @@ struct OSModuleInfo { OSModuleInfo* mNext; OSModuleInfo* mPrev; u32 mNumSections; - struct { //Needed to get an assert corret; very likely bigger + struct { //Needed to get an assert correct; very likely bigger u32 sectionInfoOffset; } info; u32 mModuleNameOffset; diff --git a/libs/JSystem/JKernel/JKRThread.cpp b/libs/JSystem/JKernel/JKRThread.cpp index a9b1500360..dcecd222cd 100644 --- a/libs/JSystem/JKernel/JKRThread.cpp +++ b/libs/JSystem/JKernel/JKRThread.cpp @@ -6,7 +6,7 @@ #include "JSystem/JKernel/JKRThread.h" #include "JSystem/JKernel/JKRExpHeap.h" #include "JSystem/JUtility/JUTAssert.h" -#include "MSL_C.PPCEABI.bare.H/MSL_Common/src/printf.h" +#include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.h" #include "dol2asm.h" #include "dolphin/types.h" diff --git a/libs/JSystem/JUtility/JUTDirectPrint.cpp b/libs/JSystem/JUtility/JUTDirectPrint.cpp index 43d84c9aa8..5c84f565d2 100644 --- a/libs/JSystem/JUtility/JUTDirectPrint.cpp +++ b/libs/JSystem/JUtility/JUTDirectPrint.cpp @@ -4,7 +4,7 @@ // #include "JSystem/JUtility/JUTDirectPrint.h" -#include "MSL_C.PPCEABI.bare.H/MSL_Common/src/printf.h" +#include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.h" #include "Runtime.PPCEABI.H/__va_arg.h" #include "dol2asm.h" #include "dolphin/os/OSCache.h" diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index d81f12bb98..7b745ed2d7 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -8,76 +8,10 @@ #include "dolphin/types.h" #include "dolphin/os/OS.h" #include "JSystem/JUtility/JUTConsole.h" -#include "m_Do/m_Do_dvd_thread.h" #include "m_Do/m_Do_ext.h" -#include "JSystem/JKernel/JKRFileCache.h" -#include "dolphin/os/OSLink.h" #include "MSL_C.PPCEABI.bare.H/MSL_Common/Src/printf.h" #include "JSystem/JKernel/JKRDvdRipper.h" -struct DynamicModuleControlBase { - u16 mLinkCount; //0x0 - u16 mDoLinkCount; //0x2 - DynamicModuleControlBase* mPrev; //0x4 - DynamicModuleControlBase* mNext; //0x8 - - /* 802621CC */ virtual ~DynamicModuleControlBase(); //0xC - /* 800188DC */ virtual const char* getModuleName() const; - /* 80263210 */ virtual int getModuleSize() const; - /* 80263200 */ virtual const char* getModuleTypeString() const; - /* 80262470 */ virtual void dump(); - /* 802631FC */ virtual void dump2(); - /* 802631DC */ virtual bool do_load(); - /* 802631F4 */ virtual bool do_load_async(); - /* 802631E4 */ virtual bool do_unload(); - /* 802631D4 */ virtual BOOL do_link(); - /* 802631EC */ virtual bool do_unlink(); - /* 80262284 */ DynamicModuleControlBase(); - /* 802622D0 */ bool link(); - /* 80262364 */ bool unlink(); - /* 802623EC */ bool load_async(); - /* 8026242C */ bool force_unlink(); - - static inline DynamicModuleControlBase* getFirstClass() {return mFirst;} - inline DynamicModuleControlBase* getNextClass() {return mNext;} - - - static DynamicModuleControlBase* mFirst; - static DynamicModuleControlBase* mLast; -}; - -struct DynamicModuleControl : DynamicModuleControlBase { - /* 800188E4 */ virtual ~DynamicModuleControl(); - /* 80263218 */ virtual const char* getModuleName() const; - /* 80263000 */ virtual int getModuleSize() const; - /* 80263070 */ virtual const char* getModuleTypeString() const; - //virtual void dump(); - /* 80262C0C */ virtual void dump2(); - /* 802627E8 */ virtual bool do_load(); - /* 80262AFC */ virtual bool do_load_async(); - /* 80262BC4 */ virtual bool do_unload(); - /* 80262C5C */ virtual BOOL do_link(); - /* 80262F28 */ virtual bool do_unlink(); - /* 80262660 */ DynamicModuleControl(char const*); - /* 802626D0 */ static JKRArchive* mountCallback(void*); - /* 8026275C */ bool initialize(); - /* 80262794 */ static void* callback(void*); - - OSModuleInfo* mModule; //0x10 - void* mBss; //0x14 - u32 unk_24; //0x18 - const char* mName; //0x1c - u8 mResourceType; //0x20 - u8 unk_33; //0x21 - u16 mChecksum; //0x22 - s32 mSize; //0x24 - mDoDvdThd_callback_c* mAsyncLoadCallback; //0x28 - - static u32 sAllocBytes; - static JKRArchive* sArchive; - static JKRFileCache* sFileCache; -}; - // // Forward References: // @@ -167,14 +101,23 @@ DynamicModuleControlBase* DynamicModuleControlBase::mLast; /* 802621CC-80262284 25CB0C 00B8+00 1/0 2/2 0/0 .text __dt__24DynamicModuleControlBaseFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm DynamicModuleControlBase::~DynamicModuleControlBase() { - nofralloc -#include "asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s" +DynamicModuleControlBase::~DynamicModuleControlBase() { + force_unlink(); + if (mPrev!=NULL) { + mPrev->mNext = mNext; + } + if (mNext!=NULL) { + mNext->mPrev = mPrev; + } + if (mFirst==this) { + mFirst = mNext; + } + if (mLast==this) { + mLast = mPrev; + } + mNext = NULL; + mPrev = NULL; } -#pragma pop /* 80262284-802622D0 25CBC4 004C+00 1/1 0/0 0/0 .text __ct__24DynamicModuleControlBaseFv */ @@ -248,30 +191,37 @@ void DynamicModuleControlBase::dump() { int totalSize = 0; JUTReportConsole_f("\nDynamicModuleControlBase::dump()\n"); JUTReportConsole_f("Do Lnk Size Name\n"); + //lbl_80262608 while (current!=NULL) { - if (current->mDoLinkCount!=0||current->mLinkCount!=0) { - int size = current->getModuleSize(); + //lbl_802624B8 + u16 doLinkCount = current->mDoLinkCount; + u16 linkCount = current->mLinkCount; + if (doLinkCount!=0||linkCount!=0) { + //lbl_802624D0 + u32 size = current->getModuleSize(); const char* name = current->getModuleName(); - if (size>=0) { - if (name==NULL) { - name = "(Null)"; - } + if(size<0xFFFFFFFF) { + name = (name!=NULL) ? name : "(Null)"; + //lbl_80262524 const char* type = current->getModuleTypeString(); - JUTReportConsole_f("%3d%3d%5.1f %05x %-4s %-24s ",mDoLinkCount,mLinkCount,(float)size*((float)1/(float)1024),size,type,name); - totalSize = totalSize + size; - }else{ - if (name==NULL) { - name = "(Null)"; - } + JUTReportConsole_f("%3d%3d%5.1f %05x %-4s %-24s ",doLinkCount,linkCount,size*(1.0f/1024.0f),size,type,name); + totalSize=totalSize+size; + }else{ + //lbl_80262588 + name = (name!=NULL) ? name : "(Null)"; + //lbl_802625A4 const char* type = current->getModuleTypeString(); - JUTReportConsole_f("%3d%3d ???? ????? %-4s %-24s ",mDoLinkCount,mLinkCount,type,name); + JUTReportConsole_f("%3d%3d ???? ????? %-4s %-24s ",doLinkCount,linkCount,type,name); } + //lbl_802625DC + current->dump2(); + JUTReportConsole_f("\n"); } - current->dump2(); - JUTReportConsole_f("\n"); - current=current->getNextClass(); + //lbl_80262604 + current = getNextClass(); } - JUTReportConsole_f("TotalSize %6.2f %06x\n\n",(float)totalSize*(float)(1/1024),totalSize); + //lbl_80262608 + JUTReportConsole_f("TotalSize %6.2f %06x\n\n",(1.0f/1024.0f)*totalSize,totalSize); } #else /* ############################################################################################## */ @@ -342,7 +292,7 @@ SECTION_DEAD static char const* const stringBase_8039A57B = "Base"; JKRArchive* DynamicModuleControl::mountCallback(void* param_0) { JKRExpHeap* heap = mDoExt_getArchiveHeap(); sFileCache = JKRFileCache::mount("/rel/Final/Release",heap,NULL); - sArchive = JKRArchive::mount("RELS.arc",JKRArchive::MOUNT_COMP,heap,JKRArchive::MOUNT_DIRECTION_HEAD); + sArchive = JKRArchive::mount("aRELS.arc",JKRArchive::MOUNT_COMP,heap,JKRArchive::MOUNT_DIRECTION_HEAD); if (sArchive == NULL) { OSReport_Warning("マウント失敗ですが単にアーカイブを作ってないだけなら遅いだけです %s\n","RELS.arc"); } @@ -378,7 +328,6 @@ static u32 calcSum2(u16 const* data, u32 size) { #ifdef NONMATCHING bool DynamicModuleControl::do_load() { - if (mModule!=NULL) { return true; } @@ -545,8 +494,8 @@ BOOL DynamicModuleControl::do_link() { OSGetTime(); OSGetTime(); if(mModule->mModuleVersion>=3) { - u32 unk = mModule->fixSize + 0x1f; - u32 unk3 = unk & ~0x1f; + u32 unk = mModule->fixSize; + u32 unk3 = (unk+0x1f) & ~0x1f; u32 unk2 = (u32)mModule+unk3; s32 size = JKRHeap::getSize(mModule,NULL); if(size<0) { @@ -704,25 +653,6 @@ SECTION_DATA extern void* __vt__20DynamicModuleControl[13] = { (void*)do_unlink__20DynamicModuleControlFv, }; - - -/* 803C34F4-803C3528 020614 0034+00 2/2 0/0 0/0 .data __vt__24DynamicModuleControlBase */ -SECTION_DATA extern void* __vt__24DynamicModuleControlBase[13] = { - (void*)NULL /* RTTI */, - (void*)NULL, - (void*)__dt__24DynamicModuleControlBaseFv, - (void*)getModuleName__24DynamicModuleControlBaseCFv, - (void*)getModuleSize__24DynamicModuleControlBaseCFv, - (void*)getModuleTypeString__24DynamicModuleControlBaseCFv, - (void*)dump__24DynamicModuleControlBaseFv, - (void*)dump2__24DynamicModuleControlBaseFv, - (void*)do_load__24DynamicModuleControlBaseFv, - (void*)do_load_async__24DynamicModuleControlBaseFv, - (void*)do_unload__24DynamicModuleControlBaseFv, - (void*)do_link__24DynamicModuleControlBaseFv, - (void*)do_unlink__24DynamicModuleControlBaseFv, -}; - /* 80263088-8026308C 25D9C8 0004+00 0/0 0/0 756/756 .text ModuleProlog */ extern "C" void ModuleProlog() { /* empty function */ From d0a7d3cd3414a9c29436300eba56a89886059e44 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Tue, 11 Jan 2022 19:46:30 -0700 Subject: [PATCH 03/11] fix intentional diff I made for testing --- src/DynamicLink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 7b745ed2d7..cbdda00e69 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -292,7 +292,7 @@ SECTION_DEAD static char const* const stringBase_8039A57B = "Base"; JKRArchive* DynamicModuleControl::mountCallback(void* param_0) { JKRExpHeap* heap = mDoExt_getArchiveHeap(); sFileCache = JKRFileCache::mount("/rel/Final/Release",heap,NULL); - sArchive = JKRArchive::mount("aRELS.arc",JKRArchive::MOUNT_COMP,heap,JKRArchive::MOUNT_DIRECTION_HEAD); + sArchive = JKRArchive::mount("RELS.arc",JKRArchive::MOUNT_COMP,heap,JKRArchive::MOUNT_DIRECTION_HEAD); if (sArchive == NULL) { OSReport_Warning("マウント失敗ですが単にアーカイブを作ってないだけなら遅いだけです %s\n","RELS.arc"); } From 0adee83f89da16fe7a870f244f3b4c0e92bbe490 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Tue, 11 Jan 2022 20:20:58 -0700 Subject: [PATCH 04/11] prepare makefile for shiftability --- Makefile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index dd11eceada..db75a5bf14 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,9 @@ LDSCRIPT := $(BUILD_DIR)/ldscript.lcf # Outputs DOL := $(BUILD_DIR)/main.dol +DOL_SHIFT := $(BUILD_DIR)/main_shift.dol ELF := $(DOL:.dol=.elf) +ELF_SHIFT := $(DOL_SHIFT:.dol=.elf) MAP := $(BUILD_DIR)/dolzel2.map # include list of object files @@ -94,7 +96,10 @@ SBSS_PDHR := 10 default: all -all: dirs $(DOL) +check: + $(SHA1SUM) -c $(TARGET).sha1 + +all: dirs $(DOL) check # Make sure build directory exists before compiling anything dirs: @@ -103,7 +108,6 @@ dirs: $(DOL): $(ELF) | tools $(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL) - $(SHA1SUM) -c $(TARGET).sha1 clean: rm -f -d -r $(BUILD_DIR)/libs @@ -136,6 +140,16 @@ $(ELF): $(LIBS) $(O_FILES) @$(PYTHON) tools/lcf.py dol --output $(LDSCRIPT) $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) +$(ELF_SHIFT): $(LIBS) $(O_FILES) + @echo $(O_FILES) > build/o_files + @$(PYTHON) tools/lcf.py dol --shift --output $(LDSCRIPT) + $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) + +$(DOL_SHIFT): $(ELF_SHIFT) | tools + $(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL) + +shift: dirs $(DOL_SHIFT) + # $(BUILD_DIR)/%.o: %.cpp @mkdir -p $(@D) @@ -157,4 +171,4 @@ include tools/elf2dol/Makefile ### Debug Print ### print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true -.PHONY: default all dirs clean tools docs print-% +.PHONY: default all dirs clean tools docs shift print-% From c72012c5d8c12966a2ea997798cf706e84612a79 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Tue, 11 Jan 2022 21:12:44 -0700 Subject: [PATCH 05/11] Add basic dol shiftability Fixed an incorrect function name --- Makefile | 7 +++--- include/dolphin/mtx/mtx.h | 1 + include/m_Do/m_Do_mtx.h | 6 ++--- src/m_Do/m_Do_mtx.cpp | 2 +- tools/lcf.py | 48 +++++++++++++++++++++++++++++++++++---- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index be9d52b094..6ee58131ab 100644 --- a/Makefile +++ b/Makefile @@ -96,11 +96,10 @@ SBSS_PDHR := 10 default: all -check: +dol: $(DOL) $(SHA1SUM) -c $(TARGET).sha1 -all: dirs $(DOL) check - +all: dirs dol # Make sure build directory exists before compiling anything dirs: @mkdir -p build @@ -142,7 +141,7 @@ $(ELF): $(LIBS) $(O_FILES) $(ELF_SHIFT): $(LIBS) $(O_FILES) @echo $(O_FILES) > build/o_files - @$(PYTHON) tools/lcf.py dol --shift --output $(LDSCRIPT) + @$(PYTHON) tools/lcf.py dol_shift --output $(LDSCRIPT) $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) $(DOL_SHIFT): $(ELF_SHIFT) | tools diff --git a/include/dolphin/mtx/mtx.h b/include/dolphin/mtx/mtx.h index a842ce7b00..adab16dbe9 100644 --- a/include/dolphin/mtx/mtx.h +++ b/include/dolphin/mtx/mtx.h @@ -9,6 +9,7 @@ typedef float Mtx[3][4]; typedef float Mtx33[3][3]; typedef float Mtx23[2][3]; typedef f32 (*MtxP)[4]; +typedef const f32 (*CMtxP)[4]; //Change name later? extern "C" { void PSMTXIdentity(Mtx matrix); diff --git a/include/m_Do/m_Do_mtx.h b/include/m_Do/m_Do_mtx.h index 30c90bdd62..22ebf7c826 100644 --- a/include/m_Do/m_Do_mtx.h +++ b/include/m_Do/m_Do_mtx.h @@ -1,8 +1,8 @@ #ifndef M_DO_M_DO_MTX_H #define M_DO_M_DO_MTX_H -#include "SSystem/SComponent/c_Xyz.h" -#include "SSystem/SComponent/c_sXyz.h" +#include "SSystem/SComponent/c_xyz.h" +#include "SSystem/SComponent/c_sxyz.h" #include "dolphin/mtx/mtx.h" #include "dolphin/mtx/quat.h" #include "dolphin/types.h" @@ -15,7 +15,7 @@ void mDoMtx_ZrotS(Mtx, s16); void mDoMtx_YrotS(Mtx, s16); void mDoMtx_XrotS(Mtx, s16); void mDoMtx_YrotM(Mtx, s16); -void mDoMtx_MtxToRot(MtxP, csXyz*); +void mDoMtx_MtxToRot(CMtxP, csXyz*); class mDoMtx_stack_c { public: diff --git a/src/m_Do/m_Do_mtx.cpp b/src/m_Do/m_Do_mtx.cpp index 8f9b9f025c..9075b8eebf 100644 --- a/src/m_Do/m_Do_mtx.cpp +++ b/src/m_Do/m_Do_mtx.cpp @@ -287,7 +287,7 @@ asm void mDoMtx_QuatConcat(Quaternion const* param_0, Quaternion const* param_1, #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void mDoMtx_MtxToRot(MtxP param_0, csXyz* param_1) { +asm void mDoMtx_MtxToRot(CMtxP param_0, csXyz* param_1) { nofralloc #include "asm/m_Do/m_Do_mtx/mDoMtx_MtxToRot__FPA4_CfP5csXyz.s" } diff --git a/tools/lcf.py b/tools/lcf.py index 028dc916f6..a350382ae9 100644 --- a/tools/lcf.py +++ b/tools/lcf.py @@ -33,11 +33,17 @@ VERSION = "1.0" sys.path.append("defs") -def lcf_generate(output_path): +def lcf_generate(output_path,shiftable,map_file): """Script for generating .lcf files""" import module0 + if shiftable == True: + print("Generating LCF for shiftability") + map_file = open(map_file,'r') + map_file = map_file.read() + map_file = map_file.splitlines() + # load symbols from compiled files symbols = [] for archive in ARCHIVES: @@ -95,7 +101,17 @@ def lcf_generate(output_path): if symbol["type"] == "LinkerGenerated": # linker handles these symbols continue - file.write(f"\t\"{symbol['label']}\" = 0x{symbol['addr']:08X};\n") + addr = symbol['addr'] + if shiftable==True: + for line in map_file: + if type(symbol['name'])==str and line.find(' '+symbol['name']+' ')!=-1 and name[0] != "@" or type(symbol['label']) == str and line.find(' '+symbol['label']+' ')!=-1: + linesplit = line.split() + if len(linesplit) > 3 and linesplit[2]!="NOT": + addr = int(linesplit[2],16) + file.write(f"\t\"{symbol['label']}\" = 0x{addr:08X};\n") + else: + file.write(f"\t\"{symbol['label']}\" = 0x{addr:08X};\n") + file.write("\n") # @stringBase0 is generated by the compiler. The dol2asm is using a trick to @@ -106,7 +122,18 @@ def lcf_generate(output_path): file.write("\t/* @stringBase0 */\n") for x in module0.SYMBOLS: if x["type"] == "StringBase": - file.write('\t"%s" = 0x%08X;\n' % (x["label"], x["addr"])) + addr = x['addr'] + if shiftable==True: + obj = (module0.TRANSLATION_UNITS[x['tu']].split('/')[-1])+'.o' + #print(obj) + for line in map_file: + if line.find(' '+obj)!=-1 and line.find(' '+x['name']+' ')!=-1 or line.find('\t'+obj)!=-1 and line.find(' '+x['name']+' ')!=-1: + linesplit = line.split() + if len(linesplit) > 3: + addr = int(linesplit[2],16) + file.write("\t\"%s\" = 0x%08X;\n" % (x['label'], addr)) + else: + file.write("\t\"%s\" = 0x%08X;\n" % (x['label'], addr)) file.write("}\n") file.write("\n") @@ -384,7 +411,20 @@ def lcf(): default="build/dolzel2/ldscript.lcf", ) def dol(output_path): - lcf_generate(output_path) + lcf_generate(output_path,False,None) + +@lcf.command(name="dol_shift") +@click.option( + "--output", + "-o", + "output_path", + required=False, + type=PathPath(file_okay=True, dir_okay=False), + default="build/dolzel2/ldscript.lcf", +) +@click.option('--map','-m','map_file',required=False,type=PathPath(file_okay=True, dir_okay=False), default="build/dolzel2/dolzel2.map") +def dol_shift(output_path,map_file): + lcf_generate(output_path,True,map_file) @lcf.command(name="rel") From e1246d9b0a4628fc997e6ab5f2031371bc661e4c Mon Sep 17 00:00:00 2001 From: jdflyer Date: Sat, 15 Jan 2022 17:59:59 -0700 Subject: [PATCH 06/11] Shiftable --- Makefile | 11 +- rel/d/a/e/d_a_e_wb/d_a_e_wb.cpp | 6 +- src/DynamicLink.cpp | 2 +- tools/extract_game_assets.py | 66 ++++- tools/package_game_assets.py | 433 ++++++++++++++++++++++++++++++++ tools/tp.py | 2 +- 6 files changed, 512 insertions(+), 8 deletions(-) create mode 100644 tools/package_game_assets.py diff --git a/Makefile b/Makefile index 6ee58131ab..b3a8a8bcc8 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,7 @@ clean_rels: tools: $(ELF2DOL) assets: + @mkdir -p game @cd game; $(PYTHON) ../tools/extract_game_assets.py ../$(IMAGENAME) docs: @@ -149,6 +150,14 @@ $(DOL_SHIFT): $(ELF_SHIFT) | tools shift: dirs $(DOL_SHIFT) +game: | shift rels + @mkdir -p game + @$(PYTHON) tools/package_game_assets.py game $(BUILD_DIR) + +rungame: game + @echo If you are playing on a shifted game make sure Hyrule Field Speed hack is disabled in dolphin! + dolphin-emu $(BUILD_DIR)/game/sys/main.dol + # $(BUILD_DIR)/%.o: %.cpp @mkdir -p $(@D) @@ -170,4 +179,4 @@ include tools/elf2dol/Makefile ### Debug Print ### print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true -.PHONY: default all dirs clean tools docs shift print-% +.PHONY: default all dirs clean tools docs shift game rungame print-% diff --git a/rel/d/a/e/d_a_e_wb/d_a_e_wb.cpp b/rel/d/a/e/d_a_e_wb/d_a_e_wb.cpp index b149a30ec2..246722a94c 100644 --- a/rel/d/a/e/d_a_e_wb/d_a_e_wb.cpp +++ b/rel/d/a/e/d_a_e_wb/d_a_e_wb.cpp @@ -277,7 +277,7 @@ extern "C" static void cMtx_XrotM__FPA4_fs(); extern "C" static void JMAFastSqrt__Ff(); extern "C" static void dComIfGp_particle_set__FUlUsPC4cXyzPC5csXyzPC4cXyz(); extern "C" void cancelOriginalDemo__9daHorse_cFv(); -extern "C" void __ct__10JAISoundIDFUl(); +extern "C" void __ct__10JAISoundIDFUl(u32* this_replacement,u32 param_0); extern "C" static void dComIfGp_getVibration__Fv(); extern "C" void __ct__4cXyzFfff(); extern "C" void onDemoJumpDistance__9daHorse_cFff(); @@ -4970,8 +4970,8 @@ asm void daHorse_c::cancelOriginalDemo() { #pragma pop /* 807E27D0-807E27D8 -00001 0008+00 0/0 0/0 0/0 .text __ct__10JAISoundIDFUl */ -JAISoundID::JAISoundID(u32 param_0) { - *(u32*)this = (u32)(param_0); +extern "C" void __ct__10JAISoundIDFUl(u32* this_replacement,u32 param_0) { + *(u32*)this_replacement = (u32)(param_0); } /* 807E27D8-807E27E8 010438 0010+00 1/1 0/0 0/0 .text dComIfGp_getVibration__Fv */ diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index cbdda00e69..097227d06d 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -372,7 +372,7 @@ bool DynamicModuleControl::do_load() { } } if(mModule==NULL&&sFileCache!=NULL) { - mModule = (OSModuleInfo*)sFileCache->getResource(0x72656C73,buffer); + mModule = (OSModuleInfo*)sFileCache->getResource(0x72656C73/*rels*/,buffer); if(mModule!=NULL) { mSize = 0; mResourceType = 11; diff --git a/tools/extract_game_assets.py b/tools/extract_game_assets.py index 77eca329ed..44124d3d3c 100644 --- a/tools/extract_game_assets.py +++ b/tools/extract_game_assets.py @@ -7,6 +7,13 @@ Usage: `python tools/extract_game_assets.py` """ fstInfoPosition = 0x424 +bootPosition = 0x0 +bootSize = 0x440 +bi2Position = 0x440 +bi2Size = 0x2000 +apploaderPosition = 0x2440 +dolInfoPosition = 0x420 + numFileEntries = 0 """ @@ -94,7 +101,7 @@ Write the current folder to disk and return it's name/last entry number def writeFolder(parsedFstBin, i): - folderPath = i["folderName"] + "/" + folderPath = i["folderName"] + "/" lastEntryNumber = i["lastEntryNumber"] if i["parentFolderEntryNumber"] == 0: @@ -125,6 +132,9 @@ def writeAssets(parsedFstBin, handler): # Write the folder structure and files to disc j = 0 folderStack = [] + if not os.path.exists("./files/"): + os.makedirs("./files/") + os.chdir('./files/') folderStack.append({"folderName": "./", "lastEntryNumber": numFileEntries}) for i in parsedFstBin: j += 1 @@ -143,6 +153,38 @@ def writeAssets(parsedFstBin, handler): while folderStack[-1]["lastEntryNumber"] == j + 1: folderStack.pop() +def writeSys(boot,bi2,apploader,dol,fst): + if not os.path.exists("./sys/"): + os.makedirs("./sys/") + open("./sys/boot.bin","wb").write(boot) + open("./sys/bi2.bin","wb").write(bi2) + open("./sys/apploader.img","wb").write(apploader) + open("./sys/main.dol","wb").write(dol) + open("./sys/fst.bin","wb").write(fst) + +def getDolInfo(disc): + disc.seek(dolInfoPosition) + dolOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + dolSize = 0 + for i in range(7): + disc.seek(dolOffset+(i*4)) + segmentOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + disc.seek(dolOffset+0x90+(i*4)) + segmentSize = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + if (segmentOffset+segmentSize)>dolSize: + dolSize = segmentOffset + segmentSize + + for i in range(11): + disc.seek(dolOffset+0x1c+(i*4)) + dataOffset = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + disc.seek(dolOffset+0xac+(i*4)) + dataSize = int.from_bytes(bytearray(disc.read(4)), byteorder="big") + if (dataOffset+dataSize)>dolSize: + dolSize = dataOffset + dataSize + + return dolOffset, dolSize + + def extract(path): with open(path, "rb") as f: @@ -150,10 +192,30 @@ def extract(path): f.seek(fstInfoPosition) fstOffset, fstSize = getFstInfo(f, fstInfoPosition) + f.seek(bootPosition) + bootBytes = bytearray(f.read(bootSize)) + + f.seek(bi2Position) + bi2Bytes = bytearray(f.read(bi2Size)) + + f.seek(apploaderPosition+0x14) + apploaderSize = int.from_bytes(bytearray(f.read(4)), byteorder="big") + f.seek(apploaderPosition+0x18) + trailerSize = int.from_bytes(bytearray(f.read(4)), byteorder="big") + apploaderMainSize = 0x20 + apploaderSize + trailerSize + f.seek(apploaderPosition) + apploaderBytes = bytearray(f.read(apploaderMainSize)) + dolOffset, dolSize = getDolInfo(f) + f.seek(dolOffset) + dolBytes = bytearray(f.read(dolSize)) + + # Seek to fst.bin and retrieve it f.seek(fstOffset) fstBinBytes = bytearray(f.read(fstSize)) + writeSys(bootBytes,bi2Bytes,apploaderBytes,dolBytes,fstBinBytes) + # Parse fst.bin parsedFstBin = parseFstBin(fstBinBytes) @@ -162,7 +224,7 @@ def extract(path): def main(): - extract(sys.argv[1], "rb") + extract(sys.argv[1]) if __name__ == "__main__": diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py new file mode 100644 index 0000000000..5ca061f275 --- /dev/null +++ b/tools/package_game_assets.py @@ -0,0 +1,433 @@ +import os +import sys +import shutil +import extract_game_assets +from pathlib import Path +import hashlib +import struct + + +def sha1_from_data(data): + sha1 = hashlib.sha1() + sha1.update(data) + + return sha1.hexdigest().upper() + +def copy(path,destPath): + for root,dirs,files in os.walk(str(path)): + for file in files: + outputDir = destPath/Path(str(root)) + #print(str(outputDir.absolute())+file) + if not outputDir.absolute().exists(): + os.makedirs(outputDir.absolute()) + outputFile = Path(str(outputDir.absolute())+"/"+str(file)) + inFile = Path(str(Path(root).absolute())+"/"+str(file)) + if not outputFile.exists(): + print(str(inFile)+" -> "+str(outputFile)) + shutil.copyfile(inFile,outputFile) + else: + inf = open(inFile,"rb") + inSum = sha1_from_data(bytearray(inf.read())) + outf = open(outputFile,"rb") + outSum = sha1_from_data(bytearray(outf.read())) + if inSum!=outSum: + print(str(inFile)+" -> "+str(outputFile)) + shutil.copyfile(inFile,outputFile) + + +aMemRels = """d_a_alldie.rel +d_a_andsw2.rel +d_a_bd.rel +d_a_canoe.rel +d_a_cstaf.rel +d_a_demo_item.rel +d_a_door_bossl1.rel +d_a_econt.rel +d_a_e_dn.rel +d_a_e_fm.rel +d_a_e_ga.rel +d_a_e_hb.rel +d_a_e_nest.rel +d_a_e_rd.rel +d_a_fr.rel +d_a_grass.rel +d_a_kytag05.rel +d_a_kytag10.rel +d_a_kytag11.rel +d_a_kytag14.rel +d_a_mg_fish.rel +d_a_npc_besu.rel +d_a_npc_fairy_seirei.rel +d_a_npc_fish.rel +d_a_npc_henna.rel +d_a_npc_kakashi.rel +d_a_npc_kkri.rel +d_a_npc_kolin.rel +d_a_npc_maro.rel +d_a_npc_taro.rel +d_a_npc_tkj.rel +d_a_obj_bhashi.rel +d_a_obj_bkdoor.rel +d_a_obj_bosswarp.rel +d_a_obj_cboard.rel +d_a_obj_digplace.rel +d_a_obj_eff.rel +d_a_obj_fmobj.rel +d_a_obj_gptaru.rel +d_a_obj_hhashi.rel +d_a_obj_kanban2.rel +d_a_obj_kbacket.rel +d_a_obj_kgate.rel +d_a_obj_klift00.rel +d_a_obj_ktonfire.rel +d_a_obj_ladder.rel +d_a_obj_lv2candle.rel +d_a_obj_magne_arm.rel +d_a_obj_metalbox.rel +d_a_obj_mgate.rel +d_a_obj_nameplate.rel +d_a_obj_ornament_cloth.rel +d_a_obj_rope_bridge.rel +d_a_obj_stick.rel +d_a_obj_stonemark.rel +d_a_obj_swallshutter.rel +d_a_obj_swpropeller.rel +d_a_obj_swpush5.rel +d_a_obj_yobikusa.rel +d_a_scene_exit2.rel +d_a_shop_item.rel +d_a_sq.rel +d_a_swc00.rel +d_a_tag_ajnot.rel +d_a_tag_attack_item.rel +d_a_tag_cstasw.rel +d_a_tag_gstart.rel +d_a_tag_hinit.rel +d_a_tag_hjump.rel +d_a_tag_hstop.rel +d_a_tag_lv2prchk.rel +d_a_tag_magne.rel +d_a_tag_mhint.rel +d_a_tag_mstop.rel +d_a_tag_spring.rel +d_a_tag_statue_evt.rel +d_a_ykgr.rel""" + +mMemRels = """d_a_andsw.rel +d_a_arrow.rel +d_a_bg.rel +d_a_bg_obj.rel +d_a_boomerang.rel +d_a_crod.rel +d_a_demo00.rel +d_a_disappear.rel +d_a_dmidna.rel +d_a_door_dbdoor00.rel +d_a_door_knob00.rel +d_a_door_shutter.rel +d_a_door_spiral.rel +d_a_dshutter.rel +d_a_ep.rel +d_a_hitobj.rel +d_a_kytag00.rel +d_a_kytag04.rel +d_a_kytag17.rel +d_a_mg_rod.rel +d_a_midna.rel +d_a_nbomb.rel +d_a_obj_brakeeff.rel +d_a_obj_burnbox.rel +d_a_obj_carry.rel +d_a_obj_ito.rel +d_a_obj_life_container.rel +d_a_obj_movebox.rel +d_a_obj_swpush.rel +d_a_obj_timer.rel +d_a_obj_yousei.rel +d_a_path_line.rel +d_a_scene_exit.rel +d_a_set_bgobj.rel +d_a_spinner.rel +d_a_suspend.rel +d_a_swhit0.rel +d_a_tag_allmato.rel +d_a_tag_attention.rel +d_a_tag_camera.rel +d_a_tag_chkpoint.rel +d_a_tag_event.rel +d_a_tag_evt.rel +d_a_tag_evtarea.rel +d_a_tag_evtmsg.rel +d_a_tag_howl.rel +d_a_tag_kmsg.rel +d_a_tag_lantern.rel +d_a_tag_mist.rel +d_a_tag_msg.rel +d_a_tag_push.rel +d_a_tag_telop.rel +d_a_tbox.rel +d_a_tbox2.rel +d_a_vrbox.rel +d_a_vrbox2.rel +f_pc_profile_lst.rel""" + +#Because libarc is only geared toward reading from arcs I'm writing my own arc writer in this file + +class HEADER: + RARC : int + length : int + headerLength : int + fileDataOffset : int + fileDataLen : int + fileDataLen2 : int + unk1 : int + unk2 : int + +class INFO: + numNodes : int + firstNodeOffset : int + totalDirNum : int + firstDirOffset : int + stringTableLen : int + stringTableOffset : int + numDirsThatAreFiles : int + unk1 : int + unk2 : int + +class NODE: + NAME : int + stringTableOffset: int + hash : int + numDirs : int + firstDirIndex : int + +class DIRECTORY: + dirIndex : int + stringHash : int + type : int + stringOffset : int + fileOffset : int + fileLength : int + unk1 : int + +def computeHash(string): + hash = 0 + for char in string: + hash = hash*3 + hash = hash + ord(char) + + if hash>65535: + hash=hash%65535 + return hash + +def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): + file = DIRECTORY() + file.dirIndex = index + file.stringHash = computeHash(name) + file.type = 0xA500 + file.stringOffset = stringTable.find(name) + path = None + for relPath in paths: + if str(relPath).find(name)!=-1: + path = relPath + file.fileLength = os.path.getsize(path) + file.fileOffset = sizeIndex + sizeIndex = sizeIndex + file.fileLength + 1 + file.unk1 = 0 + fileData = open(path,"rb") + data += fileData.read(file.fileLength) + fileData.close() + dirs.append(file) + + return dirs,data,sizeIndex + + +def copyRelFiles(buildPath,aMemList,mMemList): + relArcPaths = [] + for root,dirs,files in os.walk(str(buildPath/"rel")): + for file in files: + if file.find(".rel")!=-1: + relArcFound = False + for rel in aMemList: + if rel==file: + relArcFound = True + for rel in mMemList: + if rel==file: + relArcFound = True + fullPath = Path(root+"/"+file) + print(str(fullPath)+" -> "+str(buildPath/"game/files/rel/Final/Release"/file)) + shutil.copy(fullPath,buildPath/"game/files/rel/Final/Release/") #We're copying uncompressed rels here, we should compress in the future! + if relArcFound==True: + relArcPaths.append(fullPath) + #print(relArcPaths) + + #After writing this all I found out we don't actually need RELS.arc to load rels lol, keeping it here for the future in case we want to match RELS.arc + + arcHeader = HEADER() + arcHeader.RARC = 0x52415243 + arcHeader.headerLength = 0x20 + arcHeader.unk1 = 0 + arcHeader.unk2 = 0 + infoBlock = INFO() + infoBlock.numNodes = 5 + infoBlock.numDirsThatAreFiles = 142 + rootNode = NODE() + rootNode.NAME = 0x524F4F54 + rootNode.numDirs = 4 + rootNode.firstDirIndex = 0 + rootNode.hash = computeHash("rels") + aMemNode = NODE() + aMemNode.NAME = 0x414d454d + aMemNode.hash = computeHash("amem") + aMemNode.numDirs = 79 + aMemNode.firstDirIndex = 4 + mMemNode = NODE() + mMemNode.hash = computeHash("mmem") + mMemNode.NAME = 0x4d4d454d + mMemNode.numDirs = 59 + mMemNode.firstDirIndex = 83 + + stringTable = "\x2E\0\x2E\x2E\0rels\0amem\0" + for rel in aMemList: + stringTable = stringTable+rel+'\0' + stringTable = stringTable+"mmem\0" + for rel in mMemList: + stringTable = stringTable+rel+'\0' + + rootNode.stringTableOffset = stringTable.find("rels") + aMemNode.stringTableOffset = stringTable.find("amem") + mMemNode.stringTableOffset = stringTable.find("mmem") + + aMemDir = DIRECTORY() + aMemDir.dirIndex = 0xFFFF + aMemDir.type = 0x200 + aMemDir.stringOffset = stringTable.find("amem") + aMemDir.stringHash = computeHash("amem") + aMemDir.fileOffset = 1 + aMemDir.fileLength = 0x10 + aMemDir.unk1 = 0 + + mMemDir = DIRECTORY() + mMemDir.dirIndex = 0xFFFF + mMemDir.type = 0x200 + mMemDir.stringOffset = stringTable.find("mmem") + mMemDir.stringHash = computeHash("mmem") + mMemDir.fileOffset = 2 + mMemDir.fileLength = 0x10 + mMemDir.unk1 = 0 + + unkDir = DIRECTORY() + unkDir.dirIndex = 0xFFFF + unkDir.stringHash = 0x2E + unkDir.type = 0x200 + unkDir.stringOffset = 0 + unkDir.fileOffset = 0 + unkDir.fileLength = 0x10 + unkDir.unk1 = 0 + + unkDir2 = DIRECTORY() + unkDir2.dirIndex = 0xFFFF + unkDir2.stringHash = 0xB8 + unkDir2.type = 0x200 + unkDir2.stringOffset = 2 + unkDir2.fileOffset = 0xFFFFFFFF + unkDir2.fileLength = 0x10 + unkDir2.unk1 = 0 + + dirs = [aMemDir,mMemDir,unkDir,unkDir2] + + data = bytearray() + + dirIndex = 4 + sizeIndex = 0 + for rel in aMemList: + retdirs,retdata,retSize = addFile(dirIndex,sizeIndex,dirs,rel,stringTable,relArcPaths,data) + dirIndex = dirIndex+1 + sizeIndex = retSize + dirs = retdirs + data = retdata + for rel in mMemList: + retdirs,retdata,retSize = addFile(dirIndex,sizeIndex,dirs,rel,stringTable,relArcPaths,data) + dirIndex = dirIndex+1 + sizeIndex = retSize + #print(hex(dirIndex)) + dirs = retdirs + data = retdata + + arcHeader.length = sizeIndex+len(stringTable)+0x20+0x20+0x30+(len(dirs)*0x14)+len(data) + arcHeader.fileDataOffset=0x14E0 + arcHeader.fileDataLen=len(data) + arcHeader.fileDataLen2=arcHeader.fileDataLen + + infoBlock.firstNodeOffset = 0x20 + infoBlock.firstDirOffset = 0x60 + infoBlock.stringTableLen = len(stringTable) + infoBlock.stringTableOffset = 0xB80 + infoBlock.unk1 = 0x100 + infoBlock.unk2 = 0 + infoBlock.totalDirNum = len(dirs) + + + outputArcFile = open(buildPath/"game/files/RELS.arc","wb") + outputArcFile.seek(0) + + outputArcFile.write(struct.pack(">IIIIIIII",arcHeader.RARC,arcHeader.length,arcHeader.headerLength,arcHeader.fileDataOffset,arcHeader.fileDataLen,arcHeader.fileDataLen2,arcHeader.unk1,arcHeader.unk2)) + outputArcFile.write(struct.pack(">IIIIIIHHI",infoBlock.numNodes,infoBlock.firstNodeOffset,infoBlock.totalDirNum,infoBlock.firstDirOffset,infoBlock.stringTableLen,infoBlock.stringTableOffset,infoBlock.numDirsThatAreFiles,infoBlock.unk1,infoBlock.unk2)) + outputArcFile.write(struct.pack(">IIHHI",rootNode.NAME,rootNode.stringTableOffset,rootNode.hash,rootNode.numDirs,rootNode.firstDirIndex)) + outputArcFile.write(struct.pack(">IIHHI",aMemNode.NAME,aMemNode.stringTableOffset,aMemNode.hash,aMemNode.numDirs,aMemNode.firstDirIndex)) + outputArcFile.write(struct.pack(">IIHHI",mMemNode.NAME,mMemNode.stringTableOffset,mMemNode.hash,mMemNode.numDirs,mMemNode.firstDirIndex)) + outputArcFile.write(bytearray(16)) + for dir in dirs: + outputArcFile.write(struct.pack(">HHHHIII",dir.dirIndex,dir.stringHash,dir.type,dir.stringOffset,dir.fileOffset,dir.fileLength,dir.unk1)) + unkData = [0x8A ,0xCF ,0x7F ,0xA5 ,0x00 ,0x09 ,0x36 ,0x00 ,0x0D ,0x08 ,0xA0 ,0x00 ,0x00 ,0x0C ,0xD8 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x8B ,0x9B ,0xF7 ,0xA5 ,0x00 ,0x09 ,0x45 ,0x00 ,0x0D ,0x15 ,0x80 ,0x00 ,0x00 ,0x21 ,0xED ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0x00 ,0x2E ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0x00 ,0xB8 ,0x02 ,0x00 ,0x00 ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00] + outputArcFile.write(bytearray(unkData)) + strBytearray = bytearray() + strBytearray.extend(map(ord,stringTable)) + outputArcFile.write(strBytearray) + outputArcFile.write(bytearray(6)) + outputArcFile.write(data) + + outputArcFile.truncate() + outputArcFile.close() + + + + + + + + + + + + + +def main(gamePath,buildPath): + if not gamePath.exists(): + gamePath.mkdir(parents=True, exist_ok=True) + + iso = Path("gz2e01.iso") + if not iso.exists() or not iso.is_file(): + print("gz2e01.iso doesn't exist in project directory!") + sys.exit(1) + + if not (gamePath/"files").exists() or not (gamePath/"sys").exists(): + print("ISO is not extracted; extracting...") + previousDir = os.getcwd() + os.chdir(str(gamePath.absolute())) + extract_game_assets.extract("../" + str(iso)) + os.chdir(previousDir) + + print("Copying game files...") + copy(gamePath,buildPath.absolute()) + + print(str(buildPath/"main_shift.dol")+" -> "+str(buildPath/"game/sys/main.dol")) + shutil.copyfile(buildPath/"main_shift.dol",buildPath/"game/sys/main.dol") + + copyRelFiles(buildPath,aMemRels.splitlines(),mMemRels.splitlines()) + + + + +if __name__ == "__main__": + main(Path(sys.argv[1]),Path(sys.argv[2])) \ No newline at end of file diff --git a/tools/tp.py b/tools/tp.py index ff70a71a41..64c0eed53a 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -351,7 +351,7 @@ def check(debug, rels, game_path, build_path): CONSOLE.print(text) try: - check_sha1(game_path, build_path, rels) + check_sha1(game_path/"files", build_path, rels) text = Text(" OK") text.stylize("bold green") CONSOLE.print(text) From 8a9f18c45ff629ea2f6cfbdc089be43b30718c0e Mon Sep 17 00:00:00 2001 From: jdflyer Date: Sun, 16 Jan 2022 15:15:24 -0700 Subject: [PATCH 07/11] Shift Fixes I also updated elf2dol --- tools/package_game_assets.py | 74 ++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py index 5ca061f275..a8ea2e0675 100644 --- a/tools/package_game_assets.py +++ b/tools/package_game_assets.py @@ -5,6 +5,8 @@ import extract_game_assets from pathlib import Path import hashlib import struct +import ctypes +import oead def sha1_from_data(data): @@ -216,8 +218,8 @@ def computeHash(string): hash = hash*3 hash = hash + ord(char) - if hash>65535: - hash=hash%65535 + hash = ctypes.c_ushort(hash) + hash = hash.value return hash def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): @@ -230,12 +232,15 @@ def addFile(index,sizeIndex,dirs,name,stringTable,paths,data): for relPath in paths: if str(relPath).find(name)!=-1: path = relPath - file.fileLength = os.path.getsize(path) - file.fileOffset = sizeIndex - sizeIndex = sizeIndex + file.fileLength + 1 file.unk1 = 0 fileData = open(path,"rb") - data += fileData.read(file.fileLength) + compressedData = oead.yaz0.compress(fileData.read()) + padding = (0x20-(len(compressedData)%0x20)) + file.fileLength = len(compressedData) + file.fileOffset = sizeIndex + sizeIndex = sizeIndex + file.fileLength + padding + data += compressedData + data += bytearray(padding) fileData.close() dirs.append(file) @@ -255,13 +260,20 @@ def copyRelFiles(buildPath,aMemList,mMemList): if rel==file: relArcFound = True fullPath = Path(root+"/"+file) - print(str(fullPath)+" -> "+str(buildPath/"game/files/rel/Final/Release"/file)) - shutil.copy(fullPath,buildPath/"game/files/rel/Final/Release/") #We're copying uncompressed rels here, we should compress in the future! - if relArcFound==True: + if relArcFound==False: + print(str(fullPath)+" -> "+str(buildPath/"game/files/rel/Final/Release"/file)) + relSource = open(fullPath,"rb") + data = relSource.read() + relSource.close() + data = oead.yaz0.compress(data) + relNew = open(buildPath/"game/files/rel/Final/Release"/file,"wb") + relNew.write(data) + relNew.truncate() + relNew.close() + else: relArcPaths.append(fullPath) - #print(relArcPaths) - - #After writing this all I found out we don't actually need RELS.arc to load rels lol, keeping it here for the future in case we want to match RELS.arc + + arcHeader = HEADER() arcHeader.RARC = 0x52415243 @@ -269,7 +281,7 @@ def copyRelFiles(buildPath,aMemList,mMemList): arcHeader.unk1 = 0 arcHeader.unk2 = 0 infoBlock = INFO() - infoBlock.numNodes = 5 + infoBlock.numNodes = 3 infoBlock.numDirsThatAreFiles = 142 rootNode = NODE() rootNode.NAME = 0x524F4F54 @@ -287,12 +299,13 @@ def copyRelFiles(buildPath,aMemList,mMemList): mMemNode.numDirs = 59 mMemNode.firstDirIndex = 83 - stringTable = "\x2E\0\x2E\x2E\0rels\0amem\0" + stringTable = ".\0..\0rels\0amem\0" for rel in aMemList: stringTable = stringTable+rel+'\0' stringTable = stringTable+"mmem\0" for rel in mMemList: stringTable = stringTable+rel+'\0' + stringTable = stringTable+"\0\0\0\0\0\0" rootNode.stringTableOffset = stringTable.find("rels") aMemNode.stringTableOffset = stringTable.find("amem") @@ -346,6 +359,9 @@ def copyRelFiles(buildPath,aMemList,mMemList): sizeIndex = retSize dirs = retdirs data = retdata + dirs.append(unkDir) + dirs.append(unkDir2) + dirIndex = dirIndex+2 for rel in mMemList: retdirs,retdata,retSize = addFile(dirIndex,sizeIndex,dirs,rel,stringTable,relArcPaths,data) dirIndex = dirIndex+1 @@ -353,8 +369,28 @@ def copyRelFiles(buildPath,aMemList,mMemList): #print(hex(dirIndex)) dirs = retdirs data = retdata + unkDir3 = DIRECTORY() + unkDir3.dirIndex = 0xFFFF + unkDir3.stringHash = 0x2E + unkDir3.type = 0x200 + unkDir3.stringOffset = 0 + unkDir3.fileOffset = 2 + unkDir3.fileLength = 0x10 + unkDir3.unk1 = 0 - arcHeader.length = sizeIndex+len(stringTable)+0x20+0x20+0x30+(len(dirs)*0x14)+len(data) + unkDir4 = DIRECTORY() + unkDir4.dirIndex = 0xFFFF + unkDir4.stringHash = 0xB8 + unkDir4.type = 0x200 + unkDir4.stringOffset = 2 + unkDir4.fileOffset = 0 + unkDir4.fileLength = 0x10 + unkDir4.unk1 = 0 + dirs.append(unkDir3) + dirs.append(unkDir4) + dirIndex = dirIndex+2 + + arcHeader.length = len(stringTable)+0x20+0x20+0x30+(len(dirs)*0x14)+len(data) arcHeader.fileDataOffset=0x14E0 arcHeader.fileDataLen=len(data) arcHeader.fileDataLen2=arcHeader.fileDataLen @@ -365,13 +401,13 @@ def copyRelFiles(buildPath,aMemList,mMemList): infoBlock.stringTableOffset = 0xB80 infoBlock.unk1 = 0x100 infoBlock.unk2 = 0 - infoBlock.totalDirNum = len(dirs) + infoBlock.totalDirNum = 0x8E outputArcFile = open(buildPath/"game/files/RELS.arc","wb") outputArcFile.seek(0) - outputArcFile.write(struct.pack(">IIIIIIII",arcHeader.RARC,arcHeader.length,arcHeader.headerLength,arcHeader.fileDataOffset,arcHeader.fileDataLen,arcHeader.fileDataLen2,arcHeader.unk1,arcHeader.unk2)) + outputArcFile.write(struct.pack(">IIIIIIII",arcHeader.RARC,arcHeader.length,arcHeader.headerLength,arcHeader.fileDataOffset,arcHeader.fileDataLen,arcHeader.unk1,arcHeader.fileDataLen2,arcHeader.unk2)) outputArcFile.write(struct.pack(">IIIIIIHHI",infoBlock.numNodes,infoBlock.firstNodeOffset,infoBlock.totalDirNum,infoBlock.firstDirOffset,infoBlock.stringTableLen,infoBlock.stringTableOffset,infoBlock.numDirsThatAreFiles,infoBlock.unk1,infoBlock.unk2)) outputArcFile.write(struct.pack(">IIHHI",rootNode.NAME,rootNode.stringTableOffset,rootNode.hash,rootNode.numDirs,rootNode.firstDirIndex)) outputArcFile.write(struct.pack(">IIHHI",aMemNode.NAME,aMemNode.stringTableOffset,aMemNode.hash,aMemNode.numDirs,aMemNode.firstDirIndex)) @@ -379,12 +415,10 @@ def copyRelFiles(buildPath,aMemList,mMemList): outputArcFile.write(bytearray(16)) for dir in dirs: outputArcFile.write(struct.pack(">HHHHIII",dir.dirIndex,dir.stringHash,dir.type,dir.stringOffset,dir.fileOffset,dir.fileLength,dir.unk1)) - unkData = [0x8A ,0xCF ,0x7F ,0xA5 ,0x00 ,0x09 ,0x36 ,0x00 ,0x0D ,0x08 ,0xA0 ,0x00 ,0x00 ,0x0C ,0xD8 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x8B ,0x9B ,0xF7 ,0xA5 ,0x00 ,0x09 ,0x45 ,0x00 ,0x0D ,0x15 ,0x80 ,0x00 ,0x00 ,0x21 ,0xED ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0x00 ,0x2E ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0x00 ,0xB8 ,0x02 ,0x00 ,0x00 ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00] - outputArcFile.write(bytearray(unkData)) + outputArcFile.write(bytearray(8)) strBytearray = bytearray() strBytearray.extend(map(ord,stringTable)) outputArcFile.write(strBytearray) - outputArcFile.write(bytearray(6)) outputArcFile.write(data) outputArcFile.truncate() From db9079ede27d33ae24b8b706168318601d1f13df Mon Sep 17 00:00:00 2001 From: jdflyer Date: Sun, 16 Jan 2022 15:16:08 -0700 Subject: [PATCH 08/11] Shift Fixes --- Makefile | 2 +- asm/dolphin/os/OS/OSInit.s | 12 +- asm/dolphin/os/OSThread/__OSThreadInit.s | 8 +- asm/init/__init_registers.s | 12 +- libs/dolphin/os/OS.cpp | 3 + libs/dolphin/os/OSThread.cpp | 3 + src/DynamicLink.cpp | 6 +- src/init.cpp | 4 + tools/elf2dol/elf2dol.c | 878 +++++++++++------------ tools/requirements.txt | 3 +- 10 files changed, 450 insertions(+), 481 deletions(-) diff --git a/Makefile b/Makefile index b3a8a8bcc8..63fed2bb70 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ $(ELF): $(LIBS) $(O_FILES) @$(PYTHON) tools/lcf.py dol --output $(LDSCRIPT) $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) -$(ELF_SHIFT): $(LIBS) $(O_FILES) +$(ELF_SHIFT): $(DOL) @echo $(O_FILES) > build/o_files @$(PYTHON) tools/lcf.py dol_shift --output $(LDSCRIPT) $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) diff --git a/asm/dolphin/os/OS/OSInit.s b/asm/dolphin/os/OS/OSInit.s index 482078ac8e..c5ebfc66a6 100644 --- a/asm/dolphin/os/OS/OSInit.s +++ b/asm/dolphin/os/OS/OSInit.s @@ -71,8 +71,8 @@ lbl_8033A060: /* 8033A06C 80 63 00 30 */ lwz r3, 0x30(r3) /* 8033A070 28 03 00 00 */ cmplwi r3, 0 /* 8033A074 40 82 00 10 */ bne lbl_8033A084 -/* 8033A078 3C 60 80 46 */ lis r3, 0x8046 /* 0x80459BE0@ha */ -/* 8033A07C 38 63 9B E0 */ addi r3, r3, 0x9BE0 /* 0x80459BE0@l */ +/* 8033A078 3C 60 80 46 */ lis r3, _stack_end+0x3018@ha /* 0x80459BE0@ha */ +/* 8033A07C 38 63 9B E0 */ addi r3, r3, _stack_end+0x3018@l /* 0x80459BE0@l */ /* 8033A080 48 00 00 04 */ b lbl_8033A084 lbl_8033A084: /* 8033A084 48 00 12 21 */ bl OSSetArenaLo @@ -86,8 +86,8 @@ lbl_8033A084: /* 8033A0A4 80 03 00 00 */ lwz r0, 0(r3) /* 8033A0A8 28 00 00 02 */ cmplwi r0, 2 /* 8033A0AC 40 80 00 18 */ bge lbl_8033A0C4 -/* 8033A0B0 3C 60 80 45 */ lis r3, 0x8045 /* 0x80457BC8@ha */ -/* 8033A0B4 38 63 7B C8 */ addi r3, r3, 0x7BC8 /* 0x80457BC8@l */ +/* 8033A0B0 3C 60 80 45 */ lis r3, _stack_end+0x1000@ha /* 0x80457BC8@ha */ +/* 8033A0B4 38 63 7B C8 */ addi r3, r3, _stack_end+0x1000@l /* 0x80457BC8@l */ /* 8033A0B8 38 03 00 1F */ addi r0, r3, 0x1f /* 8033A0BC 54 03 00 34 */ rlwinm r3, r0, 0, 0, 0x1a /* 8033A0C0 48 00 11 E5 */ bl OSSetArenaLo @@ -96,8 +96,8 @@ lbl_8033A0C4: /* 8033A0C8 80 63 00 34 */ lwz r3, 0x34(r3) /* 8033A0CC 28 03 00 00 */ cmplwi r3, 0 /* 8033A0D0 40 82 00 10 */ bne lbl_8033A0E0 -/* 8033A0D4 3C 60 81 70 */ lis r3, 0x8170 /* 0x81700000@ha */ -/* 8033A0D8 38 63 00 00 */ addi r3, r3, 0x0000 /* 0x81700000@l */ +/* 8033A0D4 3C 60 81 70 */ lis r3, __ArenaHi@ha /* 0x81700000@ha */ +/* 8033A0D8 38 63 00 00 */ addi r3, r3, __ArenaHi@l /* 0x81700000@l */ /* 8033A0DC 48 00 00 04 */ b lbl_8033A0E0 lbl_8033A0E0: /* 8033A0E0 48 00 11 BD */ bl OSSetArenaHi diff --git a/asm/dolphin/os/OSThread/__OSThreadInit.s b/asm/dolphin/os/OSThread/__OSThreadInit.s index a71f328cda..538e9e5d8f 100644 --- a/asm/dolphin/os/OSThread/__OSThreadInit.s +++ b/asm/dolphin/os/OSThread/__OSThreadInit.s @@ -31,11 +31,11 @@ lbl_80340B1C: /* 80340B90 4B FF B4 71 */ bl OSClearContext /* 80340B94 7F E3 FB 78 */ mr r3, r31 /* 80340B98 4B FF B2 A1 */ bl OSSetCurrentContext -/* 80340B9C 3C 60 80 45 */ lis r3, 0x8045 /* 0x80457BC8@ha */ -/* 80340BA0 38 03 7B C8 */ addi r0, r3, 0x7BC8 /* 0x80457BC8@l */ -/* 80340BA4 3C 60 80 45 */ lis r3, 0x8045 /* 0x80456BC8@ha */ +/* 80340B9C 3C 60 80 45 */ lis r3, _stack_end+0x1000@ha /* 0x80457BC8@ha */ +/* 80340BA0 38 03 7B C8 */ addi r0, r3, _stack_end+0x1000@l /* 0x80457BC8@l */ +/* 80340BA4 3C 60 80 45 */ lis r3, _stack_end@ha /* 0x80456BC8@ha */ /* 80340BA8 90 1C 07 1C */ stw r0, 0x71c(r28) -/* 80340BAC 38 03 6B C8 */ addi r0, r3, 0x6BC8 /* 0x80456BC8@l */ +/* 80340BAC 38 03 6B C8 */ addi r0, r3, _stack_end@l /* 0x80456BC8@l */ /* 80340BB0 90 1C 07 20 */ stw r0, 0x720(r28) /* 80340BB4 3C 60 DE AE */ lis r3, 0xDEAE /* 0xDEADBABE@ha */ /* 80340BB8 38 03 BA BE */ addi r0, r3, 0xBABE /* 0xDEADBABE@l */ diff --git a/asm/init/__init_registers.s b/asm/init/__init_registers.s index 3b5461325c..638d815523 100644 --- a/asm/init/__init_registers.s +++ b/asm/init/__init_registers.s @@ -28,10 +28,10 @@ lbl_800032B0: /* 80003318 3B A0 00 00 */ li r29, 0 /* 8000331C 3B C0 00 00 */ li r30, 0 /* 80003320 3B E0 00 00 */ li r31, 0 -/* 80003324 3C 20 80 45 */ lis r1, 0x8045 /* 0x80457BC8@h */ -/* 80003328 60 21 7B C8 */ ori r1, r1, 0x7BC8 /* 0x80457BC8@l */ -/* 8000332C 3C 40 80 45 */ lis r2, 0x8045 /* 0x80459A00@h */ -/* 80003330 60 42 9A 00 */ ori r2, r2, 0x9A00 /* 0x80459A00@l */ -/* 80003334 3D A0 80 45 */ lis r13, 0x8045 /* 0x80458580@h */ -/* 80003338 61 AD 85 80 */ ori r13, r13, 0x8580 /* 0x80458580@l */ +/* 80003324 3C 20 80 45 */ lis r1, _stack_end+0x1000@h /* 0x80457BC8@h */ +/* 80003328 60 21 7B C8 */ ori r1, r1, _stack_end+0x1000@l /* 0x80457BC8@l */ +/* 8000332C 3C 40 80 45 */ lis r2, _SDA2_BASE_@h /* 0x80459A00@h */ +/* 80003330 60 42 9A 00 */ ori r2, r2, _SDA2_BASE_@l /* 0x80459A00@l */ +/* 80003334 3D A0 80 45 */ lis r13, _SDA_BASE_@h /* 0x80458580@h */ +/* 80003338 61 AD 85 80 */ ori r13, r13, _SDA_BASE_@l /* 0x80458580@l */ /* 8000333C 4E 80 00 20 */ blr diff --git a/libs/dolphin/os/OS.cpp b/libs/dolphin/os/OS.cpp index 51e546482c..f9272dcc78 100644 --- a/libs/dolphin/os/OS.cpp +++ b/libs/dolphin/os/OS.cpp @@ -497,6 +497,9 @@ u8 __OSStartTime[4]; extern u8 data_80451634[4]; u8 data_80451634[4]; +extern void* __ArenaHi; +extern void* _stack_end; + /* 80339F60-8033A440 3348A0 04E0+00 0/0 2/2 0/0 .text OSInit */ #pragma push #pragma optimization_level 0 diff --git a/libs/dolphin/os/OSThread.cpp b/libs/dolphin/os/OSThread.cpp index ed39bb20f3..19b72d3afa 100644 --- a/libs/dolphin/os/OSThread.cpp +++ b/libs/dolphin/os/OSThread.cpp @@ -119,6 +119,9 @@ static u8 RunQueueHint[4]; static u8 Reschedule[4 + 4 /* padding */]; /* 80340B1C-80340C74 33B45C 0158+00 0/0 1/1 0/0 .text __OSThreadInit */ + +extern void* _stack_end; + #pragma push #pragma optimization_level 0 #pragma optimizewithasm off diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 097227d06d..a4ae041f7e 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -342,19 +342,19 @@ bool DynamicModuleControl::do_load() { snprintf(buffer,64,"%s.rel",mName); if(mModule==NULL&&sArchive!=NULL) { if(mModule==NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x4D4D454D,buffer,sArchive); + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x4D4D454D/*MMEM*/,buffer,sArchive); if(mModule!=NULL) { mResourceType = 1; } } if(mModule==NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x414D454D,buffer,sArchive); + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x414D454D/*AMEM*/,buffer,sArchive); if(mModule!=NULL) { mResourceType = 2; } } if(mModule==NULL) { - mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x444D454D,buffer,sArchive); + mModule = (OSModuleInfo*)JKRArchive::getGlbResource(0x444D454D/*DMEM*/,buffer,sArchive); if(mModule!=NULL) { mResourceType = 3; } diff --git a/src/init.cpp b/src/init.cpp index f787ad2eea..121b6fa7f0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -102,6 +102,10 @@ SECTION_INIT asm void __start() { } #pragma pop +extern void* _stack_end; +extern void* _SDA2_BASE_; +extern void* _SDA_BASE_; + /* 800032B0-80003340 0001B0 0090+00 1/1 0/0 0/0 .init __init_registers */ #pragma push #pragma optimization_level 0 diff --git a/tools/elf2dol/elf2dol.c b/tools/elf2dol/elf2dol.c index aaa360ee2b..86320dafd5 100644 --- a/tools/elf2dol/elf2dol.c +++ b/tools/elf2dol/elf2dol.c @@ -1,98 +1,106 @@ -#include -#include -#include #include +#include +#include +#include #include #include #ifndef MAX //! Get the maximum of two values -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef MIN //! Get the minimum of two values -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -#define EI_NIDENT 16 +#define ARRAY_COUNT(arr) (sizeof(arr)/sizeof((arr)[0])) + +#define EI_NIDENT 16 typedef struct { - unsigned char e_ident[EI_NIDENT]; - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint32_t e_entry; - uint32_t e_phoff; - uint32_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; + unsigned char e_ident[EI_NIDENT]; + uint16_t e_type; + uint16_t e_machine; + uint32_t e_version; + uint32_t e_entry; + uint32_t e_phoff; + uint32_t e_shoff; + uint32_t e_flags; + uint16_t e_ehsize; + uint16_t e_phentsize; + uint16_t e_phnum; + uint16_t e_shentsize; + uint16_t e_shnum; + uint16_t e_shstrndx; } Elf32_Ehdr; -#define EI_CLASS 4 -#define EI_DATA 5 -#define EI_VERSION 6 -#define EI_PAD 7 -#define EI_NIDENT 16 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_PAD 7 +#define EI_NIDENT 16 -#define ELFCLASS32 1 -#define ELFDATA2MSB 2 -#define EV_CURRENT 1 +#define ELFCLASS32 1 +#define ELFDATA2MSB 2 +#define EV_CURRENT 1 -#define ET_EXEC 2 -#define EM_PPC 20 +#define ET_EXEC 2 +#define EM_PPC 20 typedef struct { - uint32_t p_type; - uint32_t p_offset; - uint32_t p_vaddr; - uint32_t p_paddr; - uint32_t p_filesz; - uint32_t p_memsz; - uint32_t p_flags; - uint32_t p_align; + uint32_t p_type; + uint32_t p_offset; + uint32_t p_vaddr; + uint32_t p_paddr; + uint32_t p_filesz; + uint32_t p_memsz; + uint32_t p_flags; + uint32_t p_align; } Elf32_Phdr; -#define PT_LOAD 1 -#define PF_R 4 -#define PF_W 2 -#define PF_X 1 +#define PT_LOAD 1 +#define PF_R 4 +#define PF_W 2 +#define PF_X 1 int verbosity = 0; #if BYTE_ORDER == BIG_ENDIAN #define swap32(x) (x) -#define swaf16(x) (x) +#define swap16(x) (x) #else -static inline uint32_t swap32(uint32_t v) { - return (v >> 24) | ((v >> 8) & 0x0000FF00) | ((v << 8) & 0x00FF0000) | (v << 24); +static inline uint32_t swap32(uint32_t v) +{ + return (v >> 24) | + ((v >> 8) & 0x0000FF00) | + ((v << 8) & 0x00FF0000) | + (v << 24); } -static inline uint16_t swaf16(uint16_t v) { - return (v >> 8) | (v << 8); +static inline uint16_t swap16(uint16_t v) +{ + return (v >> 8) | (v << 8); } #endif /* BIG_ENDIAN */ typedef struct { - uint32_t text_off[7]; - uint32_t data_off[11]; - uint32_t text_addr[7]; - uint32_t data_addr[11]; - uint32_t text_size[7]; - uint32_t data_size[11]; - uint32_t bss_addr; - uint32_t bss_size; - uint32_t entry; - uint32_t pad[7]; + + uint32_t text_off[7]; + uint32_t data_off[11]; + uint32_t text_addr[7]; + uint32_t data_addr[11]; + uint32_t text_size[7]; + uint32_t data_size[11]; + uint32_t bss_addr; + uint32_t bss_size; + uint32_t entry; + uint32_t pad[7]; } DOL_hdr; #define HAVE_BSS 1 @@ -105,435 +113,385 @@ typedef struct { #define DOL_ALIGN(x) (((x) + DOL_ALIGNMENT - 1) & ~(DOL_ALIGNMENT - 1)) typedef struct { - DOL_hdr header; - int text_cnt; - int data_cnt; - uint32_t text_elf_off[7]; - uint32_t text_elf_size[7]; - uint32_t data_elf_off[11]; - uint32_t data_elf_size[11]; - uint32_t flags; - FILE* elf; + DOL_hdr header; + int text_cnt; + int data_cnt; + uint32_t text_elf_off[7]; + uint32_t data_elf_off[11]; + uint32_t flags; + FILE *elf; } DOL_map; -// We need to track 2 PDHR sizes in the event this is for Wii, but for Gamecube -// we only need the first element(s). -uint32_t sdataSizes[2] = {0, 0}; -uint32_t sbssSizes[2] = {0, 0}; - -uint32_t skip_phdr[32] = { 0 }; - -void usage(const char* name) { - fprintf(stderr, "Usage: %s [-h] [-v] [-s phdr] [--] elf-file dol-file\n", name); - fprintf(stderr, " Convert an ELF file to a DOL file (by segments)\n"); - fprintf(stderr, " Options:\n"); - fprintf(stderr, " -h Show this help\n"); - fprintf(stderr, " -v Be more verbose (twice for even more)\n"); - fprintf(stderr, " -s Skip PHDR\n"); +void usage(const char *name) +{ + fprintf(stderr, "Usage: %s [-h] [-v] [--] elf-file dol-file\n", name); + fprintf(stderr, " Convert an ELF file to a DOL file (by segments)\n"); + fprintf(stderr, " Options:\n"); + fprintf(stderr, " -h Show this help\n"); + fprintf(stderr, " -v Be more verbose (twice for even more)\n"); } -#define die(x) \ - { \ - fprintf(stderr, x "\n"); \ - exit(1); \ - } -#define perrordie(x) \ - { \ - perror(x); \ - exit(1); \ - } +#define die(x) { fprintf(stderr, x "\n"); exit(1); } +#define perrordie(x) { perror(x); exit(1); } -void ferrordie(FILE* f, const char* str) { - if (ferror(f)) { - fprintf(stderr, "Error while "); - perrordie(str); - } else if (feof(f)) { - fprintf(stderr, "EOF while %s\n", str); - exit(1); - } else { - fprintf(stderr, "Unknown error while %s\n", str); - exit(1); - } +void ferrordie(FILE *f, const char *str) +{ + if(ferror(f)) { + fprintf(stderr, "Error while "); + perrordie(str); + } else if(feof(f)) { + fprintf(stderr, "EOF while %s\n", str); + exit(1); + } else { + fprintf(stderr, "Unknown error while %s\n", str); + exit(1); + } } -void add_bss(DOL_map* map, uint32_t paddr, uint32_t memsz) { - if (map->flags & HAVE_BSS) { - uint32_t start = swap32(map->header.bss_addr); - uint32_t size = swap32(map->header.bss_size); - uint32_t addr = (start + size); - if (addr == paddr) { - map->header.bss_size = swap32(size + memsz); - } - } else { - map->header.bss_addr = swap32(paddr); - map->header.bss_size = swap32(memsz); - map->flags |= HAVE_BSS; - } +void add_bss(DOL_map *map, uint32_t paddr, uint32_t memsz) +{ + if(map->flags & HAVE_BSS) { + uint32_t curr_start = swap32(map->header.bss_addr); + uint32_t curr_size = swap32(map->header.bss_size); + if (paddr < curr_start) + map->header.bss_addr = swap32(paddr); + // Total BSS size should be the end of the last bss section minus the + // start of the first bss section. + if (paddr + memsz > curr_start + curr_size) + map->header.bss_size = swap32(paddr + memsz - curr_start); + } else { + map->header.bss_addr = swap32(paddr); + map->header.bss_size = swap32(memsz); + map->flags |= HAVE_BSS; + } } -void increment_bss_size(DOL_map* map, uint32_t memsz) { - // because it can be byte swapped, we need to force the add via a temporary. - uint32_t preAdd = swap32(map->header.bss_size); - preAdd += memsz; - map->header.bss_size = swap32(preAdd); +void read_elf_segments(DOL_map *map, const char *elf) +{ + int read, i; + Elf32_Ehdr ehdr; + + if(verbosity >= 2) + fprintf(stderr, "Reading ELF file...\n"); + + map->elf = fopen(elf, "rb"); + if(!map->elf) + perrordie("Could not open ELF file"); + + read = fread(&ehdr, sizeof(ehdr), 1, map->elf); + if(read != 1) + ferrordie(map->elf, "reading ELF header"); + + if(memcmp(&ehdr.e_ident[0], "\177ELF", 4)) + die("Invalid ELF header"); + if(ehdr.e_ident[EI_CLASS] != ELFCLASS32) + die("Invalid ELF class"); + if(ehdr.e_ident[EI_DATA] != ELFDATA2MSB) + die("Invalid ELF byte order"); + if(ehdr.e_ident[EI_VERSION] != EV_CURRENT) + die("Invalid ELF ident version"); + if(swap32(ehdr.e_version) != EV_CURRENT) + die("Invalid ELF version"); + if(swap16(ehdr.e_type) != ET_EXEC) + die("ELF is not an executable"); + if(swap16(ehdr.e_machine) != EM_PPC) + die("Machine is not PowerPC"); + if(!swap32(ehdr.e_entry)) + die("ELF has no entrypoint"); + + map->header.entry = ehdr.e_entry; + + if(verbosity >= 2) + fprintf(stderr, "Valid ELF header found\n"); + + uint16_t phnum = swap16(ehdr.e_phnum); + uint32_t phoff = swap32(ehdr.e_phoff); + Elf32_Phdr *phdrs; + + if(!phnum || !phoff) + die("ELF has no program headers"); + + if(swap16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) + die("Invalid program header entry size"); + + phdrs = malloc(phnum * sizeof(Elf32_Phdr)); + + if(fseek(map->elf, phoff, SEEK_SET) < 0) + ferrordie(map->elf, "reading ELF program headers"); + read = fread(phdrs, sizeof(Elf32_Phdr), phnum, map->elf); + if(read != phnum) + ferrordie(map->elf, "reading ELF program headers"); + + for(i=0; i= 2) + fprintf(stderr, "PHDR %d: 0x%x [0x%x] -> 0x%08x [0x%x] flags 0x%x\n", + i, offset, filesz, paddr, memsz, flags); + if(flags & PF_X) { + // TEXT segment + if(!(flags & PF_R)) + fprintf(stderr, "Warning: non-readable segment %d\n", i); + if(flags & PF_W) + fprintf(stderr, "Warning: writable and executable segment %d\n", i); + if(filesz > memsz) { + fprintf(stderr, "Error: TEXT segment %d memory size (0x%x) smaller than file size (0x%x)\n", + i, memsz, filesz); + exit(1); + } else if (memsz > filesz) { + add_bss(map, paddr + filesz, memsz - filesz); + } + if(map->text_cnt >= MAX_TEXT_SEGMENTS) { + die("Error: Too many TEXT segments"); + } + map->header.text_addr[map->text_cnt] = swap32(paddr); + map->header.text_size[map->text_cnt] = swap32(filesz); + map->text_elf_off[map->text_cnt] = offset; + map->text_cnt++; + } else { + // DATA or BSS segment + if(!(flags & PF_R)) + fprintf(stderr, "Warning: non-readable segment %d\n", i); + if(filesz == 0) { + // BSS segment + add_bss(map, paddr, memsz); + } else { + // DATA segment + if(filesz > memsz) { + fprintf(stderr, "Error: segment %d memory size (0x%x) is smaller than file size (0x%x)\n", + i, memsz, filesz); + exit(1); + } + if(map->data_cnt >= MAX_DATA_SEGMENTS) { + die("Error: Too many DATA segments"); + } + map->header.data_addr[map->data_cnt] = swap32(paddr); + map->header.data_size[map->data_cnt] = swap32(filesz); + map->data_elf_off[map->data_cnt] = offset; + map->data_cnt++; + } + } + + } else { + if(verbosity >= 1) + fprintf(stderr, "Skipping empty program header %d\n", i); + } + } else if(verbosity >= 1) { + fprintf(stderr, "Skipping program header %d of type %d\n", i, swap32(phdrs[i].p_type)); + } + } + if(verbosity >= 2) { + fprintf(stderr, "Segments:\n"); + for(i=0; itext_cnt; i++) { + fprintf(stderr, " TEXT %d: 0x%08x [0x%x] from ELF offset 0x%x\n", + i, swap32(map->header.text_addr[i]), swap32(map->header.text_size[i]), + map->text_elf_off[i]); + } + for(i=0; idata_cnt; i++) { + fprintf(stderr, " DATA %d: 0x%08x [0x%x] from ELF offset 0x%x\n", + i, swap32(map->header.data_addr[i]), swap32(map->header.data_size[i]), + map->data_elf_off[i]); + } + if(map->flags & HAVE_BSS) + fprintf(stderr, " BSS segment: 0x%08x [0x%x]\n", swap32(map->header.bss_addr), + swap32(map->header.bss_size)); + } } -void align_bss_size(DOL_map* map) { - map->header.bss_size = swap32(DOL_ALIGN(swap32(map->header.bss_size))); +void map_dol(DOL_map *map) +{ + uint32_t fpos; + int i; + + if(verbosity >= 2) + fprintf(stderr, "Laying out DOL file...\n"); + + fpos = DOL_ALIGN(sizeof(DOL_hdr)); + + for(i=0; itext_cnt; i++) { + if(verbosity >= 2) + fprintf(stderr, " TEXT segment %d at 0x%x\n", i, fpos); + map->header.text_off[i] = swap32(fpos); + fpos = DOL_ALIGN(fpos + swap32(map->header.text_size[i])); + } + for(i=0; idata_cnt; i++) { + if(verbosity >= 2) + fprintf(stderr, " DATA segment %d at 0x%x\n", i, fpos); + map->header.data_off[i] = swap32(fpos); + fpos = DOL_ALIGN(fpos + swap32(map->header.data_size[i])); + } + + if(map->text_cnt == 0) { + if(verbosity >= 1) + fprintf(stderr, "Note: adding dummy TEXT segment to work around IOS bug\n"); + map->header.text_off[0] = swap32(DOL_ALIGN(sizeof(DOL_hdr))); + } + if(map->data_cnt == 0) { + if(verbosity >= 1) + fprintf(stderr, "Note: adding dummy DATA segment to work around IOS bug\n"); + map->header.data_off[0] = swap32(DOL_ALIGN(sizeof(DOL_hdr))); + } } -void read_elf_segments(DOL_map* map, const char* elf, uint32_t sdata_pdhr, uint32_t sbss_pdhr, - const char* platform) { - int read, i; - Elf32_Ehdr ehdr; - int isWii = !(strcmp(platform, "wii")) ? 1 : 0; +#define BLOCK (1024*1024) - if (verbosity >= 2) - fprintf(stderr, "Reading ELF file...\n"); +void fcpy(FILE *dst, FILE *src, uint32_t dst_off, uint32_t src_off, uint32_t size) +{ + int left = size; + int read; + int written; + int block; + void *blockbuf; - map->elf = fopen(elf, "rb"); - if (!map->elf) - perrordie("Could not open ELF file"); - - read = fread(&ehdr, sizeof(ehdr), 1, map->elf); - if (read != 1) - ferrordie(map->elf, "reading ELF header"); - - if (memcmp(&ehdr.e_ident[0], "\177ELF", 4)) - die("Invalid ELF header"); - if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) - die("Invalid ELF class"); - if (ehdr.e_ident[EI_DATA] != ELFDATA2MSB) - die("Invalid ELF byte order"); - if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) - die("Invalid ELF ident version"); - if (swap32(ehdr.e_version) != EV_CURRENT) - die("Invalid ELF version"); - if (swaf16(ehdr.e_type) != ET_EXEC) - die("ELF is not an executable"); - if (swaf16(ehdr.e_machine) != EM_PPC) - die("Machine is not PowerPC"); - if (!swap32(ehdr.e_entry)) - die("ELF has no entrypoint"); - - map->header.entry = ehdr.e_entry; - - if (verbosity >= 2) - fprintf(stderr, "Valid ELF header found\n"); - - uint16_t phnum = swaf16(ehdr.e_phnum); - uint32_t phoff = swap32(ehdr.e_phoff); - Elf32_Phdr* phdrs; - - if (!phnum || !phoff) - die("ELF has no program headers"); - - if (swaf16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) - die("Invalid program header entry size"); - - phdrs = malloc(phnum * sizeof(Elf32_Phdr)); - - if (fseek(map->elf, phoff, SEEK_SET) < 0) - ferrordie(map->elf, "reading ELF program headers"); - read = fread(phdrs, sizeof(Elf32_Phdr), phnum, map->elf); - if (read != phnum) - ferrordie(map->elf, "reading ELF program headers"); - - for (i = 0; i < phnum; i++) { - if(skip_phdr[i]) { - if(verbosity >= 1) - fprintf(stderr, "Skipping program header %d because -s\n", i); - continue; - } - - if (swap32(phdrs[i].p_type) == PT_LOAD) { - uint32_t offset = swap32(phdrs[i].p_offset); - uint32_t paddr = swap32(phdrs[i].p_vaddr); - uint32_t filesz = swap32(phdrs[i].p_filesz); - uint32_t memsz = swap32(phdrs[i].p_memsz); - uint32_t flags = swap32(phdrs[i].p_flags); - if (memsz) { - if (verbosity >= 2) - fprintf(stderr, "PHDR %d: 0x%x [0x%x] -> 0x%08x [0x%x] flags 0x%x\n", i, offset, - filesz, paddr, memsz, flags); - if (flags & PF_X) { - // TEXT segment - if (!(flags & PF_R)) - fprintf(stderr, "Warning: non-readable segment %d\n", i); - if (flags & PF_W) - fprintf(stderr, "Warning: writable and executable segment %d\n", i); - if (filesz > memsz) { - fprintf(stderr, - "Error: TEXT segment %d memory size (0x%x) smaller than file size " - "(0x%x)\n", - i, memsz, filesz); - exit(1); - } else if (memsz > filesz) { - add_bss(map, paddr + filesz, memsz - filesz); - } - if (map->text_cnt >= MAX_TEXT_SEGMENTS) { - die("Error: Too many TEXT segments"); - } - map->header.text_addr[map->text_cnt] = swap32(paddr); - map->header.text_size[map->text_cnt] = swap32(DOL_ALIGN(filesz)); - map->text_elf_off[map->text_cnt] = offset; - map->text_elf_size[map->text_cnt] = filesz; - map->text_cnt++; - } else { - // DATA or BSS segment - if (!(flags & PF_R)) - fprintf(stderr, "Warning: non-readable segment %d\n", i); - if (filesz == 0) { - // BSS segment - add_bss(map, paddr, memsz); - - // We need to keep PHDF sizes, so track these. - if (i == sbss_pdhr) { - sbssSizes[0] = memsz; - } else if (isWii && i == sbss_pdhr + 2) { - sbssSizes[1] = memsz; - } - } else { - // DATA segment - if (filesz > memsz) { - fprintf(stderr, - "Error: segment %d memory size (0x%x) is smaller than file " - "size (0x%x)\n", - i, memsz, filesz); - exit(1); - } - if (map->data_cnt >= MAX_DATA_SEGMENTS) { - die("Error: Too many DATA segments"); - } - // Track sdata as well. - if (i == sdata_pdhr) { - sdataSizes[0] = memsz; - } else if (isWii && i == sdata_pdhr + 2) { - sdataSizes[1] = memsz; - } - - map->header.data_addr[map->data_cnt] = swap32(paddr); - map->header.data_size[map->data_cnt] = swap32(DOL_ALIGN(filesz)); - map->data_elf_off[map->data_cnt] = offset; - map->data_elf_size[map->data_cnt] = filesz; - map->data_cnt++; - } - } - - } else { - if (verbosity >= 1) - fprintf(stderr, "Skipping empty program header %d\n", i); - } - } else if (verbosity >= 1) { - fprintf(stderr, "Skipping program header %d of type %d\n", i, swap32(phdrs[i].p_type)); - } - } - align_bss_size(map); - increment_bss_size(map, sdataSizes[0]); - align_bss_size(map); - increment_bss_size(map, sdataSizes[1]); - align_bss_size(map); - increment_bss_size(map, sbssSizes[0]); - align_bss_size(map); - // .sbss2 is added without aligning the size - increment_bss_size(map, sbssSizes[1]); - if (verbosity >= 2) { - fprintf(stderr, "Segments:\n"); - for (i = 0; i < map->text_cnt; i++) { - fprintf(stderr, " TEXT %d: 0x%08x [0x%x] from ELF offset 0x%x\n", i, - swap32(map->header.text_addr[i]), swap32(map->header.text_size[i]), - map->text_elf_off[i]); - } - for (i = 0; i < map->data_cnt; i++) { - fprintf(stderr, " DATA %d: 0x%08x [0x%x] from ELF offset 0x%x\n", i, - swap32(map->header.data_addr[i]), swap32(map->header.data_size[i]), - map->data_elf_off[i]); - } - if (map->flags & HAVE_BSS) - fprintf(stderr, " BSS segment: 0x%08x [0x%x]\n", swap32(map->header.bss_addr), - swap32(map->header.bss_size)); - } + if(fseek(src, src_off, SEEK_SET) < 0) + ferrordie(src, "reading ELF segment data"); + if(fseek(dst, dst_off, SEEK_SET) < 0) + ferrordie(dst, "writing DOL segment data"); + + blockbuf = malloc(MIN(BLOCK, left)); + + while(left) { + block = MIN(BLOCK, left); + read = fread(blockbuf, 1, block, src); + if(read != block) { + free(blockbuf); + ferrordie(src, "reading ELF segment data"); + } + written = fwrite(blockbuf, 1, block, dst); + if(written != block) { + free(blockbuf); + ferrordie(dst, "writing DOL segment data"); + } + left -= block; + } + free(blockbuf); } -void map_dol(DOL_map* map) { - uint32_t fpos; - int i; +void fpad(FILE *dst, uint32_t dst_off, uint32_t size) +{ + uint32_t i; - if (verbosity >= 2) - fprintf(stderr, "Laying out DOL file...\n"); - - fpos = DOL_ALIGN(sizeof(DOL_hdr)); - - for (i = 0; i < map->text_cnt; i++) { - if (verbosity >= 2) - fprintf(stderr, " TEXT segment %d at 0x%x\n", i, fpos); - map->header.text_off[i] = swap32(fpos); - fpos = DOL_ALIGN(fpos + swap32(map->header.text_size[i])); - } - for (i = 0; i < map->data_cnt; i++) { - if (verbosity >= 2) - fprintf(stderr, " DATA segment %d at 0x%x\n", i, fpos); - map->header.data_off[i] = swap32(fpos); - fpos = DOL_ALIGN(fpos + swap32(map->header.data_size[i])); - } - - if (map->text_cnt == 0) { - if (verbosity >= 1) - fprintf(stderr, "Note: adding dummy TEXT segment to work around IOS bug\n"); - map->header.text_off[0] = swap32(DOL_ALIGN(sizeof(DOL_hdr))); - } - if (map->data_cnt == 0) { - if (verbosity >= 1) - fprintf(stderr, "Note: adding dummy DATA segment to work around IOS bug\n"); - map->header.data_off[0] = swap32(DOL_ALIGN(sizeof(DOL_hdr))); - } + if(fseek(dst, dst_off, SEEK_SET) < 0) + ferrordie(dst, "writing DOL segment data"); + for(i=0; i= 2) + fprintf(stderr, "Writing DOL file...\n"); + + dolf = fopen(dol, "wb"); + if(!dolf) + perrordie("Could not open DOL file"); + + if(verbosity >= 2) { + fprintf(stderr, "DOL header:\n"); + for(i=0; itext_cnt); i++) + fprintf(stderr, " TEXT %d @ 0x%08x [0x%x] off 0x%x\n", i, + swap32(map->header.text_addr[i]), swap32(map->header.text_size[i]), + swap32(map->header.text_off[i])); + for(i=0; idata_cnt); i++) + fprintf(stderr, " DATA %d @ 0x%08x [0x%x] off 0x%x\n", i, + swap32(map->header.data_addr[i]), swap32(map->header.data_size[i]), + swap32(map->header.data_off[i])); + if(swap32(map->header.bss_addr) && swap32(map->header.bss_size)) + fprintf(stderr, " BSS @ 0x%08x [0x%x]\n", swap32(map->header.bss_addr), + swap32(map->header.bss_size)); + fprintf(stderr, " Entry: 0x%08x\n", swap32(map->header.entry)); + fprintf(stderr, "Writing DOL header...\n"); + } + + // Write DOL header with aligned text and data section sizes + DOL_hdr aligned_header = map->header; + for(i=0; itext_cnt; i++) { + uint32_t size = swap32(map->header.text_size[i]); + uint32_t padded_size = DOL_ALIGN(size); + if(verbosity >= 2) + fprintf(stderr, "Writing TEXT segment %d...\n", i); + fcpy(dolf, map->elf, swap32(map->header.text_off[i]), map->text_elf_off[i], size); + if (padded_size > size) + fpad(dolf, swap32(map->header.text_off[i]) + size, padded_size - size); + } + for(i=0; idata_cnt; i++) { + uint32_t size = swap32(map->header.data_size[i]); + uint32_t padded_size = DOL_ALIGN(size); + if(verbosity >= 2) + fprintf(stderr, "Writing DATA segment %d...\n", i); + fcpy(dolf, map->elf, swap32(map->header.data_off[i]), map->data_elf_off[i], size); + if (padded_size > size) + fpad(dolf, swap32(map->header.data_off[i]) + size, padded_size - size); + } + + if(verbosity >= 2) + fprintf(stderr, "All done!\n"); + + fclose(map->elf); + fclose(dolf); } -void write_dol(DOL_map* map, const char* dol) { - FILE* dolf; - int written; - int i; +int main(int argc, char **argv) +{ + char **arg; - if (verbosity >= 2) - fprintf(stderr, "Writing DOL file...\n"); + if(argc < 2) { + usage(argv[0]); + return 1; + } + arg = &argv[1]; + argc--; - dolf = fopen(dol, "wb"); - if (!dolf) - perrordie("Could not open DOL file"); + while(argc && *arg[0] == '-') { + if(!strcmp(*arg, "-h")) { + usage(argv[0]); + return 1; + } else if(!strcmp(*arg, "-v")) { + verbosity++; + } else if(!strcmp(*arg, "--")) { + arg++; + argc--; + break; + } else { + fprintf(stderr, "Unrecognized option %s\n", *arg); + usage(argv[0]); + return 1; + } + arg++; + argc--; + } + if(argc < 2) { + usage(argv[0]); + exit(1); + } - if (verbosity >= 2) { - fprintf(stderr, "DOL header:\n"); - for (i = 0; i < MAX(1, map->text_cnt); i++) - fprintf(stderr, " TEXT %d @ 0x%08x [0x%06x] off 0x%08x\n", i, - swap32(map->header.text_addr[i]), swap32(map->header.text_size[i]), - swap32(map->header.text_off[i])); - for (i = 0; i < MAX(1, map->data_cnt); i++) - fprintf(stderr, " DATA %d @ 0x%08x [0x%06x] off 0x%08x\n", i, - swap32(map->header.data_addr[i]), swap32(map->header.data_size[i]), - swap32(map->header.data_off[i])); - if (swap32(map->header.bss_addr) && swap32(map->header.bss_size)) - fprintf(stderr, " BSS @ 0x%08x [0x%06x]\n", swap32(map->header.bss_addr), - swap32(map->header.bss_size)); - fprintf(stderr, " Entry: 0x%08x\n", swap32(map->header.entry)); - fprintf(stderr, "Writing DOL header...\n"); - } + const char *elf_file = arg[0]; + const char *dol_file = arg[1]; - written = fwrite(&map->header, sizeof(DOL_hdr), 1, dolf); - if (written != 1) - ferrordie(dolf, "writing DOL header"); + DOL_map map; - for (i = 0; i < map->text_cnt; i++) { - if (verbosity >= 2) - fprintf(stderr, "Writing TEXT segment %d...\n", i); - fcpy(dolf, map->elf, swap32(map->header.text_off[i]), map->text_elf_off[i], - swap32(map->header.text_size[i]), map->text_elf_size[i]); - } - for (i = 0; i < map->data_cnt; i++) { - if (verbosity >= 2) - fprintf(stderr, "Writing DATA segment %d...\n", i); - fcpy(dolf, map->elf, swap32(map->header.data_off[i]), map->data_elf_off[i], - swap32(map->header.data_size[i]), map->data_elf_size[i]); - } + memset(&map, 0, sizeof(map)); - if (verbosity >= 2) - fprintf(stderr, "All done!\n"); - - fclose(map->elf); - fclose(dolf); -} - -int main(int argc, char** argv) { - char** arg; - - if (argc < 2) { - usage(argv[0]); - return 1; - } - arg = &argv[1]; - argc--; - - while (argc && *arg[0] == '-') { - if (!strcmp(*arg, "-h")) { - usage(argv[0]); - return 1; - } else if (!strcmp(*arg, "-v")) { - verbosity++; - } else if (!strcmp(*arg, "-s")) { - arg++; - argc--; - skip_phdr[atoi(arg[0])] = 1; - } else if (!strcmp(*arg, "--")) { - arg++; - argc--; - break; - } else { - fprintf(stderr, "Unrecognized option %s\n", *arg); - usage(argv[0]); - return 1; - } - arg++; - argc--; - } - if (argc < 2) { - usage(argv[0]); - exit(1); - } - - const char* elf_file = arg[0]; - const char* dol_file = arg[1]; - uint32_t sdata_pdhr = atoi(arg[2]); - uint32_t sbss_pdhr = atoi(arg[3]); - const char* platform = arg[4]; - - DOL_map map; - - memset(&map, 0, sizeof(map)); - - read_elf_segments(&map, elf_file, sdata_pdhr, sbss_pdhr, platform); - map_dol(&map); - write_dol(&map, dol_file); - - return 0; -} + read_elf_segments(&map, elf_file); + map_dol(&map); + write_dol(&map, dol_file); + + return 0; +} \ No newline at end of file diff --git a/tools/requirements.txt b/tools/requirements.txt index 8becbe26de..bcc34c4116 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -7,4 +7,5 @@ colorama ansiwrap watchdog python-Levenshtein -cxxfilt \ No newline at end of file +cxxfilt +oead \ No newline at end of file From 641b04d4709a25a847e1782101063f62b1425e4f Mon Sep 17 00:00:00 2001 From: jdflyer Date: Sun, 16 Jan 2022 15:18:29 -0700 Subject: [PATCH 09/11] Removed Unused asm --- asm/DynamicLink/ModuleConstructorsX.s | 20 ------- asm/DynamicLink/ModuleDestructorsX.s | 20 ------- asm/DynamicLink/ModuleUnresolved.s | 51 ---------------- .../__ct__20DynamicModuleControlFPCc.s | 29 ---------- .../__ct__24DynamicModuleControlBaseFv.s | 22 ------- .../__dt__24DynamicModuleControlBaseFv.s | 52 ----------------- asm/DynamicLink/calcSum2__FPCUsUl.s | 13 ----- .../callback__20DynamicModuleControlFPv.s | 12 ---- .../do_load_async__20DynamicModuleControlFv.s | 56 ------------------ .../do_unlink__20DynamicModuleControlFv.s | 58 ------------------- .../do_unload__20DynamicModuleControlFv.s | 20 ------- .../dump2__20DynamicModuleControlFv.s | 22 ------- ...rce_unlink__24DynamicModuleControlBaseFv.s | 19 ------ ...getModuleName__20DynamicModuleControlCFv.s | 3 - ...getModuleSize__20DynamicModuleControlCFv.s | 32 ---------- ...uleTypeString__20DynamicModuleControlCFv.s | 7 --- ...ypeString__24DynamicModuleControlBaseCFv.s | 5 -- .../initialize__20DynamicModuleControlFv.s | 15 ----- .../link__24DynamicModuleControlBaseFv.s | 42 -------------- ...load_async__24DynamicModuleControlBaseFv.s | 19 ------ ...mountCallback__20DynamicModuleControlFPv.s | 37 ------------ .../unlink__24DynamicModuleControlBaseFv.s | 37 ------------ ...FP18JPAEmitterWorkDataP15JPABaseParticle.s | 18 ------ 23 files changed, 609 deletions(-) delete mode 100644 asm/DynamicLink/ModuleConstructorsX.s delete mode 100644 asm/DynamicLink/ModuleDestructorsX.s delete mode 100644 asm/DynamicLink/ModuleUnresolved.s delete mode 100644 asm/DynamicLink/__ct__20DynamicModuleControlFPCc.s delete mode 100644 asm/DynamicLink/__ct__24DynamicModuleControlBaseFv.s delete mode 100644 asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s delete mode 100644 asm/DynamicLink/calcSum2__FPCUsUl.s delete mode 100644 asm/DynamicLink/callback__20DynamicModuleControlFPv.s delete mode 100644 asm/DynamicLink/do_load_async__20DynamicModuleControlFv.s delete mode 100644 asm/DynamicLink/do_unlink__20DynamicModuleControlFv.s delete mode 100644 asm/DynamicLink/do_unload__20DynamicModuleControlFv.s delete mode 100644 asm/DynamicLink/dump2__20DynamicModuleControlFv.s delete mode 100644 asm/DynamicLink/force_unlink__24DynamicModuleControlBaseFv.s delete mode 100644 asm/DynamicLink/getModuleName__20DynamicModuleControlCFv.s delete mode 100644 asm/DynamicLink/getModuleSize__20DynamicModuleControlCFv.s delete mode 100644 asm/DynamicLink/getModuleTypeString__20DynamicModuleControlCFv.s delete mode 100644 asm/DynamicLink/getModuleTypeString__24DynamicModuleControlBaseCFv.s delete mode 100644 asm/DynamicLink/initialize__20DynamicModuleControlFv.s delete mode 100644 asm/DynamicLink/link__24DynamicModuleControlBaseFv.s delete mode 100644 asm/DynamicLink/load_async__24DynamicModuleControlBaseFv.s delete mode 100644 asm/DynamicLink/mountCallback__20DynamicModuleControlFPv.s delete mode 100644 asm/DynamicLink/unlink__24DynamicModuleControlBaseFv.s delete mode 100644 asm/JSystem/JParticle/JPABaseShape/JPADrawParticleCallBack__FP18JPAEmitterWorkDataP15JPABaseParticle.s diff --git a/asm/DynamicLink/ModuleConstructorsX.s b/asm/DynamicLink/ModuleConstructorsX.s deleted file mode 100644 index b92346f54b..0000000000 --- a/asm/DynamicLink/ModuleConstructorsX.s +++ /dev/null @@ -1,20 +0,0 @@ -lbl_8026314C: -/* 8026314C 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80263150 7C 08 02 A6 */ mflr r0 -/* 80263154 90 01 00 14 */ stw r0, 0x14(r1) -/* 80263158 93 E1 00 0C */ stw r31, 0xc(r1) -/* 8026315C 7C 7F 1B 78 */ mr r31, r3 -/* 80263160 48 00 00 10 */ b lbl_80263170 -lbl_80263164: -/* 80263164 7D 89 03 A6 */ mtctr r12 -/* 80263168 4E 80 04 21 */ bctrl -/* 8026316C 3B FF 00 04 */ addi r31, r31, 4 -lbl_80263170: -/* 80263170 81 9F 00 00 */ lwz r12, 0(r31) -/* 80263174 28 0C 00 00 */ cmplwi r12, 0 -/* 80263178 40 82 FF EC */ bne lbl_80263164 -/* 8026317C 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80263180 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80263184 7C 08 03 A6 */ mtlr r0 -/* 80263188 38 21 00 10 */ addi r1, r1, 0x10 -/* 8026318C 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/ModuleDestructorsX.s b/asm/DynamicLink/ModuleDestructorsX.s deleted file mode 100644 index a348f8ef81..0000000000 --- a/asm/DynamicLink/ModuleDestructorsX.s +++ /dev/null @@ -1,20 +0,0 @@ -lbl_80263190: -/* 80263190 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80263194 7C 08 02 A6 */ mflr r0 -/* 80263198 90 01 00 14 */ stw r0, 0x14(r1) -/* 8026319C 93 E1 00 0C */ stw r31, 0xc(r1) -/* 802631A0 7C 7F 1B 78 */ mr r31, r3 -/* 802631A4 48 00 00 10 */ b lbl_802631B4 -lbl_802631A8: -/* 802631A8 7D 89 03 A6 */ mtctr r12 -/* 802631AC 4E 80 04 21 */ bctrl -/* 802631B0 3B FF 00 04 */ addi r31, r31, 4 -lbl_802631B4: -/* 802631B4 81 9F 00 00 */ lwz r12, 0(r31) -/* 802631B8 28 0C 00 00 */ cmplwi r12, 0 -/* 802631BC 40 82 FF EC */ bne lbl_802631A8 -/* 802631C0 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 802631C4 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802631C8 7C 08 03 A6 */ mtlr r0 -/* 802631CC 38 21 00 10 */ addi r1, r1, 0x10 -/* 802631D0 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/ModuleUnresolved.s b/asm/DynamicLink/ModuleUnresolved.s deleted file mode 100644 index 3cdabb7079..0000000000 --- a/asm/DynamicLink/ModuleUnresolved.s +++ /dev/null @@ -1,51 +0,0 @@ -lbl_80263090: -/* 80263090 94 21 FF E0 */ stwu r1, -0x20(r1) -/* 80263094 7C 08 02 A6 */ mflr r0 -/* 80263098 90 01 00 24 */ stw r0, 0x24(r1) -/* 8026309C 39 61 00 20 */ addi r11, r1, 0x20 -/* 802630A0 48 0F F1 3D */ bl _savegpr_29 -/* 802630A4 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 802630A8 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 802630AC 38 63 02 D0 */ addi r3, r3, 0x2d0 -/* 802630B0 4C C6 31 82 */ crclr 6 -/* 802630B4 4B DA 3B 59 */ bl OSReport_Error -/* 802630B8 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 802630BC 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 802630C0 38 63 03 03 */ addi r3, r3, 0x303 -/* 802630C4 4C C6 31 82 */ crclr 6 -/* 802630C8 4B DA 3B 45 */ bl OSReport_Error -/* 802630CC 3B C0 00 00 */ li r30, 0 -/* 802630D0 48 0D 8F 29 */ bl OSGetStackPointer -/* 802630D4 7C 7D 1B 78 */ mr r29, r3 -/* 802630D8 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 802630DC 3B E3 A4 A0 */ addi r31, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 802630E0 48 00 00 20 */ b lbl_80263100 -lbl_802630E4: -/* 802630E4 38 7F 03 28 */ addi r3, r31, 0x328 -/* 802630E8 7F A4 EB 78 */ mr r4, r29 -/* 802630EC 80 BD 00 00 */ lwz r5, 0(r29) -/* 802630F0 80 DD 00 04 */ lwz r6, 4(r29) -/* 802630F4 4C C6 31 82 */ crclr 6 -/* 802630F8 4B DA 3B 15 */ bl OSReport_Error -/* 802630FC 83 BD 00 00 */ lwz r29, 0(r29) -lbl_80263100: -/* 80263100 28 1D 00 00 */ cmplwi r29, 0 -/* 80263104 41 82 00 1C */ beq lbl_80263120 -/* 80263108 3C 1D 00 01 */ addis r0, r29, 1 -/* 8026310C 28 00 FF FF */ cmplwi r0, 0xffff -/* 80263110 41 82 00 10 */ beq lbl_80263120 -/* 80263114 28 1E 00 10 */ cmplwi r30, 0x10 -/* 80263118 3B DE 00 01 */ addi r30, r30, 1 -/* 8026311C 41 80 FF C8 */ blt lbl_802630E4 -lbl_80263120: -/* 80263120 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80263124 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80263128 38 63 00 C2 */ addi r3, r3, 0xc2 -/* 8026312C 4C C6 31 82 */ crclr 6 -/* 80263130 4B DA 3A DD */ bl OSReport_Error -/* 80263134 39 61 00 20 */ addi r11, r1, 0x20 -/* 80263138 48 0F F0 F1 */ bl _restgpr_29 -/* 8026313C 80 01 00 24 */ lwz r0, 0x24(r1) -/* 80263140 7C 08 03 A6 */ mtlr r0 -/* 80263144 38 21 00 20 */ addi r1, r1, 0x20 -/* 80263148 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/__ct__20DynamicModuleControlFPCc.s b/asm/DynamicLink/__ct__20DynamicModuleControlFPCc.s deleted file mode 100644 index 999135f334..0000000000 --- a/asm/DynamicLink/__ct__20DynamicModuleControlFPCc.s +++ /dev/null @@ -1,29 +0,0 @@ -lbl_80262660: -/* 80262660 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262664 7C 08 02 A6 */ mflr r0 -/* 80262668 90 01 00 14 */ stw r0, 0x14(r1) -/* 8026266C 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80262670 93 C1 00 08 */ stw r30, 8(r1) -/* 80262674 7C 7E 1B 78 */ mr r30, r3 -/* 80262678 7C 9F 23 78 */ mr r31, r4 -/* 8026267C 4B FF FC 09 */ bl __ct__24DynamicModuleControlBaseFv -/* 80262680 3C 60 80 3C */ lis r3, __vt__20DynamicModuleControl@ha /* 0x803C34C0@ha */ -/* 80262684 38 03 34 C0 */ addi r0, r3, __vt__20DynamicModuleControl@l /* 0x803C34C0@l */ -/* 80262688 90 1E 00 0C */ stw r0, 0xc(r30) -/* 8026268C 38 00 00 00 */ li r0, 0 -/* 80262690 90 1E 00 10 */ stw r0, 0x10(r30) -/* 80262694 90 1E 00 14 */ stw r0, 0x14(r30) -/* 80262698 90 1E 00 18 */ stw r0, 0x18(r30) -/* 8026269C 93 FE 00 1C */ stw r31, 0x1c(r30) -/* 802626A0 98 1E 00 20 */ stb r0, 0x20(r30) -/* 802626A4 98 1E 00 21 */ stb r0, 0x21(r30) -/* 802626A8 B0 1E 00 22 */ sth r0, 0x22(r30) -/* 802626AC 90 1E 00 24 */ stw r0, 0x24(r30) -/* 802626B0 90 1E 00 28 */ stw r0, 0x28(r30) -/* 802626B4 7F C3 F3 78 */ mr r3, r30 -/* 802626B8 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 802626BC 83 C1 00 08 */ lwz r30, 8(r1) -/* 802626C0 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802626C4 7C 08 03 A6 */ mtlr r0 -/* 802626C8 38 21 00 10 */ addi r1, r1, 0x10 -/* 802626CC 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/__ct__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/__ct__24DynamicModuleControlBaseFv.s deleted file mode 100644 index 17632ca4ed..0000000000 --- a/asm/DynamicLink/__ct__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,22 +0,0 @@ -lbl_80262284: -/* 80262284 3C 80 80 3C */ lis r4, __vt__24DynamicModuleControlBase@ha /* 0x803C34F4@ha */ -/* 80262288 38 04 34 F4 */ addi r0, r4, __vt__24DynamicModuleControlBase@l /* 0x803C34F4@l */ -/* 8026228C 90 03 00 0C */ stw r0, 0xc(r3) -/* 80262290 38 00 00 00 */ li r0, 0 -/* 80262294 B0 03 00 00 */ sth r0, 0(r3) -/* 80262298 B0 03 00 02 */ sth r0, 2(r3) -/* 8026229C 90 03 00 08 */ stw r0, 8(r3) -/* 802622A0 80 0D 8B B8 */ lwz r0, mFirst__24DynamicModuleControlBase(r13) -/* 802622A4 28 00 00 00 */ cmplwi r0, 0 -/* 802622A8 40 82 00 08 */ bne lbl_802622B0 -/* 802622AC 90 6D 8B B8 */ stw r3, mFirst__24DynamicModuleControlBase(r13) -lbl_802622B0: -/* 802622B0 80 0D 8B BC */ lwz r0, mLast__24DynamicModuleControlBase(r13) -/* 802622B4 90 03 00 04 */ stw r0, 4(r3) -/* 802622B8 80 83 00 04 */ lwz r4, 4(r3) -/* 802622BC 28 04 00 00 */ cmplwi r4, 0 -/* 802622C0 41 82 00 08 */ beq lbl_802622C8 -/* 802622C4 90 64 00 08 */ stw r3, 8(r4) -lbl_802622C8: -/* 802622C8 90 6D 8B BC */ stw r3, mLast__24DynamicModuleControlBase(r13) -/* 802622CC 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s deleted file mode 100644 index 1542ec56eb..0000000000 --- a/asm/DynamicLink/__dt__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,52 +0,0 @@ -lbl_802621CC: -/* 802621CC 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802621D0 7C 08 02 A6 */ mflr r0 -/* 802621D4 90 01 00 14 */ stw r0, 0x14(r1) -/* 802621D8 93 E1 00 0C */ stw r31, 0xc(r1) -/* 802621DC 93 C1 00 08 */ stw r30, 8(r1) -/* 802621E0 7C 7E 1B 79 */ or. r30, r3, r3 -/* 802621E4 7C 9F 23 78 */ mr r31, r4 -/* 802621E8 41 82 00 80 */ beq lbl_80262268 -/* 802621EC 3C 80 80 3C */ lis r4, __vt__24DynamicModuleControlBase@ha /* 0x803C34F4@ha */ -/* 802621F0 38 04 34 F4 */ addi r0, r4, __vt__24DynamicModuleControlBase@l /* 0x803C34F4@l */ -/* 802621F4 90 1E 00 0C */ stw r0, 0xc(r30) -/* 802621F8 48 00 02 35 */ bl force_unlink__24DynamicModuleControlBaseFv -/* 802621FC 80 7E 00 04 */ lwz r3, 4(r30) -/* 80262200 28 03 00 00 */ cmplwi r3, 0 -/* 80262204 41 82 00 0C */ beq lbl_80262210 -/* 80262208 80 1E 00 08 */ lwz r0, 8(r30) -/* 8026220C 90 03 00 08 */ stw r0, 8(r3) -lbl_80262210: -/* 80262210 80 7E 00 08 */ lwz r3, 8(r30) -/* 80262214 28 03 00 00 */ cmplwi r3, 0 -/* 80262218 41 82 00 0C */ beq lbl_80262224 -/* 8026221C 80 1E 00 04 */ lwz r0, 4(r30) -/* 80262220 90 03 00 04 */ stw r0, 4(r3) -lbl_80262224: -/* 80262224 80 0D 8B B8 */ lwz r0, mFirst__24DynamicModuleControlBase(r13) -/* 80262228 7C 00 F0 40 */ cmplw r0, r30 -/* 8026222C 40 82 00 0C */ bne lbl_80262238 -/* 80262230 80 1E 00 08 */ lwz r0, 8(r30) -/* 80262234 90 0D 8B B8 */ stw r0, mFirst__24DynamicModuleControlBase(r13) -lbl_80262238: -/* 80262238 80 0D 8B BC */ lwz r0, mLast__24DynamicModuleControlBase(r13) -/* 8026223C 7C 00 F0 40 */ cmplw r0, r30 -/* 80262240 40 82 00 0C */ bne lbl_8026224C -/* 80262244 80 1E 00 04 */ lwz r0, 4(r30) -/* 80262248 90 0D 8B BC */ stw r0, mLast__24DynamicModuleControlBase(r13) -lbl_8026224C: -/* 8026224C 38 00 00 00 */ li r0, 0 -/* 80262250 90 1E 00 08 */ stw r0, 8(r30) -/* 80262254 90 1E 00 04 */ stw r0, 4(r30) -/* 80262258 7F E0 07 35 */ extsh. r0, r31 -/* 8026225C 40 81 00 0C */ ble lbl_80262268 -/* 80262260 7F C3 F3 78 */ mr r3, r30 -/* 80262264 48 06 CA D9 */ bl __dl__FPv -lbl_80262268: -/* 80262268 7F C3 F3 78 */ mr r3, r30 -/* 8026226C 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80262270 83 C1 00 08 */ lwz r30, 8(r1) -/* 80262274 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262278 7C 08 03 A6 */ mtlr r0 -/* 8026227C 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262280 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/calcSum2__FPCUsUl.s b/asm/DynamicLink/calcSum2__FPCUsUl.s deleted file mode 100644 index b67570c736..0000000000 --- a/asm/DynamicLink/calcSum2__FPCUsUl.s +++ /dev/null @@ -1,13 +0,0 @@ -lbl_802627C0: -/* 802627C0 38 A0 00 00 */ li r5, 0 -/* 802627C4 48 00 00 14 */ b lbl_802627D8 -lbl_802627C8: -/* 802627C8 A0 03 00 00 */ lhz r0, 0(r3) -/* 802627CC 7C A5 02 14 */ add r5, r5, r0 -/* 802627D0 38 84 FF FE */ addi r4, r4, -2 -/* 802627D4 38 63 00 02 */ addi r3, r3, 2 -lbl_802627D8: -/* 802627D8 28 04 00 00 */ cmplwi r4, 0 -/* 802627DC 40 82 FF EC */ bne lbl_802627C8 -/* 802627E0 7C A3 2B 78 */ mr r3, r5 -/* 802627E4 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/callback__20DynamicModuleControlFPv.s b/asm/DynamicLink/callback__20DynamicModuleControlFPv.s deleted file mode 100644 index 750672c5c7..0000000000 --- a/asm/DynamicLink/callback__20DynamicModuleControlFPv.s +++ /dev/null @@ -1,12 +0,0 @@ -lbl_80262794: -/* 80262794 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262798 7C 08 02 A6 */ mflr r0 -/* 8026279C 90 01 00 14 */ stw r0, 0x14(r1) -/* 802627A0 81 83 00 0C */ lwz r12, 0xc(r3) -/* 802627A4 81 8C 00 20 */ lwz r12, 0x20(r12) -/* 802627A8 7D 89 03 A6 */ mtctr r12 -/* 802627AC 4E 80 04 21 */ bctrl -/* 802627B0 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802627B4 7C 08 03 A6 */ mtlr r0 -/* 802627B8 38 21 00 10 */ addi r1, r1, 0x10 -/* 802627BC 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/do_load_async__20DynamicModuleControlFv.s b/asm/DynamicLink/do_load_async__20DynamicModuleControlFv.s deleted file mode 100644 index f96084217e..0000000000 --- a/asm/DynamicLink/do_load_async__20DynamicModuleControlFv.s +++ /dev/null @@ -1,56 +0,0 @@ -lbl_80262AFC: -/* 80262AFC 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262B00 7C 08 02 A6 */ mflr r0 -/* 80262B04 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262B08 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80262B0C 7C 7F 1B 78 */ mr r31, r3 -/* 80262B10 80 03 00 28 */ lwz r0, 0x28(r3) -/* 80262B14 28 00 00 00 */ cmplwi r0, 0 -/* 80262B18 40 82 00 50 */ bne lbl_80262B68 -/* 80262B1C 80 1F 00 10 */ lwz r0, 0x10(r31) -/* 80262B20 28 00 00 00 */ cmplwi r0, 0 -/* 80262B24 41 82 00 0C */ beq lbl_80262B30 -/* 80262B28 38 60 00 01 */ li r3, 1 -/* 80262B2C 48 00 00 84 */ b lbl_80262BB0 -lbl_80262B30: -/* 80262B30 3C 60 80 26 */ lis r3, callback__20DynamicModuleControlFPv@ha /* 0x80262794@ha */ -/* 80262B34 38 63 27 94 */ addi r3, r3, callback__20DynamicModuleControlFPv@l /* 0x80262794@l */ -/* 80262B38 7F E4 FB 78 */ mr r4, r31 -/* 80262B3C 4B DB 31 39 */ bl create__20mDoDvdThd_callback_cFPFPv_PvPv -/* 80262B40 90 7F 00 28 */ stw r3, 0x28(r31) -/* 80262B44 80 1F 00 28 */ lwz r0, 0x28(r31) -/* 80262B48 28 00 00 00 */ cmplwi r0, 0 -/* 80262B4C 40 82 00 1C */ bne lbl_80262B68 -/* 80262B50 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80262B54 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80262B58 38 63 01 DF */ addi r3, r3, 0x1df -/* 80262B5C 80 9F 00 1C */ lwz r4, 0x1c(r31) -/* 80262B60 4C C6 31 82 */ crclr 6 -/* 80262B64 4B DA 40 A9 */ bl OSReport_Error -lbl_80262B68: -/* 80262B68 80 7F 00 28 */ lwz r3, 0x28(r31) -/* 80262B6C 28 03 00 00 */ cmplwi r3, 0 -/* 80262B70 41 82 00 3C */ beq lbl_80262BAC -/* 80262B74 88 03 00 0C */ lbz r0, 0xc(r3) -/* 80262B78 2C 00 00 00 */ cmpwi r0, 0 -/* 80262B7C 41 82 00 30 */ beq lbl_80262BAC -/* 80262B80 28 03 00 00 */ cmplwi r3, 0 -/* 80262B84 41 82 00 18 */ beq lbl_80262B9C -/* 80262B88 38 80 00 01 */ li r4, 1 -/* 80262B8C 81 83 00 10 */ lwz r12, 0x10(r3) -/* 80262B90 81 8C 00 08 */ lwz r12, 8(r12) -/* 80262B94 7D 89 03 A6 */ mtctr r12 -/* 80262B98 4E 80 04 21 */ bctrl -lbl_80262B9C: -/* 80262B9C 38 00 00 00 */ li r0, 0 -/* 80262BA0 90 1F 00 28 */ stw r0, 0x28(r31) -/* 80262BA4 38 60 00 01 */ li r3, 1 -/* 80262BA8 48 00 00 08 */ b lbl_80262BB0 -lbl_80262BAC: -/* 80262BAC 38 60 00 00 */ li r3, 0 -lbl_80262BB0: -/* 80262BB0 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80262BB4 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262BB8 7C 08 03 A6 */ mtlr r0 -/* 80262BBC 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262BC0 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/do_unlink__20DynamicModuleControlFv.s b/asm/DynamicLink/do_unlink__20DynamicModuleControlFv.s deleted file mode 100644 index 232412a7ed..0000000000 --- a/asm/DynamicLink/do_unlink__20DynamicModuleControlFv.s +++ /dev/null @@ -1,58 +0,0 @@ -lbl_80262F28: -/* 80262F28 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262F2C 7C 08 02 A6 */ mflr r0 -/* 80262F30 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262F34 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80262F38 93 C1 00 08 */ stw r30, 8(r1) -/* 80262F3C 7C 7E 1B 78 */ mr r30, r3 -/* 80262F40 48 0D F7 BD */ bl OSGetTime -/* 80262F44 80 7E 00 10 */ lwz r3, 0x10(r30) -/* 80262F48 81 83 00 38 */ lwz r12, 0x38(r3) -/* 80262F4C 7D 89 03 A6 */ mtctr r12 -/* 80262F50 4E 80 04 21 */ bctrl -/* 80262F54 48 0D F7 A9 */ bl OSGetTime -/* 80262F58 80 7E 00 10 */ lwz r3, 0x10(r30) -/* 80262F5C 48 0D B8 4D */ bl OSUnlink -/* 80262F60 7C 7F 1B 78 */ mr r31, r3 -/* 80262F64 48 0D F7 99 */ bl OSGetTime -/* 80262F68 2C 1F 00 00 */ cmpwi r31, 0 -/* 80262F6C 40 82 00 28 */ bne lbl_80262F94 -/* 80262F70 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80262F74 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80262F78 38 63 02 97 */ addi r3, r3, 0x297 -/* 80262F7C 80 9E 00 10 */ lwz r4, 0x10(r30) -/* 80262F80 80 BE 00 14 */ lwz r5, 0x14(r30) -/* 80262F84 4C C6 31 82 */ crclr 6 -/* 80262F88 4B DA 3C 85 */ bl OSReport_Error -/* 80262F8C 38 60 00 00 */ li r3, 0 -/* 80262F90 48 00 00 58 */ b lbl_80262FE8 -lbl_80262F94: -/* 80262F94 7F C3 F3 78 */ mr r3, r30 -/* 80262F98 81 9E 00 0C */ lwz r12, 0xc(r30) -/* 80262F9C 81 8C 00 10 */ lwz r12, 0x10(r12) -/* 80262FA0 7D 89 03 A6 */ mtctr r12 -/* 80262FA4 4E 80 04 21 */ bctrl -/* 80262FA8 80 0D 8B C0 */ lwz r0, sAllocBytes__20DynamicModuleControl(r13) -/* 80262FAC 7C 03 00 50 */ subf r0, r3, r0 -/* 80262FB0 90 0D 8B C0 */ stw r0, sAllocBytes__20DynamicModuleControl(r13) -/* 80262FB4 80 7E 00 14 */ lwz r3, 0x14(r30) -/* 80262FB8 28 03 00 00 */ cmplwi r3, 0 -/* 80262FBC 41 82 00 14 */ beq lbl_80262FD0 -/* 80262FC0 38 80 00 00 */ li r4, 0 -/* 80262FC4 48 06 B5 3D */ bl free__7JKRHeapFPvP7JKRHeap -/* 80262FC8 38 00 00 00 */ li r0, 0 -/* 80262FCC 90 1E 00 14 */ stw r0, 0x14(r30) -lbl_80262FD0: -/* 80262FD0 7F C3 F3 78 */ mr r3, r30 -/* 80262FD4 81 9E 00 0C */ lwz r12, 0xc(r30) -/* 80262FD8 81 8C 00 28 */ lwz r12, 0x28(r12) -/* 80262FDC 7D 89 03 A6 */ mtctr r12 -/* 80262FE0 4E 80 04 21 */ bctrl -/* 80262FE4 38 60 00 01 */ li r3, 1 -lbl_80262FE8: -/* 80262FE8 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80262FEC 83 C1 00 08 */ lwz r30, 8(r1) -/* 80262FF0 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262FF4 7C 08 03 A6 */ mtlr r0 -/* 80262FF8 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262FFC 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/do_unload__20DynamicModuleControlFv.s b/asm/DynamicLink/do_unload__20DynamicModuleControlFv.s deleted file mode 100644 index de5e8fe8b0..0000000000 --- a/asm/DynamicLink/do_unload__20DynamicModuleControlFv.s +++ /dev/null @@ -1,20 +0,0 @@ -lbl_80262BC4: -/* 80262BC4 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262BC8 7C 08 02 A6 */ mflr r0 -/* 80262BCC 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262BD0 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80262BD4 7C 7F 1B 78 */ mr r31, r3 -/* 80262BD8 80 63 00 10 */ lwz r3, 0x10(r3) -/* 80262BDC 28 03 00 00 */ cmplwi r3, 0 -/* 80262BE0 41 82 00 14 */ beq lbl_80262BF4 -/* 80262BE4 38 80 00 00 */ li r4, 0 -/* 80262BE8 48 06 B9 19 */ bl free__7JKRHeapFPvP7JKRHeap -/* 80262BEC 38 00 00 00 */ li r0, 0 -/* 80262BF0 90 1F 00 10 */ stw r0, 0x10(r31) -lbl_80262BF4: -/* 80262BF4 38 60 00 01 */ li r3, 1 -/* 80262BF8 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80262BFC 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262C00 7C 08 03 A6 */ mtlr r0 -/* 80262C04 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262C08 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/dump2__20DynamicModuleControlFv.s b/asm/DynamicLink/dump2__20DynamicModuleControlFv.s deleted file mode 100644 index 8bdb358203..0000000000 --- a/asm/DynamicLink/dump2__20DynamicModuleControlFv.s +++ /dev/null @@ -1,22 +0,0 @@ -lbl_80262C0C: -/* 80262C0C 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262C10 7C 08 02 A6 */ mflr r0 -/* 80262C14 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262C18 80 83 00 10 */ lwz r4, 0x10(r3) -/* 80262C1C 28 04 00 00 */ cmplwi r4, 0 -/* 80262C20 41 82 00 2C */ beq lbl_80262C4C -/* 80262C24 80 C4 00 10 */ lwz r6, 0x10(r4) -/* 80262C28 80 06 00 08 */ lwz r0, 8(r6) -/* 80262C2C 54 05 00 3C */ rlwinm r5, r0, 0, 0, 0x1e -/* 80262C30 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80262C34 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80262C38 38 63 02 2E */ addi r3, r3, 0x22e -/* 80262C3C 80 06 00 0C */ lwz r0, 0xc(r6) -/* 80262C40 7C C5 02 14 */ add r6, r5, r0 -/* 80262C44 4C C6 31 82 */ crclr 6 -/* 80262C48 4B DA 3E 75 */ bl OSReport -lbl_80262C4C: -/* 80262C4C 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262C50 7C 08 03 A6 */ mtlr r0 -/* 80262C54 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262C58 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/force_unlink__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/force_unlink__24DynamicModuleControlBaseFv.s deleted file mode 100644 index d962466187..0000000000 --- a/asm/DynamicLink/force_unlink__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,19 +0,0 @@ -lbl_8026242C: -/* 8026242C 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262430 7C 08 02 A6 */ mflr r0 -/* 80262434 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262438 A0 03 00 00 */ lhz r0, 0(r3) -/* 8026243C 28 00 00 00 */ cmplwi r0, 0 -/* 80262440 41 82 00 1C */ beq lbl_8026245C -/* 80262444 38 00 00 00 */ li r0, 0 -/* 80262448 B0 03 00 00 */ sth r0, 0(r3) -/* 8026244C 81 83 00 0C */ lwz r12, 0xc(r3) -/* 80262450 81 8C 00 30 */ lwz r12, 0x30(r12) -/* 80262454 7D 89 03 A6 */ mtctr r12 -/* 80262458 4E 80 04 21 */ bctrl -lbl_8026245C: -/* 8026245C 38 60 00 01 */ li r3, 1 -/* 80262460 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262464 7C 08 03 A6 */ mtlr r0 -/* 80262468 38 21 00 10 */ addi r1, r1, 0x10 -/* 8026246C 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/getModuleName__20DynamicModuleControlCFv.s b/asm/DynamicLink/getModuleName__20DynamicModuleControlCFv.s deleted file mode 100644 index 975f0b0048..0000000000 --- a/asm/DynamicLink/getModuleName__20DynamicModuleControlCFv.s +++ /dev/null @@ -1,3 +0,0 @@ -lbl_80263218: -/* 80263218 80 63 00 1C */ lwz r3, 0x1c(r3) -/* 8026321C 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/getModuleSize__20DynamicModuleControlCFv.s b/asm/DynamicLink/getModuleSize__20DynamicModuleControlCFv.s deleted file mode 100644 index 396008ce88..0000000000 --- a/asm/DynamicLink/getModuleSize__20DynamicModuleControlCFv.s +++ /dev/null @@ -1,32 +0,0 @@ -lbl_80263000: -/* 80263000 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80263004 7C 08 02 A6 */ mflr r0 -/* 80263008 90 01 00 14 */ stw r0, 0x14(r1) -/* 8026300C 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80263010 93 C1 00 08 */ stw r30, 8(r1) -/* 80263014 7C 7E 1B 78 */ mr r30, r3 -/* 80263018 80 63 00 10 */ lwz r3, 0x10(r3) -/* 8026301C 28 03 00 00 */ cmplwi r3, 0 -/* 80263020 41 82 00 34 */ beq lbl_80263054 -/* 80263024 38 80 00 00 */ li r4, 0 -/* 80263028 48 06 B6 89 */ bl getSize__7JKRHeapFPvP7JKRHeap -/* 8026302C 7C 7F 1B 78 */ mr r31, r3 -/* 80263030 80 7E 00 14 */ lwz r3, 0x14(r30) -/* 80263034 28 03 00 00 */ cmplwi r3, 0 -/* 80263038 41 82 00 0C */ beq lbl_80263044 -/* 8026303C 38 80 00 00 */ li r4, 0 -/* 80263040 48 06 B6 71 */ bl getSize__7JKRHeapFPvP7JKRHeap -lbl_80263044: -/* 80263044 80 7E 00 10 */ lwz r3, 0x10(r30) -/* 80263048 80 03 00 20 */ lwz r0, 0x20(r3) -/* 8026304C 7C 7F 02 14 */ add r3, r31, r0 -/* 80263050 48 00 00 08 */ b lbl_80263058 -lbl_80263054: -/* 80263054 38 60 00 00 */ li r3, 0 -lbl_80263058: -/* 80263058 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 8026305C 83 C1 00 08 */ lwz r30, 8(r1) -/* 80263060 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80263064 7C 08 03 A6 */ mtlr r0 -/* 80263068 38 21 00 10 */ addi r1, r1, 0x10 -/* 8026306C 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/getModuleTypeString__20DynamicModuleControlCFv.s b/asm/DynamicLink/getModuleTypeString__20DynamicModuleControlCFv.s deleted file mode 100644 index e08d7daf2a..0000000000 --- a/asm/DynamicLink/getModuleTypeString__20DynamicModuleControlCFv.s +++ /dev/null @@ -1,7 +0,0 @@ -lbl_80263070: -/* 80263070 88 03 00 20 */ lbz r0, 0x20(r3) -/* 80263074 54 00 17 3A */ rlwinm r0, r0, 2, 0x1c, 0x1d -/* 80263078 3C 60 80 3C */ lis r3, strings@ha /* 0x803C34B0@ha */ -/* 8026307C 38 63 34 B0 */ addi r3, r3, strings@l /* 0x803C34B0@l */ -/* 80263080 7C 63 00 2E */ lwzx r3, r3, r0 -/* 80263084 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/getModuleTypeString__24DynamicModuleControlBaseCFv.s b/asm/DynamicLink/getModuleTypeString__24DynamicModuleControlBaseCFv.s deleted file mode 100644 index c0ba5020ff..0000000000 --- a/asm/DynamicLink/getModuleTypeString__24DynamicModuleControlBaseCFv.s +++ /dev/null @@ -1,5 +0,0 @@ -lbl_80263200: -/* 80263200 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80263204 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80263208 38 63 00 DB */ addi r3, r3, 0xdb -/* 8026320C 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/initialize__20DynamicModuleControlFv.s b/asm/DynamicLink/initialize__20DynamicModuleControlFv.s deleted file mode 100644 index 3154deacba..0000000000 --- a/asm/DynamicLink/initialize__20DynamicModuleControlFv.s +++ /dev/null @@ -1,15 +0,0 @@ -lbl_8026275C: -/* 8026275C 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262760 7C 08 02 A6 */ mflr r0 -/* 80262764 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262768 38 00 00 00 */ li r0, 0 -/* 8026276C 90 0D 8B C8 */ stw r0, sFileCache__20DynamicModuleControl(r13) -/* 80262770 90 0D 8B C0 */ stw r0, sAllocBytes__20DynamicModuleControl(r13) -/* 80262774 90 0D 8B C4 */ stw r0, sArchive__20DynamicModuleControl(r13) -/* 80262778 38 60 00 00 */ li r3, 0 -/* 8026277C 4B FF FF 55 */ bl mountCallback__20DynamicModuleControlFPv -/* 80262780 38 60 00 01 */ li r3, 1 -/* 80262784 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262788 7C 08 03 A6 */ mtlr r0 -/* 8026278C 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262790 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/link__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/link__24DynamicModuleControlBaseFv.s deleted file mode 100644 index 99efcf61e9..0000000000 --- a/asm/DynamicLink/link__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,42 +0,0 @@ -lbl_802622D0: -/* 802622D0 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802622D4 7C 08 02 A6 */ mflr r0 -/* 802622D8 90 01 00 14 */ stw r0, 0x14(r1) -/* 802622DC 93 E1 00 0C */ stw r31, 0xc(r1) -/* 802622E0 7C 7F 1B 78 */ mr r31, r3 -/* 802622E4 A0 03 00 00 */ lhz r0, 0(r3) -/* 802622E8 28 00 00 00 */ cmplwi r0, 0 -/* 802622EC 40 82 00 4C */ bne lbl_80262338 -/* 802622F0 81 83 00 0C */ lwz r12, 0xc(r3) -/* 802622F4 81 8C 00 20 */ lwz r12, 0x20(r12) -/* 802622F8 7D 89 03 A6 */ mtctr r12 -/* 802622FC 4E 80 04 21 */ bctrl -/* 80262300 7F E3 FB 78 */ mr r3, r31 -/* 80262304 81 9F 00 0C */ lwz r12, 0xc(r31) -/* 80262308 81 8C 00 2C */ lwz r12, 0x2c(r12) -/* 8026230C 7D 89 03 A6 */ mtctr r12 -/* 80262310 4E 80 04 21 */ bctrl -/* 80262314 2C 03 00 00 */ cmpwi r3, 0 -/* 80262318 40 82 00 0C */ bne lbl_80262324 -/* 8026231C 38 60 00 00 */ li r3, 0 -/* 80262320 48 00 00 30 */ b lbl_80262350 -lbl_80262324: -/* 80262324 A0 7F 00 02 */ lhz r3, 2(r31) -/* 80262328 28 03 FF FF */ cmplwi r3, 0xffff -/* 8026232C 40 80 00 0C */ bge lbl_80262338 -/* 80262330 38 03 00 01 */ addi r0, r3, 1 -/* 80262334 B0 1F 00 02 */ sth r0, 2(r31) -lbl_80262338: -/* 80262338 A0 7F 00 00 */ lhz r3, 0(r31) -/* 8026233C 28 03 FF FF */ cmplwi r3, 0xffff -/* 80262340 40 80 00 0C */ bge lbl_8026234C -/* 80262344 38 03 00 01 */ addi r0, r3, 1 -/* 80262348 B0 1F 00 00 */ sth r0, 0(r31) -lbl_8026234C: -/* 8026234C 38 60 00 01 */ li r3, 1 -lbl_80262350: -/* 80262350 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 80262354 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262358 7C 08 03 A6 */ mtlr r0 -/* 8026235C 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262360 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/load_async__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/load_async__24DynamicModuleControlBaseFv.s deleted file mode 100644 index 80763e9f5c..0000000000 --- a/asm/DynamicLink/load_async__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,19 +0,0 @@ -lbl_802623EC: -/* 802623EC 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802623F0 7C 08 02 A6 */ mflr r0 -/* 802623F4 90 01 00 14 */ stw r0, 0x14(r1) -/* 802623F8 A0 03 00 00 */ lhz r0, 0(r3) -/* 802623FC 28 00 00 00 */ cmplwi r0, 0 -/* 80262400 40 82 00 18 */ bne lbl_80262418 -/* 80262404 81 83 00 0C */ lwz r12, 0xc(r3) -/* 80262408 81 8C 00 24 */ lwz r12, 0x24(r12) -/* 8026240C 7D 89 03 A6 */ mtctr r12 -/* 80262410 4E 80 04 21 */ bctrl -/* 80262414 48 00 00 08 */ b lbl_8026241C -lbl_80262418: -/* 80262418 38 60 00 01 */ li r3, 1 -lbl_8026241C: -/* 8026241C 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262420 7C 08 03 A6 */ mtlr r0 -/* 80262424 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262428 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/mountCallback__20DynamicModuleControlFPv.s b/asm/DynamicLink/mountCallback__20DynamicModuleControlFPv.s deleted file mode 100644 index 12a6c4d0e9..0000000000 --- a/asm/DynamicLink/mountCallback__20DynamicModuleControlFPv.s +++ /dev/null @@ -1,37 +0,0 @@ -lbl_802626D0: -/* 802626D0 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802626D4 7C 08 02 A6 */ mflr r0 -/* 802626D8 90 01 00 14 */ stw r0, 0x14(r1) -/* 802626DC 93 E1 00 0C */ stw r31, 0xc(r1) -/* 802626E0 4B DA C7 0D */ bl mDoExt_getArchiveHeap__Fv -/* 802626E4 7C 7F 1B 78 */ mr r31, r3 -/* 802626E8 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 802626EC 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 802626F0 38 63 00 E0 */ addi r3, r3, 0xe0 -/* 802626F4 7F E4 FB 78 */ mr r4, r31 -/* 802626F8 38 A0 00 00 */ li r5, 0 -/* 802626FC 48 07 22 B9 */ bl mount__12JKRFileCacheFPCcP7JKRHeapPCc -/* 80262700 90 6D 8B C8 */ stw r3, sFileCache__20DynamicModuleControl(r13) -/* 80262704 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80262708 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 8026270C 38 63 00 F3 */ addi r3, r3, 0xf3 -/* 80262710 38 80 00 04 */ li r4, 4 -/* 80262714 7F E5 FB 78 */ mr r5, r31 -/* 80262718 38 C0 00 01 */ li r6, 1 -/* 8026271C 48 07 30 C9 */ bl mount__10JKRArchiveFPCcQ210JKRArchive10EMountModeP7JKRHeapQ210JKRArchive15EMountDirection -/* 80262720 90 6D 8B C4 */ stw r3, sArchive__20DynamicModuleControl(r13) -/* 80262724 28 03 00 00 */ cmplwi r3, 0 -/* 80262728 40 82 00 1C */ bne lbl_80262744 -/* 8026272C 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 80262730 38 83 A4 A0 */ addi r4, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 80262734 38 64 00 FC */ addi r3, r4, 0xfc -/* 80262738 38 84 00 F3 */ addi r4, r4, 0xf3 -/* 8026273C 4C C6 31 82 */ crclr 6 -/* 80262740 4B DA 45 AD */ bl OSReport_Warning -lbl_80262744: -/* 80262744 80 6D 8B C4 */ lwz r3, sArchive__20DynamicModuleControl(r13) -/* 80262748 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 8026274C 80 01 00 14 */ lwz r0, 0x14(r1) -/* 80262750 7C 08 03 A6 */ mtlr r0 -/* 80262754 38 21 00 10 */ addi r1, r1, 0x10 -/* 80262758 4E 80 00 20 */ blr diff --git a/asm/DynamicLink/unlink__24DynamicModuleControlBaseFv.s b/asm/DynamicLink/unlink__24DynamicModuleControlBaseFv.s deleted file mode 100644 index 92be895fc4..0000000000 --- a/asm/DynamicLink/unlink__24DynamicModuleControlBaseFv.s +++ /dev/null @@ -1,37 +0,0 @@ -lbl_80262364: -/* 80262364 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 80262368 7C 08 02 A6 */ mflr r0 -/* 8026236C 90 01 00 14 */ stw r0, 0x14(r1) -/* 80262370 93 E1 00 0C */ stw r31, 0xc(r1) -/* 80262374 7C 7F 1B 78 */ mr r31, r3 -/* 80262378 A0 83 00 00 */ lhz r4, 0(r3) -/* 8026237C 28 04 00 00 */ cmplwi r4, 0 -/* 80262380 41 82 00 40 */ beq lbl_802623C0 -/* 80262384 38 04 FF FF */ addi r0, r4, -1 -/* 80262388 B0 1F 00 00 */ sth r0, 0(r31) -/* 8026238C A0 1F 00 00 */ lhz r0, 0(r31) -/* 80262390 28 00 00 00 */ cmplwi r0, 0 -/* 80262394 40 82 00 40 */ bne lbl_802623D4 -/* 80262398 81 83 00 0C */ lwz r12, 0xc(r3) -/* 8026239C 81 8C 00 30 */ lwz r12, 0x30(r12) -/* 802623A0 7D 89 03 A6 */ mtctr r12 -/* 802623A4 4E 80 04 21 */ bctrl -/* 802623A8 7F E3 FB 78 */ mr r3, r31 -/* 802623AC 81 9F 00 0C */ lwz r12, 0xc(r31) -/* 802623B0 81 8C 00 28 */ lwz r12, 0x28(r12) -/* 802623B4 7D 89 03 A6 */ mtctr r12 -/* 802623B8 4E 80 04 21 */ bctrl -/* 802623BC 48 00 00 18 */ b lbl_802623D4 -lbl_802623C0: -/* 802623C0 3C 60 80 3A */ lis r3, DynamicLink__stringBase0@ha /* 0x8039A4A0@ha */ -/* 802623C4 38 63 A4 A0 */ addi r3, r3, DynamicLink__stringBase0@l /* 0x8039A4A0@l */ -/* 802623C8 7F E4 FB 78 */ mr r4, r31 -/* 802623CC 4C C6 31 82 */ crclr 6 -/* 802623D0 4B DA 49 1D */ bl OSReport_Warning -lbl_802623D4: -/* 802623D4 38 60 00 01 */ li r3, 1 -/* 802623D8 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 802623DC 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802623E0 7C 08 03 A6 */ mtlr r0 -/* 802623E4 38 21 00 10 */ addi r1, r1, 0x10 -/* 802623E8 4E 80 00 20 */ blr diff --git a/asm/JSystem/JParticle/JPABaseShape/JPADrawParticleCallBack__FP18JPAEmitterWorkDataP15JPABaseParticle.s b/asm/JSystem/JParticle/JPABaseShape/JPADrawParticleCallBack__FP18JPAEmitterWorkDataP15JPABaseParticle.s deleted file mode 100644 index 149a87e135..0000000000 --- a/asm/JSystem/JParticle/JPABaseShape/JPADrawParticleCallBack__FP18JPAEmitterWorkDataP15JPABaseParticle.s +++ /dev/null @@ -1,18 +0,0 @@ -lbl_8027A414: -/* 8027A414 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 8027A418 7C 08 02 A6 */ mflr r0 -/* 8027A41C 90 01 00 14 */ stw r0, 0x14(r1) -/* 8027A420 7C 85 23 78 */ mr r5, r4 -/* 8027A424 80 83 00 00 */ lwz r4, 0(r3) -/* 8027A428 80 64 00 F0 */ lwz r3, 0xf0(r4) -/* 8027A42C 28 03 00 00 */ cmplwi r3, 0 -/* 8027A430 41 82 00 14 */ beq lbl_8027A444 -/* 8027A434 81 83 00 00 */ lwz r12, 0(r3) -/* 8027A438 81 8C 00 10 */ lwz r12, 0x10(r12) -/* 8027A43C 7D 89 03 A6 */ mtctr r12 -/* 8027A440 4E 80 04 21 */ bctrl -lbl_8027A444: -/* 8027A444 80 01 00 14 */ lwz r0, 0x14(r1) -/* 8027A448 7C 08 03 A6 */ mtlr r0 -/* 8027A44C 38 21 00 10 */ addi r1, r1, 0x10 -/* 8027A450 4E 80 00 20 */ blr From ecc987f34cff6397e9785063effcc5f2e7dc33c5 Mon Sep 17 00:00:00 2001 From: jdflyer Date: Mon, 17 Jan 2022 20:00:12 -0700 Subject: [PATCH 10/11] Hyrule field speedhack and shiftability fixes --- Makefile | 2 + include/d/map/d_map_path.h | 14 ++- include/dolphin/gx/GX.h | 4 + src/d/map/d_map_path.cpp | 187 +++++++++++++++++++++---------------- tools/lcf.py | 7 ++ 5 files changed, 131 insertions(+), 83 deletions(-) diff --git a/Makefile b/Makefile index 63fed2bb70..fa8b99b94d 100644 --- a/Makefile +++ b/Makefile @@ -144,9 +144,11 @@ $(ELF_SHIFT): $(DOL) @echo $(O_FILES) > build/o_files @$(PYTHON) tools/lcf.py dol_shift --output $(LDSCRIPT) $(LD) -application $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files $(LIBS) + @cp -v $(ELF_SHIFT) $(ELF) $(DOL_SHIFT): $(ELF_SHIFT) | tools $(ELF2DOL) $< $@ $(SDATA_PDHR) $(SBSS_PDHR) $(TARGET_COL) + @cp -v $(DOL_SHIFT) $(DOL) shift: dirs $(DOL_SHIFT) diff --git a/include/d/map/d_map_path.h b/include/d/map/d_map_path.h index f4fc8a3f2e..e1efd518f8 100644 --- a/include/d/map/d_map_path.h +++ b/include/d/map/d_map_path.h @@ -6,7 +6,13 @@ class dDrawPath_c : public dDlst_base_c { public: - struct line_class {}; + struct line_class { + /*0x0*/ u8 unk0; + /*0x1*/ u8 unk1; + /*0x2*/ u8 unk2; + /*0x3*/ u8 unk3; + /*0x4*/ u16* unk4; + }; struct poly_class {}; @@ -52,7 +58,7 @@ public: virtual void isDrawPath() = 0; virtual void preRenderingMap() = 0; virtual void postRenderingMap() = 0; - virtual void getBackColor() const = 0; + virtual GXColor* getBackColor() const = 0; }; class dRenderingFDAmap_c : public dRenderingMap_c { @@ -65,8 +71,8 @@ public: /* 8002ABF8 */ virtual ~dRenderingFDAmap_c(); /* 8003D188 */ virtual void preRenderingMap(); /* 8003D320 */ virtual void postRenderingMap(); - /* 8003D68C */ virtual void getDecoLineColor(int, int); - /* 8003D6B8 */ virtual void getDecorationLineWidth(int); + /* 8003D68C */ virtual GXColor* getDecoLineColor(int, int); + /* 8003D6B8 */ virtual s32 getDecorationLineWidth(int); private: /* 0x04 */ int field_0x4; diff --git a/include/dolphin/gx/GX.h b/include/dolphin/gx/GX.h index d7aeb521c6..d5bd716e52 100644 --- a/include/dolphin/gx/GX.h +++ b/include/dolphin/gx/GX.h @@ -990,6 +990,10 @@ inline void GXPosition2u16(u16 x, u16 y) { GFX_FIFO(u16) = y; } +inline void GXPosition1x16(u16 x) { + GFX_FIFO(u16) = x; +} + inline void GXEnd() {} }; diff --git a/src/d/map/d_map_path.cpp b/src/d/map/d_map_path.cpp index b673a6283f..ab7b736490 100644 --- a/src/d/map/d_map_path.cpp +++ b/src/d/map/d_map_path.cpp @@ -17,16 +17,25 @@ struct dRes_control_c { /* 8003C2EC */ void getRes(char const*, s32, dRes_info_c*, int); }; + struct dMpath_n { struct dTexObjAggregate_c { /* 8003C85C */ void create(); /* 8003C8F4 */ void remove(); - /* 8003D740 */ ~dTexObjAggregate_c(); + /* 8003D740 */ ~dTexObjAggregate_c() {remove();}; + inline dTexObjAggregate_c() { + for(int i = 0;i<7;i++) { + mTexObjs[i] = NULL; + } + } + GXTexObj* mTexObjs[7]; }; - static u8 m_texObjAgg[28]; + static dTexObjAggregate_c m_texObjAgg; }; +STATIC_ASSERT(sizeof(dMpath_n::dTexObjAggregate_c)==28); + // // Forward References: // @@ -78,9 +87,9 @@ extern "C" void _savegpr_28(); extern "C" void _restgpr_26(); extern "C" void _restgpr_27(); extern "C" void _restgpr_28(); -extern "C" extern u8 g_mDoMtx_identity[48 + 24 /* padding */]; +extern "C" extern Mtx g_mDoMtx_identity; extern "C" extern u8 g_dComIfG_gameInfo[122384]; -extern "C" extern u8 g_clearColor[4]; +extern "C" extern GXColor g_clearColor; // // Declarations: @@ -232,48 +241,49 @@ asm void dRenderingFDAmap_c::setTevSettingIntensityTextureToCI() const { } #pragma pop -/* ############################################################################################## */ -/* 80451E08-80451E0C 000408 0004+00 3/3 0/0 0/0 .sdata2 @3836 */ -SECTION_SDATA2 static u8 lit_3836[4] = { - 0x00, - 0x00, - 0x00, - 0x00, -}; - /* 8003D0AC-8003D188 0379EC 00DC+00 1/1 0/0 0/0 .text drawBack__18dRenderingFDAmap_cCFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void dRenderingFDAmap_c::drawBack() const { - nofralloc -#include "asm/d/map/d_map_path/drawBack__18dRenderingFDAmap_cCFv.s" +void dRenderingFDAmap_c::drawBack() const { + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS,GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0,GX_VA_POS,GX_CLR_RGBA,GX_F32,0); + GXColor* colorPtr = getBackColor(); + GXSetTevColor(GX_TEVREG0,*colorPtr); + GXBegin(GX_QUADS,GX_VTXFMT0,4); + GXPosition3f32(-field_0x8,-field_0xc,0); + GXPosition3f32(field_0x8,-field_0xc,0); + GXPosition3f32(field_0x8,field_0xc,0); + GXPosition3f32(-field_0x8,field_0xc,0); + GXEnd(); } -#pragma pop - -/* ############################################################################################## */ -/* 80451E0C-80451E10 00040C 0004+00 1/1 0/0 0/0 .sdata2 @3846 */ -SECTION_SDATA2 static f32 lit_3846 = 1.0f; - -/* 80451E10-80451E14 000410 0004+00 1/1 0/0 0/0 .sdata2 @3847 */ -SECTION_SDATA2 static f32 lit_3847 = 0.5f; - -/* 80451E14-80451E18 000414 0004+00 1/1 0/0 0/0 .sdata2 @3848 */ -SECTION_SDATA2 static f32 lit_3848 = 10000.0f; - -/* 80451E18-80451E20 000418 0008+00 1/1 0/0 0/0 .sdata2 @3850 */ -SECTION_SDATA2 static f64 lit_3850 = 4503599627370496.0 /* cast u32 to float */; /* 8003D188-8003D320 037AC8 0198+00 1/0 8/0 0/0 .text preRenderingMap__18dRenderingFDAmap_cFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void dRenderingFDAmap_c::preRenderingMap() { - nofralloc -#include "asm/d/map/d_map_path/preRenderingMap__18dRenderingFDAmap_cFv.s" +void dRenderingFDAmap_c::preRenderingMap() { + GXSetViewport(0.0f,0.0f,field_0x1c,field_0x1e,0.0f,1.0f); + GXSetScissor(0,0,field_0x1c,field_0x1e); + GXSetNumChans(1); + GXSetNumTevStages(1); + GXSetChanCtrl(GX_COLOR0A0,GX_FALSE,GX_SRC_REG,GX_SRC_REG,GX_LIGHT_NULL,GX_DF_NONE,GX_AF_NONE); + GXSetAlphaCompare(GX_ALWAYS,0,GX_AOP_OR,GX_ALWAYS,0); + GXSetZCompLoc(GX_TRUE); + GXSetZMode(GX_FALSE,GX_ALWAYS,GX_FALSE); + GXSetBlendMode(GX_BM_NONE,GX_BL_SRC_ALPHA,GX_BL_INV_SRC_ALPHA,GX_LO_CLEAR); + GXColor color = g_clearColor; + GXSetFog(GX_FOG_NONE,0.0f,0.0f,0.0f,0.0f,color); + GXSetCullMode(GX_CULL_NONE); + GXSetDither(GX_FALSE); + GXSetNumIndStages(0); + GXSetClipMode(GX_FALSE); + setTevSettingNonTextureDirectColor(); + float right = field_0x8*0.5f; + float top = field_0xc*0.5f; + Mtx44 matrix; + C_MTXOrtho(matrix,top,-top,-right,right,0.0f,10000.0f); + GXSetProjection(matrix,GX_ORTHOGRAPHIC); + GXLoadPosMtxImm(g_mDoMtx_identity,GX_PNMTX0); + GXSetCurrentMtx(0); + drawBack(); } -#pragma pop /* 8003D320-8003D3C0 037C60 00A0+00 1/0 7/1 0/0 .text postRenderingMap__18dRenderingFDAmap_cFv */ #pragma push @@ -285,29 +295,73 @@ asm void dRenderingFDAmap_c::postRenderingMap() { } #pragma pop -/* ############################################################################################## */ -/* 80424678-80424684 051398 000C+00 1/1 0/0 0/0 .bss @3639 */ -static u8 lit_3639[12]; - /* 80424684-804246A0 0513A4 001C+00 2/2 5/5 0/0 .bss m_texObjAgg__8dMpath_n */ -u8 dMpath_n::m_texObjAgg[28]; +dMpath_n::dTexObjAggregate_c dMpath_n::m_texObjAgg; + +/* Enabling the following definition will modify the following function to + * make the map look worse for extra speed in the emulator, especially in large + * areas such as hyrule field. + */ +//#define HYRULE_FIELD_SPEEDHACK /* 8003D3C0-8003D68C 037D00 02CC+00 0/0 2/2 0/0 .text * renderingDecoration__18dRenderingFDAmap_cFPCQ211dDrawPath_c10line_class */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void dRenderingFDAmap_c::renderingDecoration(dDrawPath_c::line_class const* param_0) { - nofralloc -#include "asm/d/map/d_map_path/renderingDecoration__18dRenderingFDAmap_cFPCQ211dDrawPath_c10line_class.s" +void dRenderingFDAmap_c::renderingDecoration(dDrawPath_c::line_class const* line) { + s32 width = getDecorationLineWidth(line->unk1); + if (width<=0) { + return; + } + setTevSettingIntensityTextureToCI(); + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS,GX_INDEX16); + GXSetVtxDesc(GX_VA_TEX0,GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0,GX_VA_POS,GX_POS_XY,GX_F32,0); + GXSetVtxAttrFmt(GX_VTXFMT0,GX_VA_TEX0,GX_POS_XYZ,GX_F32,0); + GXSetNumTevStages(1); + GXLoadTexObj(dMpath_n::m_texObjAgg.mTexObjs[6],GX_TEXMAP0); + u16* unk = line->unk4; + s32 unk2 = line->unk2; + GXSetLineWidth(width,GX_TO_ONE); + GXSetPointSize(width,GX_TO_ONE); + GXColor* lineColorPtr = getDecoLineColor(line->unk0&0x3f,line->unk1); + GXColor lineColor = *lineColorPtr; + GXSetTevColor(GX_TEVREG0,lineColor); + lineColor.r = lineColor.r-4; + GXSetTevColor(GX_TEVREG1,lineColor); + for (int i = 0; i 3 and linesplit[2]!="NOT": + if line.find("lit_")!=-1: + lbl = symbol['label'] + for literal in literals_found: + if literal == lbl: + print("Warning! two literals with the same name found!\n"+lbl) + literals_found.append(symbol['label']) addr = int(linesplit[2],16) file.write(f"\t\"{symbol['label']}\" = 0x{addr:08X};\n") else: From 252c5daba7a1517f535aefac068e69b22e7b8d7f Mon Sep 17 00:00:00 2001 From: jdflyer Date: Mon, 17 Jan 2022 20:19:43 -0700 Subject: [PATCH 11/11] Formatting fixes --- Makefile | 8 ++++++++ include/DynamicLink.h | 29 +++++++++++++++-------------- include/d/map/d_map_path.h | 10 +++++----- include/d/map/d_map_path_dmap.h | 2 +- src/DynamicLink.cpp | 2 +- src/d/map/d_map_path_dmap.cpp | 2 +- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index fa8b99b94d..5d5d377d5f 100644 --- a/Makefile +++ b/Makefile @@ -113,8 +113,16 @@ clean: rm -f -d -r $(BUILD_DIR)/src rm -f $(ELF) rm -f $(DOL) + rm -f $(ELF_SHIFT) + rm -f $(DOL_SHIFT) rm -f $(BUILD_DIR)/*.a +clean_game: + rm -r -f -d $(TARGET)/game + +clean_assets: + rm -r -f -d game + clean_all: rm -f -d -r build diff --git a/include/DynamicLink.h b/include/DynamicLink.h index 633ba0abf8..638eb61937 100644 --- a/include/DynamicLink.h +++ b/include/DynamicLink.h @@ -7,12 +7,13 @@ #include "JSystem/JKernel/JKRFileCache.h" struct DynamicModuleControlBase { - u16 mLinkCount; //0x0 - u16 mDoLinkCount; //0x2 - DynamicModuleControlBase* mPrev; //0x4 - DynamicModuleControlBase* mNext; //0x8 + /* 0x00 */u16 mLinkCount; + /* 0x02 */u16 mDoLinkCount; + /* 0x04 */DynamicModuleControlBase* mPrev; + /* 0x08 */DynamicModuleControlBase* mNext; - /* 802621CC */ virtual ~DynamicModuleControlBase(); //0xC + /* 0x0C */ /*vtable*/ + /* 802621CC */ virtual ~DynamicModuleControlBase(); /* 800188DC */ virtual const char* getModuleName() const; /* 80263210 */ virtual int getModuleSize() const; /* 80263200 */ virtual const char* getModuleTypeString() const; @@ -54,15 +55,15 @@ struct DynamicModuleControl : DynamicModuleControlBase { /* 8026275C */ bool initialize(); /* 80262794 */ static void* callback(void*); - OSModuleInfo* mModule; //0x10 - void* mBss; //0x14 - u32 unk_24; //0x18 - const char* mName; //0x1c - u8 mResourceType; //0x20 - u8 unk_33; //0x21 - u16 mChecksum; //0x22 - s32 mSize; //0x24 - mDoDvdThd_callback_c* mAsyncLoadCallback; //0x28 + /* 0x10 */OSModuleInfo* mModule; + /* 0x14 */void* mBss; + /* 0x18 */u32 unk_24; + /* 0x1c */const char* mName; + /* 0x20 */u8 mResourceType; + /* 0x21 */u8 unk_33; + /* 0x22 */u16 mChecksum; + /* 0x24 */s32 mSize; + /* 0x28 */mDoDvdThd_callback_c* mAsyncLoadCallback; static u32 sAllocBytes; static JKRArchive* sArchive; diff --git a/include/d/map/d_map_path.h b/include/d/map/d_map_path.h index e1efd518f8..6aadaabc0c 100644 --- a/include/d/map/d_map_path.h +++ b/include/d/map/d_map_path.h @@ -7,11 +7,11 @@ class dDrawPath_c : public dDlst_base_c { public: struct line_class { - /*0x0*/ u8 unk0; - /*0x1*/ u8 unk1; - /*0x2*/ u8 unk2; - /*0x3*/ u8 unk3; - /*0x4*/ u16* unk4; + /* 0x00 */ u8 unk0; + /* 0x01 */ u8 unk1; + /* 0x02 */ u8 unk2; + /* 0x03 */ u8 unk3; + /* 0x04 */ u16* unk4; }; struct poly_class {}; diff --git a/include/d/map/d_map_path_dmap.h b/include/d/map/d_map_path_dmap.h index d556a2f672..b80b343860 100644 --- a/include/d/map/d_map_path_dmap.h +++ b/include/d/map/d_map_path_dmap.h @@ -78,7 +78,7 @@ public: /* 8003FF14 */ virtual void preDrawPath(); /* 8003FFC4 */ virtual void postDrawPath(); /* 800402C0 */ virtual void isDrawPath(); - /* 8003FE4C */ virtual void getBackColor() const; + /* 8003FE4C */ virtual GXColor* getBackColor() const; /* 800402E0 */ virtual bool getFirstDrawLayerNo(); /* 800402E8 */ virtual void getNextDrawLayerNo(int); /* 800409E0 */ virtual void isDrawIconSingle(dTres_c::data_s const*, int, int, bool, bool, diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index a4ae041f7e..8c505b9a12 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -669,7 +669,7 @@ extern "C" void ModuleUnresolved() { OSReport_Error("Address: Back Chain LR Save\n"); u32 i = 0; u32* stackPtr = (u32*)OSGetStackPointer(); - while(stackPtr!=NULL&&(u32)stackPtr!=0xFFFFFFFF&&i++<0x10) { + while((stackPtr != NULL) && ((u32)stackPtr != 0xFFFFFFFF) && (i++ < 0x10)) { OSReport_Error("0x%08x: 0x%08x 0x%08x\n",stackPtr,*stackPtr,*(stackPtr+1)); stackPtr = (u32*)*stackPtr; } diff --git a/src/d/map/d_map_path_dmap.cpp b/src/d/map/d_map_path_dmap.cpp index 9ff7bf674f..45e5aa933b 100644 --- a/src/d/map/d_map_path_dmap.cpp +++ b/src/d/map/d_map_path_dmap.cpp @@ -635,7 +635,7 @@ SECTION_SDATA2 static u8 l_mapBaseColor[4] = { #pragma push #pragma optimization_level 0 #pragma optimizewithasm off -asm void renderingDAmap_c::getBackColor() const { +asm GXColor* renderingDAmap_c::getBackColor() const { nofralloc #include "asm/d/map/d_map_path_dmap/getBackColor__16renderingDAmap_cCFv.s" }