1 /*---------------------------------------------------------------------------*
2 Project: rsodemo
3 File: static.c
4
5 Copyright 2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 @version $Id: static.c,v 1.9 2006/09/11 06:35:22 srd_komatu Exp $
14
15 $NoKeywords: $
16 *---------------------------------------------------------------------------*/
17
18 #include <revolution.h>
19
20 #include <revolution/rso.h>
21 #include <revolution/RSOLink.h>
22
23
24 #ifdef _DEBUG
25 #define MODULE_D "/dD.rso"
26 #define STATIC_RSO "/staticD.sel"
27 #else
28 #define MODULE_D "/d.rso"
29 #define STATIC_RSO "/static.sel"
30 #endif
31
32 #define DLL_EXPORT
33 #define DLL_SYMBOL(s) (*s)
34
35 #include "d.h"
36
37 #undef DLL_EXPORT
38 #undef DLL_SYMBOL
39
40 // File created using makeinc.exe from d.h.
41 // % makeinc.exe -o d.inc -l moduleD d.h
42 #include "d.inc"
43
44 //
45 void _unresolved();
46 //
47 extern void sub(void);
48
49 /*---------------------------------------------------------------------------*
50 Load
51 *---------------------------------------------------------------------------*/
52 // Load and link the specified module
RsoLoad(char * moduleName)53 static RSOObjectHeader* RsoLoad(char* moduleName)
54 {
55 DVDFileInfo fileInfo;
56 s32 length;
57 BOOL result;
58 RSOObjectHeader* module;
59 u8* bss;
60
61 result = DVDOpen(moduleName, &fileInfo);
62 if (!result)
63 return NULL;
64 length = (s32) OSRoundUp32B(DVDGetLength(&fileInfo));
65 module = OSAllocFromArenaLo((u32) length, 32);
66 result = DVDRead(&fileInfo, module, length, 0);
67 if (!result)
68 return NULL;
69 DVDClose(&fileInfo);
70
71 if (module->bssSize > 0)
72 {
73 bss = OSAllocFromArenaLo(module->bssSize, 32); // alloc bss area
74 }
75 RSOLinkList(module, bss);
76
77 return module;
78 }
79
80 // Load and link the static module
StaticRsoLoad(char * moduleName)81 static RSOObjectHeader* StaticRsoLoad(char* moduleName)
82 {
83 DVDFileInfo fileInfo;
84 s32 length;
85 BOOL result;
86 RSOObjectHeader* module;
87
88 result = DVDOpen(moduleName, &fileInfo);
89 if (!result)
90 return NULL;
91 length = (s32) OSRoundUp32B(DVDGetLength(&fileInfo));
92 module = OSAllocFromArenaLo((u32) length, 32);
93 result = DVDRead(&fileInfo, module, length, 0);
94 if (!result)
95 return NULL;
96 DVDClose(&fileInfo);
97
98 RSOListInit(module);
99
100 return module;
101 }
102
103 //
_unresolved()104 void _unresolved()
105 {
106 OSReport("_unresolved func.\n");
107 }
108
109
110 //main
main(void)111 int main(void)
112 {
113 RSOObjectHeader* staticRso;
114 RSOObjectHeader* moduleD;
115
116 // Generate weak symbol 'InlineFunc'
117 DVDInit();
118
119 // Read data
120 // Load static rso file
121 OSReport("Loading static rso...\n");
122 staticRso = StaticRsoLoad(STATIC_RSO);
123 if (!staticRso)
124 return 1;
125
126 // Load and link module D
127 OSReport("Linking module D...\n");
128 moduleD = RsoLoad(MODULE_D);
129 if (!moduleD) {
130 return 1;
131 }
132
133 // Check whether all symbols are resolved
134 if (RSOIsImportSymbolResolvedAll(moduleD))
135 {
136 OSReport("moduleD's ImportSymbol is resolved all.\n");
137 }
138
139 //
140 OSReport("\nD prolog()\n");
141 ((u32 (*)(void)) moduleD->prolog)();
142
143 OSReport("\n-- ResolvedModule_d --\n");
144 //
145 ResolvedModule_moduleD(moduleD);
146 //
147 FuncD_1(1);
148 FuncD_2(2,3);
149 OSReport("g_intD = %d\n",*g_intD);
150 //
151 sub();
152
153 //
154 OSReport("\nD epilog()\n");
155 ((u32 (*)(void)) moduleD->epilog)();
156 RSOUnLinkList(moduleD);
157 UnresolvedModule_moduleD();
158 //
159 OSReport("\nRSOLink finish all!\n");
160
161 return 0;
162 }
163