/*---------------------------------------------------------------------------* Project: rsodemo File: static.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. @version $Id: static.c,v 1.9 2006/09/11 06:35:22 srd_komatu Exp $ $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #ifdef _DEBUG #define MODULE_D "/dD.rso" #define STATIC_RSO "/staticD.sel" #else #define MODULE_D "/d.rso" #define STATIC_RSO "/static.sel" #endif #define DLL_EXPORT #define DLL_SYMBOL(s) (*s) #include "d.h" #undef DLL_EXPORT #undef DLL_SYMBOL // File created using makeinc.exe from d.h. // % makeinc.exe -o d.inc -l moduleD d.h #include "d.inc" // void _unresolved(); // extern void sub(void); /*---------------------------------------------------------------------------* Load *---------------------------------------------------------------------------*/ // Load and link the specified module static RSOObjectHeader* RsoLoad(char* moduleName) { DVDFileInfo fileInfo; s32 length; BOOL result; RSOObjectHeader* module; u8* bss; result = DVDOpen(moduleName, &fileInfo); if (!result) return NULL; length = (s32) OSRoundUp32B(DVDGetLength(&fileInfo)); module = OSAllocFromArenaLo((u32) length, 32); result = DVDRead(&fileInfo, module, length, 0); if (!result) return NULL; DVDClose(&fileInfo); if (module->bssSize > 0) { bss = OSAllocFromArenaLo(module->bssSize, 32); // alloc bss area } RSOLinkList(module, bss); return module; } // Load and link the static module static RSOObjectHeader* StaticRsoLoad(char* moduleName) { DVDFileInfo fileInfo; s32 length; BOOL result; RSOObjectHeader* module; result = DVDOpen(moduleName, &fileInfo); if (!result) return NULL; length = (s32) OSRoundUp32B(DVDGetLength(&fileInfo)); module = OSAllocFromArenaLo((u32) length, 32); result = DVDRead(&fileInfo, module, length, 0); if (!result) return NULL; DVDClose(&fileInfo); RSOListInit(module); return module; } // void _unresolved() { OSReport("_unresolved func.\n"); } //main int main(void) { RSOObjectHeader* staticRso; RSOObjectHeader* moduleD; // Generate weak symbol 'InlineFunc' DVDInit(); // Read data // Load static rso file OSReport("Loading static rso...\n"); staticRso = StaticRsoLoad(STATIC_RSO); if (!staticRso) return 1; // Load and link module D OSReport("Linking module D...\n"); moduleD = RsoLoad(MODULE_D); if (!moduleD) { return 1; } // Check whether all symbols are resolved if (RSOIsImportSymbolResolvedAll(moduleD)) { OSReport("moduleD's ImportSymbol is resolved all.\n"); } // OSReport("\nD prolog()\n"); ((u32 (*)(void)) moduleD->prolog)(); OSReport("\n-- ResolvedModule_d --\n"); // ResolvedModule_moduleD(moduleD); // FuncD_1(1); FuncD_2(2,3); OSReport("g_intD = %d\n",*g_intD); // sub(); // OSReport("\nD epilog()\n"); ((u32 (*)(void)) moduleD->epilog)(); RSOUnLinkList(moduleD); UnresolvedModule_moduleD(); // OSReport("\nRSOLink finish all!\n"); return 0; }