1 /*---------------------------------------------------------------------------*
2 Project: rsodemo
3 File: d.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 $NoKeywords: $
14 *---------------------------------------------------------------------------*/
15
16 #include <revolution.h>
17
18 #define DLL_EXPORT extern
19 #define DLL_SYMBOL(s) s
20
21 #include "d.h"
22
23 #undef DLL_EXPORT
24 #undef DLL_SYMBOL
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 typedef void (*voidfunctionptr) (void); /* ptr to function returning void */
31 __declspec(section ".init") extern voidfunctionptr _ctors[];
32 __declspec(section ".init") extern voidfunctionptr _dtors[];
33
34 void _prolog(void);
35 void _epilog(void);
36 void _unresolved(void);
37
38 int g_intD = 5;
39 #ifdef __cplusplus
40 }
41 #endif
42
_prolog(void)43 void _prolog(void)
44 {
45 voidfunctionptr *constructor;
46
47 /*
48 * call static initializers
49 */
50 //
51 for (constructor = _ctors; *constructor; constructor++) {
52 (*constructor)();
53 }
54 }
55
_epilog(void)56 void _epilog(void)
57 {
58 voidfunctionptr *destructor;
59
60 /*
61 * call destructors
62 */
63 for (destructor = _dtors; *destructor; destructor++) {
64 (*destructor)();
65 }
66 }
67
_unresolved(void)68 void _unresolved(void)
69 {
70 u32 i;
71 u32* p;
72
73 OSReport("\nError: D called an unlinked function.\n");
74 OSReport("Address: Back Chain LR Save\n");
75 for (i = 0, p = (u32*) OSGetStackPointer(); // get current sp
76 p && (u32) p != 0xffffffff && i++ < 16;
77 p = (u32*) *p) // get caller sp
78 {
79 OSReport("0x%08x: 0x%08x 0x%08x\n", p, p[0], p[1]);
80 }
81 OSReport("\n");
82 }
83
84 //
FuncD_1(int a)85 int FuncD_1(int a)
86 {
87 OSReport("FuncD_1 Call a = %d\n",a);
88 return a;
89 }
90
91 //
FuncD_2(int a,int b)92 void FuncD_2(int a,int b)
93 {
94 OSReport("FuncD_2 Call a = %d b = %d\n",a,b);
95 }
96