1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin OS relocatable module demo
3   File:     b.cpp
4 
5   Copyright 2000-2002 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   $Log: b.cpp,v $
14   Revision 1.2  02/20/2006 04:13:12  mitu
15   changed include path from dolphin/ to revolution/.
16 
17   Revision 1.1  01/26/2006 08:01:00  hiratsu
18   Relocatable module demo.
19 
20 
21     3     8/23/02 17:43 Shiki
22     Added call to InlineFunc().
23 
24     2     01/04/02 13:43:00 Shiki
25     Added _unresolved() and IsBThere().
26 
27     1     10/31/00 3:50p Shiki
28     Modified from .c version.
29 
30     1     4/14/00 11:37p Shiki
31     Initial check-in.
32   $NoKeywords: $
33  *---------------------------------------------------------------------------*/
34 
35 #include <revolution/os.h>
36 #include "inline.h"
37 #include "b.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 typedef void (*voidfunctionptr) (void); /* ptr to function returning void */
44 __declspec(section ".init") extern voidfunctionptr _ctors[];
45 __declspec(section ".init") extern voidfunctionptr _dtors[];
46 
47 void _prolog(void);
48 void _epilog(void);
49 void _unresolved(void);
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
_prolog(void)55 void _prolog(void)
56 {
57     voidfunctionptr *constructor;
58 
59     /*
60      *  call static initializers
61      */
62     for (constructor = _ctors; *constructor; constructor++) {
63         (*constructor)();
64     }
65     MainB();
66 }
67 
_epilog(void)68 void _epilog(void)
69 {
70     voidfunctionptr *destructor;
71 
72     /*
73      *  call destructors
74      */
75     for (destructor = _dtors; *destructor; destructor++) {
76         (*destructor)();
77     }
78 }
79 
_unresolved(void)80 void _unresolved(void)
81 {
82     u32     i;
83     u32*    p;
84 
85     OSReport("\nError: B called an unlinked function.\n");
86     OSReport("Address:      Back Chain    LR Save\n");
87     for (i = 0, p = (u32*) OSGetStackPointer(); // get current sp
88          p && (u32) p != 0xffffffff && i++ < 16;
89          p = (u32*) *p)                         // get caller sp
90     {
91         OSReport("0x%08x:   0x%08x    0x%08x\n", p, p[0], p[1]);
92     }
93     OSReport("\n");
94 }
95 
96 int B::count;
97 
98 B StaticB01;
99 B StaticB02;
100 
MainB(void)101 void MainB(void)
102 {
103     OSReport("Hello, I'm MainB()!\n");
104 
105     // Generate weak symbol 'InlineFunc'
106     InlineFunc(5, 6);
107 
108     B b;
109     IsAThere();
110 }
111 
IsBThere(void)112 void IsBThere(void)
113 {
114     OSReport("Yes, I'm B.\n");
115 }
116