1 /*---------------------------------------------------------------------------*
2   Project:  rsodemo
3   File:     g.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 // use_lmw_stmw is turned ON tentatively
17 //#pragma use_lmw_stmw on
18 
19 //
20 #include <revolution.h>
21 #include "h.h"
22 #include "g.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef void (*voidfunctionptr) (void); /* ptr to function returning void */
29 __declspec(section ".init") extern voidfunctionptr _ctors[];
30 __declspec(section ".init") extern voidfunctionptr _dtors[];
31 
32 void _prolog(void);
33 void _epilog(void);
34 void _unresolved(void);
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
_prolog(void)40 void _prolog(void)
41 {
42     voidfunctionptr *constructor;
43 
44     /*
45      *  call static initializers
46      */
47     //
48     for (constructor = _ctors; *constructor; constructor++) {
49         (*constructor)();
50     }
51 }
52 
_epilog(void)53 void _epilog(void)
54 {
55     voidfunctionptr *destructor;
56 
57     /*
58      *  call destructors
59      */
60     for (destructor = _dtors; *destructor; destructor++) {
61         (*destructor)();
62     }
63 }
64 
_unresolved(void)65 void _unresolved(void)
66 {
67     u32     i;
68     u32*    p;
69 
70     OSReport("\nError: G called an unlinked function.\n");
71     OSReport("Address:      Back Chain    LR Save\n");
72     for (i = 0, p = (u32*) OSGetStackPointer(); // get current sp
73          p && (u32) p != 0xffffffff && i++ < 16;
74          p = (u32*) *p)                         // get caller sp
75     {
76         OSReport("0x%08x:   0x%08x    0x%08x\n", p, p[0], p[1]);
77     }
78     OSReport("\n");
79 }
80 
81 
MainG(void)82 void MainG(void)
83 {
84     OSReport("Hello, I'm MainG()!\n");
85     //
86     MainH();
87     //
88     IsHThere();
89     //
90     OSReport("Bye, I'm MainG()!\n");
91 }
92 
93 //
IsGThere(void)94 void IsGThere(void)
95 {
96     OSReport("Yes, I'm G.\n");
97 }
98 
99 //
IsGThere2(void)100 void IsGThere2(void)
101 {
102     OSReport("Yes, I'm G 2.\n");
103 }
104 //
IsGThere3(void)105 void IsGThere3(void)
106 {
107     OSReport("Yes, I'm G 3.\n");
108 }
109 
110